Last active
December 13, 2015 23:49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// create post type | |
add_action( 'init', 'create_post_type' ); | |
function create_post_type() { | |
$conf = array( | |
'public' => true, | |
'has_archive' => true, | |
'menu_position' => 5, | |
'show_in_nav_menus' => true, | |
'hierarchical' => true, | |
'has_archive' => true, | |
'supports' => array('title', 'editor', 'content', 'page-attributes'), | |
'taxonomies' => array('category', 'post_tag'), | |
); | |
$conf['labels'] = array( | |
'name' => __( 'Architecte Posts' ), | |
'singular_name' => __( 'Architecte' ) | |
); | |
$conf['rewrite'] = array('slug' => 'architect'); | |
register_post_type( 'architect_subpage',$conf); | |
$conf['labels'] = array( | |
'name' => __( 'Interior Posts' ), | |
'singular_name' => __( 'Interior' ) | |
); | |
$conf['rewrite'] = array('slug' => 'interior'); | |
register_post_type( 'interior_subpage',$conf); | |
} | |
// remove posts menu since it's not in use | |
function remove_menus () { | |
global $menu; | |
$restricted = array(__('Posts')); | |
end ($menu); | |
while (prev($menu)){ | |
$value = explode(' ',$menu[key($menu)][0]); | |
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);} | |
} | |
} | |
add_action('admin_menu', 'remove_menus'); | |
/* Define the custom box */ | |
add_action( 'add_meta_boxes', 'wpse_61041_add_custom_box' ); | |
/* Do something with the data entered */ | |
add_action( 'save_post', 'wpse_61041_save_postdata' ); | |
/* Adds a box to the main column on the Post and Page edit screens */ | |
function wpse_61041_add_custom_box() { | |
add_meta_box( | |
'wpse_61041_sectionid', | |
'Publish in Menu', | |
'wpse_61041_inner_custom_box', | |
'architect_subpage', | |
'side', | |
'high' | |
); | |
} | |
/* Prints the box content */ | |
function wpse_61041_inner_custom_box($post) | |
{ | |
// Use nonce for verification | |
wp_nonce_field( 'wpse_61041_wpse_61041_field_nonce', 'wpse_61041_noncename' ); | |
// Get saved value, if none exists, "default" is selected | |
$saved = get_post_meta( $post->ID, 'in_menu', true); | |
if( !$saved ) | |
$saved = 'no'; | |
$fields = array( | |
'yes' => __('Yes', 'wpse'), | |
'no' => __('No', 'wpse'), | |
); | |
foreach($fields as $key => $label) | |
{ | |
printf( | |
'<input type="radio" name="in_menu" value="%1$s" id="in_menu[%1$s]" %3$s />'. | |
'<label for="in_menu[%1$s]"> %2$s ' . | |
'</label><br>', | |
esc_attr($key), | |
esc_html($label), | |
checked($saved, $key, false) | |
); | |
} | |
} | |
/* When the post is saved, saves our custom data */ | |
function wpse_61041_save_postdata( $post_id ) | |
{ | |
// verify if this is an auto save routine. | |
// If it is our form has not been submitted, so we dont want to do anything | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
return; | |
// verify this came from the our screen and with proper authorization, | |
// because save_post can be triggered at other times | |
if ( !wp_verify_nonce( $_POST['wpse_61041_noncename'], 'wpse_61041_wpse_61041_field_nonce' ) ) | |
return; | |
if ( isset($_POST['in_menu']) && $_POST['in_menu'] != "" ){ | |
update_post_meta( $post_id, 'in_menu', $_POST['in_menu'] ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment