first commit
This commit is contained in:
96
inc/core/Options/AlphaColorControl.php
Normal file
96
inc/core/Options/AlphaColorControl.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Alpha color picker customizer control.
|
||||
*
|
||||
* This control adds a second slider for opacity to the stock WordPress color picker,
|
||||
* and it includes logic to seamlessly convert between RGBa and Hex color values as
|
||||
* opacity is added to or removed from a color.
|
||||
*
|
||||
* This Alpha Color Picker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this Alpha Color Picker. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use \WP_Customize_Control;
|
||||
|
||||
if ( class_exists( '\WP_Customize_Control' ) ) {
|
||||
/**
|
||||
* Alpha color picker control class.
|
||||
*/
|
||||
class AlphaColorControl extends WP_Customize_Control {
|
||||
/**
|
||||
* Control name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'alpha-color';
|
||||
|
||||
/**
|
||||
* Add support for palettes to be passed in.
|
||||
*
|
||||
* Supported palette values are true, false, or an array of RGBa and Hex colors.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $palette;
|
||||
|
||||
/**
|
||||
* Add support for showing the opacity value on the slider handle.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $show_opacity;
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles.
|
||||
*/
|
||||
public function enqueue() {
|
||||
wp_enqueue_style( 'alpha-color-picker', get_theme_file_uri( 'inc/alpha-color-picker.css' ), array( 'wp-color-picker' ), PRESSBOOK_VERSION );
|
||||
|
||||
wp_enqueue_script( 'alpha-color-picker', get_theme_file_uri( 'js/alpha-color-picker.js' ), array( 'jquery', 'wp-color-picker' ), PRESSBOOK_VERSION, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the control.
|
||||
*/
|
||||
public function render_content() {
|
||||
// Process the palette.
|
||||
if ( is_array( $this->palette ) ) {
|
||||
$palette = implode( '|', $this->palette );
|
||||
} else {
|
||||
// Default to true.
|
||||
$palette = ( ( false === $this->palette ) || ( 'false' === $this->palette ) ) ? 'false' : 'true';
|
||||
}
|
||||
|
||||
// Support passing show_opacity as string or boolean. Default to true.
|
||||
$show_opacity = ( ( false === $this->show_opacity ) || ( 'false' === $this->show_opacity ) ) ? 'false' : 'true';
|
||||
|
||||
// Output the label and description if they were passed in.
|
||||
if ( isset( $this->label ) && ( '' !== $this->label ) ) {
|
||||
echo '<span class="customize-control-title">' . esc_html( $this->label ) . '</span>';
|
||||
}
|
||||
if ( isset( $this->description ) && ( '' !== $this->description ) ) {
|
||||
echo '<span class="description customize-control-description">' . esc_html( $this->description ) . '</span>';
|
||||
}
|
||||
?>
|
||||
|
||||
<label>
|
||||
<input class="alpha-color-control" type="text" data-show-opacity="<?php echo esc_attr( $show_opacity ); ?>" data-palette="<?php echo esc_attr( $palette ); ?>" data-default-color="<?php echo esc_attr( $this->settings['default']->default ); ?>" <?php $this->link(); ?>>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
58
inc/core/Options/BlockSection.php
Normal file
58
inc/core/Options/BlockSection.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer block section base class.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
|
||||
/**
|
||||
* Base class for block section service classes.
|
||||
*/
|
||||
abstract class BlockSection extends Options {
|
||||
/**
|
||||
* Get an array of pattern-blocks formatted as [ ID => Title ].
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pattern_blocks_choices() {
|
||||
$pattern_blocks = get_posts(
|
||||
array(
|
||||
'post_type' => 'wp_block',
|
||||
'numberposts' => 100,
|
||||
)
|
||||
);
|
||||
|
||||
$pattern_blocks_choices = array( 0 => esc_html__( 'Select a block', 'pressbook' ) );
|
||||
foreach ( $pattern_blocks as $block ) {
|
||||
$pattern_blocks_choices[ $block->ID ] = $block->post_title;
|
||||
}
|
||||
|
||||
return $pattern_blocks_choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Block description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function block_description() {
|
||||
return wp_kses(
|
||||
sprintf(
|
||||
/* translators: %s: URL to the pattern-blocks admin page. */
|
||||
__( 'This is the content of the block section. You can create or edit the block section in the <a href="%s" target="_blank">Pattern Blocks Manager (opens in a new window)</a>.<br>After creating the pattern block, you may need to refresh this customizer page and then select the newly created block.<br>The selected block content will appear on the block section.', 'pressbook' ),
|
||||
esc_url( admin_url( 'edit.php?post_type=wp_block' ) )
|
||||
),
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
'br' => array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
493
inc/core/Options/Blog.php
Normal file
493
inc/core/Options/Blog.php
Normal file
@ -0,0 +1,493 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer blog options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Blog options service class.
|
||||
*/
|
||||
class Blog extends Options {
|
||||
/**
|
||||
* Add blog options for theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_blog( $wp_customize );
|
||||
|
||||
$this->set_archive_post_layout_lg( $wp_customize );
|
||||
|
||||
$this->set_archive_content( $wp_customize );
|
||||
|
||||
$this->set_show_archv_title( $wp_customize );
|
||||
|
||||
$this->set_hide_post_meta_all( $wp_customize );
|
||||
$this->set_hide_post_meta_date( $wp_customize );
|
||||
$this->set_hide_post_meta_author( $wp_customize );
|
||||
$this->set_hide_post_meta_cat( $wp_customize );
|
||||
$this->set_hide_post_meta_tag( $wp_customize );
|
||||
|
||||
$this->set_featured_label( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Blog Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_blog( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_blog',
|
||||
array(
|
||||
'title' => esc_html__( 'Blog Options', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the blog options in here.', 'pressbook' ),
|
||||
'priority' => 156,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Archive Post Layout (Large-Screen Devices).
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_archive_post_layout_lg( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_archive_post_layout_lg',
|
||||
array(
|
||||
'default' => self::get_archive_post_layout_lg( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_archive_post_layout_lg',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'radio',
|
||||
'choices' => array(
|
||||
'rows' => esc_html__( 'Thumbnail-Content - Rows', 'pressbook' ),
|
||||
'columns' => esc_html__( 'Thumbnail-Content - Columns (Contain)', 'pressbook' ),
|
||||
'cover' => esc_html__( 'Thumbnail-Content - Columns (Cover)', 'pressbook' ),
|
||||
),
|
||||
'label' => esc_html__( 'Blog Archive Post Layout (Large-Screen Devices)', 'pressbook' ),
|
||||
'description' => esc_html__( 'Select the layout for the blog post in archive pages. Default: Thumbnail-Content - Columns (Cover)', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Archive Post Layout (Large-Screen Devices).
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_archive_post_layout_lg( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_archive_post_layout_lg', 'cover' );
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_archive_post_layout_lg', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Archive Content.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_archive_content( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_archive_content',
|
||||
array(
|
||||
'default' => self::get_archive_content( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_archive_content',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'radio',
|
||||
'choices' => array(
|
||||
'full' => esc_html__( 'Full text', 'pressbook' ),
|
||||
'excerpt' => esc_html__( 'Summary', 'pressbook' ),
|
||||
),
|
||||
'label' => esc_html__( 'Blog Archive Content', 'pressbook' ),
|
||||
'description' => esc_html__( 'Select the content to show in the blog archive pages. Default: Summary', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Archive Content.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_archive_content( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_archive_content', 'excerpt' );
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_archive_content', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Show Archive Page Title.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_show_archv_title( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_show_archv_title',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_show_archv_title( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_show_archv_title',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show Archive Page Title', 'pressbook' ),
|
||||
'description' => esc_html__( 'In archive pages, you can show the archive title and archive description. This is applicable to any archive pages like tag, category, etc.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Show Archive Page Title.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return bool
|
||||
*/
|
||||
public static function get_show_archv_title( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_show_archive_title', true );
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_show_archv_title', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide Post Meta: All.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_hide_post_meta_all( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_hide_post_meta[all]',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_hide_post_meta_default( 'all' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_hide_post_meta[all]',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Post Meta: Hide All', 'pressbook' ),
|
||||
'description' => esc_html__( 'Hide all the post meta data including date, author, number of comments, etc.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide Post Meta: Date.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_hide_post_meta_date( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_hide_post_meta[date]',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_hide_post_meta_default( 'date' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_hide_post_meta[date]',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Post Meta: Hide Date', 'pressbook' ),
|
||||
'description' => esc_html__( 'Hide only the post date. Checking the "Post Meta: Hide All" option will override this option.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide Post Meta: Author.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_hide_post_meta_author( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_hide_post_meta[author]',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_hide_post_meta_default( 'author' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_hide_post_meta[author]',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Post Meta: Hide Author', 'pressbook' ),
|
||||
'description' => esc_html__( 'Hide only the post author. Checking the "Post Meta: Hide All" option will override this option.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide Post: Hide Categories.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_hide_post_meta_cat( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_hide_post_meta[cat]',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_hide_post_meta_default( 'cat' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_hide_post_meta[cat]',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Post: Hide Categories', 'pressbook' ),
|
||||
'description' => esc_html__( 'Hide the post categories.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide Post: Hide Tags.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_hide_post_meta_tag( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_hide_post_meta[tag]',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_hide_post_meta_default( 'tag' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_hide_post_meta[tag]',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Post: Hide Tags', 'pressbook' ),
|
||||
'description' => esc_html__( 'Hide the post tags.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Hide Post Meta.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_hide_post_meta() {
|
||||
return wp_parse_args(
|
||||
get_theme_mod( 'set_hide_post_meta', array() ),
|
||||
self::get_hide_post_meta_default()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Hide Post Meta.
|
||||
*
|
||||
* @param string $key Setting key.
|
||||
* @return mixed|array
|
||||
*/
|
||||
public static function get_hide_post_meta_default( $key = '' ) {
|
||||
$default = apply_filters(
|
||||
'pressbook_default_hide_post_meta',
|
||||
array(
|
||||
'all' => false,
|
||||
'date' => false,
|
||||
'author' => false,
|
||||
'cat' => false,
|
||||
'tag' => false,
|
||||
)
|
||||
);
|
||||
|
||||
if ( array_key_exists( $key, $default ) ) {
|
||||
return $default[ $key ];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Featured (Sticky Post) Label.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_featured_label( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_featured_label',
|
||||
array(
|
||||
'default' => self::get_featured_label( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_featured_label',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'text',
|
||||
'label' => esc_html__( 'Featured (Sticky Post) Label', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can change the "Featured" label for the sticky posts. Leave it empty for default text.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Featured (Sticky Post) Label.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_featured_label( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_featured_label', '' );
|
||||
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_featured_label', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text: Featured (Sticky Post) Label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function featured_label_text() {
|
||||
$label = self::get_featured_label();
|
||||
if ( '' !== $label ) {
|
||||
return $label;
|
||||
}
|
||||
|
||||
return esc_html_x( 'Featured', 'Label for sticky posts', 'pressbook' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entry meta class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function entry_meta_class() {
|
||||
$hide_post_meta = self::get_hide_post_meta();
|
||||
|
||||
$entry_meta_class = 'entry-meta';
|
||||
if ( $hide_post_meta['all'] ) {
|
||||
$entry_meta_class .= ' hide-entry-meta';
|
||||
}
|
||||
if ( $hide_post_meta['date'] ) {
|
||||
$entry_meta_class .= ' hide-posted-on';
|
||||
}
|
||||
if ( $hide_post_meta['author'] ) {
|
||||
$entry_meta_class .= ' hide-posted-by';
|
||||
}
|
||||
|
||||
return apply_filters( 'pressbook_entry_meta_class', $entry_meta_class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entry meta categories class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function entry_meta_cat_class() {
|
||||
$hide_post_meta = self::get_hide_post_meta();
|
||||
|
||||
$entry_meta_cat_class = 'cat-links';
|
||||
if ( $hide_post_meta['cat'] ) {
|
||||
$entry_meta_cat_class .= ' hide-clip';
|
||||
}
|
||||
|
||||
return apply_filters( 'pressbook_entry_meta_cat_class', $entry_meta_cat_class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entry meta tags class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function entry_meta_tag_class() {
|
||||
$hide_post_meta = self::get_hide_post_meta();
|
||||
|
||||
$entry_meta_tag_class = 'tag-links';
|
||||
if ( $hide_post_meta['tag'] ) {
|
||||
$entry_meta_tag_class .= ' hide-clip';
|
||||
}
|
||||
|
||||
return apply_filters( 'pressbook_entry_meta_tag_class', $entry_meta_tag_class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get archive title class and option.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function archv_title() {
|
||||
$show_archv_title = self::get_show_archv_title();
|
||||
$archv_title_class = 'page-title';
|
||||
$archv_header_class = 'pb-archv-header';
|
||||
if ( $show_archv_title ) {
|
||||
$archv_title_class .= ' pb-archv-title';
|
||||
$archv_header_class .= ' pb-archv-header-show';
|
||||
} else {
|
||||
$archv_title_class .= ' screen-reader-text';
|
||||
}
|
||||
|
||||
return array(
|
||||
'show' => $show_archv_title,
|
||||
'class' => apply_filters( 'pressbook_archv_title_class', $archv_title_class ),
|
||||
'header' => apply_filters( 'pressbook_archv_header_class', $archv_header_class ),
|
||||
);
|
||||
}
|
||||
}
|
194
inc/core/Options/Colors.php
Normal file
194
inc/core/Options/Colors.php
Normal file
@ -0,0 +1,194 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer colors options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Colors options service class.
|
||||
*/
|
||||
class Colors extends Options {
|
||||
/**
|
||||
* Add colors options for the theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->set_header_bg_color( $wp_customize );
|
||||
$this->set_site_title_color( $wp_customize );
|
||||
$this->set_tagline_color( $wp_customize );
|
||||
|
||||
$this->set_button_bg_color_1( $wp_customize );
|
||||
$this->set_button_bg_color_2( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Header Background Color.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_header_bg_color( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[header_bg_color]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'header_bg_color' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_alpha_color' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new AlphaColorControl(
|
||||
$wp_customize,
|
||||
'set_styles[header_bg_color]',
|
||||
array(
|
||||
'section' => 'colors',
|
||||
'label' => esc_html__( 'Header Background Color', 'pressbook' ),
|
||||
'settings' => 'set_styles[header_bg_color]',
|
||||
'palette' => self::default_alpha_palette(),
|
||||
'show_opacity' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Site Title Color.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_site_title_color( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[site_title_color]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'site_title_color' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => 'sanitize_hex_color',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'set_styles[site_title_color]',
|
||||
array(
|
||||
'section' => 'colors',
|
||||
'label' => esc_html__( 'Site Title Color', 'pressbook' ),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Tagline Color.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_tagline_color( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[tagline_color]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'tagline_color' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => 'sanitize_hex_color',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'set_styles[tagline_color]',
|
||||
array(
|
||||
'section' => 'colors',
|
||||
'label' => esc_html__( 'Tagline Color', 'pressbook' ),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Button Background Color 1.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_button_bg_color_1( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[button_bg_color_1]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'button_bg_color_1' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_alpha_color' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new AlphaColorControl(
|
||||
$wp_customize,
|
||||
'set_styles[button_bg_color_1]',
|
||||
array(
|
||||
'section' => 'colors',
|
||||
'label' => esc_html__( 'Button Gradient Background 1', 'pressbook' ),
|
||||
'settings' => 'set_styles[button_bg_color_1]',
|
||||
'palette' => true,
|
||||
'show_opacity' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Button Background Color 2.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_button_bg_color_2( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[button_bg_color_2]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'button_bg_color_2' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_alpha_color' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new AlphaColorControl(
|
||||
$wp_customize,
|
||||
'set_styles[button_bg_color_2]',
|
||||
array(
|
||||
'section' => 'colors',
|
||||
'label' => esc_html__( 'Button Gradient Background 2', 'pressbook' ),
|
||||
'settings' => 'set_styles[button_bg_color_2]',
|
||||
'palette' => true,
|
||||
'show_opacity' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default alpha color palette.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function default_alpha_palette() {
|
||||
return apply_filters(
|
||||
'pressbook_default_alpha_color_palette',
|
||||
array(
|
||||
'#ffffff',
|
||||
'#000000',
|
||||
'rgba(28,28,28,0.95)',
|
||||
'rgba(7,18,66,0.95)',
|
||||
'rgba(0,33,21,0.95)',
|
||||
'rgba(0,0,0,0.8)',
|
||||
'rgba(22,0,0,0.95)',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
176
inc/core/Options/Content.php
Normal file
176
inc/core/Options/Content.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer content layout options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
|
||||
/**
|
||||
* Content layout options service class.
|
||||
*/
|
||||
class Content extends Options {
|
||||
/**
|
||||
* Add content layout options for the theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_content( $wp_customize );
|
||||
|
||||
$this->set_content_layout_no_t_padding( $wp_customize );
|
||||
$this->set_content_layout_no_b_padding( $wp_customize );
|
||||
$this->set_content_layout_no_x_padding( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Content Layout Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_content( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_content',
|
||||
array(
|
||||
'title' => esc_html__( 'Content Layout', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the content layout options in here.', 'pressbook' ),
|
||||
'priority' => 154,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Remove Top Padding.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_content_layout_no_t_padding( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_content_layout[no_t_padding]',
|
||||
array(
|
||||
'default' => self::get_content_layout_default( 'no_t_padding' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_content_layout[no_t_padding]',
|
||||
array(
|
||||
'section' => 'sec_content',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Remove Top Padding', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Remove Bottom Padding.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_content_layout_no_b_padding( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_content_layout[no_b_padding]',
|
||||
array(
|
||||
'default' => self::get_content_layout_default( 'no_b_padding' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_content_layout[no_b_padding]',
|
||||
array(
|
||||
'section' => 'sec_content',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Remove Bottom Padding', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Remove Horizontal Padding.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_content_layout_no_x_padding( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_content_layout[no_x_padding]',
|
||||
array(
|
||||
'default' => self::get_content_layout_default( 'no_x_padding' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_content_layout[no_x_padding]',
|
||||
array(
|
||||
'section' => 'sec_content',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Remove Horizontal Padding', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Content Layout.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_content_layout() {
|
||||
return wp_parse_args(
|
||||
get_theme_mod( 'set_content_layout', array() ),
|
||||
self::get_content_layout_default()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Content Layout.
|
||||
*
|
||||
* @param string $key Setting key.
|
||||
* @return mixed|array
|
||||
*/
|
||||
public static function get_content_layout_default( $key = '' ) {
|
||||
$default = apply_filters(
|
||||
'pressbook_default_content_layout',
|
||||
array(
|
||||
'no_t_padding' => false,
|
||||
'no_b_padding' => false,
|
||||
'no_x_padding' => false,
|
||||
)
|
||||
);
|
||||
|
||||
if ( array_key_exists( $key, $default ) ) {
|
||||
return $default[ $key ];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get body classes for content layout.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_content_layout_body_class() {
|
||||
$content_layout = self::get_content_layout();
|
||||
|
||||
$body_class = '';
|
||||
if ( $content_layout['no_t_padding'] ) {
|
||||
$body_class .= ' content-no-t-padding';
|
||||
}
|
||||
if ( $content_layout['no_b_padding'] ) {
|
||||
$body_class .= ' content-no-b-padding';
|
||||
}
|
||||
if ( $content_layout['no_x_padding'] ) {
|
||||
$body_class .= ' content-no-x-padding';
|
||||
}
|
||||
|
||||
return ltrim( $body_class );
|
||||
}
|
||||
}
|
147
inc/core/Options/Fonts.php
Normal file
147
inc/core/Options/Fonts.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer fonts options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Fonts options service class.
|
||||
*/
|
||||
class Fonts extends Options {
|
||||
/**
|
||||
* Fonts choices.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $choices = array();
|
||||
|
||||
/**
|
||||
* Add fonts options for theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_fonts( $wp_customize );
|
||||
|
||||
$this->set_button_font_wgt( $wp_customize );
|
||||
$this->set_heading_font_wgt( $wp_customize );
|
||||
$this->set_site_title_font_wgt( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Fonts Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_fonts( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_fonts',
|
||||
array(
|
||||
'title' => esc_html__( 'Fonts', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the fonts options in here.', 'pressbook' ),
|
||||
'priority' => 42,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Button Font Weight.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_button_font_wgt( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[button_font_wgt]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'button_font_wgt' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_styles[button_font_wgt]',
|
||||
array(
|
||||
'section' => 'sec_fonts',
|
||||
'type' => 'select',
|
||||
'choices' => $this->font_weights(),
|
||||
'label' => esc_html__( 'Button Font Weight', 'pressbook' ),
|
||||
'description' => esc_html__( 'Default: 600', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Heading Font Weight.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_heading_font_wgt( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[heading_font_wgt]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'heading_font_wgt' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_styles[heading_font_wgt]',
|
||||
array(
|
||||
'section' => 'sec_fonts',
|
||||
'type' => 'select',
|
||||
'choices' => $this->font_weights(),
|
||||
'label' => esc_html__( 'Heading Font Weight', 'pressbook' ),
|
||||
'description' => esc_html__( 'Default: 700', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Site Title Font Weight.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_site_title_font_wgt( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[site_title_font_wgt]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'site_title_font_wgt' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_styles[site_title_font_wgt]',
|
||||
array(
|
||||
'section' => 'sec_fonts',
|
||||
'type' => 'select',
|
||||
'choices' => $this->font_weights(),
|
||||
'label' => esc_html__( 'Site Title Font Weight', 'pressbook' ),
|
||||
'description' => esc_html__( 'Default: 700', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Font Weights.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function font_weights() {
|
||||
return array(
|
||||
'400' => esc_html_x( '400', 'Font Weight', 'pressbook' ),
|
||||
'500' => esc_html_x( '500', 'Font Weight', 'pressbook' ),
|
||||
'600' => esc_html_x( '600', 'Font Weight', 'pressbook' ),
|
||||
'700' => esc_html_x( '700', 'Font Weight', 'pressbook' ),
|
||||
);
|
||||
}
|
||||
}
|
237
inc/core/Options/Footer.php
Normal file
237
inc/core/Options/Footer.php
Normal file
@ -0,0 +1,237 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer footer options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Footer options service class.
|
||||
*/
|
||||
class Footer extends Options {
|
||||
/**
|
||||
* Add footer options for theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_footer( $wp_customize );
|
||||
|
||||
$this->set_copyright_text( $wp_customize );
|
||||
$this->set_hide_go_to_top( $wp_customize );
|
||||
|
||||
$this->set_footer_bg_color( $wp_customize );
|
||||
$this->set_footer_credit_link_color( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Footer Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_footer( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_footer',
|
||||
array(
|
||||
'title' => esc_html__( 'Footer Options', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the footer options in here.', 'pressbook' ),
|
||||
'priority' => 160,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Copyright Text.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_copyright_text( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_copyright_text',
|
||||
array(
|
||||
'default' => self::get_copyright_text( true ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_copyright_text' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_copyright_text',
|
||||
array(
|
||||
'section' => 'sec_footer',
|
||||
'type' => 'textarea',
|
||||
'label' => esc_html__( 'Copyright Text', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can change the copyright text in the footer. You may use the following tags: em, strong, span, a, br.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
'set_copyright_text',
|
||||
array(
|
||||
'selector' => '.copyright-text',
|
||||
'container_inclusive' => true,
|
||||
'render_callback' => array( $this, 'render_copyright_text' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Copyright Text.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_copyright_text( $get_default = false ) {
|
||||
$default = apply_filters(
|
||||
'pressbook_default_copyright_text',
|
||||
sprintf(
|
||||
/* translators: 1: current year, 2: blog name */
|
||||
esc_html__( 'Copyright © %1$s %2$s.', 'pressbook' ),
|
||||
esc_html( date_i18n( _x( 'Y', 'copyright date format', 'pressbook' ) ) ),
|
||||
get_bloginfo( 'name', 'display' ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
)
|
||||
);
|
||||
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_copyright_text', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render copyright text for selective refresh.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_copyright_text() {
|
||||
get_template_part( 'template-parts/footer/copyright-text' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide Go To Top Button.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_hide_go_to_top( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_hide_go_to_top',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_hide_go_to_top( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_hide_go_to_top',
|
||||
array(
|
||||
'section' => 'sec_footer',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Hide Go To Top Button', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Hide Go To Top Button.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return bool
|
||||
*/
|
||||
public static function get_hide_go_to_top( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_hide_go_to_top', false );
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_hide_go_to_top', $default );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add setting: Footer Background Color.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_footer_bg_color( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[footer_bg_color]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'footer_bg_color' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_alpha_color' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new AlphaColorControl(
|
||||
$wp_customize,
|
||||
'set_styles[footer_bg_color]',
|
||||
array(
|
||||
'section' => 'sec_footer',
|
||||
'label' => esc_html__( 'Footer Background Color', 'pressbook' ),
|
||||
'settings' => 'set_styles[footer_bg_color]',
|
||||
'palette' => Colors::default_alpha_palette(),
|
||||
'show_opacity' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Footer Credit Link Color.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_footer_credit_link_color( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[footer_credit_link_color]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'footer_credit_link_color' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => 'sanitize_hex_color',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'set_styles[footer_credit_link_color]',
|
||||
array(
|
||||
'section' => 'sec_footer',
|
||||
'label' => esc_html__( 'Footer Credit Link Color', 'pressbook' ),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get allowed tags for copyright text.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function copyright_text_allowed_tags() {
|
||||
return apply_filters(
|
||||
'pressbook_copyright_text_allowed_tags',
|
||||
array(
|
||||
'span' => array( 'class' => array() ),
|
||||
'em' => array(),
|
||||
'strong' => array(),
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'title' => array(),
|
||||
'rel' => array(),
|
||||
'class' => array(),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
332
inc/core/Options/FooterBlock.php
Normal file
332
inc/core/Options/FooterBlock.php
Normal file
@ -0,0 +1,332 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer footer block options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
/**
|
||||
* Footer block options service class.
|
||||
*/
|
||||
class FooterBlock extends BlockSection {
|
||||
const SETTING_KEYS = array( 'id', 'full_width', 'b_margin', 'in_front', 'in_blog', 'in_archive', 'in_post', 'in_page' );
|
||||
|
||||
/**
|
||||
* Add footer block options for the theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_footer_block( $wp_customize );
|
||||
|
||||
$this->set_footer_block( $wp_customize, 1 );
|
||||
$this->selective_refresh_block_1( $wp_customize, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Footer Block Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_footer_block( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_footer_block',
|
||||
array(
|
||||
'title' => esc_html__( 'Footer Block', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the footer block options in here.', 'pressbook' ),
|
||||
'priority' => 153,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Footer Block.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
* @param int $number Block number.
|
||||
*/
|
||||
public function set_footer_block( $wp_customize, $number = 1 ) {
|
||||
$setting_key = ( 'set_footer_block[' . absint( $number ) . ']' );
|
||||
|
||||
$set_id = ( $setting_key . '[id]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_id,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_footer_block_default( 'id' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_block_post' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_id,
|
||||
array(
|
||||
'section' => 'sec_footer_block',
|
||||
'type' => 'select',
|
||||
'choices' => $this->pattern_blocks_choices(),
|
||||
'label' => sprintf(
|
||||
/* translators: %s: footer block number */
|
||||
esc_html__( 'Footer Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
'description' => $this->block_description(),
|
||||
)
|
||||
);
|
||||
|
||||
$set_full_width = ( $setting_key . '[full_width]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_full_width,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_footer_block_default( 'full_width' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_full_width,
|
||||
array(
|
||||
'section' => 'sec_footer_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Set Full Width', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: footer block number */
|
||||
esc_html__( 'Footer Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_b_margin = ( $setting_key . '[b_margin]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_b_margin,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_footer_block_default( 'b_margin' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_b_margin,
|
||||
array(
|
||||
'section' => 'sec_footer_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Bottom Margin', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: footer block number */
|
||||
esc_html__( 'Footer Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_front = ( $setting_key . '[in_front]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_front,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_footer_block_default( 'in_front' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_front,
|
||||
array(
|
||||
'section' => 'sec_footer_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Front Page', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: footer block number */
|
||||
esc_html__( 'Footer Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_blog = ( $setting_key . '[in_blog]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_blog,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_footer_block_default( 'in_blog' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_blog,
|
||||
array(
|
||||
'section' => 'sec_footer_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Blog Page', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: footer block number */
|
||||
esc_html__( 'Footer Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_archive = ( $setting_key . '[in_archive]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_archive,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_footer_block_default( 'in_archive' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_archive,
|
||||
array(
|
||||
'section' => 'sec_footer_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Archive Pages', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: footer block number */
|
||||
esc_html__( 'Footer Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_post = ( $setting_key . '[in_post]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_post,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_footer_block_default( 'in_post' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_post,
|
||||
array(
|
||||
'section' => 'sec_footer_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Posts', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: footer block number */
|
||||
esc_html__( 'Footer Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_page = ( $setting_key . '[in_page]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_page,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_footer_block_default( 'in_page' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_page,
|
||||
array(
|
||||
'section' => 'sec_footer_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Pages', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: footer block number */
|
||||
esc_html__( 'Footer Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Footer Block.
|
||||
*
|
||||
* @param int $number Block number.
|
||||
* @return array.
|
||||
*/
|
||||
public static function get_footer_block( $number = 1 ) {
|
||||
$setting_key = get_theme_mod( 'set_footer_block', array() );
|
||||
|
||||
if ( array_key_exists( $number, $setting_key ) ) {
|
||||
return wp_parse_args(
|
||||
$setting_key[ $number ],
|
||||
self::get_footer_block_default()
|
||||
);
|
||||
}
|
||||
|
||||
return self::get_footer_block_default();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Footer Block.
|
||||
*
|
||||
* @param string $key Setting key.
|
||||
* @return mixed|array
|
||||
*/
|
||||
public static function get_footer_block_default( $key = '' ) {
|
||||
$default = apply_filters(
|
||||
'pressbook_default_footer_block',
|
||||
array(
|
||||
'id' => '',
|
||||
'full_width' => false,
|
||||
'b_margin' => true,
|
||||
'in_front' => true,
|
||||
'in_blog' => true,
|
||||
'in_archive' => false,
|
||||
'in_post' => false,
|
||||
'in_page' => false,
|
||||
)
|
||||
);
|
||||
|
||||
if ( array_key_exists( $key, $default ) ) {
|
||||
return $default[ $key ];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selective Refresh: Footer Block 1.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
* @param int $number Block number.
|
||||
*/
|
||||
public function selective_refresh_block_1( $wp_customize, $number ) {
|
||||
$setting_key = ( 'set_footer_block[' . absint( $number ) . ']' );
|
||||
|
||||
foreach ( static::SETTING_KEYS as $key ) {
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
( $setting_key . '[' . $key . ']' ),
|
||||
array(
|
||||
'selector' => '.footer-block-' . absint( $number ),
|
||||
'container_inclusive' => true,
|
||||
'render_callback' => function() {
|
||||
get_template_part( 'template-parts/footer/block-section' );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
127
inc/core/Options/General.php
Normal file
127
inc/core/Options/General.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer general options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
|
||||
/**
|
||||
* General options service class.
|
||||
*/
|
||||
class General extends Options {
|
||||
/**
|
||||
* Add general options for theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_general( $wp_customize );
|
||||
|
||||
$this->set_search_form_button_text( $wp_customize );
|
||||
$this->set_read_more_text( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: General Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_general( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_general',
|
||||
array(
|
||||
'title' => esc_html__( 'General Options', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the general options in here.', 'pressbook' ),
|
||||
'priority' => 156,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Search Form Button Text.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_search_form_button_text( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_search_form_button_text',
|
||||
array(
|
||||
'default' => self::get_search_form_button_text( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_search_form_button_text',
|
||||
array(
|
||||
'section' => 'sec_general',
|
||||
'type' => 'text',
|
||||
'label' => esc_html__( 'Search Form Button Text', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can change the search form button text. Leave it empty for default text. This does not change the button text of search form widget block. To change that, you can directly edit the search form widget block in the editor itself.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Search Form Button Text.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_search_form_button_text( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_search_form_button_text', '' );
|
||||
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_search_form_button_text', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Read More Text.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_read_more_text( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_read_more_text',
|
||||
array(
|
||||
'default' => self::get_read_more_text( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_read_more_text',
|
||||
array(
|
||||
'section' => 'sec_general',
|
||||
'type' => 'text',
|
||||
'label' => esc_html__( 'Read More Text', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can change the "Read More" text. Leave it empty for default text.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Read More Text.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_read_more_text( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_read_more_text', '' );
|
||||
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_read_more_text', $default );
|
||||
}
|
||||
}
|
332
inc/core/Options/HeaderBlock.php
Normal file
332
inc/core/Options/HeaderBlock.php
Normal file
@ -0,0 +1,332 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer header block options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
/**
|
||||
* Header block options service class.
|
||||
*/
|
||||
class HeaderBlock extends BlockSection {
|
||||
const SETTING_KEYS = array( 'id', 'full_width', 't_margin', 'in_front', 'in_blog', 'in_archive', 'in_post', 'in_page' );
|
||||
|
||||
/**
|
||||
* Add header block options for the theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_header_block( $wp_customize );
|
||||
|
||||
$this->set_header_block( $wp_customize, 1 );
|
||||
$this->selective_refresh_block_1( $wp_customize, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Header Block Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_header_block( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_header_block',
|
||||
array(
|
||||
'title' => esc_html__( 'Header Block', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the header block options in here.', 'pressbook' ),
|
||||
'priority' => 153,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Header Block.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
* @param int $number Block number.
|
||||
*/
|
||||
public function set_header_block( $wp_customize, $number = 1 ) {
|
||||
$setting_key = ( 'set_header_block[' . absint( $number ) . ']' );
|
||||
|
||||
$set_id = ( $setting_key . '[id]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_id,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_header_block_default( 'id' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_block_post' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_id,
|
||||
array(
|
||||
'section' => 'sec_header_block',
|
||||
'type' => 'select',
|
||||
'choices' => $this->pattern_blocks_choices(),
|
||||
'label' => sprintf(
|
||||
/* translators: %s: header block number */
|
||||
esc_html__( 'Header Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
'description' => $this->block_description(),
|
||||
)
|
||||
);
|
||||
|
||||
$set_full_width = ( $setting_key . '[full_width]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_full_width,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_header_block_default( 'full_width' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_full_width,
|
||||
array(
|
||||
'section' => 'sec_header_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Set Full Width', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: header block number */
|
||||
esc_html__( 'Header Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_t_margin = ( $setting_key . '[t_margin]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_t_margin,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_header_block_default( 't_margin' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_t_margin,
|
||||
array(
|
||||
'section' => 'sec_header_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Top Margin', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: header block number */
|
||||
esc_html__( 'Header Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_front = ( $setting_key . '[in_front]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_front,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_header_block_default( 'in_front' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_front,
|
||||
array(
|
||||
'section' => 'sec_header_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Front Page', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: header block number */
|
||||
esc_html__( 'Header Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_blog = ( $setting_key . '[in_blog]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_blog,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_header_block_default( 'in_blog' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_blog,
|
||||
array(
|
||||
'section' => 'sec_header_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Blog Page', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: header block number */
|
||||
esc_html__( 'Header Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_archive = ( $setting_key . '[in_archive]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_archive,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_header_block_default( 'in_archive' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_archive,
|
||||
array(
|
||||
'section' => 'sec_header_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Archive Pages', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: header block number */
|
||||
esc_html__( 'Header Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_post = ( $setting_key . '[in_post]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_post,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_header_block_default( 'in_post' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_post,
|
||||
array(
|
||||
'section' => 'sec_header_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Posts', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: header block number */
|
||||
esc_html__( 'Header Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$set_in_page = ( $setting_key . '[in_page]' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$set_in_page,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_header_block_default( 'in_page' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
$set_in_page,
|
||||
array(
|
||||
'section' => 'sec_header_block',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Show in Pages', 'pressbook' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %s: header block number */
|
||||
esc_html__( 'Header Block %s', 'pressbook' ),
|
||||
absint( $number )
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Header Block.
|
||||
*
|
||||
* @param int $number Block number.
|
||||
* @return array.
|
||||
*/
|
||||
public static function get_header_block( $number = 1 ) {
|
||||
$setting_key = get_theme_mod( 'set_header_block', array() );
|
||||
|
||||
if ( array_key_exists( $number, $setting_key ) ) {
|
||||
return wp_parse_args(
|
||||
$setting_key[ $number ],
|
||||
self::get_header_block_default()
|
||||
);
|
||||
}
|
||||
|
||||
return self::get_header_block_default();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Header Block.
|
||||
*
|
||||
* @param string $key Setting key.
|
||||
* @return mixed|array
|
||||
*/
|
||||
public static function get_header_block_default( $key = '' ) {
|
||||
$default = apply_filters(
|
||||
'pressbook_default_header_block',
|
||||
array(
|
||||
'id' => '',
|
||||
'full_width' => false,
|
||||
't_margin' => true,
|
||||
'in_front' => true,
|
||||
'in_blog' => true,
|
||||
'in_archive' => false,
|
||||
'in_post' => false,
|
||||
'in_page' => false,
|
||||
)
|
||||
);
|
||||
|
||||
if ( array_key_exists( $key, $default ) ) {
|
||||
return $default[ $key ];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selective Refresh: Header Block 1.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
* @param int $number Block number.
|
||||
*/
|
||||
public function selective_refresh_block_1( $wp_customize, $number ) {
|
||||
$setting_key = ( 'set_header_block[' . absint( $number ) . ']' );
|
||||
|
||||
foreach ( static::SETTING_KEYS as $key ) {
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
( $setting_key . '[' . $key . ']' ),
|
||||
array(
|
||||
'selector' => '.header-block-' . absint( $number ),
|
||||
'container_inclusive' => true,
|
||||
'render_callback' => function() {
|
||||
get_template_part( 'template-parts/header/block-section' );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
154
inc/core/Options/HeaderImage.php
Normal file
154
inc/core/Options/HeaderImage.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer header image options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Header image options service class.
|
||||
*/
|
||||
class HeaderImage extends Options {
|
||||
/**
|
||||
* Add header image options for the theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->set_header_bg_position( $wp_customize );
|
||||
$this->set_header_bg_repeat( $wp_customize );
|
||||
$this->set_header_bg_size( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Header Background Position.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_header_bg_position( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[header_bg_position]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'header_bg_position' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_styles[header_bg_position]',
|
||||
array(
|
||||
'section' => 'header_image',
|
||||
'type' => 'select',
|
||||
'choices' => $this->background_positions(),
|
||||
'label' => esc_html__( 'Header Background Position', 'pressbook' ),
|
||||
'description' => esc_html__( 'Default: Center Center', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Header Background Repeat.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_header_bg_repeat( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[header_bg_repeat]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'header_bg_repeat' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_styles[header_bg_repeat]',
|
||||
array(
|
||||
'section' => 'header_image',
|
||||
'type' => 'radio',
|
||||
'choices' => $this->background_repeat(),
|
||||
'label' => esc_html__( 'Header Background Repeat', 'pressbook' ),
|
||||
'description' => esc_html__( 'Default: Repeat', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Header Background Size.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_header_bg_size( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[header_bg_size]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'header_bg_size' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_styles[header_bg_size]',
|
||||
array(
|
||||
'section' => 'header_image',
|
||||
'type' => 'radio',
|
||||
'choices' => $this->background_sizes(),
|
||||
'label' => esc_html__( 'Header Background Size', 'pressbook' ),
|
||||
'description' => esc_html__( 'Default: Contain', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Positions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function background_positions() {
|
||||
return array(
|
||||
'left-top' => esc_html__( 'Left Top', 'pressbook' ),
|
||||
'left-center' => esc_html__( 'Left Center', 'pressbook' ),
|
||||
'left-bottom' => esc_html__( 'Left Bottom', 'pressbook' ),
|
||||
'right-top' => esc_html__( 'Right Top', 'pressbook' ),
|
||||
'right-center' => esc_html__( 'Right Center', 'pressbook' ),
|
||||
'right-bottom' => esc_html__( 'Right Bottom', 'pressbook' ),
|
||||
'center-top' => esc_html__( 'Center Top', 'pressbook' ),
|
||||
'center-center' => esc_html__( 'Center Center', 'pressbook' ),
|
||||
'center-bottom' => esc_html__( 'Center Bottom', 'pressbook' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Repeat.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function background_repeat() {
|
||||
return array(
|
||||
'repeat' => esc_html__( 'Repeat', 'pressbook' ),
|
||||
'repeat-x' => esc_html__( 'Repeat X', 'pressbook' ),
|
||||
'repeat-y' => esc_html__( 'Repeat Y', 'pressbook' ),
|
||||
'no-repeat' => esc_html__( 'No Repeat', 'pressbook' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Background Sizes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function background_sizes() {
|
||||
return array(
|
||||
'auto' => esc_html__( 'Auto', 'pressbook' ),
|
||||
'cover' => esc_html__( 'Cover', 'pressbook' ),
|
||||
'contain' => esc_html__( 'Contain', 'pressbook' ),
|
||||
);
|
||||
}
|
||||
}
|
115
inc/core/Options/PrimaryNavbar.php
Normal file
115
inc/core/Options/PrimaryNavbar.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer primary navbar options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Primary navbar options service class.
|
||||
*/
|
||||
class PrimaryNavbar extends Options {
|
||||
/**
|
||||
* Add primary navbar options for theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_primary_navbar( $wp_customize );
|
||||
|
||||
$this->set_primary_navbar_bg_color( $wp_customize );
|
||||
$this->set_primary_navbar_search( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Primary Navbar Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_primary_navbar( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_primary_navbar',
|
||||
array(
|
||||
'title' => esc_html__( 'Primary Navbar', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the primary navbar options in here.', 'pressbook' ),
|
||||
'priority' => 153,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Primary Navbar Background Color.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_primary_navbar_bg_color( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[primary_navbar_bg_color]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'primary_navbar_bg_color' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_alpha_color' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new AlphaColorControl(
|
||||
$wp_customize,
|
||||
'set_styles[primary_navbar_bg_color]',
|
||||
array(
|
||||
'section' => 'sec_primary_navbar',
|
||||
'label' => esc_html__( 'Primary Navbar Background Color', 'pressbook' ),
|
||||
'settings' => 'set_styles[primary_navbar_bg_color]',
|
||||
'palette' => true,
|
||||
'show_opacity' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Enable Primary Navbar Search Form.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_primary_navbar_search( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_primary_navbar_search',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_primary_navbar_search( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_primary_navbar_search',
|
||||
array(
|
||||
'section' => 'sec_primary_navbar',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Enable Primary Navbar Search Form', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Enable Primary Navbar Search Form.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return bool
|
||||
*/
|
||||
public static function get_primary_navbar_search( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_primary_navbar_search', true );
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_primary_navbar_search', $default );
|
||||
}
|
||||
}
|
89
inc/core/Options/Sanitizer.php
Normal file
89
inc/core/Options/Sanitizer.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Options Sanitizer.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
/**
|
||||
* Sanitizer for theme options.
|
||||
*/
|
||||
class Sanitizer {
|
||||
/**
|
||||
* Checkbox sanitization.
|
||||
*
|
||||
* Sanitization callback for 'checkbox' type controls. This callback sanitizes `$checked`
|
||||
* as a boolean value, either TRUE or FALSE.
|
||||
*
|
||||
* @param bool $checked Whether the checkbox is checked.
|
||||
* @return bool Whether the checkbox is checked.
|
||||
*/
|
||||
public static function sanitize_checkbox( $checked ) {
|
||||
return ( isset( $checked ) && true === $checked ) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize select.
|
||||
*
|
||||
* @param string $input The input from the setting.
|
||||
* @param object $setting The selected setting.
|
||||
*
|
||||
* @return string $input|$setting->default The input from the setting or the default setting.
|
||||
*/
|
||||
public static function sanitize_select( $input, $setting ) {
|
||||
$input = sanitize_key( $input );
|
||||
$choices = $setting->manager->get_control( $setting->id )->choices;
|
||||
return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize block post.
|
||||
*
|
||||
* @param int $input post id.
|
||||
* @return int
|
||||
*/
|
||||
public static function sanitize_block_post( $input ) {
|
||||
$post_id = absint( $input );
|
||||
if ( $post_id && 'wp_block' === get_post_type( $post_id ) ) {
|
||||
return $post_id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to sanitize alpha color.
|
||||
*
|
||||
* @param string $value Hex or RGBA color.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function sanitize_alpha_color( $value ) {
|
||||
// This pattern will check and match 3/6/8-character hex, rgb, rgba, hsl, & hsla colors.
|
||||
$pattern = '/^(\#[\da-f]{3}|\#[\da-f]{6}|\#[\da-f]{8}|rgba\(((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*,\s*){2}((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*)(,\s*(0\.\d+|1))\)|hsla\(\s*((\d{1,2}|[1-2]\d{2}|3([0-5]\d|60)))\s*,\s*((\d{1,2}|100)\s*%)\s*,\s*((\d{1,2}|100)\s*%)(,\s*(0\.\d+|1))\)|rgb\(((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*,\s*){2}((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*)|hsl\(\s*((\d{1,2}|[1-2]\d{2}|3([0-5]\d|60)))\s*,\s*((\d{1,2}|100)\s*%)\s*,\s*((\d{1,2}|100)\s*%)\))$/';
|
||||
\preg_match( $pattern, $value, $matches );
|
||||
// Return the 1st match found.
|
||||
if ( isset( $matches[0] ) ) {
|
||||
if ( is_string( $matches[0] ) ) {
|
||||
return $matches[0];
|
||||
}
|
||||
if ( is_array( $matches[0] ) && isset( $matches[0][0] ) ) {
|
||||
return $matches[0][0];
|
||||
}
|
||||
}
|
||||
// If no match was found, return an empty string.
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize copyright text.
|
||||
*
|
||||
* @param string $input Input text.
|
||||
* @return string
|
||||
*/
|
||||
public static function sanitize_copyright_text( $input ) {
|
||||
$allowed = Footer::copyright_text_allowed_tags();
|
||||
return wp_kses( $input, $allowed );
|
||||
}
|
||||
}
|
341
inc/core/Options/Sidebar.php
Normal file
341
inc/core/Options/Sidebar.php
Normal file
@ -0,0 +1,341 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer sidebar layout options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Sidebar layout options service class.
|
||||
*/
|
||||
class Sidebar extends Options {
|
||||
/**
|
||||
* Add sidebar layout options for the theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_sidebar( $wp_customize );
|
||||
|
||||
$this->set_side_widget_layout_double_lg( $wp_customize );
|
||||
|
||||
$this->set_side_widget_border_color( $wp_customize );
|
||||
|
||||
$this->set_side_widget_no_t_padding( $wp_customize );
|
||||
$this->set_side_widget_no_b_padding( $wp_customize );
|
||||
$this->set_side_widget_no_x_padding( $wp_customize );
|
||||
$this->set_side_widget_no_shadow( $wp_customize );
|
||||
|
||||
$this->set_sticky_sidebar( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Sidebar Layout Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_sidebar( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_sidebar',
|
||||
array(
|
||||
'title' => esc_html__( 'Sidebar Layout', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the sidebar layout options in here.', 'pressbook' ),
|
||||
'priority' => 155,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Double Sidebars Layout (Large-Screen Devices).
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_side_widget_layout_double_lg( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_side_widget[layout_double_lg]',
|
||||
array(
|
||||
'default' => self::get_side_widget_default( 'layout_double_lg' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_side_widget[layout_double_lg]',
|
||||
array(
|
||||
'section' => 'sec_sidebar',
|
||||
'type' => 'radio',
|
||||
'choices' => array(
|
||||
'' => esc_html__( 'One Left and One Right', 'pressbook' ),
|
||||
'left' => esc_html__( 'Both Sidebars to the Left', 'pressbook' ),
|
||||
'right' => esc_html__( 'Both Sidebars to the Right', 'pressbook' ),
|
||||
),
|
||||
'label' => esc_html__( 'Double Sidebars Layout (Large-Screen Devices)', 'pressbook' ),
|
||||
'description' => esc_html__( 'Set the layout for the double sidebars. This applies only when both the sidebars (left and right) are active. A sidebar is active when there is at least one widget in it.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Side Widget Border Color.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_side_widget_border_color( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[side_widget_border_color]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'side_widget_border_color' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_alpha_color' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new AlphaColorControl(
|
||||
$wp_customize,
|
||||
'set_styles[side_widget_border_color]',
|
||||
array(
|
||||
'section' => 'sec_sidebar',
|
||||
'label' => esc_html__( 'Side Widget Border Color', 'pressbook' ),
|
||||
'settings' => 'set_styles[side_widget_border_color]',
|
||||
'palette' => Colors::default_alpha_palette(),
|
||||
'show_opacity' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Remove Top Padding.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_side_widget_no_t_padding( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_side_widget[no_t_padding]',
|
||||
array(
|
||||
'default' => self::get_side_widget_default( 'no_t_padding' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_side_widget[no_t_padding]',
|
||||
array(
|
||||
'section' => 'sec_sidebar',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Remove Top Padding', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Remove Bottom Padding.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_side_widget_no_b_padding( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_side_widget[no_b_padding]',
|
||||
array(
|
||||
'default' => self::get_side_widget_default( 'no_b_padding' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_side_widget[no_b_padding]',
|
||||
array(
|
||||
'section' => 'sec_sidebar',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Remove Bottom Padding', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Remove Horizontal Padding.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_side_widget_no_x_padding( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_side_widget[no_x_padding]',
|
||||
array(
|
||||
'default' => self::get_side_widget_default( 'no_x_padding' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_side_widget[no_x_padding]',
|
||||
array(
|
||||
'section' => 'sec_sidebar',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Remove Horizontal Padding', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Remove Box Shadow.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_side_widget_no_shadow( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_side_widget[no_shadow]',
|
||||
array(
|
||||
'default' => self::get_side_widget_default( 'no_shadow' ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_side_widget[no_shadow]',
|
||||
array(
|
||||
'section' => 'sec_sidebar',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Remove Box Shadow', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Side Widget.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_side_widget() {
|
||||
return wp_parse_args(
|
||||
get_theme_mod( 'set_side_widget', array() ),
|
||||
self::get_side_widget_default()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Side Widget.
|
||||
*
|
||||
* @param string $key Setting key.
|
||||
* @return mixed|array
|
||||
*/
|
||||
public static function get_side_widget_default( $key = '' ) {
|
||||
$default = apply_filters(
|
||||
'pressbook_default_side_widget',
|
||||
array(
|
||||
'layout_double_lg' => '',
|
||||
'no_t_padding' => false,
|
||||
'no_b_padding' => false,
|
||||
'no_x_padding' => false,
|
||||
'no_shadow' => false,
|
||||
)
|
||||
);
|
||||
|
||||
if ( array_key_exists( $key, $default ) ) {
|
||||
return $default[ $key ];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Sticky Sidebar.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_sticky_sidebar( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_sticky_sidebar',
|
||||
array(
|
||||
'default' => self::get_sticky_sidebar( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_sticky_sidebar',
|
||||
array(
|
||||
'section' => 'sec_sidebar',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Sticky-Floating Sidebar', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can enable or disable sticky sidebar that floats on scrolling.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Sticky Sidebar.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return bool
|
||||
*/
|
||||
public static function get_sticky_sidebar( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_sticky_sidebar', true );
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_sticky_sidebar', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get body classes for side widget.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_side_widget_body_class() {
|
||||
$side_widget = self::get_side_widget();
|
||||
|
||||
$body_class = '';
|
||||
if ( $side_widget['layout_double_lg'] ) {
|
||||
$body_class .= ' side-widget-ld-lg-' . esc_attr( $side_widget['layout_double_lg'] );
|
||||
}
|
||||
if ( $side_widget['no_t_padding'] ) {
|
||||
$body_class .= ' side-widget-no-t-padding';
|
||||
}
|
||||
if ( $side_widget['no_b_padding'] ) {
|
||||
$body_class .= ' side-widget-no-b-padding';
|
||||
}
|
||||
if ( $side_widget['no_x_padding'] ) {
|
||||
$body_class .= ' side-widget-no-x-padding';
|
||||
}
|
||||
if ( $side_widget['no_shadow'] ) {
|
||||
$body_class .= ' side-widget-no-shadow';
|
||||
}
|
||||
|
||||
return ltrim( $body_class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sticky sidebar breakpoint screen width.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function get_sticky_breakpoint() {
|
||||
$double_bp = 1279;
|
||||
$single_bp = 1023;
|
||||
|
||||
if ( is_active_sidebar( 'sidebar-1' ) ) {
|
||||
if ( is_active_sidebar( 'sidebar-2' ) ) {
|
||||
return $double_bp;
|
||||
} else {
|
||||
return $single_bp;
|
||||
}
|
||||
} elseif ( is_active_sidebar( 'sidebar-2' ) ) {
|
||||
return $single_bp;
|
||||
} else {
|
||||
return $single_bp;
|
||||
}
|
||||
}
|
||||
}
|
450
inc/core/Options/SiteIdentity.php
Normal file
450
inc/core/Options/SiteIdentity.php
Normal file
@ -0,0 +1,450 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer site identity options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Site identity options service class.
|
||||
*/
|
||||
class SiteIdentity extends Options {
|
||||
const SETTING_NAMES = array( 'logo', 'site_title', 'tagline' );
|
||||
const SETTING_SIZES = array( 'lg', 'md', 'sm' );
|
||||
|
||||
/**
|
||||
* Register service features.
|
||||
*/
|
||||
public function register() {
|
||||
add_action( 'customize_register', array( $this, 'customize_register' ) );
|
||||
add_action( 'customize_preview_init', array( $this, 'customize_preview_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add site identity options for theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
// Selective refresh for site title.
|
||||
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
|
||||
|
||||
// Selective refresh for site tagline.
|
||||
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
|
||||
|
||||
$this->set_hide_site_title( $wp_customize );
|
||||
$this->set_hide_site_tagline( $wp_customize );
|
||||
|
||||
foreach ( self::SETTING_NAMES as $name ) {
|
||||
foreach ( self::SETTING_SIZES as $size ) {
|
||||
$this->set_size( $wp_customize, $name, $size );
|
||||
$this->selective_refresh_size( $wp_customize, $name, $size );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide Site Title.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_hide_site_title( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_hide_site_title',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_hide_site_title( true ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_hide_site_title',
|
||||
array(
|
||||
'section' => 'title_tagline',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Hide Site Title', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
'set_hide_site_title',
|
||||
array(
|
||||
'selector' => '.site-branding',
|
||||
'container_inclusive' => true,
|
||||
'render_callback' => array( $this, 'render_site_branding' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Hide Site Title.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return bool
|
||||
*/
|
||||
public static function get_hide_site_title( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_hide_site_title', false );
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_hide_site_title', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide Site Tagline.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_hide_site_tagline( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_hide_site_tagline',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_hide_site_tagline( true ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_hide_site_tagline',
|
||||
array(
|
||||
'section' => 'title_tagline',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Hide Site Tagline', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
'set_hide_site_tagline',
|
||||
array(
|
||||
'selector' => '.site-branding',
|
||||
'container_inclusive' => true,
|
||||
'render_callback' => array( $this, 'render_site_branding' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Hide Site Tagline.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return bool
|
||||
*/
|
||||
public static function get_hide_site_tagline( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_default_hide_site_tagline', false );
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_hide_site_tagline', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Size.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
* @param string $name Setting name.
|
||||
* @param string $size Screen size.
|
||||
*/
|
||||
public function set_size( $wp_customize, $name, $size ) {
|
||||
$key = ( 'set_' . $name . '_size[' . $size . ']' );
|
||||
|
||||
$wp_customize->add_setting(
|
||||
$key,
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_size_default( $name, $size ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_select' ),
|
||||
)
|
||||
);
|
||||
|
||||
$method_label = ( 'get_' . $name . '_size_label' );
|
||||
|
||||
$wp_customize->add_control(
|
||||
$key,
|
||||
array(
|
||||
'section' => 'title_tagline',
|
||||
'type' => 'select',
|
||||
'choices' => $this->sizes(),
|
||||
'label' => self::$method_label()['label'][ $size ],
|
||||
'description' => self::$method_label()['desc'][ $size ],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Size.
|
||||
*
|
||||
* @param string $name Setting name.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_size( $name ) {
|
||||
return wp_parse_args(
|
||||
get_theme_mod( ( 'set_' . $name . '_size' ), array() ),
|
||||
self::get_size_default( $name )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Size.
|
||||
*
|
||||
* @param string $name Setting name.
|
||||
* @param string $size Screen size.
|
||||
* @return array|string
|
||||
*/
|
||||
public static function get_size_default( $name, $size = '' ) {
|
||||
$method_default = ( 'get_' . $name . '_size_default' );
|
||||
|
||||
$default = apply_filters(
|
||||
( 'pressbook_default_' . $name . '_size' ),
|
||||
self::$method_default()
|
||||
);
|
||||
|
||||
if ( '' === $size ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if ( array_key_exists( $size, $default ) ) {
|
||||
return $default[ $size ];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Logo Size.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_logo_size_default() {
|
||||
return array(
|
||||
'sm' => 1,
|
||||
'md' => 1,
|
||||
'lg' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Size Title Size.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_site_title_size_default() {
|
||||
return array(
|
||||
'sm' => 2,
|
||||
'md' => 2,
|
||||
'lg' => 2,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Tagline Size.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_tagline_size_default() {
|
||||
return array(
|
||||
'sm' => 2,
|
||||
'md' => 2,
|
||||
'lg' => 2,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting label: Logo Size.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_logo_size_label() {
|
||||
return array(
|
||||
'label' => array(
|
||||
'sm' => esc_html__( 'Logo Size (Small-Screen Devices)', 'pressbook' ),
|
||||
'md' => esc_html__( 'Logo Size (Medium-Screen Devices)', 'pressbook' ),
|
||||
'lg' => esc_html__( 'Logo Size (Large-Screen Devices)', 'pressbook' ),
|
||||
),
|
||||
'desc' => array(
|
||||
'sm' => esc_html_x( 'Default: Size 1', 'Default: Logo Size (Small-Screen Devices)', 'pressbook' ),
|
||||
'md' => esc_html_x( 'Default: Size 1', 'Default: Logo Size (Medium-Screen Devices)', 'pressbook' ),
|
||||
'lg' => esc_html_x( 'Default: Size 1', 'Default: Logo Size (Large-Screen Devices)', 'pressbook' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting label: Site Title Size.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_site_title_size_label() {
|
||||
return array(
|
||||
'label' => array(
|
||||
'sm' => esc_html__( 'Site Title Size (Small-Screen Devices)', 'pressbook' ),
|
||||
'md' => esc_html__( 'Site Title Size (Medium-Screen Devices)', 'pressbook' ),
|
||||
'lg' => esc_html__( 'Site Title Size (Large-Screen Devices)', 'pressbook' ),
|
||||
),
|
||||
'desc' => array(
|
||||
'sm' => esc_html_x( 'Default: Size 2', 'Default: Site Title Size (Small-Screen Devices)', 'pressbook' ),
|
||||
'md' => esc_html_x( 'Default: Size 2', 'Default: Site Title Size (Medium-Screen Devices)', 'pressbook' ),
|
||||
'lg' => esc_html_x( 'Default: Size 2', 'Default: Site Title Size (Large-Screen Devices)', 'pressbook' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting label: Tagline Size.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_tagline_size_label() {
|
||||
return array(
|
||||
'label' => array(
|
||||
'sm' => esc_html__( 'Tagline Size (Small-Screen Devices)', 'pressbook' ),
|
||||
'md' => esc_html__( 'Tagline Size (Medium-Screen Devices)', 'pressbook' ),
|
||||
'lg' => esc_html__( 'Tagline Size (Large-Screen Devices)', 'pressbook' ),
|
||||
),
|
||||
'desc' => array(
|
||||
'sm' => esc_html_x( 'Default: Size 2', 'Default: Tagline Size (Small-Screen Devices)', 'pressbook' ),
|
||||
'md' => esc_html_x( 'Default: Size 2', 'Default: Tagline Size (Medium-Screen Devices)', 'pressbook' ),
|
||||
'lg' => esc_html_x( 'Default: Size 2', 'Default: Tagline Size (Large-Screen Devices)', 'pressbook' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selective Refresh: Size.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
* @param string $name Setting name.
|
||||
* @param string $size Screen size.
|
||||
*/
|
||||
public function selective_refresh_size( $wp_customize, $name, $size ) {
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
( 'set_' . $name . '_size[' . $size . ']' ),
|
||||
array(
|
||||
'selector' => '.site-branding',
|
||||
'container_inclusive' => true,
|
||||
'render_callback' => array( $this, 'render_site_branding' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render site branding for selective refresh.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_site_branding() {
|
||||
get_template_part( 'template-parts/header/site-branding' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available sizes.
|
||||
*
|
||||
* @return array.
|
||||
*/
|
||||
public function sizes() {
|
||||
return array(
|
||||
'1' => esc_html__( 'Size 1', 'pressbook' ),
|
||||
'2' => esc_html__( 'Size 2', 'pressbook' ),
|
||||
'3' => esc_html__( 'Size 3', 'pressbook' ),
|
||||
'4' => esc_html__( 'Size 4', 'pressbook' ),
|
||||
'5' => esc_html__( 'Size 5', 'pressbook' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds JS handlers to make theme customizer preview reload changes asynchronously.
|
||||
*/
|
||||
public function customize_preview_scripts() {
|
||||
wp_enqueue_script( 'pressbook-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview', 'jquery' ), PRESSBOOK_VERSION, true );
|
||||
|
||||
wp_localize_script(
|
||||
'pressbook-customizer',
|
||||
'pressbook',
|
||||
array(
|
||||
'styles' => CSSRules::output_array(),
|
||||
'handle_id' => apply_filters( 'pressbook_inline_style_handle_id', 'pressbook-style-inline-css' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site logo title class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function logo_title_class() {
|
||||
$logo_title_classs = 'site-logo-title';
|
||||
if ( self::get_hide_site_title() && self::get_hide_site_tagline() ) {
|
||||
$logo_title_classs .= ' site-logo-only';
|
||||
}
|
||||
|
||||
$top_banner = TopBanner::get_top_banner();
|
||||
if ( '' !== wp_get_attachment_image( $top_banner['image'] ) ) {
|
||||
if ( ! $top_banner['hide_sm'] ) {
|
||||
$logo_title_classs .= ' has-banner-next-sm';
|
||||
}
|
||||
|
||||
if ( ! $top_banner['hide_md'] ) {
|
||||
$logo_title_classs .= ' has-banner-next-md';
|
||||
}
|
||||
|
||||
$logo_title_classs .= ' has-banner-next-lg';
|
||||
}
|
||||
|
||||
$logo = self::get_size( 'logo' );
|
||||
foreach ( self::SETTING_SIZES as $size ) {
|
||||
$logo_title_classs .= ( ' logo--' . $size . '-size-' . $logo[ $size ] );
|
||||
}
|
||||
|
||||
return apply_filters( 'pressbook_site_logo_title_classs', $logo_title_classs );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site title class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function title_class() {
|
||||
$title_class = 'site-title';
|
||||
if ( self::get_hide_site_title() ) {
|
||||
$title_class .= ' hide-clip';
|
||||
}
|
||||
|
||||
$site_title = self::get_size( 'site_title' );
|
||||
foreach ( self::SETTING_SIZES as $size ) {
|
||||
$title_class .= ( ' site-title--' . $size . '-size-' . $site_title[ $size ] );
|
||||
}
|
||||
|
||||
return apply_filters( 'pressbook_site_title_class', $title_class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get site tagline class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function tagline_class() {
|
||||
$tagline_class = 'site-tagline';
|
||||
if ( self::get_hide_site_tagline() ) {
|
||||
$tagline_class .= ' hide-clip';
|
||||
}
|
||||
|
||||
$site_tagline = self::get_size( 'tagline' );
|
||||
foreach ( self::SETTING_SIZES as $size ) {
|
||||
$tagline_class .= ( ' tagline--' . $size . '-size-' . $site_tagline[ $size ] );
|
||||
}
|
||||
|
||||
return apply_filters( 'pressbook_site_tagline_class', $tagline_class );
|
||||
}
|
||||
}
|
473
inc/core/Options/TopBanner.php
Normal file
473
inc/core/Options/TopBanner.php
Normal file
@ -0,0 +1,473 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer top banner options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Top banner options service class
|
||||
*/
|
||||
class TopBanner extends Options {
|
||||
const MAIN_SETTING_KEYS = array( 'image', 'link_url', 'link_title', 'link_rel', 'link_new_tab', 'shadow' );
|
||||
const DEVICE_SETTING_KEYS = array( 'hide_sm', 'hide_md' );
|
||||
|
||||
/**
|
||||
* Add top banner options for theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_top_banner( $wp_customize );
|
||||
|
||||
$this->set_top_banner_image( $wp_customize );
|
||||
$this->set_top_banner_link_url( $wp_customize );
|
||||
$this->set_top_banner_link_title( $wp_customize );
|
||||
$this->set_top_banner_link_rel( $wp_customize );
|
||||
$this->set_top_banner_link_new_tab( $wp_customize );
|
||||
$this->set_top_banner_shadow( $wp_customize );
|
||||
$this->set_top_banner_max_height( $wp_customize );
|
||||
$this->set_top_banner_hide_sm( $wp_customize );
|
||||
$this->set_top_banner_hide_md( $wp_customize );
|
||||
$this->selective_refresh_top_banner_main_keys( $wp_customize );
|
||||
$this->selective_refresh_top_banner_device_keys( $wp_customize );
|
||||
|
||||
$this->set_top_banner_block( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Top Banner Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_top_banner( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_top_banner',
|
||||
array(
|
||||
'title' => esc_html__( 'Top Banner', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the top banner options in here.', 'pressbook' ),
|
||||
'priority' => 152,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Banner Image.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_image( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_top_banner[image]',
|
||||
array(
|
||||
'default' => self::get_top_banner_default( 'image' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => 'absint',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Cropped_Image_Control(
|
||||
$wp_customize,
|
||||
'set_top_banner[image]',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'label' => esc_html__( 'Top Banner Image', 'pressbook' ),
|
||||
'description' => esc_html__( 'Select the top banner image. The theme works best with an image size of 728 x 90 pixels. ', 'pressbook' ),
|
||||
'flex_width' => true,
|
||||
'flex_height' => true,
|
||||
'width' => 728,
|
||||
'height' => 90,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Banner Link - URL.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_link_url( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_top_banner[link_url]',
|
||||
array(
|
||||
'default' => self::get_top_banner_default( 'link_url' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => 'esc_url_raw',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_top_banner[link_url]',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'url',
|
||||
'label' => esc_html__( 'Top Banner Link - URL', 'pressbook' ),
|
||||
'description' => esc_html__( 'Enter the URL for the banner link.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Banner Link - Title.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_link_title( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_top_banner[link_title]',
|
||||
array(
|
||||
'default' => self::get_top_banner_default( 'link_title' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_top_banner[link_title]',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'text',
|
||||
'label' => esc_html__( 'Top Banner Link - Title', 'pressbook' ),
|
||||
'description' => esc_html__( 'Enter the "title" attribute for the banner link.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Banner Link - Rel.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_link_rel( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_top_banner[link_rel]',
|
||||
array(
|
||||
'default' => self::get_top_banner_default( 'link_rel' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_top_banner[link_rel]',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'text',
|
||||
'label' => esc_html__( 'Top Banner Link - Rel', 'pressbook' ),
|
||||
'description' => esc_html__( 'Enter the "rel" attribute for the banner link.', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Banner Link - Open in New Tab.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_link_new_tab( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_top_banner[link_new_tab]',
|
||||
array(
|
||||
'default' => self::get_top_banner_default( 'link_new_tab' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_top_banner[link_new_tab]',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Top Banner Link - Open in New Tab', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Banner Shadow Effect.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_shadow( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_top_banner[shadow]',
|
||||
array(
|
||||
'default' => self::get_top_banner_default( 'shadow' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_top_banner[shadow]',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Top Banner Shadow Effect', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Banner Maximum Height.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_max_height( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[top_banner_max_height]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'top_banner_max_height' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => 'absint',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_styles[top_banner_max_height]',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'number',
|
||||
'label' => esc_html__( 'Top Banner Maximum Height', 'pressbook' ),
|
||||
'description' => esc_html__( 'Set the maximum height allowed for the top banner image in pixels. Default: 150', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide in Small-Screen Devices.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_hide_sm( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_top_banner[hide_sm]',
|
||||
array(
|
||||
'default' => self::get_top_banner_default( 'hide_sm' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_top_banner[hide_sm]',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Hide in Small-Screen Devices', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Hide in Medium-Screen Devices.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_hide_md( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_top_banner[hide_md]',
|
||||
array(
|
||||
'default' => self::get_top_banner_default( 'hide_md' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_checkbox' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_top_banner[hide_md]',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'checkbox',
|
||||
'label' => esc_html__( 'Hide in Medium-Screen Devices', 'pressbook' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Top Banner.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_top_banner() {
|
||||
return wp_parse_args(
|
||||
get_theme_mod( 'set_top_banner', array() ),
|
||||
self::get_top_banner_default()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default setting: Top Banner.
|
||||
*
|
||||
* @param string $key Setting key.
|
||||
* @return mixed|array
|
||||
*/
|
||||
public static function get_top_banner_default( $key = '' ) {
|
||||
$default = apply_filters(
|
||||
'pressbook_default_top_banner',
|
||||
array(
|
||||
'image' => '',
|
||||
'link_url' => '#',
|
||||
'link_title' => '',
|
||||
'link_rel' => '',
|
||||
'link_new_tab' => true,
|
||||
'shadow' => false,
|
||||
'hide_sm' => true,
|
||||
'hide_md' => false,
|
||||
)
|
||||
);
|
||||
|
||||
if ( array_key_exists( $key, $default ) ) {
|
||||
return $default[ $key ];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selective Refresh: Top Banner Main Keys.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function selective_refresh_top_banner_main_keys( $wp_customize ) {
|
||||
foreach ( self::MAIN_SETTING_KEYS as $key ) {
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
( 'set_top_banner[' . $key . ']' ),
|
||||
array(
|
||||
'selector' => '.top-banner',
|
||||
'container_inclusive' => true,
|
||||
'render_callback' => function() {
|
||||
get_template_part( 'template-parts/header/top-banner' );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selective Refresh: Top Banner Device Keys.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function selective_refresh_top_banner_device_keys( $wp_customize ) {
|
||||
foreach ( self::DEVICE_SETTING_KEYS as $key ) {
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
( 'set_top_banner[' . $key . ']' ),
|
||||
array(
|
||||
'selector' => '.site-branding',
|
||||
'container_inclusive' => true,
|
||||
'render_callback' => function() {
|
||||
get_template_part( 'template-parts/header/site-branding' );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top banner class.
|
||||
*
|
||||
* @param array $top_banner Top banner settings.
|
||||
* @return string
|
||||
*/
|
||||
public static function top_banner_class( $top_banner ) {
|
||||
$top_banner_class = 'top-banner';
|
||||
if ( $top_banner['shadow'] ) {
|
||||
$top_banner_class .= ' top-banner-shadow';
|
||||
}
|
||||
|
||||
if ( $top_banner['hide_sm'] ) {
|
||||
$top_banner_class .= ' top-banner-hide-sm';
|
||||
}
|
||||
if ( $top_banner['hide_md'] ) {
|
||||
$top_banner_class .= ' top-banner-hide-md';
|
||||
}
|
||||
|
||||
return apply_filters( 'pressbook_top_banner_class', $top_banner_class, $top_banner );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Banner Block Section.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_banner_block( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_top_banner_block',
|
||||
array(
|
||||
'type' => 'theme_mod',
|
||||
'default' => self::get_top_banner_block( true ),
|
||||
'transport' => 'refresh',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_block_post' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
'set_top_banner_block',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'select',
|
||||
'choices' => $this->pattern_blocks_choices(),
|
||||
'label' => esc_html__( 'Top Banner Block Section', 'pressbook' ),
|
||||
'description' => wp_kses(
|
||||
sprintf(
|
||||
/* translators: %s: URL to the pattern-blocks admin page. */
|
||||
__( 'You can use this to replace top banner image and use any custom block (For example: "Custom HTML block"). This is the content of the block section. You can create or edit the block section in the <a href="%s" target="_blank">Pattern Blocks Manager (opens in a new window)</a>.<br>After creating the pattern block, you may need to refresh this customizer page and then select the newly created block.<br>The selected block content will appear on the block section, replacing the top banner image and overriding its related options.', 'pressbook' ),
|
||||
esc_url( admin_url( 'edit.php?post_type=wp_block' ) )
|
||||
),
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
'br' => array(),
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting: Top Banner Block Section.
|
||||
*
|
||||
* @param bool $get_default Get default.
|
||||
* @return string
|
||||
*/
|
||||
public static function get_top_banner_block( $get_default = false ) {
|
||||
$default = apply_filters( 'pressbook_top_banner_block_default', '' );
|
||||
if ( $get_default ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return get_theme_mod( 'set_top_banner_block', $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of pattern-blocks formatted as [ ID => Title ].
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function pattern_blocks_choices() {
|
||||
$pattern_blocks = get_posts(
|
||||
array(
|
||||
'post_type' => 'wp_block',
|
||||
'numberposts' => 100,
|
||||
)
|
||||
);
|
||||
|
||||
$pattern_blocks_choices = array( 0 => esc_html__( 'Select a block', 'pressbook' ) );
|
||||
foreach ( $pattern_blocks as $block ) {
|
||||
$pattern_blocks_choices[ $block->ID ] = $block->post_title;
|
||||
}
|
||||
|
||||
return $pattern_blocks_choices;
|
||||
}
|
||||
}
|
104
inc/core/Options/TopNavbar.php
Normal file
104
inc/core/Options/TopNavbar.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Customizer top navbar options service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\CSSRules;
|
||||
|
||||
/**
|
||||
* Top navbar options service class.
|
||||
*/
|
||||
class TopNavbar extends Options {
|
||||
/**
|
||||
* Add top navbar options for theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_top_navbar( $wp_customize );
|
||||
|
||||
$this->set_top_navbar_bg_color_1( $wp_customize );
|
||||
$this->set_top_navbar_bg_color_2( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Top Navbar Options.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_top_navbar( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
'sec_top_navbar',
|
||||
array(
|
||||
'title' => esc_html__( 'Top Navbar', 'pressbook' ),
|
||||
'description' => esc_html__( 'You can customize the top navbar options in here.', 'pressbook' ),
|
||||
'priority' => 151,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Navbar Background Color 1.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_navbar_bg_color_1( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[top_navbar_bg_color_1]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'top_navbar_bg_color_1' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_alpha_color' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new AlphaColorControl(
|
||||
$wp_customize,
|
||||
'set_styles[top_navbar_bg_color_1]',
|
||||
array(
|
||||
'section' => 'sec_top_navbar',
|
||||
'label' => esc_html__( 'Top Navbar Gradient Background 1', 'pressbook' ),
|
||||
'settings' => 'set_styles[top_navbar_bg_color_1]',
|
||||
'palette' => true,
|
||||
'show_opacity' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add setting: Top Navbar Background Color 1.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function set_top_navbar_bg_color_2( $wp_customize ) {
|
||||
$wp_customize->add_setting(
|
||||
'set_styles[top_navbar_bg_color_2]',
|
||||
array(
|
||||
'default' => CSSRules::default_styles( 'top_navbar_bg_color_2' ),
|
||||
'transport' => 'postMessage',
|
||||
'sanitize_callback' => array( Sanitizer::class, 'sanitize_alpha_color' ),
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new AlphaColorControl(
|
||||
$wp_customize,
|
||||
'set_styles[top_navbar_bg_color_2]',
|
||||
array(
|
||||
'section' => 'sec_top_navbar',
|
||||
'label' => esc_html__( 'Top Navbar Gradient Background 2', 'pressbook' ),
|
||||
'settings' => 'set_styles[top_navbar_bg_color_2]',
|
||||
'palette' => true,
|
||||
'show_opacity' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
229
inc/core/Options/Upsell.php
Normal file
229
inc/core/Options/Upsell.php
Normal file
@ -0,0 +1,229 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
|
||||
/**
|
||||
* Upsell customizer service.
|
||||
*
|
||||
* @package PressBook
|
||||
*/
|
||||
|
||||
namespace PressBook\Options;
|
||||
|
||||
use PressBook\Options;
|
||||
use PressBook\Helpers;
|
||||
|
||||
/**
|
||||
* Upsell service class.
|
||||
*/
|
||||
class Upsell extends Options {
|
||||
/**
|
||||
* Add upsell in the theme customizer.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
$this->sec_upsell( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: Upsell.
|
||||
*
|
||||
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
|
||||
*/
|
||||
public function sec_upsell( $wp_customize ) {
|
||||
if ( method_exists( $wp_customize, 'register_section_type' ) ) {
|
||||
$wp_customize->register_section_type( \PressBook_Upsell_Section::class );
|
||||
}
|
||||
|
||||
if ( method_exists( $wp_customize, 'register_control_type' ) ) {
|
||||
$wp_customize->register_control_type( \PressBook_Upsell_Control::class );
|
||||
}
|
||||
|
||||
$wp_customize->add_section(
|
||||
new \PressBook_Upsell_Section(
|
||||
$wp_customize,
|
||||
'pressbook_premium',
|
||||
array(
|
||||
'title' => esc_html__( 'Premium Available', 'pressbook' ),
|
||||
'button_text' => esc_html__( 'Get Premium', 'pressbook' ),
|
||||
'button_url' => esc_url( Helpers::get_upsell_buy_url() ),
|
||||
'priority' => 1,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'addon_colors',
|
||||
array(
|
||||
'section' => 'colors',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'More color options like button text color, link color, theme accent color, RGBA colors, fonts selector, and many more options are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_fonts',
|
||||
array(
|
||||
'section' => 'sec_fonts',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'Advanced typography settings: font-family, font-size, body font-weight, line-height, over 50+ Google fonts, and custom Google font loader are available to select for the headings and body text in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_top_navbar',
|
||||
array(
|
||||
'section' => 'sec_top_navbar',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'Multiple eye-catching block patterns, custom gradient color options, header blocks, footer blocks, and many more options are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) . '#description' ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_top_banner',
|
||||
array(
|
||||
'section' => 'sec_top_banner',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'Multiple eye-catching block patterns, custom gradient color scheme, header blocks, footer blocks are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) . '#description' ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_primary_navbar',
|
||||
array(
|
||||
'section' => 'sec_primary_navbar',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'More color options for primary navigation are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) . '#description' ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_header_block',
|
||||
array(
|
||||
'section' => 'sec_header_block',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'More header blocks and footer blocks are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_footer_block',
|
||||
array(
|
||||
'section' => 'sec_footer_block',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'More footer blocks and header blocks are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_content',
|
||||
array(
|
||||
'section' => 'sec_content',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'Content background, text color, button color, link color and many more options are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_sidebar',
|
||||
array(
|
||||
'section' => 'sec_sidebar',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'Sidebar background, text color, post meta color, and many more options are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_blog',
|
||||
array(
|
||||
'section' => 'sec_blog',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'More blog options and advanced theme options are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \PressBook_Upsell_Control(
|
||||
$wp_customize,
|
||||
'sec_footer',
|
||||
array(
|
||||
'section' => 'sec_footer',
|
||||
'type' => 'pressbook-addon',
|
||||
'label' => esc_html__( 'Learn More', 'pressbook' ),
|
||||
'description' => esc_html__( 'More footer and color options are available in our premium version.', 'pressbook' ),
|
||||
'url' => ( esc_url( Helpers::get_upsell_detail_url() ) ),
|
||||
'priority' => 999,
|
||||
'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user