' . sprintf( wp_kses( /* translators: %1$s: link to customizer, %2$s section name */ __( 'Theme options for this page can be found in Appearance -> Customize -> %2$s.', 'bicycleshop' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( admin_url( '/customize.php?autofocus[panel]=section_blog_layout' ) ), esc_html__( 'Blog settings', 'bicycleshop' ) ) . '

'; } function bicycleshop__no_meta_shop_page_notice() { echo '

' . sprintf( wp_kses( /* translators: %1$s: link to customizer, %2$s section name */ __( 'Theme options for this page can be found in Appearance -> Customize -> %2$s.', 'bicycleshop' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( admin_url( '/customize.php?autofocus[panel]=section_shop_general' ) ), esc_html__( 'Shop(WooCommerce) settings', 'bicycleshop' ) ) . '

'; } /** * Meta boxes in different post types */ function bicycleshop_admin_meta_boxes(){ global $bicycleshop_a13; if(current_user_can( 'edit_posts' )){ add_meta_box( 'sktwb_theme_options', __( 'Blog post details', 'bicycleshop' ), 'bicycleshop_meta_main_opts', 'post', 'normal', 'default', array('func' => 'bicycleshop_meta_boxes_post')//callback ); } if(current_user_can( 'edit_pages' )){ //don't display page metaboxes on special pages $current_page_id = get_the_ID(); //blog page if($current_page_id == get_option( 'page_for_posts' )){ add_meta_box( 'sktwb_theme_options_notice', __( 'Page details', 'bicycleshop' ), 'bicycleshop__no_meta_posts_page_notice', 'page', 'normal', 'default' ); } //shop page elseif(bicycleshop_is_woocommerce_activated() &&( $current_page_id == wc_get_page_id( 'shop' ) )){ add_meta_box( 'sktwb_theme_options_notice', __( 'Page details', 'bicycleshop' ), 'bicycleshop__no_meta_shop_page_notice', 'page', 'normal', 'default' ); } else{ add_meta_box( 'sktwb_theme_options', __( 'Page details', 'bicycleshop' ), 'bicycleshop_meta_main_opts', 'page', 'normal', 'default', array('func' => 'bicycleshop_meta_boxes_page')//callback ); } } } add_action( 'add_meta_boxes', 'bicycleshop_admin_meta_boxes'); /** * Generates inputs in meta boxes * * @param object $post * @param array $meta_box */ function bicycleshop_meta_main_opts( $post, $meta_box ){ // Use nonce for verification wp_nonce_field( 'sktwb_customization' , 'sktwb_noncename' ); $input_prefix = BICYCLESHOP_INPUT_PREFIX; /** @noinspection PhpIncludeInspection */ require_once get_template_directory() . '/advance/meta.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound $callback_name = $meta_box['args']['func']; $meta_boxes = $callback_name(); //collect defaults if it is "new post" page global $pagenow, $bicycleshop_a13; if('post-new.php' == $pagenow ) { foreach ( $meta_boxes as $meta_tab ) { foreach( $meta_tab as $meta ) { if( isset( $meta['id'] ) ){ $bicycleshop_a13->defaults_of_meta[ $meta['id'] ] = isset( $meta['default'] ) ? $meta['default'] : ''; } } } unset($meta);// be safe, don't loose your hair :-) } $fieldset_open = false; $tabs_to_create = array(); echo '
'; foreach ( $meta_boxes as $meta_tab ) { foreach( $meta_tab as $meta ) { //ASSIGNING VALUE $value = ''; if ( isset( $meta['id'] ) ){ //get value $value = get_post_meta($post->ID, '_'.$meta['id'] , true); //use default if no value if( !strlen($value) ){ $value = ( isset( $meta['default'] )? $meta['default'] : '' ); } } $params = array( 'style' => '', 'value' => $value ); /* * print tag according to type */ if ( $meta['type'] === 'fieldset' ) { if ( $fieldset_open ) { echo '
'; } $class = 'fieldset static'; if( isset( $meta['is_prototype'] ) ){ $class .= ' prototype'; } if( isset( $meta['tab'] ) && $meta['tab'] === true ){ $class .= ' fieldset_tab'; $tabs_to_create[] = $meta; } echo '
'; if( isset( $meta['notice'] ) && strlen($meta['notice']) ){ echo '

'.wp_kses_data($meta['notice']).'

'; } //companion plugin is needed if( isset( $meta['companion_required'] ) && $meta['companion_required'] === true ){ bicycleshop_is_companion_plugin_ready(); } $fieldset_open = true; } //checks for all normal options elseif( bicycleshop_print_form_controls($meta, $params, true ) ){ continue; } /*********************************************** * SPECIAL field types ************************************************/ elseif ( $meta['type'] === 'multi-upload' ) { ?>
/> Ctrl(Cmd) or Shift key while selecting them with mouse.', 'bicycleshop' )); ?>
' . esc_textarea( $value ) . ''; //prototype of single linked item echo '
'; //hide item bicycleshop_admin_gallery_item_html( 'attachment-preview image', 'thumbnail', get_theme_file_uri( 'images/holders/video_150x100.png') ); echo '
'; ?> '; } echo '
';//.sktwb-settings .sktwb-metas if(count($tabs_to_create)){ echo ''; } echo '
'; } /** * Saving meta's in post * * @param int $post_id */ function bicycleshop_save_post($post_id){ static $done = 0; $done++; if( $done > 1 ){ return;//no double saving same things } $input_prefix = BICYCLESHOP_INPUT_PREFIX; // verify if this is an auto save routine. // If it is our form has not been submitted, so we do not 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( ! isset( $_POST['sktwb_noncename'] ) ) return; if ( !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['sktwb_noncename'] ) ), 'sktwb_customization' ) ) return; //lets get all fields that need to be saved /** @noinspection PhpIncludeInspection */ require_once get_template_directory() . '/advance/meta.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound $meta_boxes = array(); if( isset( $_POST['post_type'] ) ){ switch( sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ){ case 'post': $meta_boxes = bicycleshop_meta_boxes_post(); break; case 'page': $meta_boxes = bicycleshop_meta_boxes_page(); break; } //saving meta $is_prototype = false; foreach ( $meta_boxes as $meta_tab ) { foreach( $meta_tab as $meta ) { //check is it prototype if ( $meta['type'] === 'fieldset' ) { if( isset( $meta['is_prototype'] ) ){ $is_prototype = true; } else{ $is_prototype = false; } continue; } //don't save fields of prototype if($is_prototype){ continue; } if( isset( $meta['id'] ) && isset( $_POST[ $input_prefix . $meta['id'] ] ) ){ $val = sanitize_text_field( wp_unslash( $_POST[ $input_prefix . $meta['id'] ] ) ); update_post_meta( $post_id, '_' . $meta['id'], apply_filters( 'bicycleshop_save_post_meta', $val, $meta['id'] ) ); } } } } } add_action( 'save_post', 'bicycleshop_save_post' );