Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- if(!class_exists('catchyTitle')) :
- class catchyTitle
- {
- // Add meta box
- public static function metaBox()
- {
- $screen = get_current_screen();
- if('post' != $screen->post_type)
- return;
- add_meta_box('catchy_title', 'Short Title', array('catchyTitle', 'metaBoxShow'), 'post', 'normal', 'high');
- }
- // Show meta box
- public static function metaBoxShow()
- {
- global $post;
- // Use nonce for verification
- wp_nonce_field(plugin_basename( __FILE__ ), 'catchy_title_nonce');
- // Get current value
- $meta = get_post_meta($post->ID, 'catchy_title', true);
- echo '
- <div id="titlewrap">
- <label for="catchy_title" class="">Enter shorter title here</label>
- <input type="text" autocomplete="off" id="catchy_title" value="'.$meta.'" size="20" name="catchy_title">
- </div>';
- }
- // Save the meta data on form post
- public static function saveMeta($postId)
- {
- // Did the user intend to change this value
- if(!isset($_POST['catchy_title_nonce']) || !wp_verify_nonce($_POST['catchy_title_nonce'], plugin_basename( __FILE__ )))
- return;
- // Check autosave
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return $postId;
- }
- // Check permissions
- if(!current_user_can('edit_post', $postId))
- return $postId;
- $old = get_post_meta($postId, 'catchy_title', true);
- $new = $_POST['catchy_title'];
- if ($new && $new != $old) {
- update_post_meta($postId, 'catchy_title', $new);
- } elseif ('' == $new && $old) {
- delete_post_meta($postId, 'catchy_title', $old);
- }
- }
- }
- if(is_admin())
- {
- add_action('admin_head', array('catchyTitle', 'metaBox'));
- add_action('save_post', array('catchyTitle', 'saveMeta'));
- }
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement