/** * This DB update converts the theme's custom fields into a single database entry for each posts and pages */ function graphene_convert_meta($post_id) { /* Do the conversion */ $custom_fields = graphene_custom_fields_defaults(); $graphene_meta = array(); foreach ($custom_fields as $custom_field => $default_val) { $current_value = get_post_meta($post_id, '_graphene_' . $custom_field, true); if ($current_value !== false) { if ($default_val !== $current_value && $current_value != 'global') { $graphene_meta[$custom_field] = $current_value; } delete_post_meta($post_id, '_graphene_' . $custom_field); } } if ($graphene_meta) { update_post_meta($post_id, '_graphene_meta', $graphene_meta); } }
/** * Get the custom fields for the post * * @param int $post_id The ID for the post to get the custom fields for * @param string $field The key for the custom field to retrieve. * @return string Custom field value | array All custom fields if $field is not defined * * @package Graphene * @since Graphene 1.8 */ function graphene_get_post_meta($post_id, $field = '') { global $graphene_post_meta; if (!is_array($graphene_post_meta)) { $graphene_post_meta = array(); } if (!array_key_exists($post_id, $graphene_post_meta)) { if (get_post_meta($post_id, '_graphene_slider_img')) { graphene_convert_meta($post_id); } $current_post_meta = get_post_meta($post_id, '_graphene_meta', true); if (!$current_post_meta) { $graphene_post_meta[$post_id] = graphene_custom_fields_defaults(); } else { $graphene_post_meta[$post_id] = array_merge(graphene_custom_fields_defaults(), $current_post_meta); } } if (!$field) { $post_meta = $graphene_post_meta[$post_id]; } else { if (!in_array($field, array('slider_imgurl', 'slider_url')) && $graphene_post_meta[$post_id][$field] == 'global') { $graphene_post_meta[$post_id][$field] = ''; } $post_meta = $graphene_post_meta[$post_id][$field]; } return apply_filters('graphene_get_post_meta', $post_meta, $post_id, $field); }
/** * Display the custom meta box content */ function graphene_custom_meta($post) { // Use nonce for verification wp_nonce_field('graphene_save_custom_meta', 'graphene_save_custom_meta'); /* Get the current settings */ $graphene_meta = get_post_meta($post->ID, '_graphene_meta', true); if (!$graphene_meta) { $graphene_meta = array(); } $graphene_meta = array_merge(graphene_custom_fields_defaults(), $graphene_meta); ?> <p><?php _e("These settings will only be applied to this particular post or page you're editing. They will override the global settings set in the Graphene Options or Graphene Display options page.", 'graphene'); ?> </p> <h4><?php _e('Slider options', 'graphene'); ?> </h4> <table class="form-table"> <tr> <th scope="row"> <label for="graphene_slider_img"><?php _e('Slider image', 'graphene'); ?> </label> </th> <td> <select id="graphene_slider_img" name="graphene_slider_img"> <option value="" <?php selected($graphene_meta['slider_img'], ''); ?> ><?php _e('Use global setting', 'graphene'); ?> </option> <option value="disabled" <?php selected($graphene_meta['slider_img'], 'disabled'); ?> ><?php _e("Don't show image", 'graphene'); ?> </option> <option value="featured_image" <?php selected($graphene_meta['slider_img'], 'featured_image'); ?> ><?php _e('Featured Image', 'graphene'); ?> </option> <option value="post_image" <?php selected($graphene_meta['slider_img'], 'post_image'); ?> ><?php _e('First image in post', 'graphene'); ?> </option> <option value="custom_url" <?php selected($graphene_meta['slider_img'], 'custom_url'); ?> ><?php _e('Custom URL', 'graphene'); ?> </option> </select> </td> </tr> <tr> <th scope="row"> <label for="graphene_slider_imgurl"><?php _e('Custom slider image URL', 'graphene'); ?> </label> </th> <td> <input type="text" id="graphene_slider_imgurl" name="graphene_slider_imgurl" class="widefat code" value="<?php echo $graphene_meta['slider_imgurl']; ?> " size="60" /><br /> <span class="description"><?php _e('Make sure you select Custom URL in the slider image option above to use this custom url.', 'graphene'); ?> </span> </td> </tr> <tr> <th scope="row"> <label for="graphene_slider_url"><?php _e('Custom slider URL', 'graphene'); ?> </label> </th> <td> <input type="text" id="graphene_slider_url" name="graphene_slider_url" class="widefat code" value="<?php echo $graphene_meta['slider_url']; ?> " size="60" /><br /> <span class="description"><?php _e('Use this to override the link that is used in the slider.', 'graphene'); ?> </span> </td> </tr> </table> <h4><?php _e('Display options', 'graphene'); ?> </h4> <table class="form-table"> <tr> <th scope="row"> <label for="graphene_show_addthis"><?php _e('AddThis Social Sharing button', 'graphene'); ?> </label> </th> <td> <select id="graphene_show_addthis" name="graphene_show_addthis"> <option value="" <?php selected($graphene_meta['show_addthis'], ''); ?> ><?php _e('Use global setting', 'graphene'); ?> </option> <option value="show" <?php selected($graphene_meta['show_addthis'], 'show'); ?> ><?php _e('Show button', 'graphene'); ?> </option> <option value="hide" <?php selected($graphene_meta['show_addthis'], 'hide'); ?> ><?php _e('Hide button', 'graphene'); ?> </option> </select> </td> </tr> <?php if ('post' == $post->post_type) { ?> <tr> <th scope="row"> <label for="graphene_post_date_display"><?php _e('Post date display', 'graphene'); ?> </label> </th> <td> <select id="graphene_post_date_display" name="graphene_post_date_display"> <option value="" <?php selected($graphene_meta['post_date_display'], ''); ?> ><?php _e('Use global setting', 'graphene'); ?> </option> <option value="hidden" <?php selected($graphene_meta['post_date_display'], 'hidden'); ?> ><?php _e('Hidden', 'graphene'); ?> </option> <option value="icon_no_year" <?php selected($graphene_meta['post_date_display'], 'icon_no_year'); ?> ><?php _e('As an icon (without the year)', 'graphene'); ?> </option> <option value="icon_plus_year" <?php selected($graphene_meta['post_date_display'], 'icon_plus_year'); ?> ><?php _e('As an icon (including the year)', 'graphene'); ?> </option> <option value="text" <?php selected($graphene_meta['post_date_display'], 'text'); ?> ><?php _e('As inline text', 'graphene'); ?> </option> </select> </td> </tr> <?php } ?> </table> <?php if ('page' == $post->post_type) { ?> <h4><?php _e('Navigation options', 'graphene'); ?> </h4> <table class="form-table"> <tr> <th scope="row"> <label for="graphene_nav_description"><?php _e('Description', 'graphene'); ?> </label> </th> <td> <input type="text" id="graphene_nav_description" name="graphene_nav_description" value="<?php echo $graphene_meta['nav_description']; ?> " size="60" /><br /> <span class="description"><?php _e('Only required if you need a description in the navigation menu and you are not using a custom menu.', 'graphene'); ?> </span> </td> </tr> </table> <?php } }