• ninjaboy

    (@ninjaboy)


    I am creating a small plugin that modifies core functionality on the write post/page panels. Learning from this will be incorporated into a GPL licensed plugin for the community to use once I have got it tidied up and it has an options page!

    I have got my head totally around add_meta_box – the Codex page on this is surprisingly complete with some great example code (thank you!)

    Apart from adding my own boxes (no problems, all working), part of what I’m doing is modifying the existing meta_boxes in the panels – for instance the comments and ping metabox.

    I have no trouble removing this with remove_meta_box and have simply duplicated the function called page_comments_status_meta_box from wpadmin/edit-page-form.php in my plugin – modifying it to requirements.

    I can confirm this works perfectly and does indeed do my extra stuff along with retaining the core functionality to turn comments on and off.

    However, I notice that when the add_meta_box function is called in wp-admin/edit-page-form.php it has a different argument at the end

    function page_comments_status_meta_box($post){
    ?>
    <input name="advanced_view" type="hidden" value="1" />
    <p><label for="comment_status" class="selectit">
    <input name="comment_status" type="checkbox" id="comment_status" value="open" <?php checked($post->comment_status, 'open'); ?> />
    <?php _e('Allow Comments') ?></label></p>
    <p><label for="ping_status" class="selectit"><input name="ping_status" type="checkbox" id="ping_status" value="open" <?php checked($post->ping_status, 'open'); ?> /> <?php _e('Allow Pings') ?></label></p>
    <p><?php _e('These settings apply to this page only. “Pings” are <a href="https://codex.www.ads-software.com/Introduction_to_Blogging#Managing_Comments" target="_blank">trackbacks and pingbacks</a>.'); ?></p>
    <?php
    }
    add_meta_box('pagecommentstatusdiv', __('Discussion'), 'page_comments_status_meta_box', 'page', 'normal', 'core');

    I don’t seem to be able to find any reference to ‘core’ which is the priority – can anyone confirm what this is please? Does this do any sanitization or other checks or does it simply position it? Obviously I tried putting this in my own plugin code (normally I supply the argument ‘advanced’ or ‘side’ here) and it broke it.

    The structure of add_meta_box is
    add_meta_box( $id, $title, $callback, $page, $context, $priority );

    Also (more importantly) with my own meta_boxes, when I am saving data (eg custom fields) I am running through a nonce check and sanitization process for the data submitted – do I have to do this for the example above, eg controlling comments or does WordPress do this automatically with core functionality?

    I want to follow best practice and understand how this works – is it secure to just replicate a function as I have done, or do I need to build in my own checks, security and sanitization as I have pulled it out of the core code? Sorry for the lengthy post – I’d really appreciate any information anyone has, especially on security for this please!

  • The topic ‘add_meta_box development – replicating core post/page functionality in plugins’ is closed to new replies.