How To Show Chechbox Result From Metabox To Single Post Wordpress? - php

Ask to everyone, i have problem. Here i try to use multiple chechbox to my custom post metabox.
<?php
function prodetail() {
add_meta_box('pro_metabox', 'Detail Property', 'pro_metabox', 'property', 'normal', 'default');
}
function pro_metabox() {
global $post;
echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
$postmeta = maybe_unserialize( get_post_meta( $post->ID, 'elements', true ) );
$elements = array(
'pool' => 'Pool',
'garage' => 'Garage',
'balcon' => 'Balcon',
'yard' => 'Yard',
'internet' => 'Internet'
);
foreach ( $elements as $id => $element) {
if ( is_array( $postmeta ) && in_array( $id, $postmeta ) ) {
$checked = 'checked="checked"';
} else {
$checked = null;
}
?>
<div class="pro-inn">
<div class="procols">
<div class="pro-inn">
<input type="checkbox" name="multval[]" value="<?php echo $id; ?>" <?php echo $checked; ?> />
<?php echo $element;?>
</div>
</div>
</div>
<?php
}
}
function pro_meta($post_id, $post) {
if ( !wp_verify_nonce( $_POST['eventmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
if ( ! empty( $_POST['multval'] ) ) {
update_post_meta( $post_id, 'elements', $_POST['multval'] );
} else {
delete_post_meta( $post_id, 'elements' );
}
}
add_action('save_post', 'pro_meta', 1, 2);
?>
help me to add code to show this checked result to single.php because my code use foreach just show Array text not show text like Pool Garage Balcon ect.
Thanks

Use this code in your single.php file for your custom post
$meta_value = get_post_meta( $post->ID, 'elements', true );
foreach($meta_value as $key=>$value){
echo $value . ' ';
}
It will show results same as you mentioned in the question ie:
(Pool Garage Balcon ect.)

Related

How to convert the WordPress meta box Page Attributes->Page Template dropdown to radio buttons?

I would like to be able to change the Page Attribute "Templates" dropdown to radio buttons, to allow me to have corresponding thumbnails next to them.
It looks like this question was already asked here - Is it possible to make WordPress page attribute meta box select option display as images? - however no code was ever supplied and looking at the comments it appears that the user answered their own question?
I have already removed and replaced the Page Attributes meta box on functions.php, as per below:
add_action( 'add_meta_boxes', 'wpse44966_add_meta_box' );
function wpse44966_add_meta_box( $post_type ){
remove_meta_box(
'pageparentdiv',
'page',
'side');
add_meta_box(
'wpse44966-meta-box',
'page' == $post_type ? __('Page Style Templates') : __('Attributes'),
'wpse44966_meta_box_cb',
'page',
'side',
'low');
}
I am then able to call back the "Templates" dropdown in my own meta box - I have also included the page_template_dropdown function (renamed 'page_template_dropdown_show_it').
function page_template_dropdown_show_it( $default = '', $post_type = 'page' ) {
$templates = get_page_templates( null, $post_type );
ksort( $templates );
foreach ( array_keys( $templates ) as $template ) {
$selected = selected( $default, $templates[ $template ], false );
echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>';
}
}
function wpse44966_meta_box_cb( $post ){
echo 'Please select from the below';
if ( count( get_page_templates( $post ) ) > 0 && get_option( 'page_for_posts' ) != $post->ID ) :
$template = ! empty( $post->page_template ) ? $post->page_template : false; ?>
<p class="post-attributes-label-wrapper"><label class="post-attributes-label" for="page_template"><?php _e( 'Template' ); ?></label><?php do_action( 'page_attributes_meta_box_template', $template, $post ); ?></p>
<select name="page_template" id="page_template">
<?php $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'meta-box' ); ?>
<option value="default"><?php echo esc_html( $default_title ); ?></option>
<?php page_template_dropdown_show_it( $template, $post->post_type ); ?>
</select>
<?php endif;
}
However, when I then amend both page_template_dropdown_show_it and wpse44966_meta_box_cb to show radio buttons, the changes are applied visually but nothing happens when you select them?
function page_template_dropdown_show_it( $default = '', $post_type = 'page' ) {
$templates = get_page_templates( null, $post_type );
ksort( $templates );
foreach ( array_keys( $templates ) as $template ) {
$checked = checked( $default, $templates[ $template ], false );
echo "\n\t<input type='radio' name='page_template' value='" . esc_attr( $templates[ $template ] ) . "' $checked>" . esc_html( $template );
}
}
function wpse44966_meta_box_cb( $post ){
echo 'Please select from the below';
if ( count( get_page_templates( $post ) ) > 0 && get_option( 'page_for_posts' ) != $post->ID ) :
$template = ! empty( $post->page_template ) ? $post->page_template : false; ?>
<p class="post-attributes-label-wrapper"><label class="post-attributes-label" for="page_template"><?php _e( 'Template' ); ?></label><?php do_action( 'page_attributes_meta_box_template', $template, $post ); ?></p>
<?php $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'meta-box' ); ?>
<input type='radio' name='page_template' value="default"><?php echo esc_html( $default_title ); ?>
<?php page_template_dropdown_show_it( $template, $post->post_type ); ?>
<?php endif;
}
It's obviously not as simple as a straight swap-out (as it isn't working), but the only thing that I can see that is missing is now there is nothing carrying the id="page_template", whereas before it was included in the below:
<select name="page_template" id="page_template">
So, it appears that I was correct that the issue was that the id "page_template" was no longer being passed.
To solve this, all I have done is applied some Javascript (using the admin_enqueue_scripts function) which adds the id "page_template" to the radio button that has been selected.

Adding a dropdown metabox to page admin including all post categories and storing the value

I am trying to add a custom meta box to page-admin that shows all my post-categories as options. I already made the meta box appear but i can not figure out how to show the categories. The dropdown is empty.
Here is my code:
function cd_meta_box_page()
{
global $page;
$values = get_post_custom( $page->ID );
$selected = isset( $values['my_meta_box_page'] ) ? esc_attr( $values['my_meta_box_page'] [0] ) : '';
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>
<p>
Wählen Sie hier eine Kategore aus welcher die Beiträge in die Seite geladen werden sollen.
</p>
<p>
<label for="my_meta_box_page">Kategorien</label>
<select name="my_meta_box_page" id="my_meta_box_page">
<?php
$args = array(
'orderby' => 'id',
'hide_empty'=> 0,
'child_of' => 5, //Child From Boxes Category
);
$categories = get_categories($args);
foreach ($categories as $cat) {
echo '<option value="'.$cat->name; selected( $selected, $cat->name ); echo '">'.$cat->name; echo'</option>';
$args2= array("orderby"=>'name', "category" => $cat->cat_ID); // Get Post from each Sub-Category
$posts_in_category = get_posts($args2);
}
?>
</select>
</p>
<?php
}
I can not find my fault. Can anyone help, please?
Thank you!
EDIT:
I found the issue. Deleting the following line helped:
'child_of' => 5, //Child From Boxes Category
Now I have the problem that wordpress does not store my selection. Saving the value of my_meta_box_postvariante works fine. But the value for my_meta_box_page is always staying default. I can not make it work... My code:
function cd_meta_box_page()
{
// $post is already set, and contains an object: the WordPress post
global $post;
$values = get_post_custom( $post->ID );
$selected = isset( $values['my_meta_box_page'] ) ? esc_attr( $values['my_meta_box_page'] [0] ) : '';
// We'll use this nonce field later on when saving.
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>
<p>
Wählen Sie hier eine Kategore aus welcher die Beiträge in die Seite geladen werden sollen.<br />
</p>
<p>
<label for="my_meta_box_page">Kategorien</label>
<select name="my_meta_box_page" id="my_meta_box_page">
<?php
$args = array(
'orderby' => 'id',
'hide_empty'=> 0,
);
$categories = get_categories($args);
foreach ($categories as $cat) {
echo '<option value="'.$cat->name; selected( $selected, $cat->name ); echo '">'.$cat->name; echo'</option>';
}
?>
</select>
</p>
<?php
}
add_action( 'save_post', 'cd_meta_box_save' );
function cd_meta_box_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchors can only have href attribute
)
);
// Make sure your data is set before trying to save it
if( isset( $_POST['my_meta_box_postvariante'] ) )
update_post_meta( $post_id, 'my_meta_box_postvariante', esc_attr( $_POST['my_meta_box_postvariante'] ) );
if( isset( $_POST['my_meta_box_page'] ) )
update_post_meta( $post_id, 'my_meta_box_page', esc_attr( $_POST['my_meta_box_page'] ) );
}
?>

Wordpress save only last custom field

I want to have three dropdown list that allow user select Author, Post and Testimonial. But wordpress only save last dropdown.
This is first dropdown:
//allow authors list on posts
add_action( 'add_meta_boxes', 'author_list_add' );
function author_list_add() {
add_meta_box( 'my-meta-box-id', 'Post Author', 'author_list', 'post', 'normal', 'high' );
}
function author_list( $post ) {
$values = get_post_custom( $post->ID );
$selected = isset( $values['custom_author'] ) ? esc_attr( $values['custom_author'][0] ) : '';
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce ');
?>
<p>
<label for="custom_author">Select author</label>
<br>
<select name="custom_author" id="custom_author">
<option value="0" <?php selected( $selected, '0' ); ?>>No author</option>
<?php
$args = array('post_type' => 'member');
$loop = get_posts($args);
foreach ($loop as $post) : setup_postdata($post);
$name = $post->post_title;
$link = $post->ID;
?>
<option value="<?php echo $link; ?>" <?php selected( $selected, $link ); ?>><?php echo $name; ?></option>
<?php
endforeach;
?>
</select>
</p>
<?php
}
add_action( 'save_post', 'author_list_save' );
function author_list_save( $post_id ) {
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
// Probably a good idea to make sure your data is set
if( isset( $_POST['custom_author'] ) )
update_post_meta( $post_id, 'custom_author', esc_attr( $_POST['custom_author'] ) );
}
The second Part:
//allow select testimonial list on posts
add_action( 'add_meta_boxes', 'testimonial_select_box_add' );
$types = array( 'post', 'page' );
function testimonial_select_box_add() {
add_meta_box( 'testimonial-box', 'Testimonial in bottom row', 'testimonial_select_box', $types, 'normal', 'high' );
}
function testimonial_select_box( $post ) {
$values = get_post_custom( $post->ID );
$selected = isset( $values['testimonial_select'] ) ? esc_attr( $values['testimonial_select'][0] ) : '';
wp_nonce_field( 'testimonial_meta_box_nonce', 'meta_box_nonce' );
?>
<p>
<label for="testimonial_select">Select Testimonial</label>
<br>
<select name="testimonial_select" id="testimonial_select">
<option value="0" <?php selected( $selected, '0' ); ?>>None</option>
<?php
$args = array('post_type' => 'testimonial','posts_per_page' => -1);
$loop = get_posts($args);
foreach ($loop as $post) : setup_postdata($post);
$name = $post->post_title;
$link = $post->ID;
?>
<option value="<?php echo $link; ?>" <?php selected( $selected, $link ); ?>><?php echo $name; ?></option>
<?php
endforeach;
?>
</select>
</p>
<?php
}
add_action( 'save_post', 'testimonial_select_box_save' );
function testimonial_select_box_save( $post_id ) {
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'testimonial_meta_box_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
// Probably a good idea to make sure your data is set
if( isset( $_POST['testimonial_select'] ) )
update_post_meta( $post_id, 'testimonial_select', esc_attr( $_POST['testimonial_select'] ) );
}
And last one:
//allow select Post list on posts
add_action( 'add_meta_boxes', 'post_select_box_add' );
function post_select_box_add() {
add_meta_box( 'post-box', 'Post in bottom row', 'post_select_box',$types, 'normal', 'high' );
}
function post_select_box( $post ) {
$values = get_post_custom( $post->ID );
$selected = isset( $values['post_select'] ) ? esc_attr( $values['post_select'][0] ) : '';
wp_nonce_field( 'post_meta_box_nonce', 'meta_box_nonce' );
?>
<p>
<label for="post_select">Select Post</label>
<br>
<select name="post_select" id="post_select">
<option value="0" <?php selected( $selected, '0' ); ?>>None</option>
<?php
$args = array('post_type' => 'post','posts_per_page' => -1);
$loop = get_posts($args);
foreach ($loop as $post) : setup_postdata($post);
$name = $post->post_title;
$link = $post->ID;
?>
<option value="<?php echo $link; ?>" <?php selected( $selected, $link ); ?>><?php echo $name; ?></option>
<?php
endforeach;
?>
</select>
</p>
<?php
}
add_action( 'save_post', 'post_select_box_save' );
function post_select_box_save( $post_id ) {
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'post_meta_box_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
// Probably a good idea to make sure your data is set
if( isset( $_POST['post_select'] ) )
update_post_meta( $post_id, 'post_select', esc_attr( $_POST['post_select'] ) );
}
as you can see, function and ID names are unique, but only last one saved.
this is what happened when I save :
As per my comment, each of your nonces seems to have the same name (meta_box_nonce), so there may be a clash if all three fields are submitted in the same form. Trying giving them unique names (in both your wp_nonce_field and wp_verify_nonce calls).

cant display custom meta box data

im creating a custom metabox as such:
<?php
/**
* Plugin Name: Relaterade sidor
* Description: lägg till relaterade sidor
* Version: 1.0
* Author: test
* Author URI: test
*
*/
function relaterade_sidor_get_meta( $value ) {
global $post;
$field = get_post_meta( $post->ID, $value, true );
if ( ! empty( $field ) ) {
return is_array( $field ) ? stripslashes_deep( $field ) : stripslashes( wp_kses_decode_entities( $field ) );
} else {
return false;
}
}
function relaterade_sidor_add_meta_box() {
add_meta_box(
'relaterade_sidor-relaterade-sidor',
__( 'relaterade sidor', 'relaterade_sidor' ),
'relaterade_sidor_relaterade_sidor_html',
'post',
'normal',
'default'
);
add_meta_box(
'relaterade_sidor-relaterade-sidor',
__( 'relaterade sidor', 'relaterade_sidor' ),
'relaterade_sidor_relaterade_sidor_html',
'page',
'normal',
'default'
);
}
add_action( 'add_meta_boxes', 'relaterade_sidor_add_meta_box' );
function relaterade_sidor_relaterade_sidor_html( $post) {
wp_nonce_field( '_relaterade_sidor_relaterade_sidor_nonce', 'relaterade_sidor_relaterade_sidor_nonce' ); ?>
<p>relaterade sidor</p>
<p>
<label for="relaterade_sidor_relaterade_sidor_url"><?php _e( 'Url', 'relaterade_sidor' ); ?></label><br>
<input type="text" name="relaterade_sidor_relaterade_sidor_url" id="relaterade_sidor_relaterade_sidor_url" value="<?php echo relaterade_sidor_get_meta( 'relaterade_sidor_relaterade_sidor_url' ); ?>">
</p><?php
}
function relaterade_sidor_relaterade_sidor_save( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( ! isset( $_POST['relaterade_sidor_relaterade_sidor_nonce'] ) || ! wp_verify_nonce( $_POST['relaterade_sidor_relaterade_sidor_nonce'], '_relaterade_sidor_relaterade_sidor_nonce' ) ) return;
if ( ! current_user_can( 'edit_post' ) ) return;
if ( isset( $_POST['relaterade_sidor_relaterade_sidor_url'] ) )
update_post_meta( $post_id, 'relaterade_sidor_relaterade_sidor_url', esc_attr( $_POST['relaterade_sidor_relaterade_sidor_url'] ) );
}
add_action( 'save_post', 'relaterade_sidor_relaterade_sidor_save' );
/*
Usage: relaterade_sidor_get_meta( 'relaterade_sidor_relaterade_sidor_url' )
*/
?>
the text remains in the textfield after saving/updating so I guess that means it is saved to the database, but when trying to display the data in a page or post I only get blank.
I tried with both these ones:
<?php if (have_posts()) : while (have_posts()) : the_post();
$intro = get_post_meta(get_the_ID(), 'relaterade_sidor-relaterade-sidor', true);
echo "content: " . $intro;
?>
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'relaterade_sidor-relaterade-sidor', true);
wp_reset_query();
?>
But I only get blank, cant get it to display the content saved in the custom meta textbox.
Sorry, was trying to connect it to the metabox name when i should connect the key,
$intro = get_post_meta(get_the_ID(), 'relaterade_sidor_relaterade_sidor_url', true);
echo "content: " . $intro;
works just fine inside the loop
I suggest CMB2 library. No more headaches with metaboxes ;)
https://stackoverflow.com/a/31662024/5162081

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