' .
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.', 'posterity' ),
array(
'a' => array(
'href' => array()
)
)
),
esc_url( admin_url( '/customize.php?autofocus[panel]=section_blog_layout' ) ),
esc_html__( 'Blog settings', 'posterity' )
) . '
';
}
function posterity__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.', 'posterity' ),
array(
'a' => array(
'href' => array()
)
)
),
esc_url( admin_url( '/customize.php?autofocus[panel]=section_shop_general' ) ),
esc_html__( 'Shop(WooCommerce) settings', 'posterity' )
) . '
';
}
/**
* Meta boxes in different post types
*/
function posterity_admin_meta_boxes(){
global $posterity_a13;
if(current_user_can( 'edit_posts' )){
add_meta_box(
'sktwb_theme_options',
__( 'Blog post details', 'posterity' ),
'posterity_meta_main_opts',
'post',
'normal',
'default',
array('func' => 'posterity_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', 'posterity' ),
'posterity__no_meta_posts_page_notice',
'page',
'normal',
'default'
);
}
//shop page
elseif(posterity_is_woocommerce_activated() &&( $current_page_id == wc_get_page_id( 'shop' ) )){
add_meta_box(
'sktwb_theme_options_notice',
__( 'Page details', 'posterity' ),
'posterity__no_meta_shop_page_notice',
'page',
'normal',
'default'
);
}
else{
add_meta_box(
'sktwb_theme_options',
__( 'Page details', 'posterity' ),
'posterity_meta_main_opts',
'page',
'normal',
'default',
array('func' => 'posterity_meta_boxes_page')//callback
);
}
}
}
add_action( 'add_meta_boxes', 'posterity_admin_meta_boxes');
/**
* Generates inputs in meta boxes
*
* @param object $post
* @param array $meta_box
*/
function posterity_meta_main_opts( $post, $meta_box ){
// Use nonce for verification
wp_nonce_field( 'sktwb_customization' , 'sktwb_noncename' );
$input_prefix = POSTERITY_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, $posterity_a13;
if('post-new.php' == $pagenow ) {
foreach ( $meta_boxes as $meta_tab ) {
foreach( $meta_tab as $meta ) {
if( isset( $meta['id'] ) ){
$posterity_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 '';//.sktwb-settings .sktwb-metas
if(count($tabs_to_create)){
echo '';
}
echo '
';
}
/**
* Saving meta's in post
*
* @param int $post_id
*/
function posterity_save_post($post_id){
static $done = 0;
$done++;
if( $done > 1 ){
return;//no double saving same things
}
$input_prefix = POSTERITY_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 = posterity_meta_boxes_post();
break;
case 'page':
$meta_boxes = posterity_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( 'posterity_save_post_meta', $val, $meta['id'] ) );
}
}
}
}
}
add_action( 'save_post', 'posterity_save_post' );