/******************************************************************************/
/* Metaboxes */
function add_banner_link_metabox(){
$id = "link";
$title = "Link do Banner";
$callback = "add_banner_link_inner_metabox";
$post_types = array("slide");
foreach($post_types as $post_type) {
add_meta_box(
$id,
$title,
$callback,
$post_type
);
}
}
add_action('add_meta_boxes', 'add_banner_link_metabox');
function add_banner_link_inner_metabox($post) {
wp_nonce_field('add_banner_link_inner_metabox', 'add_banner_link_inner_metabox_nonce');
$value = get_post_meta($post->ID, 'link', true);
echo '<label for="link">';
_e( "Link do Banner", 'textdomain' );
echo '</label> ';
echo '<input type="text" id="link" name="link" value="' . esc_attr($value) . '" size="44" />';
}
function add_banner_link_save_postdata( $post_id ) {
if ( ! isset( $_POST['add_banner_link_inner_metabox_nonce'] ) )
return $post_id;
$nonce = $_POST['add_banner_link_inner_metabox_nonce'];
if ( ! wp_verify_nonce( $nonce, 'add_banner_link_inner_metabox' ) )
return $post_id;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
if ( 'page' == $_POST['superbanner'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
$mydata = sanitize_text_field( $_POST['link'] );
update_post_meta( $post_id, 'link', $mydata );
}
add_action( 'save_post', 'add_banner_link_save_postdata' );
banners_link_metabox
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.