| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- function page_options_meta() {
- add_meta_box( 'page_option', esc_html__( 'Page Options', 'taskereasy' ), 'page_option_meta', 'page', 'normal', 'high' );
- }
- add_action( 'add_meta_boxes', 'page_options_meta' );
- /**
- * Outputs the content of the meta box
- */
- function page_option_meta( $post ) {
- wp_nonce_field( basename( __FILE__ ), 'pageopt_nonce' );
- $pagopt_stored_meta = get_post_meta( $post->ID );
- ?>
- <p>
- <span class="pageopt-row-title"><?php _e( 'Check if hide page banner: ', 'taskereasy' )?></span>
- <div class="pageopt-row-content">
- <label for="featured-checkbox">
- <input type="checkbox" name="page-banner" id="page-banner" value="yes" <?php if ( isset ( $pagopt_stored_meta['page-banner'] ) ) checked( $pagopt_stored_meta['page-banner'][0], 'yes' ); ?> />
- <?php _e( 'Hide Page Banner', 'taskereasy' )?>
- </label>
- </div>
- </p>
- <?php
- }
- /**
- * Saves the custom meta input
- */
- function pageopt_meta_save( $post_id ) {
- // Checks save status - overcome autosave, etc.
- $is_autosave = wp_is_post_autosave( $post_id );
- $is_revision = wp_is_post_revision( $post_id );
- $is_valid_nonce = ( isset( $_POST[ 'pageopt_nonce' ] ) && wp_verify_nonce( $_POST[ 'pageopt_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
- // Exits script depending on save status
- if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
- return;
- }
- // Checks for input and saves - save checked as yes and unchecked at no
- if( isset( $_POST[ 'page-banner' ] ) ) {
- update_post_meta( $post_id, 'page-banner', 'yes' );
- } else {
- update_post_meta( $post_id, 'page-banner', 'no' );
- }
- }
- add_action( 'save_post', 'pageopt_meta_save' );
|