Example #1
0
/**
 * Save post meta when the save_post action is called
 *
 * @since 1.0
 *
 * @param int $post_id Theme (Post) ID
 *
 * @global array $post All the data of the the current post
 * @return void
 */
function popmake_popup_theme_meta_box_save($post_id, $post)
{
    if (isset($post->post_type) && 'popup_theme' != $post->post_type) {
        return;
    }
    if (!isset($_POST['popmake_popup_theme_meta_box_nonce']) || !wp_verify_nonce($_POST['popmake_popup_theme_meta_box_nonce'], basename(__FILE__))) {
        return;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || defined('DOING_AJAX') && DOING_AJAX || isset($_REQUEST['bulk_edit'])) {
        return;
    }
    if (isset($post->post_type) && 'revision' == $post->post_type) {
        return;
    }
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }
    $field_prefix = Popmake_Popup_Theme_Fields::instance()->field_prefix;
    foreach (Popmake_Popup_Theme_Fields::instance()->get_all_fields() as $section => $fields) {
        $section_prefix = "{$field_prefix}{$section}";
        $meta_values = array();
        foreach ($fields as $field => $args) {
            $field_name = "{$section_prefix}_{$field}";
            if (isset($_POST[$field_name])) {
                $meta_values[$field] = apply_filters('popmake_metabox_save_' . $field_name, $_POST[$field_name]);
            }
        }
        update_post_meta($post_id, "popup_theme_{$section}", $meta_values);
    }
    foreach (popmake_popup_theme_meta_fields() as $field) {
        if (isset($_POST[$field])) {
            $new = apply_filters('popmake_metabox_save_' . $field, $_POST[$field]);
            update_post_meta($post_id, $field, $new);
        } else {
            delete_post_meta($post_id, $field);
        }
    }
    delete_transient('popmake_theme_styles');
    do_action('popmake_save_popup_theme', $post_id, $post);
}
function popmake_register_popup_theme_meta_fields($section, $fields = array())
{
    if (!empty($fields)) {
        Popmake_Popup_Theme_Fields::instance()->add_fields($section, $fields);
    }
}