{"id":8571,"date":"2016-02-16T18:56:22","date_gmt":"2016-02-16T23:56:22","guid":{"rendered":"httpss:\/\/www.powenko.com\/wordpress\/?p=8571"},"modified":"2016-02-16T18:56:22","modified_gmt":"2016-02-16T23:56:22","slug":"page-meta-box-%e7%af%84%e4%be%8b%e7%a8%8b%e5%bc%8f2-%e7%94%a8class-%e5%8c%85%e8%b5%b7%e4%be%86","status":"publish","type":"post","link":"https:\/\/www.powenko.com\/wordpress\/?p=8571","title":{"rendered":"page  meta box  \u7bc4\u4f8b\u7a0b\u5f0f2 \u7528Class \u5305\u8d77\u4f86"},"content":{"rendered":"<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass icblockMetaBox{\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        add_meta_box(&quot;qnimate-meta-box&quot;, &quot;Author Information&quot;, array( 'icblockMetaBox',&quot;meta_box_markup&quot;), &quot;page&quot;, &quot;normal&quot;, &quot;default&quot;, null);\r\n    }\r\n}\r\n    add_action(&quot;add_meta_boxes&quot;, array( 'icblockMetaBox', &quot;my_custom_meta_box&quot;));\r\n    add_action(&quot;save_post&quot;,array( 'icblockMetaBox', &quot;save_my_custom_meta_box&quot; ), 10, 3);\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>class icblockMetaBox{ \/* Called by save_post action to  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[],"class_list":["post-8571","post","type-post","status-publish","format-standard","hentry","category-ch13meta-box"],"_links":{"self":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8571"}],"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=8571"}],"version-history":[{"count":1,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8571\/revisions"}],"predecessor-version":[{"id":8572,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8571\/revisions\/8572"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}