Your IP : 216.73.216.1
<?php
/**
* pally Excerpt
*
* @package pally
* @since 1.0.0
*/
namespace Pally;
use WP_Customize_Manager;
/**
* Options for the blog, search and archive pages.
*
* @since 1.0.0
*/
class Excerpt {
/**
* Constructor.
*
* @since 1.0.0
* @access public
*/
public function __construct() {
add_action( 'customize_register', [ $this, 'action_register_customizer_control' ] );
add_filter( 'excerpt_length', [ $this, 'filter_excerpt_length' ], 999 );
}
/**
* Adds a Customizer section, settings, controls and partials.
*
* @param WP_Customize_Manager $wp_customize Customizer manager instance.
* @access public
* @since 1.0.0
*/
public function action_register_customizer_control( WP_Customize_Manager $wp_customize ) {
$wp_customize->add_section(
'excerpt_options',
array(
'title' => __( 'Excerpt', 'pally' ),
'panel' => 'theme_options',
'priority' => 3,
)
);
$wp_customize->add_setting(
'excerpt_length',
array(
'default' => '45',
'transport' => 'postMessage',
'sanitize_callback' => 'absint',
)
);
$wp_customize->add_control(
'excerpt_length',
array(
'label' => __( 'Excerpt length', 'pally' ),
'description' => __( 'Adjust the number of words used in the generated excerpt.', 'pally' ),
'section' => 'excerpt_options',
'type' => 'number',
)
);
$wp_customize->selective_refresh->add_partial(
'excerpt_length',
array(
'selector' => '.entry-summary',
'container_ally' => true,
)
);
}
/**
* Add the excerpt length filter
*
* @access public
* @since 1.0.0
* @return int The length of the excerpt.
*/
public function filter_excerpt_length() {
if ( ! is_admin() ) {
$excerpt_length = absint( get_theme_mod( 'excerpt_length', 45 ) );
return $excerpt_length;
}
}
}