コード例 #1
0
ファイル: post-meta.php プロジェクト: WPDevHQ/nevertheless
/**
 * Registers the theme layouts meta key 
 */
function tamatebako_layouts_register_meta()
{
    register_meta('post', tamatebako_layout_meta_key(), 'sanitize_html_class');
}
コード例 #2
0
/**
 * Saves the post layout metadata.
 */
function tamatebako_layouts_save_post($post_id, $post = '')
{
    /* Fix for attachment save issue in WordPress 3.5. @link http://core.trac.wordpress.org/ticket/21963 */
    if (!is_object($post)) {
        $post = get_post();
    }
    /* Verify the nonce for the post formats meta box. */
    if (!isset($_POST['theme-layouts-nonce']) || !wp_verify_nonce($_POST['theme-layouts-nonce'], basename(__FILE__))) {
        return $post_id;
    }
    /* Get the meta key. */
    $meta_key = tamatebako_layout_meta_key();
    /* Get the previous post layout. */
    $meta_value = tamatebako_get_post_layout($post_id);
    /* Get the submitted post layout. */
    $new_meta_value = $_POST['post-layout'];
    /* If there is no new meta value but an old value exists, delete it. */
    if (current_user_can('delete_post_meta', $post_id, $meta_key) && '' == $new_meta_value && $meta_value) {
        delete_post_meta($post_id, $meta_key);
    } elseif (current_user_can('add_post_meta', $post_id, $meta_key) && $new_meta_value && '' == $meta_value) {
        update_post_meta($post_id, $meta_key, $new_meta_value);
    } elseif (current_user_can('edit_post_meta', $post_id, $meta_key) && $meta_value !== $new_meta_value) {
        update_post_meta($post_id, $meta_key, $new_meta_value);
    }
}