{"id":8569,"date":"2016-02-16T18:52:37","date_gmt":"2016-02-16T23:52:37","guid":{"rendered":"httpss:\/\/www.powenko.com\/wordpress\/?p=8569"},"modified":"2016-02-16T18:54:52","modified_gmt":"2016-02-16T23:54:52","slug":"page-metabox-%e7%af%84%e4%be%8b%e7%a8%8b%e5%bc%8f1","status":"publish","type":"post","link":"https:\/\/www.powenko.com\/wordpress\/?p=8569","title":{"rendered":"page  metabox  \u7bc4\u4f8b\u7a0b\u5f0f1"},"content":{"rendered":"<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\r\n \/* Called by save_post action to save meta data in database. *\/\r\n    function save_my_custom_meta_box($post_id,  $post, $update)\/*$post contains info about the post and $post_id is assigned to the id of the post*\/\r\n    {\r\n        \/* Verify the nonce before proceeding. For security *\/\r\n        if (!isset($_POST&#x5B;&quot;qnimate-email-nonce&quot;]) || !wp_verify_nonce($_POST&#x5B;&quot;qnimate-email-nonce&quot;], basename(__FILE__)))\r\n          return $post_id;\r\n      \r\n        \/* Check if the current user has permission to edit the post. For security *\/\r\n        if(!current_user_can(&quot;edit_page&quot;, $post_id))\r\n            return $post_id;\r\n\r\n        \/\/check if it is autosave\r\n        if(defined(&quot;DOING_AUTOSAVE&quot;) &amp;&amp; DOING_AUTOSAVE)\r\n            return $post_id;\r\n\r\n        \/\/check if the post type is correct\r\n        \/*\r\n        $slug = &quot;page&quot;;\r\n        if($slug != $post-&gt;post_type)\r\n            return;\r\n*\/\r\n\r\n        \/* Store the user enter value in a variable *\/\r\n        $user_entered_email_value = &quot;&quot;;\r\n        if(isset($_POST&#x5B;&quot;author-email&quot;]))\r\n        {\r\n            $user_entered_email_value = $_POST&#x5B;&quot;author-email&quot;];\r\n        }\r\n        else\r\n        {\r\n            $user_entered_email_value = &quot;&quot;;\r\n        }\r\n        update_post_meta(get_the_ID(), &quot;author-email&quot;, $user_entered_email_value);\r\n    }\r\n\r\n\r\n\r\n\r\n    \/*Callback*\/\r\n    function meta_box_markup($object)\/*$object conatins the information about the post*\/\r\n    {\r\n        \/*nonce for security purpose. more on it at httpss:\/\/codex.wordpress.org\/WordPress_Nonces *\/\r\n        wp_nonce_field(basename(__FILE__), 'qnimate-email-nonce');\r\n\r\n\r\n\r\n\r\n        ?&gt;\r\n            &lt;!-- Markup inside the custom meta box --&gt;\r\n            &lt;div&gt;\r\n                &lt;label for=&quot;author-email&quot;&gt;E-Mail Of Author&lt;\/label&gt;\r\n                &lt;!-- Retrieve the email from database. If not yet set then empty string is returned. --&gt;\r\n                &lt;input name=&quot;author-email&quot; type=&quot;email&quot; validate=&quot;true&quot; value=&quot;&lt;?php echo get_post_meta(get_the_ID(), &quot;author-email&quot;, true); ?&gt;&quot;&gt;\r\n            &lt;\/div&gt;\r\n        &lt;?php\r\n    }\r\n\r\n\r\n\r\n\r\n    function my_custom_meta_box()\r\n    {\r\n        \/*\r\n        Parameters for add_meta_box() are $id, $title, $callback, $page, $context, $priority, $callback_args\r\n        -&gt; $id is a unqiue id given to every meta box\r\n        -&gt; $title is the title displayed in custom meta box\r\n        -&gt; $callback is a function that outputs markup inside the custom meta box\r\n        -&gt; $page respresents the admin page on which the mata box will be displayed on. It can be page, post, custom post type \r\n        -&gt; $context respresents the postiton of the meta box. It can be normal, advanced or side.\r\n        -&gt; $priority is the position of the box insde the context. It can be high, core, default or low\r\n        -&gt; $cannback_args is used to pass arguements to the callback function.\r\n        *\/\r\n        add_meta_box(&quot;qnimate-meta-box&quot;, &quot;Author Information&quot;, &quot;meta_box_markup&quot;, &quot;page&quot;, &quot;normal&quot;, &quot;default&quot;, null);\r\n    }\r\n\r\n\r\n\r\n    \/* This action is responsibe for creating and displaying meta boxes *\/\r\n    add_action(&quot;add_meta_boxes&quot;,  &quot;my_custom_meta_box&quot;);\r\n\r\n\r\n\r\n\r\n    \/* Used to store the meta data in database *\/\r\n    add_action(&quot;save_post&quot;, &quot;save_my_custom_meta_box&quot; , 10, 3);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/* Called by save_post action to save meta data in data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8566,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[],"class_list":["post-8569","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ch13meta-box"],"_links":{"self":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8569"}],"collection":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8569"}],"version-history":[{"count":1,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8569\/revisions"}],"predecessor-version":[{"id":8570,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8569\/revisions\/8570"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/8566"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}