Notepad sticky plugin - php

I have this following code to give a textarea to a front end user to use it as notes on a page to write things to remember. But this code saves only one sticky note that can be edited whenever the user wants. My questions is if there is a way to save the content somewhere and have a new one every time submit is pressed. or a add new sticky button.
require_once( plugin_dir_path( __FILE__ ) . 'wp-ajax.php' );
class notepad_stikey extends WP_Ajax {
var $user;
var $username;
function __construct() {
parent::__construct();
add_action('init', array( &$this, 'setup') );
}
function setup() {
$this->user = get_current_user_id();
$this->username = get_userdata( $this->user )->user_login;
$this->notes = get_user_meta( $this->user, 'notepad_stikey', true );
$this->ph = ' '; //placeholder
if (empty( $this->notes )) {
$this->notes = $this->ph;
}
add_action('wp_enqueue_scripts', array( &$this, 'scripts') );
}
function scripts() {
wp_enqueue_script( 'notepad_stikey', plugins_url( 'notepad_stikey.js', __FILE__ ), array( 'jquery' ) );
wp_localize_script( 'notepad_stikey', 'notepad_stikey', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
}
function an_change_notepad_stikey() {
$notes = trim( $_POST['notes'] );
//if notes is empty, delete
if ( empty($notes) ) {
if ( delete_user_meta( $this->user, 'notepad_stikey' ) )
die( 'notes deleted' );
}
//notes are the same, notes = placeholder, or resaving empty notes
if ( $notes == $this->notes || $notes == $this->ph || ( empty($notes) && $this->notes == $this->ph) )
die();
//update
if ( update_user_meta( $this->user, 'notepad_stikey', $notes ) )
die( 'updated' );
//hopefully, we don't get this far. if we do, something is wrong
die( 'uh oh. notes could not be saved' );
}
}
global $notepad_stikey;
$notepad_stikey = new notepad_stikey();
add_action( 'widgets_init', 'notepad_stikey_load' );
function notepad_stikey_load() {
register_widget( 'notepad_stikey_Widget' );
}
class notepad_stikey_Widget extends WP_Widget {
function notepad_stikey_Widget() {
$widget_ops = array('classname' => 'notepad_stikey', 'description' => __( 'notepad_stikey. Only one instance please. Else this will break.', 'notepad_stikey' ) );
$control_ops = array( 'id_base' => 'notepad_stikey' );
parent::WP_Widget( 'notepad_stikey', __( 'notepad_stikey', 'notepad_stikey' ), $widget_ops, $control_ops );
}
function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
echo $before_widget;
global $notepad_stikey;
$username = $notepad_stikey->username;
$notes = $notepad_stikey->notes;
//overwrite title
$instance['title'] = 'Notepad for '. $username;
echo $instance['hide_title'] ? '' : $before_title . $instance['title'] . $after_title;
echo "<div id='notepad_stikey' class='$username' style='border: 1px solid #eee; padding: 10px 15px;min-height: 100px;'>";
echo $notes;
echo '</div><span style="float:left;color:#008;" id="notepad_stikey_response"></span><small style="float:right;">click box above to edit</small>';
echo $after_widget;
} //end widget()
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = esc_attr( $new_instance['title'] );
$instance['hide_title'] = (bool) $new_instance['hide_title'] ? 1 : 0;
return $instance;
} //end update()
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'hide_title' => 0 ) );
extract( $instance );
?>
<p>
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hide_title'); ?>" name="<?php echo $this->get_field_name('hide_title'); ?>"<?php checked( $hide_title ); ?> />
<label for="<?php echo $this->get_field_id('hide_title'); ?>"><?php _e('Hide Title?', 'notepad_stikey' );?></label>
</p>
<?php
} //end form()
}
if (!class_exists('WP_Ajax')) {
class WP_Ajax {
function __construct( $ajax_prefix = 'a', $nopriv_prefix = 'n' ) {
$regex = "/^($ajax_prefix)?($nopriv_prefix)?_|^($nopriv_prefix)? ($ajax_prefix)?_/";
$methods = get_class_methods( $this );
foreach ( $methods as $method ) {
if ( preg_match( $regex, $method, $matches ) ) {
if ( count( $matches ) > 1 ) {
$action = preg_replace( $regex, '', $method );
if ( count( $matches ) == 3 ) {
add_action( "wp_ajax_$action", array( $this, $method ) );
add_action( "wp_ajax_nopriv_$action", array( $this, $method ) );
} else {
if ( $matches[1] == $ajax_prefix ) {
add_action( "wp_ajax_$action", array( $this, $method ) );
} else {
add_action( "wp_ajax_nopriv_$action", array( $this, $method ) );
}
}
}
}
}
}
}
}
jQuery(document).ready(function($) {
$('#notepad_stikey').click(function(e) {
tag = e.target.tagName;
if ( tag != 'TEXTAREA' && tag != 'INPUT' ) {
contents = $(this).html();
$(this).html( '<textarea rows="5" cols="50" style="display:block;width:98%;height:100px;">' + contents + '</textarea><input type="submit" class="save" style="position:relative;z-index:99" />' );
}
});
$('#notepad_stikey input.save').live( 'click', function() {
new_contents = $(this).siblings('textarea').val();
$('#notepad_stikey').html( new_contents );
change_notepad_stikey( new_contents );
return false;
});
function change_notepad_stikey( notes ) {
$('#notepad_stikey_response').text( '...' );
$.post(notepad_stikey.ajaxurl,
{
'action' : 'change_notepad_stikey',
'notes' : notes
}, function(response) {
//if (response != '') {
//alert( response );
$('#notepad_stikey_response').text( response );
//}
}, 'text' );
}
});

Related

How to add custom field for upload PDF files in Woocommerce product in admin

If I need to add simply text input, I can use a function like woocommerce_wp_text_input inside (for eg.) woocommerce_product_options_advanced. Then I use woocommerce_process_product_meta where I can use update_post_meta. This is clear and handy!
Now - I would like to add a custom field with the PDF upload option as I would like to attach PDF files to the product.
So is it possible to add such a field in a similar way?
Note: This is NOT a virtual download product. It's just simple product.
You can add a custom meta boxes to upload a pdf. You can retrieve it by using <?php get_post_meta( get_the_ID(), 'advanced_options_pdf', true ); ?> on the front end. Just paste the following on your function.php file.
class Advanced_Options {
private $config = '{"title":"Advanced Options","prefix":"advanced_options_","domain":"advanced-options","class_name":"Advanced_Options","post-type":["product"],"context":"normal","priority":"default","fields":[{"type":"media","label":"PDF","return":"url","id":"advanced_options_pdf"}]}';
public function __construct() {
$this->config = json_decode( $this->config, true );
add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
add_action( 'admin_head', [ $this, 'admin_head' ] );
add_action( 'save_post', [ $this, 'save_post' ] );
}
public function add_meta_boxes() {
foreach ( $this->config['post-type'] as $screen ) {
add_meta_box(
sanitize_title( $this->config['title'] ),
$this->config['title'],
[ $this, 'add_meta_box_callback' ],
$screen,
$this->config['context'],
$this->config['priority']
);
}
}
public function admin_enqueue_scripts() {
global $typenow;
if ( in_array( $typenow, $this->config['post-type'] ) ) {
wp_enqueue_media();
}
}
public function admin_head() {
global $typenow;
if ( in_array( $typenow, $this->config['post-type'] ) ) {
?><script>
jQuery.noConflict();
(function($) {
$(function() {
$('body').on('click', '.rwp-media-toggle', function(e) {
e.preventDefault();
let button = $(this);
let rwpMediaUploader = null;
rwpMediaUploader = wp.media({
title: button.data('modal-title'),
button: {
text: button.data('modal-button')
},
multiple: true
}).on('select', function() {
let attachment = rwpMediaUploader.state().get('selection').first().toJSON();
button.prev().val(attachment[button.data('return')]);
}).open();
});
});
})(jQuery);
</script><?php
}
}
public function save_post( $post_id ) {
foreach ( $this->config['fields'] as $field ) {
switch ( $field['type'] ) {
default:
if ( isset( $_POST[ $field['id'] ] ) ) {
$sanitized = sanitize_text_field( $_POST[ $field['id'] ] );
update_post_meta( $post_id, $field['id'], $sanitized );
}
}
}
}
public function add_meta_box_callback() {
$this->fields_table();
}
private function fields_table() {
?><table class="form-table" role="presentation">
<tbody><?php
foreach ( $this->config['fields'] as $field ) {
?><tr>
<th scope="row"><?php $this->label( $field ); ?></th>
<td><?php $this->field( $field ); ?></td>
</tr><?php
}
?></tbody>
</table><?php
}
private function label( $field ) {
switch ( $field['type'] ) {
case 'media':
printf(
'<label class="" for="%s_button">%s</label>',
$field['id'], $field['label']
);
break;
default:
printf(
'<label class="" for="%s">%s</label>',
$field['id'], $field['label']
);
}
}
private function field( $field ) {
switch ( $field['type'] ) {
case 'media':
$this->input( $field );
$this->media_button( $field );
break;
default:
$this->input( $field );
}
}
private function input( $field ) {
if ( $field['type'] === 'media' ) {
$field['type'] = 'text';
}
printf(
'<input class="regular-text %s" id="%s" name="%s" %s type="%s" value="%s">',
isset( $field['class'] ) ? $field['class'] : '',
$field['id'], $field['id'],
isset( $field['pattern'] ) ? "pattern='{$field['pattern']}'" : '',
$field['type'],
$this->value( $field )
);
}
private function media_button( $field ) {
printf(
' <button class="button rwp-media-toggle" data-modal-button="%s" data-modal-title="%s" data-return="%s" id="%s_button" name="%s_button" type="button">%s</button>',
isset( $field['modal-button'] ) ? $field['modal-button'] : __( 'Select this file', 'advanced-options' ),
isset( $field['modal-title'] ) ? $field['modal-title'] : __( 'Choose a file', 'advanced-options' ),
$field['return'],
$field['id'], $field['id'],
isset( $field['button-text'] ) ? $field['button-text'] : __( 'Upload', 'advanced-options' )
);
}
private function value( $field ) {
global $post;
if ( metadata_exists( 'post', $post->ID, $field['id'] ) ) {
$value = get_post_meta( $post->ID, $field['id'], true );
} else if ( isset( $field['default'] ) ) {
$value = $field['default'];
} else {
return '';
}
return str_replace( '\u0027', "'", $value );
}
}
new Advanced_Options;

How can I set the max button click limit?

I'm trying to set max limit.When there are any 2 button pressed there must be a action (the other buttons get disabled).
This is code of the post reaction in wordpress.
I tried first something like at this link
.http://jsfiddle.net/r6KYu/ But I could not.How can I counting the clicks and set max click limit ?
(function($) {
$(document).ready(function() {
$('#zuzu_viral_reactions li').click(function() {
var unreact = ($(this).hasClass("clicked") ? true : false);
var id = $(this).parent().data("postId") || $(this).parent().data("post-id");
var url = zvr_data.ajax_url;
var reaction = $(this).data().reaction;
$.post(url, { postid: id, action: 'zvr_react', reaction: reaction, unreact: unreact }, function(data) {
console.log("Ajax: " + data);
});
$(this).toggleClass("clicked");
var howMany = parseInt($(this).find('span').text());
if (howMany > 0) {
if ($(this).hasClass("clicked")) {
howMany += 1;
} else {
howMany -= 1;
}
} else {
howMany = 1;
}
$(this).find('span').text(howMany);
});
});
})(jQuery);
document.addEventListener("touchstart", function() {}, true);
if ('createTouch' in document) {
try {
var ignore = /:hover/;
for (var i = 0; i < document.styleSheets.length; i++) {
var sheet = document.styleSheets[i];
for (var j = sheet.cssRules.length - 1; j >= 0; j--) {
var rule = sheet.cssRules[j];
if (rule.type === CSSRule.STYLE_RULE && ignore.test(rule.selectorText)) {
sheet.deleteRule(j);
}
}
}
} catch (e) {}
}
Also php file here.
<?php
/*
Plugin Name: Zuzu Viral Reactions
Plugin URI: http://tiguandesign.com/
Description: Simple WordPress reactions plugin for viral stories.
Author: Tiguan
Author URI: http://tiguandesign.com/
Licence: GPLv2
Version: 1.0
Stable Tag: 1.0
*/
class Zuzu_Viral_React {
// $reactions = array( 'like','love', 'win', 'cute', 'lol', 'omg', 'wtf', 'fail' );
function __construct() {
$this->defaults = array(
'like' => "Like",
'love' => "LOVE",
'win' => "Win",
'cute' => "Cute",
'lol' => "LOL",
'omg' => "OMG",
'wtf' => "WTF",
'fail' => "Fail",
'boxtitle' => "Your Reaction"
);
add_action('the_content', array($this,'addContent'));
add_action('the_excerpt', array($this, 'zvrdisablePlugin'));
add_action('admin_menu', array($this, 'addMenu'));
add_action( 'admin_init', array($this, 'registerSettings'));
add_action( 'wp_ajax_zvr_react', array($this,'react'));
add_action( 'wp_ajax_nopriv_zvr_react', array($this,'react' ));
add_action('wp_enqueue_scripts', array($this,'addStylesAndScripts'));
add_action( 'load-post.php', array($this, 'initMetaBox'));
add_action( 'load-post-new.php', array($this, 'initMetaBox'));
add_shortcode( 'zvr_reactions', array($this, 'shortCode') );
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array($this, 'addSettingsLink' ));
}
function addSettingsLink ( $links ) {
$link = array('Settings');
return array_merge( $links, $link );
}
function initMetaBox() {
add_action( 'add_meta_boxes', array($this, 'addMetaBox'));
add_action( 'save_post', array($this, 'savePostMeta'), 10, 2 );
}
function savePostMeta($post_id, $post) {
if ( !isset( $_POST['zvr_enable_meta_nonce'] ) || !wp_verify_nonce( $_POST['zvr_enable_meta_nonce'], basename( __FILE__ ) ) )
return $post_id;
$post_type = get_post_type_object( $post->post_type );
if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
return $post_id;
$meta_value = ( isset( $_POST['zvr_enable'] ) ? sanitize_html_class( $_POST['zvr_enable'] ) : '' );
if (empty($meta_value)) {
$meta_value = "off";
}
update_post_meta( $post_id, 'zvr_enable', $meta_value );
}
function addMetaBox() {
add_meta_box('zvr-enable-on-post', 'Zuzu Viral Reactions', array($this, 'renderMetaBox'), 'post', 'normal', 'default');
}
function renderMetaBox() {
$options = get_option( 'zvr_settings' );
$enable = isset($options['zvr_auto_enable']) ? $options['zvr_auto_enable']: 'on';
$post_id = get_the_ID();
$meta_enable = get_post_meta( $post_id, 'zvr_enable', true );
if (!empty($meta_enable)) {
$enable = $meta_enable;
}
wp_nonce_field( basename( __FILE__ ), 'zvr_enable_meta_nonce' );
?>
<label><input type="checkbox" name="zvr_enable" id="zvr-enable" <?php checked($enable, 'on')?>>Enable reactions on this post</label>
<?php
}
function addMenu() {
add_options_page('Zuzu Reaction Settings', 'Zuzu Reaction', 'manage_options', 'zvr_options', array($this, 'renderOptionsPage'));
}
function registerSettings() {
register_setting('zvr_options', 'zvr_settings');
add_settings_section( 'zvr_enable', '', array($this, 'renderEnableGuide'), 'zvr_options' );
add_settings_field( 'zvr_options-auto-enable-on', 'Show buttons on posts', array($this, 'renderRadio'), 'zvr_options', 'zvr_enable', array('value' => 'on'));
add_settings_field( 'zvr_options-auto-enable-off', "Don't show buttons on posts", array($this, 'renderRadio'), 'zvr_options', 'zvr_enable', array('value' => 'off'));
add_settings_section( 'zvr_content', '', array($this, 'renderContent'), 'zvr_options' );
add_settings_section( 'zvr_share_translations', 'Reaction box title', array($this, 'renderReactionTranslations'), 'zvr_options');
add_settings_field( 'zvr_options-boxtitle', 'Your Reaction', array($this, 'renderField'), 'zvr_options', 'zvr_share_translations', array('label' => 'boxtitle'));
add_settings_section( 'zvr_translations', 'Reactions Text', array($this, 'renderReactionTranslations'), 'zvr_options' );
add_settings_field( 'zvr_options-like', 'Like', array($this, 'renderField'), 'zvr_options', 'zvr_translations', array('label' => 'like'));
add_settings_field( 'zvr_options-love', 'Love', array($this, 'renderField'), 'zvr_options', 'zvr_translations', array('label' => 'love'));
add_settings_field( 'zvr_options-win', 'Win', array($this, 'renderField'), 'zvr_options', 'zvr_translations', array('label' => 'win'));
add_settings_field( 'zvr_options-cute', 'Cute', array($this, 'renderField'), 'zvr_options', 'zvr_translations', array('label' => 'cute'));
add_settings_field( 'zvr_options-lol', 'LOL', array($this, 'renderField'), 'zvr_options', 'zvr_translations', array('label' => 'lol'));
add_settings_field( 'zvr_options-omg', 'OMG', array($this, 'renderField'), 'zvr_options', 'zvr_translations', array('label' => 'omg'));
add_settings_field( 'zvr_options-wtf', 'WTF', array($this, 'renderField'), 'zvr_options', 'zvr_translations', array('label' => 'wtf'));
add_settings_field( 'zvr_options-fail', 'Fail', array($this, 'renderField'), 'zvr_options', 'zvr_translations', array('label' => 'fail'));
}
function shortCode() {
$options = get_option('zvr_settings');
return $this->renderPlugin($options);
}
function renderField($args) {
$label = $args['label'];
$options = get_option('zvr_settings');
$value = isset($options['zvr_'.$label]) ? $options['zvr_'.$label]: $this->defaults[$label];
echo "<input type='text' name='zvr_settings[zvr_$label]' value='".esc_attr($value)."'>";
}
function renderContent() {
?>
<div style="border-top: 1px solid #bbb; width: 100%; padding: 30px 0; margin: 30px 0; border-bottom: 1px solid #bbb;">
<h3>Adding reactions manually (short code)</h3>
<ol>
<li>You can use shortcode <code>[zvr_reactions]</code> within post or page text.</li>
<li>You can add <code>if (function_exists('zvr_reactions')) { zvr_reactions() }</code> into your templates.</li>
</ol>
</div>
<?php
}
function zvrdisablePlugin($excerpt) {
$pattern = '/zvr.*/i';
return preg_replace($pattern, '', $excerpt);
}
function renderRadio($args) {
$options = get_option( 'zvr_settings' );
$value = $args['value'];
$set_value = isset($options['zvr_auto_enable']) ? $options['zvr_auto_enable']: 'on';
?>
<input type='radio' name='zvr_settings[zvr_auto_enable]' <?php checked( $set_value, $value ); ?> value='<?php echo $value ?>'>
<?php
}
function renderReactionTranslations() {
echo "";
}
function renderEnableGuide() {
?>
<?php
}
function renderOptionsPage() {
?>
<form action='options.php' method='post'>
<p><h1>Zuzu Viral Reaction Settings</h1></p><br />
<p>Select the default setting for Zuzu Viral Reaction visibility. You can override this setting for each post in the post editor.</p>
<?php
settings_fields( 'zvr_options' );
do_settings_sections( 'zvr_options' );
?>
<?php submit_button(); ?>
</form>
<?php
}
function addContent($content) {
$options = get_option('zvr_settings');
$show_on_every_post = isset($options['zvr_auto_enable']) ? $options['zvr_auto_enable'] : 'on';
$post_id = get_the_ID();
$enabled = get_post_meta( $post_id, 'zvr_enable', true );
if (!is_page() && ($enabled=="on" || (empty($enabled) && $show_on_every_post=='on'))) {
$plugin = $this->renderPlugin($options);
$content .= $plugin;
}
return $content;
}
function renderPlugin($options) {
$post_id = get_the_ID();
$post_url = get_permalink($post_id);
$label_like =isset($options['zvr_like']) ? $options['zvr_like']: $this->defaults['like'];
$label_love =isset($options['zvr_love']) ? $options['zvr_love']: $this->defaults['love'];
$label_win =isset($options['zvr_win']) ? $options['zvr_win']: $this->defaults['win'];
$label_cute =isset($options['zvr_cute']) ? $options['zvr_cute']: $this->defaults['cute'];
$label_lol =isset($options['zvr_lol']) ? $options['zvr_lol']: $this->defaults['lol'];
$label_omg =isset($options['zvr_omg']) ? $options['zvr_omg']: $this->defaults['omg'];
$label_wtf =isset($options['zvr_wtf']) ? $options['zvr_wtf']: $this->defaults['wtf'];
$label_fail =isset($options['zvr_fail']) ? $options['zvr_fail']: $this->defaults['fail'];
$label_boxtitle =isset($options['zvr_boxtitle']) ? $options['zvr_boxtitle']: $this->defaults['boxtitle'];
ob_start() ?>
<div id="zuzu_viral_reactions">
<span style="display:none">zvr</span>
<div class="zvr-reaction-title"><?php echo $label_boxtitle ?></div>
<ul data-post-id="<?php echo $post_id ?>">
<li class="animated" data-reaction="like" <?php echo $this->getClass("like", $post_id) ?> ><img class="animated" src="<?php echo trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/img/1f44d.svg' ?>" /><em><?php echo $label_like ?></em><span><?php echo $this->getAmount("like",$post_id) ?></span></li>
<li class="animated" data-reaction="love" <?php echo $this->getClass("love", $post_id) ?> ><img class="animated" src="<?php echo trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/img/1f60d.svg' ?>" /><em><?php echo $label_love ?></em><span><?php echo $this->getAmount("love",$post_id) ?></span></li>
<li class="animated" data-reaction="win" <?php echo $this->getClass("win", $post_id) ?> ><img class="animated" src="<?php echo trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/img/1f61c.svg' ?>" /><em><?php echo $label_win ?></em><span><?php echo $this->getAmount("win",$post_id) ?></span></li>
<li class="animated" data-reaction="cute" <?php echo $this->getClass("cute", $post_id) ?> ><img class="animated" src="<?php echo trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/img/1f917.svg' ?>" /><em><?php echo $label_cute ?></em><span><?php echo $this->getAmount("cute",$post_id) ?></span></li>
<li class="animated" data-reaction="lol" <?php echo $this->getClass("lol", $post_id) ?> ><img class="animated" src="<?php echo trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/img/1f632.svg' ?>" /><em><?php echo $label_lol ?></em><span><?php echo $this->getAmount("lol",$post_id) ?></span></li>
<li class="animated" data-reaction="omg" <?php echo $this->getClass("omg", $post_id) ?> ><img class="animated" src="<?php echo trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/img/1f631.svg' ?>" /><em><?php echo $label_omg ?></em><span><?php echo $this->getAmount("omg",$post_id) ?></span></li>
<li class="animated" data-reaction="wtf" <?php echo $this->getClass("wtf", $post_id) ?> ><img class="animated" src="<?php echo trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/img/1f914.svg' ?>" /><em><?php echo $label_wtf ?></em><span><?php echo $this->getAmount("wtf",$post_id) ?></span></li>
<li class="animated" data-reaction="fail" <?php echo $this->getClass("fail", $post_id) ?> ><img class="animated" src="<?php echo trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/img/1f915.svg' ?>" /><em><?php echo $label_fail ?></em><span><?php echo $this->getAmount("fail",$post_id) ?></span></li>
</ul>
<div style="clear: both;"></div>
</div>
<?php
$plugin = ob_get_contents();
ob_clean();
return $plugin;
}
function getClass($reaction, $post_id) {
$clicked = isset($_COOKIE["zvr_reacted_".$reaction."_".$post_id]);
return ($clicked ? 'class="clicked"':'');
}
function getAmount($reaction, $post_id) {
$meta_key = "zvr_reaction_".$reaction;
$amount = get_post_meta($post_id, $meta_key, true) ? get_post_meta($post_id, $meta_key, true) : 0;
return $amount;
}
function react() {
if (isset($_POST["postid"])) {
$post_id = $_POST["postid"];
$reaction = $_POST["reaction"];
$unreact = $_POST["unreact"];
}
$amount = $this->getAmount($reaction, $post_id);
if (isset($unreact) && $unreact === "true") {
unset($_COOKIE['zvr_reacted_'.$reaction.'_'.$post_id]);
setcookie('zvr_reacted_'.$reaction.'_'.$post_id, '', time() - 3600, "/");
$amount = (int) $amount - 1;
if ($amount >=0) {
echo "Amount: ".$amount." ";
update_post_meta($post_id, "zvr_reaction_".$reaction, $amount);
}
}
else {
setcookie('zvr_reacted_'.$reaction.'_'.$post_id, $reaction, time() + (86400 * 30), "/");
$amount = (int) $amount + 1;
if ($amount >=0) {
echo "Amount: ".$amount." ";
update_post_meta($post_id, "zvr_reaction_".$reaction, $amount);
}
}
return;
}
function addStylesAndScripts() {
wp_enqueue_style( 'zvr-font', 'https://fonts.googleapis.com/css?family=Open+Sans' );
wp_enqueue_style( 'zvr-style', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/css/zvr-styles.css', array(), "1.0.3" );
wp_enqueue_script( 'zvr-script', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/js/zvr-script.js', array( 'jquery' ), "1.0.3" );
$localize = array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
);
wp_localize_script( 'zvr-script', 'zvr_data', $localize );
}
}
function zvr_reactions() {
// Call from templates
// if (function_exists('zvr_reactions')) { zvr_reactions() }
$zvr = new Zuzu_Viral_React();
$options = get_option('zvr_settings');
echo $zvr->renderPlugin($options);
}
new Zuzu_Viral_React();
you can solve this by jquery and get max length event by the following code
<label for="name">Input 1: maxlength=10</label>
<input type="text" maxlength="10" id="input-1" value="Allen"/>
$("#input-1").maxlength();
// get maxlength and other event
$("input").bind("update.maxlength", function(event, element, lastLength, length, maxLength, left){
console.log(event, element, lastLength, length, maxLength, left);
});

get the modified date of post meta box

i'm searching for a way to display the modified date of a custom field / meta box. until now, i only know how to echo
the_modified_date('l, j.n.Y');
but this one only works with the entire post.
i'am using a meta_box for additional pdf files uploading, code:
<?php class PDF_Metabox_id1 {
function __construct() {
add_action( 'post_mime_types', array( $this, 'pdf_mime_type_id1' ) );
add_action( 'add_meta_boxes', array( $this, 'admin_scripts_id1' ), 5 );
add_action( 'add_meta_boxes', array( $this, 'metabox_add_id1' ) );
add_action( 'save_post', array( $this, 'pdf_save_postdata_id1') );
add_action( 'wp_ajax_refresh_pdf', array( $this, 'refresh_pdf_id1' ) ); }
function pdf_mime_type_id1() {
$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) );
return $post_mime_types;
}
function admin_scripts_id1() {
wp_register_script( 'pdf_metabox_js', get_stylesheet_directory_uri() . '/js/pdf_metabox.js' );
}
function metabox_add_id1() {
$post_types = array( 'myposttype','anotherposttype' );
$context = 'normal'; $priority = 'low';
foreach( $post_types as $post_type ) {
add_meta_box( 'pdf_metabox_id1', __( 'PDF Box 1', 'pdf_metabox_id1' ), array( $this, 'pdf_metabox_id1' ), $post_type, $context, $priority );
wp_enqueue_media();
wp_enqueue_script( 'pdf_metabox_js' );
}
}
function pdf_metabox_id1( $post ) {
$original_post = $post; echo $this->pdf_metabox_html_id1( $post->ID ); $post = $original_post;
}
function pdf_item_id1( $id ) {
if(!$id) return; $pdf_url = esc_url_raw(wp_get_attachment_url($id)); $pdf = $pdf_url; return $pdf;
}
function pdf_metabox_html_id1( $post_id ) {
$current_value = ''; $post_meta = get_post_custom($post_id);
if( isset($post_meta['pdf_id_id1'][0] ) ) $current_value = $post_meta['pdf_id_id1'][0];
$return = ''; wp_nonce_field( plugin_basename( __FILE__ ), 'pdf_noncename' );
$return .= '<p>';
$return .= '<a title="'.__( 'PDF', 'pdf_metabox_id1' ).'" class="button button-primary insert-pdf-button" id="insert_pdf_button_id1" href="#" style="float:left">'.__( 'Upload / editiere PDF', 'pdf_metabox_id1' ).'</a><span id="pdf_spinner_id1" class="spinner" style="float:left"></span></p>';
$return .= '<div style="clear:both"></div>';
$return .= '<input type="hidden" name="pdf_id_id1" id="pdf_id_id1" value="'.$current_value.'">';
$return .= '<div style="clear:both"></div>';
$return .= '<div id="pdf_wrapper_id1">';
$pdf = $this->pdf_item_id1( $current_value ); if( empty( $pdf ) ) {
$return .= '<p>Diesem Feld ist kein PDF hinterlegt.</p>'; } else {
$return .= '<br />URL des PDF:<br /> ';
$return .= $pdf; }
$return .= '</div>';
return $return;
}
function pdf_save_postdata_id1($post_id){
if ( isset($_POST['post_type']) && 'post' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_post', $post_id ) ) return; } if ( !isset( $_POST['pdf_noncename'] ) || ! wp_verify_nonce( $_POST['pdf_noncename'], plugin_basename( __FILE__ ) ) ) return;
if(isset($_POST['pdf_id_id1']) ): update_post_meta($post_id, 'pdf_id_id1', sanitize_text_field( $_POST['pdf_id_id1'] ) );
else: if (isset($post_id)) {
delete_post_meta($post_id, 'pdf_id_id1'); }
endif;
}
function refresh_pdf_id1() {
if(isset($_POST['id'])){
$item = $_POST['id'];
if($item != '' && $item !=0){
$pdf = $this->pdf_item_id1( $item );
$ret = array();
if( !empty( $pdf ) ) {$ret['success'] = true;
$ret['pdf'] = $pdf; } else {
$ret['success'] = false; } } else {
$ret['success'] = true; $ret['pdf'] = ''; } } else {
$ret['success'] = false; } echo json_encode( $ret ); die();
}
}
$PDF_Metabox_id1 = new PDF_Metabox_id1();
in my theme i'm using:
$post_meta_id1 = get_post_custom(get_the_ID());
$pdf_id_id1 = $post_meta_id1['pdf_id_id1'][0];
$pdf_url_id1 = wp_get_attachment_url($pdf_id_id1);
...and now i want to display the modified date of this field. any ideas?
As per the comment
how do i save the modified date of this custom field and how do i get it?
You may need to check every custom field in loop one by one if any of custom fields doesnot matched with the current post data then save a new custom field to post_meta. then retrieve in your template/page.
Just an idea:
<?php
function attributes_save_postdata( $post_id ) {
$postcustom = get_post_custom( $post_id );
$is_modified = false;
foreach ( $postcustom as $key => $val ) {
var_dump( $val );
// check your post custom values and
$getpostmeta = get_post_meta( $post_id, 'your_meta_key', true );
// if database value ($getpostmeta) not equal to current post value($_POST['your_meta_key'])
if ( $getpostmeta != $_POST['your_meta_key'] ) {
$is_modified = true;
// if found any custom field updated set $modified = true
}
}
// if found any custom field updated add or update new date and time
if ( $is_modified ) {
$date = date( 'Y-m-d h:i:s' ); // example : 2016-02-02 12:00:00 current date and time
update_post_meta( $post_id, '_modifieddate', $date );
}
}
add_action( 'save_post', 'attributes_save_postdata' );
Then in your theme. get modified date.
$post_id = get_the_ID();
$getpostmeta = get_post_meta( $post_id, 'your_meta_key', true );
I think that wordpress built-in function about this would help you out even for the custom fields.
<p>Last modified: <?php the_modified_time(); ?></p>

wp_list_table bulk actions not working properly

I've been working with the wp_list_table class and creating my custom theme pages with add/edit/delete features on the row options. The problem i am having is with the bulk actions. The row actions are working just fine. Now here is where it gets weird.
If I am looking at my table in admin and I select the checkbox on a few rows, switch to bulk-delete action, then hit apply, I will not get any post data for those checkboxes. What I mean by that is the checkboxes are named as an array bulk-delete[] in html. and if I do a print_r($_request); the bulk-delete key is no present.
Now when I select a few checkboxes, and this time NOT switch to bulk-delete I just leave it saying "Bulk Actions", then hit apply, I will get the bulk-delete array but all the keys are empty.
For me totally freaking bazaar. But I am sure there is something really stupid that I missed. So here is the class in it's entirety. Please let me know what I missed.
[a secondary issue - I'd like to also show an "Country has been added" success message. Could you guys point me in the right direction for knowledge to read up on that]
Thanks in advance.
<?php
class country_class {
var $page_name = "lp-manage-countries";
public function __construct(){
//make sure the wp_list_table class has been loaded
if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
add_action( 'admin_post_add_country', array( $this, 'lp_admin_add_country') );
add_filter('set-screen-option', array( $this, 'lp_save_screen_options') , 10, 3);
//add_action( 'admin_post_bulk_action', array( $this, 'process_bulk_action') );
}
/**
* Sets the screen options up for table paging
*/
public function lp_screen_options() {
$lp_manage_countries_page = "toplevel_page_" . $this->page_name;
$screen = get_current_screen();
// get out of here if we are not on our settings page
if(!is_object($screen) || $screen->id != $lp_manage_countries_page)
return;
$args = array(
'label' => __('Countries per page'),
'default' => 25,
'option' => 'countries_per_page'
);
add_screen_option( 'per_page', $args );
}
/**
* Saves the screen option to the object class
*/
function lp_save_screen_options($status, $option, $value) {
if ( 'countries_per_page' == $option ) return $value;
return $status;
}
/**
* Installs the page and screen options
*/
public function install_countries_page(){
//Add the screen options first
add_action("load-toplevel_page_" . $this->page_name, array( $this, "lp_screen_options") );
add_menu_page('LP Countries', 'LP Countries', 'manage_options', 'lp-manage-countries', array($this, 'show_country_page'));
}
public function lp_admin_add_country(){
global $wpdb;
if( isset( $_REQUEST['country_name'] ) and !empty( $_REQUEST['country_name'] )){
$result = $wpdb->insert(
'countries',
array(
'name' => $_REQUEST['country_name']
)
);
if( $result !== false ){
wp_redirect(admin_url("admin.php?page=" . $this->page_name) );
exit;
}
}
}
/**
* Displays the page data
*/
public function show_country_page(){
if( isset( $_GET['action']) && ( $_REQUEST['action'] == "add" || $_REQUEST['action'] == "edit" )){
echo "<div class='wrap'>
<h1>Add Country</h1>
<form action='" . admin_url("admin-post.php", "http") . "' method='post'>
<input type=\"hidden\" name=\"action\" value=\"add_country\">
<table class=\"form-table\">
<tbody>
<tr>
<th scope=\"row\"><label for='country_name' xmlns=\"http://www.w3.org/1999/html\">Country Name:</label></th>
<td><input id='country_name' required class='regular-text type='text' value='' name='country_name'></input></td>
</tr>
</tbody>
</table>
<p class='submit'>
<input id='submit' class='button button-primary' type='submit' value='Save Country' name='submit'></input>
</p>
</form>";
} else {
echo "<div class=\"wrap\">
<h1>Manage Countries<a class=\"page-title-action\" href=\"".admin_url("admin.php?page=".$this->page_name."&action=add")."\">Add New</a></h1>
<form method='post'>";
//echo "<input type=\"hidden\" name=\"action\" value=\"bulk_action\">";
//Prepare Table of elements
$categories_list_table = new category_list_table();
$categories_list_table->prepare_items();
//Table of elements
$categories_list_table->display();
echo "</form>";
}
}
/**
* Creates the database for this page
*/
public function create_countries_table(){
global $wpdb;
$charset = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS `countries` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`parent_id` int(11) DEFAULT NULL,
`image` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) $charset; ";
$wpdb->query( $sql );
}
/**
* removes the page database when uninstalled
*/
public function drop_countries_table(){
global $wpdb;
$sql = "DROP TABLE `countries`;";
$wpdb->query($sql);
}
}
class category_list_table extends WP_List_Table {
public function __construct(){
parent::__construct( array(
'singular' => 'Country',
'plural' => 'Countries',
'ajax' => false)
);
}
public function get_columns(){
return $columns = array(
'cb' => '<input name="bulk-delete[]" type="checkbox" />',
'name' => __('Name'),
'parent_id' => __('Parent ID'),
'image' => __('Image')
);
}
function column_name($item) {
// create a nonce
$delete_nonce = wp_create_nonce( 'lp_delete_country' );
$edit_nonce = wp_create_nonce( 'lp_delete_country' );
$actions = array(
'edit' => sprintf('Edit', $_REQUEST['page'], 'edit', $item['id'], $edit_nonce),
'delete' => sprintf('Delete', $_REQUEST['page'], 'delete', $item['id'], $delete_nonce),
);
return sprintf('%1$s %2$s', $item['name'], $this->row_actions($actions) );
}
public function get_sortable_columns(){
return $sortable = array(
'id' => array('id',false),
'name' => array('name',false),
'parent_id' => array('parent_id', false),
'image' => array('image', false)
);
}
public function get_hidden_columns( ){
$screen = get_current_screen();
if ( is_string( $screen ) )
$screen = convert_to_screen( $screen );
return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' );
}
public function prepare_items(){
global $wpdb, $_wp_column_headers;
$screen = get_current_screen();
/** Process bulk action */
$this->process_bulk_action();
/* Prepare the query */
$query = "SELECT * FROM `countries`";
/* Order Parameters */
$orderby = !empty($_GET["orderby"]) ? mysql_real_escape_string($_GET["orderby"]) : 'ASC';
$order = !empty($_GET["order"]) ? mysql_real_escape_string($_GET["order"]) : '';
if(!empty($orderby) & !empty($order)){ $query.=' ORDER BY '.$orderby.' '.$order; }
/* Pagination Params */
//Number of elements in your table?
$totalitems = $wpdb->query($query); //return the total number of affected rows
//How many to display per page?
$perpage = get_user_meta( get_current_user_id() , 'countries_per_page', true);
if( empty($perpage)){
$perpage = 25;
}
//Which page is this?
$paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : '';
//Page Number
if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }
//How many pages do we have in total?
$totalpages = ceil($totalitems/$perpage);
//adjust the query to take pagination into account
if(!empty($paged) && !empty($perpage)){
$offset=($paged-1)*$perpage;
$query.=' LIMIT '.(int)$offset.','.(int)$perpage;
}
/* Register pagination */
$this->set_pagination_args( array(
"total_items" => $totalitems,
"total_pages" => $totalpages,
"per_page" => $perpage
)
);
/* register the columns */
$columns = $this->get_columns();
$_wp_column_headers[$screen->id]=$columns;
/* Get the items */
$this->items = $wpdb->get_results($query, 'ARRAY_A');
$hidden_columns = $this->get_hidden_columns();
$sortable_columns = $this->get_sortable_columns();
parent::get_column_info();
$this->_column_headers = array( $columns, $hidden_columns, $sortable_columns);
}
public function column_default($item, $column_name) {
//return $item[$column_name];
switch ( $column_name ) {
case 'cb':
case 'name':
case 'parent_id':
case 'image':
return $item[ $column_name ];
default:
return $item[ $column_name ];
}
}
function no_items() {
_e( 'No Countries Found.' );
}
function column_cb( $item ) {
return sprintf(
'<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['ID']
);
}
public function get_bulk_actions() {
$actions = [
'bulk-delete' => 'Delete'
];
return $actions;
}
public function process_bulk_action() {
$action = $this->current_action();
echo "action is [" . $action . "]";
if( !empty( $action ) ){
switch ($action){
case 'delete':
// In our file that handles the request, verify the nonce.
$nonce = esc_attr( $_REQUEST['_wpnonce'] );
if ( ! wp_verify_nonce( $nonce, 'lp_delete_country' ) ) {
die( 'Go get a life script kiddies' );
} else {
echo " running delete";
self::delete_country( absint( $_GET['country'] ) );
wp_redirect( esc_url( add_query_arg() ) );
exit;
}
case 'edit':
echo "we should be editing";
case 'bulk-delete':
// If the delete bulk action is triggered
echo "we triggered a bulk delete";
echo "<pre>";
print_r( $_REQUEST );
echo "</pre>";
if ( !empty( $_POST['bulk-delete'] ) ) {
$delete_ids = esc_sql( $_POST['bulk-delete'] );
// loop over the array of record IDs and delete them
foreach ( $delete_ids as $id ) {
$this->delete_country( $id );
}
wp_redirect( esc_url( add_query_arg() ) );
exit;
} else {
echo "Fucking empty";
}
default:
echo "<pre>";
print_r( $_REQUEST );
echo "</pre>";
//quietly exit;
}
} else {
echo "<pre>";
print_r( $_REQUEST );
echo "</pre>";
}
}
function delete_country( $id ) {
global $wpdb;
$wpdb->delete(
"countries",
[ 'id' => $id ]
);
}
}

VIM syntax highlighting 'buggy'?

I switched from intelliJ to VIM a few days ago and I have a few problems with my syntax highlighting. I'm mainly working with php and html and in some files some of the ; are marked with a red background (maybe meaning there is an error in my syntax?). This most likely happens when the ; is followed by a comment //. I'm pretty sure there are no errors...
Also a few files do not provide php syntax highlight at all after a blockcomment /**/ until the php tag ?> gets closed.
Any idea what im missing? Also I'd appreciate suggestions on alternatives for syntax highlighting. It's hard to find useful stuff for webdev since VIM isn't that popular in that sector I guess.
Here my current vim settings:
https://github.com/raQai/.vim
I'd appreciate your help
Edit:
Here is the code thats causing the problems:
<?php namespace KF\LINKS;
defined ( 'ABSPATH' ) or die ( 'nope!' );
/**
* Plugin Name: KF Attachment Links
* Description: Adding attatchemts to post, pages and teams (Kong Foos Team Manager)
* Version: 1.0.0
* Author: Patrick Bogdan
* Text Domain: kfl
* License: GPL2
*
* Copyright 2015 Patrick Bogdan
* TODO: Settings for post_types with checkboxes
*/
new KFLinksMetaBox();
class KFLinksMetaBox {
const kfl_key = 'kf-links-information';
function __construct() {
if (is_admin ()) {
add_action ( 'admin_enqueue_scripts', wp_enqueue_style ( 'kfl-admin-style', plugins_url( 'includes/css/admin-styles.css', plugin_basename( __FILE__ ) ) ) );
add_action ( 'admin_enqueue_scripts', wp_enqueue_script ( 'kfl-admin-js', plugins_url( 'includes/js/kfl-admin-scripts.js', plugin_basename( __FILE__ ) ) ) );
add_action ( 'add_meta_boxes', array( &$this, 'kf_links_meta_box_add' ) );
add_action ( 'save_post', array( &$this, 'kf_links_meta_box_save' ) );
}
register_deactivation_hook( __FILE__, array( &$this, 'kf_links_uninstall' ) );
add_filter( 'the_content', array( $this, 'kf_links_add_to_posts' ) );
}
function kf_links_uninstall() {
delete_post_meta_by_key( self::kfl_key );
}
function kf_links_add_to_posts( $content ) {
$links = $this->kf_links_explode( get_post_meta( get_the_ID(), self::kfl_key, true ) );
if ( $links['is_active'] == '1' && count($links['items']) > 0 ) {
$links_html = '';
if ( !empty($links['title']) ) {
$links_html .= '<strong>' . $links['title'] . '</strong>';
}
foreach ( $links['items'] as $link ) {
if ( !empty( $link['name'] ) && !empty( $link['url'] ) ) {
$links_html .= '<br />» ' . $link['name'] . '';
}
}
if ( !empty( $links_html ) ) {
$content .= '<p class="attachment-links">' . $links_html . '</p>';
}
}
return $content;
}
function kf_links_meta_box_add() {
$screens = array( 'post', 'page', 'teams' );
foreach( $screens as $screen)
{
add_meta_box (
'kf_links_meta_box', // id
'Linksammlung', // title
array( &$this, 'kf_links_meta_box_display' ), // callback
$screen, // post_type
'normal', // context
'high' // priority
);
}
}
function kf_links_meta_box_display( $post ) {
wp_nonce_field( 'kf_links_meta_box', 'kf_links_meta_box_nonce' );
$this->kf_links_meta_box_display_html( $post );
}
function kf_links_meta_box_display_html( $post )
{
$post_string = get_post_meta( $post->ID, self::kfl_key, true );
$links = $this->kf_links_explode( $post_string );
?>
<div class="kf-meta-box-checkbox">
<input onClick="kfl_checkboxDivDisplay( this.id, 'kf-links' ); kfl_creaetLinksString();" <?php if ( $links['is_active'] ) echo 'checked '; ?>type="checkbox" id="kf-links-checkbox" value="1" />
<label id="kf-links-checkbox-label" for="kf-links-checkbox">Linksammlung aktivieren</label>
</div>
<div id="kf-links" <?php if ( !$links['is_active'] ) echo 'style="display:none" '; ?>>
<div class="kf-meta-box-full">
<label for="kf-links-title">Titel der Linksammlung</label>
<input onChange="kfl_creaetLinksString()" id="kf-links-title" value="<?php echo $links['title']; ?>" placeholder="Titel der Linksammlung" />
</div>
<div class="kf-links-header">
<label>Name</label>
<label>URL</label>
</div>
<div id="kf-links-items">
<?php
foreach ( $links['items'] as $ID => $arr ) {
$this->kf_links_item_display_html( $ID, $arr, $links['is_active'] );
}
if ( count( $links['items'] ) < 1 ) {
$this->kf_links_item_display_html( 0, array( 'name' => '', 'url' => '' ), false );
}
?>
</div>
<h4>+ Weiteren Link hinzufügen</h4>
<input type="hidden" id="kf-links-counter" value="<?php echo ( ( count($links['items']) < 1 ) ? 1 : count($links['items']) ); ?>" />
<input type="hidden" name="<?php echo self::kfl_key; ?>" id="<?php echo self::kfl_key; ?>" value="<?php echo $post_string; ?>" />
</div>
<?php
}
function kf_links_item_display_html( $ID, $arr, $is_active )
{
?>
<div id="kf-links-item[<?php echo $ID; ?>]" class="kf-links-item">
<input onChange="kfl_creaetLinksString();" value="<?php echo $arr['name']; ?>" <?php if ( $is_active ) echo 'required '; ?>placeholder="Name" />
<input onChange="kfl_creaetLinksString();" value="<?php echo $arr['url']; ?>" <?php if ( $is_active ) echo 'required '; ?>placeholder="http://..." />
<input onClick="kfl_deleteLink( 'kf-links-item[<?php echo $ID; ?>]' ); kfl_creaetLinksString();" value="&cross;" type="button" class="button button-small button-primary" />
</div>
<?php
}
function kf_links_meta_box_save($post_id)
{
if ( !isset( $_POST['kf_links_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['kf_links_meta_box_nonce'], 'kf_links_meta_box' )) {
return $post_id;
}
$post_type = get_post_type_object( $_POST['post_type'] );
if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) {
return;
}
$new_meta_value = ( isset( $_POST[self::kfl_key] ) ? $_POST[self::kfl_key] : '');
update_post_meta( $post_id, self::kfl_key, $new_meta_value );
}
function kf_links_explode( $string )
{
if ( empty($string) || !is_string($string) ) {
$links['is_active'] = 0;
return $links;
}
$explode = explode( ';$;', $string );
$links['is_active'] = ( isset( $explode[0] ) ? $explode[0] : 0 );
$links['title'] = ( isset( $explode[1] ) ? $explode[1] : '' );
$links['items'] = array();
for ( $i = 2; $i < count( $explode ); $i++ ) {
$explode2 = explode( ';?;', $explode[$i] );
$link = array(
'name' => $explode2[0],
'url' => $explode2[1]
);
$links['items'][] = $link;
}
return $links;
}
}
And here some screenshots:
https://www.dropbox.com/sh/jj3gluc7ok001hu/AABq_hRiKcbbDo1E0rKpP2Jxa?dl=0
Try :syntax sync fromstart.
If that works, add autocmd BufEnter * :syntax sync fromstart to your .vimrc
Explanation: if the syntax highlighter does not process every line of code from the beginning, it may not receive a critical piece of information to understand what type of code it's processing. E.g., if you're in an HTML file and deep within a script tag, the syntax highlighter may not look back far enough to see the script tag and therefore processes your JS code as HTML.

Categories