Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
IncludeExcerpt
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 init
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addSetting
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
 render
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Setting: Include excerpt
7 *
8 * @package Beyondwords\Wordpress
9 * @author  Stuart McAlpine <stu@beyondwords.io>
10 * @since   3.0.0
11 * @since   5.0.0 Rename labels from "Prepend excerpt" to "Include excerpt".
12 */
13
14namespace Beyondwords\Wordpress\Component\Settings\Fields\IncludeExcerpt;
15
16/**
17 * IncludeExcerpt
18 *
19 * @since 3.0.0
20 */
21class IncludeExcerpt
22{
23    /**
24     * Default value.
25     *
26     * @var string
27     */
28    public const DEFAULT_VALUE = false;
29
30    /**
31     * Option name.
32     *
33     * @var string
34     */
35    public const OPTION_NAME = 'beyondwords_prepend_excerpt';
36
37    /**
38     * Init.
39     *
40     * @since 4.0.0
41     */
42    public function init()
43    {
44        add_action('admin_init', array($this, 'addSetting'));
45        add_filter('option_' . self::OPTION_NAME, 'rest_sanitize_boolean');
46    }
47
48    /**
49     * Init setting.
50     *
51     * @since 3.0.0
52     * @since 5.0.0 Rename field.
53     *
54     * @return void
55     */
56    public function addSetting()
57    {
58        register_setting(
59            'beyondwords_content_settings',
60            self::OPTION_NAME,
61            [
62                'type'              => 'boolean',
63                'sanitize_callback' => 'rest_sanitize_boolean',
64                'default'           => self::DEFAULT_VALUE,
65            ]
66        );
67
68        add_settings_field(
69            'beyondwords-include-excerpt',
70            __('Excerpt', 'speechkit'),
71            array($this, 'render'),
72            'beyondwords_content',
73            'content'
74        );
75    }
76
77    /**
78     * Render setting field.
79     *
80     * @since 3.0.0
81     * @since 4.0.0 Updated label and description
82     * @since 5.0.0 Updated label and description
83     *
84     * @return void
85     **/
86    public function render()
87    {
88        $value = get_option(self::OPTION_NAME);
89        ?>
90        <div>
91            <label>
92                <input type="hidden" name="<?php echo esc_attr(self::OPTION_NAME); ?>" value="" />
93                <input
94                    type="checkbox"
95                    id="<?php echo esc_attr(self::OPTION_NAME); ?>"
96                    name="<?php echo esc_attr(self::OPTION_NAME); ?>"
97                    value="1"
98                    <?php checked($value); ?>
99                />
100                <?php esc_html_e('Include excerpts in audio', 'speechkit'); ?>
101            </label>
102        </div>
103        <?php
104    }
105}