post_type, array( 'page' ), true ) ) { return; } if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } if ( wp_is_post_revision( $post ) ) { return; } $hide_title = array_key_exists( 'pressbook_hide_title', $_POST ) ? (bool) $_POST['pressbook_hide_title'] : self::get_meta_default( 'hide_title' ); $no_t_margin = array_key_exists( 'pressbook_no_t_margin', $_POST ) ? (bool) $_POST['pressbook_no_t_margin'] : self::get_meta_default( 'no_t_margin' ); $no_b_margin = array_key_exists( 'pressbook_no_b_margin', $_POST ) ? (bool) $_POST['pressbook_no_b_margin'] : self::get_meta_default( 'no_b_margin' ); $no_t_padding = array_key_exists( 'pressbook_no_t_padding', $_POST ) ? (bool) $_POST['pressbook_no_t_padding'] : self::get_meta_default( 'no_t_padding' ); $no_b_padding = array_key_exists( 'pressbook_no_b_padding', $_POST ) ? (bool) $_POST['pressbook_no_b_padding'] : self::get_meta_default( 'no_b_padding' ); $no_x_padding = array_key_exists( 'pressbook_no_x_padding', $_POST ) ? (bool) $_POST['pressbook_no_x_padding'] : self::get_meta_default( 'no_x_padding' ); $transparent_bg = array_key_exists( 'pressbook_transparent_bg', $_POST ) ? (bool) $_POST['pressbook_transparent_bg'] : self::get_meta_default( 'transparent_bg' ); if ( metadata_exists( 'post', $post_id, self::META_KEY ) || // Add meta key only if any of the setting is not same as the default setting. ( ( self::get_meta_default( 'hide_title' ) !== $hide_title ) || ( self::get_meta_default( 'no_t_margin' ) !== $no_t_margin ) || ( self::get_meta_default( 'no_b_margin' ) !== $no_b_margin ) || ( self::get_meta_default( 'no_t_padding' ) !== $no_t_padding ) || ( self::get_meta_default( 'no_b_padding' ) !== $no_b_padding ) || ( self::get_meta_default( 'no_x_padding' ) !== $no_x_padding ) || ( self::get_meta_default( 'transparent_bg' ) !== $transparent_bg ) ) ) { update_post_meta( $post_id, self::META_KEY, array( 'hide_title' => $hide_title, 'no_t_margin' => $no_t_margin, 'no_b_margin' => $no_b_margin, 'no_t_padding' => $no_t_padding, 'no_b_padding' => $no_b_padding, 'no_x_padding' => $no_x_padding, 'transparent_bg' => $transparent_bg, ) ); } } /** * Metabox HTML output. * * @param WP_Post $post post object. */ public function metabox_html( $post ) { $settings = self::get_meta( $post->ID ); $nonce_key = ( 'pressbook_settings_nonce_' . $post->ID ); ?>

id="pressbook_hide_title" type="checkbox" name="pressbook_hide_title" value="1">

id="pressbook_no_t_margin" type="checkbox" name="pressbook_no_t_margin" value="1">

id="pressbook_no_b_margin" type="checkbox" name="pressbook_no_b_margin" value="1">

id="pressbook_no_t_padding" type="checkbox" name="pressbook_no_t_padding" value="1">

id="pressbook_no_b_padding" type="checkbox" name="pressbook_no_b_padding" value="1">

id="pressbook_no_x_padding" type="checkbox" name="pressbook_no_x_padding" value="1">

id="pressbook_transparent_bg" type="checkbox" name="pressbook_transparent_bg" value="1">

false, 'no_t_margin' => false, 'no_b_margin' => false, 'no_t_padding' => false, 'no_b_padding' => false, 'no_x_padding' => false, 'transparent_bg' => false, ) ); if ( array_key_exists( $key, $default ) ) { return $default[ $key ]; } return $default; } /** * Get meta settings for template parts. * * @param int $id Post ID. * @return array */ public static function get_meta_config( $id ) { $meta = self::get_meta( $id ); if ( $meta['no_t_margin'] ) { $wrapper_class = ' no-t-margin'; } else { $wrapper_class = ''; } $site_main_class = ''; if ( $meta['no_b_margin'] ) { $site_main_class .= ' no-b-margin'; } if ( $meta['no_t_padding'] ) { $site_main_class .= ' no-t-padding'; } if ( $meta['no_b_padding'] ) { $site_main_class .= ' no-b-padding'; } if ( $meta['no_x_padding'] ) { $site_main_class .= ' no-x-padding'; } if ( $meta['transparent_bg'] ) { $site_main_class .= ' u-transparent-bg'; } return array( 'page_content' => ( $meta['hide_title'] ? 'page-no-title' : 'page' ), 'wrapper_class' => $wrapper_class, 'site_main_class' => $site_main_class, ); } }