function theme_set_widget_style($id, $style) { global $theme_widgets_style; if (!in_array($style, array_keys($theme_widgets_style))) { $style = 'default'; } theme_set_meta_option($id, 'theme_widget_styles', $style); }
function theme_get_meta_option($id, $name) { global $theme_default_meta_options; $value = get_post_meta($id, '_' . $name, true); if ('' === $value) { $value = theme_get_array_value(get_option($name), $id, theme_get_array_value($theme_default_meta_options, $name)); theme_set_meta_option($id, $name, $value); } return $value; }
function theme_save_post($post_id) { global $theme_post_meta_options, $theme_page_meta_options, $theme_page_header_image_meta_options; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (!isset($_POST['theme_meta_noncename']) || !wp_verify_nonce($_POST['theme_meta_noncename'], 'theme_meta_options')) { return $post_id; } // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want // to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } $meta_options = null; //posts if ('page' == $_POST['post_type']) { // Check permissions if (!current_user_can('edit_page', $post_id)) { return $post_id; } $meta_options = $theme_page_meta_options; } if ('post' == $_POST['post_type']) { $meta_options = $theme_post_meta_options; } $meta_options = array_merge($meta_options, $theme_page_header_image_meta_options); if (!$meta_options) { return $post_id; } // OK, we're authenticated: we need to find and save the data foreach ($meta_options as $value) { $id = theme_get_array_value($value, 'id'); $val = stripslashes(theme_get_array_value($_REQUEST, $id)); $type = theme_get_array_value($value, 'type'); $necessary = theme_get_array_value($value, 'necessary'); if ($necessary && !current_user_can($necessary)) { continue; } switch ($type) { case 'checkbox': $val = $val ? 1 : 0; break; case 'numeric': $val = (int) $val; break; } theme_set_meta_option($post_id, $id, $val); } return $post_id; }