Esempio n. 1
0
/**
 * Returns the Team Member's Title.
 *
 * @param int|\WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 *
 * @return string|bool The Team Member's Title, and empty string if empty, or false if we don't have a valid post.
 */
function get_team_member_title($post = 0)
{
    $post = get_post($post);
    if (empty($post)) {
        return false;
    }
    // This check is just a trick to allow some default data throughout the talk, not for production code!
    if (!function_exists(__NAMESPACE__ . '\\get_team_member_title_meta_key')) {
        return 'Code Spelunker';
    }
    $title = get_post_meta($post->ID, get_team_member_title_meta_key(), true);
    if (empty($title)) {
        return '';
    }
    return $title;
}
/**
 * Save the Team Member Meta Fields
 *
 * @param int $post_id The ID of the post we're saving meta for.
 */
function save_team_member_meta($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (get_team_members_post_type_name() !== get_post_type($post_id)) {
        return;
    }
    if (!isset($_POST['fz_team_member_nonce']) || !wp_verify_nonce($_POST['fz_team_member_nonce'], 'fz_team_member_meta')) {
        return;
    }
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }
    $meta_keys = array(get_team_member_title_meta_key(), get_team_member_twitter_meta_key());
    foreach ($meta_keys as $meta_key) {
        if (!empty($_POST[$meta_key])) {
            update_post_meta($post_id, $meta_key, $_POST[$meta_key]);
        } else {
            delete_post_meta($post_id, $meta_key);
        }
    }
}