Advertisement
Guest User

Untitled

a guest
Jun 1st, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. <?php
  2. /* Define the custom boxes */
  3. add_action('admin_menu', 'emporium_add_custom_boxes');
  4.  
  5. /* Save data entered */
  6. add_action('save_post', 'emporium_save_custom_data');
  7.  
  8. /* Adds to Post & Page screens */
  9. function emporium_add_custom_boxes() {
  10. add_meta_box( 'emporium_custom_keywords', __( 'Meta Tags', 'emporium' ), 'emporium_inner_custom_box', 'post', 'side' );
  11. add_meta_box( 'emporium_custom_keywords', __( 'Meta Tags', 'emporium' ), 'emporium_inner_custom_box', 'page', 'side' );
  12. }
  13.  
  14. // Prints the inner fields for the custom post/page section
  15. function emporium_inner_custom_box() {
  16. // Get stored custom meta
  17. global $post_id;
  18. $desc = ( get_post_meta($post_id, '_emporium_custom_description', true) ) ? get_post_meta($post_id, '_emporium_custom_description', true)
  19. : '';
  20. $keywords = ( get_post_meta($post_id, '_emporium_custom_keywords', true) ) ? get_post_meta($post_id, '_emporium_custom_keywords', true)
  21. : '';
  22.  
  23. // Use nonce for verification
  24. echo '<input type="hidden" name="emporium_noncename" id="emporium_noncename" value="' .
  25. wp_create_nonce( 'emporium') . '" />';
  26.  
  27. // Fields for data entry
  28. echo '<p><label for="emporium_custom_description">' . __('Description', 'emporium' ) . '</label><br />';
  29. echo '<input id="emporium_custom_description" type="text" name="_emporium_custom_description" value="' . $desc . '" size="40" />
  30. <label for="emporium_custom_description" class="howto">' . __('A short summary of this post or page.', 'emporium' ) . '</label></p>';
  31.  
  32. echo '<p><label for="emporium_custom_keywords">' . __('Keywords', 'emporium' ) . '</label><br />';
  33. echo '<input id="emporium_custom_keywords" type="text" name="_emporium_custom_keywords" value="' . $keywords . '" size="40" />
  34. <label for="emporium_custom_keywords" class="howto">' . __('Separate keywords with a comma or a single space.', 'emporium') . '</label></p>';
  35. }
  36.  
  37. /* When the post is saved, save custom data */
  38. function emporium_save_custom_data( $post_id ) {
  39. // verify this came from our screen & with proper authorization,
  40. if ( !isset( $_POST['emporium_noncename']) || !wp_verify_nonce( $_POST['emporium_noncename'], 'emporium' ) ) return $post_id;
  41.  
  42. // If this an autosave, don't do anything
  43. if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
  44.  
  45. // Check permissions
  46. if ( $_POST['post_type'] == 'page' && !current_user_can( 'edit_page', $post_id ) ) return $post_id;
  47. elseif ( !current_user_can( 'edit_post', $post_id ) ) return $post_id;
  48.  
  49. // Save the data
  50. $desc = $_POST['_emporium_custom_description'];
  51. $keywords = $_POST['_emporium_custom_keywords'];
  52.  
  53. update_post_meta($post_id, '_emporium_custom_description', $desc);
  54. update_post_meta($post_id, '_emporium_custom_keywords', $keywords);
  55.  
  56. return;
  57. }
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement