page  meta box  範例程式2 用Class 包起來

page meta box 範例程式2 用Class 包起來

class icblockMetaBox{
/* Called by save_post action to save meta data in database. */
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*/
/* Verify the nonce before proceeding. For security */
if (!isset($_POST["qnimate-email-nonce"]) || !wp_verify_nonce($_POST["qnimate-email-nonce"], basename(__FILE__)))
return $post_id;

/* Check if the current user has permission to edit the post. For security */
if(!current_user_can("edit_page", $post_id))
return $post_id;

//check if it is autosave
return $post_id;

//check if the post type is correct
$slug = "page";
if($slug != $post->post_type)

/* Store the user enter value in a variable */
$user_entered_email_value = "";
$user_entered_email_value = $_POST["author-email"];
$user_entered_email_value = "";
update_post_meta(get_the_ID(), "author-email", $user_entered_email_value);

function meta_box_markup($object)/*$object conatins the information about the post*/
/*nonce for security purpose. more on it at */
wp_nonce_field(basename(__FILE__), ‘qnimate-email-nonce’);

<!– Markup inside the custom meta box –>
<label for="author-email">E-Mail Of Author</label>
<!– Retrieve the email from database. If not yet set then empty string is returned. –>
<input name="author-email" type="email" validate="true" value="<?php echo get_post_meta(get_the_ID(), "author-email", true); ?>">

function my_custom_meta_box()
add_meta_box("qnimate-meta-box", "Author Information", array( ‘icblockMetaBox’,"meta_box_markup"), "page", "normal", "default", null);
add_action("add_meta_boxes", array( ‘icblockMetaBox’, "my_custom_meta_box"));
add_action("save_post",array( ‘icblockMetaBox’, "save_my_custom_meta_box" ), 10, 3);


CH02用戶資料CH03基本APICH05 分類頁面Category.phpCH09Screen Options(顯示選項)CH10外掛pluginsCH11 add_actionCH12 add_filterCH13Meta Box(自訂區塊)CH14widget(自訂模組)CH15 DBCH16AJAXCH17ShortcodeCH20 wordpress muCH30WooCommerce