Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Define the custom boxes */
- add_action('admin_menu', 'emporium_add_custom_boxes');
- /* Save data entered */
- add_action('save_post', 'emporium_save_custom_data');
- /* Adds to Post & Page screens */
- function emporium_add_custom_boxes() {
- add_meta_box( 'emporium_custom_keywords', __( 'Meta Tags', 'emporium' ), 'emporium_inner_custom_box', 'post', 'side' );
- add_meta_box( 'emporium_custom_keywords', __( 'Meta Tags', 'emporium' ), 'emporium_inner_custom_box', 'page', 'side' );
- }
- // Prints the inner fields for the custom post/page section
- function emporium_inner_custom_box() {
- // Get stored custom meta
- global $post_id;
- $desc = ( get_post_meta($post_id, '_emporium_custom_description', true) ) ? get_post_meta($post_id, '_emporium_custom_description', true)
- : '';
- $keywords = ( get_post_meta($post_id, '_emporium_custom_keywords', true) ) ? get_post_meta($post_id, '_emporium_custom_keywords', true)
- : '';
- // Use nonce for verification
- echo '<input type="hidden" name="emporium_noncename" id="emporium_noncename" value="' .
- wp_create_nonce( 'emporium') . '" />';
- // Fields for data entry
- echo '<p><label for="emporium_custom_description">' . __('Description', 'emporium' ) . '</label><br />';
- echo '<input id="emporium_custom_description" type="text" name="_emporium_custom_description" value="' . $desc . '" size="40" />
- <label for="emporium_custom_description" class="howto">' . __('A short summary of this post or page.', 'emporium' ) . '</label></p>';
- echo '<p><label for="emporium_custom_keywords">' . __('Keywords', 'emporium' ) . '</label><br />';
- echo '<input id="emporium_custom_keywords" type="text" name="_emporium_custom_keywords" value="' . $keywords . '" size="40" />
- <label for="emporium_custom_keywords" class="howto">' . __('Separate keywords with a comma or a single space.', 'emporium') . '</label></p>';
- }
- /* When the post is saved, save custom data */
- function emporium_save_custom_data( $post_id ) {
- // verify this came from our screen & with proper authorization,
- if ( !isset( $_POST['emporium_noncename']) || !wp_verify_nonce( $_POST['emporium_noncename'], 'emporium' ) ) return $post_id;
- // If this an autosave, don't do anything
- if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
- // Check permissions
- if ( $_POST['post_type'] == 'page' && !current_user_can( 'edit_page', $post_id ) ) return $post_id;
- elseif ( !current_user_can( 'edit_post', $post_id ) ) return $post_id;
- // Save the data
- $desc = $_POST['_emporium_custom_description'];
- $keywords = $_POST['_emporium_custom_keywords'];
- update_post_meta($post_id, '_emporium_custom_description', $desc);
- update_post_meta($post_id, '_emporium_custom_keywords', $keywords);
- return;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement