-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsubpages-menu-label-metabox.php
48 lines (36 loc) · 1.58 KB
/
subpages-menu-label-metabox.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( 'Invalid request.' );
}
add_action('admin_init', 'subpages_add_custom_box', 1);
add_action('save_post', 'subpages_save_postdata');
function subpages_add_custom_box() {
add_meta_box( 'subpages_menu_label', 'Subpages Extended Menu Label',
'subpages_inner_custom_box', 'page', 'side', 'low' );
}
function subpages_inner_custom_box() {
global $post;
$post_id = $post;
if (is_object($post_id)) $post_id = $post_id->ID;
wp_nonce_field( plugin_basename(__FILE__), 'subpages_page_title_metabox' );
$value = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_subpages_menu_label', true)));
echo '<label for="subpages_menu_label">' . __("Menu Label", 'subpages_textdomain' ) . '</label> ';
echo '<input type="text" id= "subpages_menu_label" name="subpages_menu_label" value="'.$value.'" size="10" />';
}
function subpages_save_postdata( $post_id ) {
if ( !isset($_POST['subpages_page_title_metabox']) || isset($_POST['subpages_page_title_metabox']) && !wp_verify_nonce( $_POST['subpages_page_title_metabox'], plugin_basename(__FILE__) )) {
return $post_id;
}
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
$menu_label = $_POST['subpages_menu_label'];
delete_post_meta($post_id, '_subpages_menu_label'); add_post_meta($post_id, '_subpages_menu_label', $menu_label);
return $menu_label;
}