init();
// Add Actions
$this->add_actions();
// End Trigger
shapeshifter_trigger_admin_metaboxes();
}
/**
* Setup Vars
**/
function init() {
$this->icons = get_option( SHAPESHIFTER_THEME_OPTIONS . 'icons_array' );
}
/**
* Add Actions
**/
function add_actions() {
// CSS JS Enqueues
add_action( 'admin_enqueue_scripts', array( $this, 'meta_boxes_enqueue_scripts' ) );
// Metaboxes Forms
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
add_action( 'save_post', array( $this, 'save_meta_box_settings' ) );
}
/**
* CSS JS Enqueues
*
* @param string $hook
**/
function meta_boxes_enqueue_scripts( $hook ) {
if ( in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
wp_enqueue_media();
# CSS
wp_enqueue_style( 'shapeshifter-meta-boxes' );
# JS
wp_enqueue_script( 'shapeshifter-meta-boxes' );
}
}
/**
* Add Meta Boxes
*
* @param string $post_type : Default Empty String ""
* @param object $post : Default Empty String ""
**/
function add_meta_boxes( $post_type = '', $post = '' ) {
if ( empty( $post_type ) ) return;
// FontAwesome Icons for H1~H6
add_meta_box(
SHAPESHIFTER_THEME_PREFIX . 'headline-icons-meta-box',
sprintf( esc_html__( '%s Settings for Title and Headlines', 'shapeshifter' ), SHAPESHIFTER_THEME_NAME ),
array( $this, 'headline_icons_meta_box_handle_callback' ),
$post_type,
'side',
'low',
array()
);
// Deactivation of Widget Areas
add_meta_box(
SHAPESHIFTER_THEME_PREFIX . 'deactivate-widget-areas-by-hook-meta-box',
sprintf( esc_html__( '%s Settings for Deactivation of Widget Areas', 'shapeshifter' ), SHAPESHIFTER_THEME_NAME ),
array( $this, 'settins_to_deactivate_widget_area' ),
$post_type,
'advanced',
'high',
array()
);
// For One Column Page Width Size Check
add_meta_box(
SHAPESHIFTER_THEME_PREFIX . 'optional-styles-for-the-page',
esc_html__( 'Optional Styles', 'shapeshifter' ),
array( $this, 'optional_styles_for_the_page' ),
$post_type,
'side',
'high',
array()
);
}
/**
* Save Posts
*
* @param int $post_id
**/
function save_meta_box_settings( $post_id ) {
// FontAwesome Icons
$this->save_fa_icons_meta_box_settings( $post_id );
// Deactivation of Widget Areas
$this->save_to_deactivate_widget_area( $post_id );
// For One Column Page Width Size Check
$this->save_to_setting_one_column_page_width_size( $post_id );
}
// Icons Settings
/**
* Print Meta Box Form for Headline Icons
*
* @param object $post
* @param array $args : Empty Array
**/
function headline_icons_meta_box_handle_callback( $post, $args = array() ) {
// From Saved Theme Mods Values
// Get
$theme_mods =ShapeShifter_Theme_Mods::get_theme_mods( SHAPESHIFTER_MAYBE_CHILD_THEME_OPTIONS );
// Headlines List
$headlines = array(
'h1' => esc_html__( 'Title', 'shapeshifter' ),//タイãã«
'h2' => 'h2',
'h3' => 'h3',
'h4' => 'h4',
'h5' => 'h5',
'h6' => 'h6'
);
// Default Values of Icon Select
$icon_def = array(
'h1' => (
( $theme_mods[ 'singular_page_h1_fontawesome_icon_select' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h1_fontawesome_icon_select' ] )
: 'f1b2'
),
'h2' => (
( $theme_mods[ 'singular_page_h2_fontawesome_icon_select' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h2_fontawesome_icon_select' ] )
: 'f04b'
),
'h3' => (
( $theme_mods[ 'singular_page_h3_fontawesome_icon_select' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h3_fontawesome_icon_select' ] )
: 'f0d0'
),
'h4' => (
( $theme_mods[ 'singular_page_h4_fontawesome_icon_select' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h4_fontawesome_icon_select' ] )
: 'none'
),
'h5' => (
( $theme_mods[ 'singular_page_h5_fontawesome_icon_select' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h5_fontawesome_icon_select' ] )
: 'none'
),
'h6' => (
( $theme_mods[ 'singular_page_h6_fontawesome_icon_select' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h6_fontawesome_icon_select' ] )
: 'none'
)
);
// Default Values of Icon Color
$color_def = array(
'h1' => (
( $theme_mods[ 'singular_page_h1_fontawesome_icon_color' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h1_fontawesome_icon_color' ] )
: '#000000'
),
'h2' => (
( $theme_mods[ 'singular_page_h2_fontawesome_icon_color' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h2_fontawesome_icon_color' ] )
: '#000000'
),
'h3' => (
( $theme_mods[ 'singular_page_h3_fontawesome_icon_color' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h3_fontawesome_icon_color' ] )
: '#000000'
),
'h4' => (
( $theme_mods[ 'singular_page_h4_fontawesome_icon_color' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h4_fontawesome_icon_color' ] )
: '#000000'
),
'h5' => (
( $theme_mods[ 'singular_page_h5_fontawesome_icon_color' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h5_fontawesome_icon_color' ] )
: '#000000'
),
'h6' => (
( $theme_mods[ 'singular_page_h6_fontawesome_icon_color' ] )
? sanitize_text_field( $theme_mods[ 'singular_page_h6_fontawesome_icon_color' ] )
: '#000000'
)
);
// Nonce
wp_nonce_field( 'meta_icons_box', 'meta_icons_box_nonce' );
// Saved Value of Icon Mods Bool
$is_fa_icons_mods_on = esc_attr(
get_post_meta(
$post->ID,
SHAPESHIFTER_THEME_POST_META . 'is_fa_icons_mods_on',
true
)
);
// Checkbox for Icon Mod
echo '
';//
echo '
';
// Each Headline
foreach( $headlines as $hl => $hl_val ) {
# Vars
# Icon Select
$icon_select = (
sanitize_text_field( get_post_meta( $post->ID, SHAPESHIFTER_THEME_POST_META . $hl . '_icons_select', true ) )
? sanitize_text_field( get_post_meta( $post->ID, SHAPESHIFTER_THEME_POST_META . $hl . '_icons_select', true ) )
: sanitize_text_field( $icon_def[ $hl ] )
);
# Icon Color
$color_val = (
sanitize_text_field( get_post_meta( $post->ID, SHAPESHIFTER_THEME_POST_META . $hl . '_icons_color', true ) )
? sanitize_text_field( get_post_meta( $post->ID, SHAPESHIFTER_THEME_POST_META . $hl . '_icons_color', true ) )
: sanitize_text_field( $color_def[ $hl ] )
);
# Icon Select
echo '
';
echo '
';
# Icon Colors
echo '
';
echo '
';
}
}
/**
* Save the Settings
*
* @param int $post_id
**/
function save_fa_icons_meta_box_settings( $post_id ) {
// Prepare
if ( ! isset( $_POST[ 'meta_icons_box_nonce' ] ) ) {
return;
}
if ( ! wp_verify_nonce( $_POST[ 'meta_icons_box_nonce' ], 'meta_icons_box' ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( isset( $_POST[ 'post_type' ] ) && 'page' == $_POST[ 'post_type' ] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// Icon Mods Bool
$my_data = sanitize_text_field(
isset( $_POST[ SHAPESHIFTER_THEME_POST_META . 'is_fa_icons_mods_on' ] )
? $_POST[ SHAPESHIFTER_THEME_POST_META . 'is_fa_icons_mods_on' ]
: ''
);
update_post_meta( $post_id, SHAPESHIFTER_THEME_POST_META . 'is_fa_icons_mods_on', $my_data );
// Each Headlines
$headlines = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' );
foreach( $headlines as $hl ) {
// Icon Select
$my_data = sanitize_text_field(
isset( $_POST[ SHAPESHIFTER_THEME_POST_META . $hl . '_icons_select' ] )
? $_POST[ SHAPESHIFTER_THEME_POST_META . $hl . '_icons_select' ]
: 'none'
);
update_post_meta( $post_id, SHAPESHIFTER_THEME_POST_META . $hl . '_icons_select', $my_data );
// Icon Color
$my_data = sanitize_text_field(
isset( $_POST[ SHAPESHIFTER_THEME_POST_META . $hl . '_icons_color' ] )
? $_POST[ SHAPESHIFTER_THEME_POST_META . $hl . '_icons_color' ]
: ''
);
update_post_meta( $post_id, SHAPESHIFTER_THEME_POST_META . $hl . '_icons_color', $my_data );
}
}
// Deactivations of Widget Areas
/**
* Print Meta Box Form for Deactivate Widget Area
*
* @param object $post
* @param array $args : Empty Array
**/
function settins_to_deactivate_widget_area( $post, $args = array() ) {
global $wp_registered_sidebars;
//echo '
'; var_dump( $wp_registered_sidebars ); echo ''; # Nonce wp_nonce_field( SHAPESHIFTER_THEME_PREFIX . 'save_to_deactivate_widget_area', SHAPESHIFTER_THEME_PREFIX . 'deactivate_widget_area_meta_box_nonce' ); # Saved Value of Deactivation of Widget Areas $deactivate_widget_area = ( is_array( get_post_meta( $post->ID, SHAPESHIFTER_THEME_POST_META . 'deactivate_widget_area', true ) ) ? get_post_meta( $post->ID, SHAPESHIFTER_THEME_POST_META . 'deactivate_widget_area', true ) : array() ); # Description esc_html_e( 'Check the widget areas to Deactivate.', 'shapeshifter' ); # Form Table Start echo '
'; echo ''; echo ' | '; echo ''; echo ''; echo ' | '; echo '
---|