• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / d5c0395617268a4e44627c6847bf3faa0a6cc695

15 Apr 2025 07:12AM UTC coverage: 52.454% (-2.1%) from 54.595%
d5c0395617268a4e44627c6847bf3faa0a6cc695

push

github

web-flow
Merge pull request #22077 from Yoast/feature/drop-php-7.2-7.3

Drop compatibility with PHP 7.2 and 7.3

7826 of 13877 branches covered (56.4%)

Branch coverage included in aggregate %.

29028 of 56382 relevant lines covered (51.48%)

42273.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/admin/class-paper-presenter.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin
6
 */
7

8
/**
9
 * Class WPSEO_presenter_paper.
10
 */
11
class WPSEO_Paper_Presenter {
12

13
        /**
14
         * Title of the paper.
15
         *
16
         * @var string
17
         */
18
        private $title;
19

20
        /**
21
         * The view variables.
22
         *
23
         * @var array
24
         */
25
        private $settings;
26

27
        /**
28
         * The path to the view file.
29
         *
30
         * @var string
31
         */
32
        private $view_file;
33

34
        /**
35
         * WPSEO_presenter_paper constructor.
36
         *
37
         * @param string      $title     The title of the paper.
38
         * @param string|null $view_file Optional. The path to the view file. Use the content setting
39
         *                               if do not wish to use a view file.
40
         * @param array       $settings  Optional. Settings for the paper.
41
         */
42
        public function __construct( $title, $view_file = null, array $settings = [] ) {
2✔
43
                $defaults = [
2✔
44
                        'paper_id'                 => null,
2✔
45
                        'paper_id_prefix'          => 'wpseo-',
2✔
46
                        'collapsible'              => false,
2✔
47
                        'collapsible_header_class' => '',
2✔
48
                        'expanded'                 => false,
2✔
49
                        'help_text'                => '',
2✔
50
                        'title_after'              => '',
2✔
51
                        'class'                    => '',
2✔
52
                        'content'                  => '',
2✔
53
                        'view_data'                => [],
2✔
54
                ];
2✔
55

56
                $this->settings  = wp_parse_args( $settings, $defaults );
2✔
57
                $this->title     = $title;
2✔
58
                $this->view_file = $view_file;
2✔
59
        }
60

61
        /**
62
         * Renders the collapsible paper and returns it as a string.
63
         *
64
         * @return string The rendered paper.
65
         */
66
        public function get_output() {
2✔
67
                $view_variables = $this->get_view_variables();
2✔
68

69
                extract( $view_variables, EXTR_SKIP );
2✔
70

71
                $content = $this->settings['content'];
2✔
72

73
                if ( $this->view_file !== null ) {
2✔
74
                        ob_start();
×
75
                        require $this->view_file;
×
76
                        $content = ob_get_clean();
×
77
                }
78

79
                ob_start();
2✔
80
                require WPSEO_PATH . 'admin/views/paper-collapsible.php';
2✔
81
                $rendered_output = ob_get_clean();
2✔
82

83
                return $rendered_output;
2✔
84
        }
85

86
        /**
87
         * Retrieves the view variables.
88
         *
89
         * @return array The view variables.
90
         */
91
        private function get_view_variables() {
2✔
92
                if ( $this->settings['help_text'] instanceof WPSEO_Admin_Help_Panel === false ) {
2✔
93
                        $this->settings['help_text'] = new WPSEO_Admin_Help_Panel( '', '', '' );
2✔
94
                }
95

96
                $view_variables = [
2✔
97
                        'class'                    => $this->settings['class'],
2✔
98
                        'collapsible'              => $this->settings['collapsible'],
2✔
99
                        'collapsible_config'       => $this->collapsible_config(),
2✔
100
                        'collapsible_header_class' => $this->settings['collapsible_header_class'],
2✔
101
                        'title_after'              => $this->settings['title_after'],
2✔
102
                        'help_text'                => $this->settings['help_text'],
2✔
103
                        'view_file'                => $this->view_file,
2✔
104
                        'title'                    => $this->title,
2✔
105
                        'paper_id'                 => $this->settings['paper_id'],
2✔
106
                        'paper_id_prefix'          => $this->settings['paper_id_prefix'],
2✔
107
                        'yform'                    => Yoast_Form::get_instance(),
2✔
108
                ];
2✔
109

110
                return array_merge( $this->settings['view_data'], $view_variables );
2✔
111
        }
112

113
        /**
114
         * Retrieves the collapsible config based on the settings.
115
         *
116
         * @return array The config.
117
         */
118
        protected function collapsible_config() {
2✔
119
                if ( empty( $this->settings['collapsible'] ) ) {
2✔
120
                        return [
2✔
121
                                'toggle_icon' => '',
2✔
122
                                'class'       => '',
2✔
123
                                'expanded'    => '',
2✔
124
                        ];
2✔
125
                }
126

127
                if ( ! empty( $this->settings['expanded'] ) ) {
×
128
                        return [
×
129
                                'toggle_icon' => 'dashicons-arrow-up-alt2',
×
130
                                'class'       => 'toggleable-container',
×
131
                                'expanded'    => 'true',
×
132
                        ];
×
133
                }
134

135
                return [
×
136
                        'toggle_icon' => 'dashicons-arrow-down-alt2',
×
137
                        'class'       => 'toggleable-container toggleable-container-hidden',
×
138
                        'expanded'    => 'false',
×
139
                ];
×
140
        }
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc