Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Register Metabox
- */
- function themeplate_register_metabox() {
- add_meta_box(
- 'post-settings',
- 'Post Settings',
- 'themeplate_post_settings_metabox',
- 'post',
- 'side',
- 'high'
- );
- }
- add_action( 'admin_init', 'themeplate_register_metabox' );
- /*
- * Post Settings Metabox
- */
- function themeplate_post_settings_metabox( $post ) {
- // wp security check
- wp_nonce_field( 'post_meta_nonce_', 'post_nonce_' );
- $sportlight_post= get_post_meta($post->ID, 'sportlight_on', true);
- ?>
- <div class="metabox-section">
- <p>
- <label for="sportlight_on">
- <input type="checkbox" name="sportlight_on" id="sportlight_on" value="on" <?php if ('on' == $sportlight_post) echo 'checked="checked"'; ?>>
- <b><?php echo esc_html__( 'SPOTLIGHT ON', 'themeplate' ) ?></b></label>
- </p>
- </div>
- <?php
- }
- function themeplate_save_postmeta( $post_id ) {
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return;
- }
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
- return;
- }
- if ( 'post' !== get_post_type( $post_id ) ) {
- return;
- }
- // security check
- if ( ! isset( $_POST['post_nonce_'] ) ) {
- return;
- }
- if ( ! wp_verify_nonce( $_POST['post_nonce_'], 'post_meta_nonce_' ) ) {
- return;
- }
- update_post_meta( $post_id, 'sportlight_on', empty( $_POST['sportlight_on'] ) ? '' : $_POST['sportlight_on'] );
- }
- add_action( 'save_post', 'themeplate_save_postmeta' );
Add Comment
Please, Sign In to add comment