Tag Info

Hot answers tagged

5

When in doubt use the API. Let’s say the structure of $wp_meta_boxes will change or go away one day. remove_meta_box() will still work, because the API is a contract between core and developers. Unsetting some keys in a global variable might break. unset() is easier to write when you want to remove a whole group: unset($wp_meta_boxes['dashboard']) is ...


4

Assuming you'd like the facility to update this data from the quickedit box whilst viewing the list of comments, you'll need a series of actions and filters. I've tried to make appropriate comments in the necessary places for you, though bear in mind i threw this all together for you with a small amount of testing(it does work though). This should get give ...


2

Your issue seems to be with too loose logic check, rather than saving. To treat valid but falsy value correctly you need something like this: if ( false !== $meta_value ) This will strictly match only the case when value doesn't contain false (return of the API when fetch failed).


2

By inspecting the file /wp-admin/nav-menus.php we can see that these meta-boxes: are rendered with: <?php do_meta_boxes( 'nav-menus', 'side', null ); ?> The file /wp-admin/includes/nav-menu.php contains the corresponding add_meta_box() calls and from that we can construct the relevant removal code: function custom_remove() { ...


2

In your save code, the value of $field['id'] is event_timeframe, which does not exist in $_POST, so your options will never save. You need to dig down into your options array to get to timestart and timeend: // loop through fields and save the data foreach ( $event_infobox_fields as $field ) { foreach ( $field['options'] as $option_key => ...


2

To provide a full code example based on Andrew's answer ... I needed a way to include a "Deck" (aka subhead) to my posts; I wanted the deck field to appear after the main title bar. /** * Add a "deck" (aka subhead) meta box to post page(s) and position it * under the title. * * @todo Move to class. * @see ...


2

From what I thought was a duplicate, we get a class to render the meta box in the Nav-Menus page. Then I used this core function to render the meta box contents. It works ok, but it's displaying some notices and may need a good cleanup. It's too much code to parse right now and I'll leave it here as starting point. The modifications I've done involve the ...


2

It was a long way around to get there but you basically have a markup error. You didn't name your select. You should have: <select id="select-taxonomy" name="<?php echo $name ?>"> // <-- here is the change <?php foreach($terms as $term) { $id = $taxonomy.'-'.$term->term_id; $value= (is_taxonomy_hierarchical($taxonomy) ? ...


2

A simple and cleaner solution would be to use !in_array ex: function mf_1_remove_meta_boxes() { if( !is_admin() && !isset( $_GET['post'] ) ) return; if( !in_array($_GET['post'], array('194','185','2') ) ) remove_meta_box( 'mf_1', 'page', 'normal' ); } this way you can just add the ids in the array and as many as you want


1

The editor is hard-coded into the form. It isn't inserted by add_meta_box. There is a hook called edit_form_after_title which you should be able to use though. Proof of concept: // use the action to create a place for your meta box function add_before_editor($post) { global $post; do_meta_boxes('post', 'pre_editor', $post); } ...


1

You can download a copy of PHP Markdown and use it to parse the textarea contents before you save it: if ( ! class_exists( 'Markdown' ) ) { require_once( plugin_dir_path(__FILE__) . '/markdown.php' ); } $textarea_contents = Markdown::defaultTransform( $textarea_contents );


1

This is was I use to convert textarea with wp_editor() wp_editor($value, "editor-name", array( 'tinymce' => array( 'theme_advanced_buttons1' => 'bold,italic,underline', 'theme_advanced_buttons2' => '', 'theme_advanced_buttons3' => '' ) ));


1

Your update_option should be inside a hook callback and should check to see if $_POST['custom_welcome_panel'] is set before trying to update the option. Otherwise that could be overwriting your option every time the page loads. And, honestly, as written I could shove anything I wanted into that option value. I'd just have to send a POST request to the site. ...



Only top voted, non community-wiki answers of a minimum length are eligible