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

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

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

0.0
/admin/filters/class-abstract-post-filter.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Filters
6
 */
7

8
/**
9
 * Class WPSEO_Abstract_Post_Filter.
10
 */
11
abstract class WPSEO_Abstract_Post_Filter implements WPSEO_WordPress_Integration {
12

13
        /**
14
         * The filter's query argument.
15
         *
16
         * @var string
17
         */
18
        public const FILTER_QUERY_ARG = 'yoast_filter';
19

20
        /**
21
         * Modify the query based on the FILTER_QUERY_ARG variable in $_GET.
22
         *
23
         * @param string $where Query variables.
24
         *
25
         * @return string The modified query.
26
         */
27
        abstract public function filter_posts( $where );
28

29
        /**
30
         * Returns the query value this filter uses.
31
         *
32
         * @return string The query value this filter uses.
33
         */
34
        abstract public function get_query_val();
35

36
        /**
37
         * Returns the total number of posts that match this filter.
38
         *
39
         * @return int The total number of posts that match this filter.
40
         */
41
        abstract protected function get_post_total();
42

43
        /**
44
         * Returns the label for this filter.
45
         *
46
         * @return string The label for this filter.
47
         */
48
        abstract protected function get_label();
49

50
        /**
51
         * Registers the hooks.
52
         *
53
         * @return void
54
         */
55
        public function register_hooks() {
×
56
                add_action( 'admin_init', [ $this, 'add_filter_links' ], 11 );
×
57

58
                add_filter( 'posts_where', [ $this, 'filter_posts' ] );
×
59

60
                if ( $this->is_filter_active() ) {
×
61
                        add_action( 'restrict_manage_posts', [ $this, 'render_hidden_input' ] );
×
62
                }
63

64
                if ( $this->is_filter_active() && $this->get_explanation() !== null ) {
×
65
                        add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_explanation_assets' ] );
×
66
                }
67
        }
68

69
        /**
70
         * Adds the filter links to the view_edit screens to give the user a filter link.
71
         *
72
         * @return void
73
         */
74
        public function add_filter_links() {
×
75
                foreach ( $this->get_post_types() as $post_type ) {
×
76
                        add_filter( 'views_edit-' . $post_type, [ $this, 'add_filter_link' ] );
×
77
                }
78
        }
79

80
        /**
81
         * Enqueues the necessary assets to display a filter explanation.
82
         *
83
         * @return void
84
         */
85
        public function enqueue_explanation_assets() {
×
86
                $asset_manager = new WPSEO_Admin_Asset_Manager();
×
87
                $asset_manager->enqueue_script( 'filter-explanation' );
×
88
                $asset_manager->enqueue_style( 'filter-explanation' );
×
89
                $asset_manager->localize_script(
×
90
                        'filter-explanation',
×
91
                        'yoastFilterExplanation',
×
92
                        [ 'text' => $this->get_explanation() ]
×
UNCOV
93
                );
×
94
        }
95

96
        /**
97
         * Adds a filter link to the views.
98
         *
99
         * @param array<string, string> $views Array with the views.
100
         *
101
         * @return array<string, string> Array of views including the added view.
102
         */
103
        public function add_filter_link( $views ) {
×
104
                $views[ 'yoast_' . $this->get_query_val() ] = sprintf(
×
105
                        '<a href="%1$s"%2$s>%3$s</a> (%4$s)',
×
106
                        esc_url( $this->get_filter_url() ),
×
107
                        ( $this->is_filter_active() ) ? ' class="current" aria-current="page"' : '',
×
108
                        $this->get_label(),
×
109
                        $this->get_post_total()
×
UNCOV
110
                );
×
111

112
                return $views;
×
113
        }
114

115
        /**
116
         * Returns a text explaining this filter. Null if no explanation is necessary.
117
         *
118
         * @return string|null The explanation or null.
119
         */
120
        protected function get_explanation() {
×
121
                return null;
×
122
        }
123

124
        /**
125
         * Renders a hidden input to preserve this filter's state when using sub-filters.
126
         *
127
         * @return void
128
         */
129
        public function render_hidden_input() {
×
130
                echo '<input type="hidden" name="' . esc_attr( self::FILTER_QUERY_ARG ) . '" value="' . esc_attr( $this->get_query_val() ) . '">';
×
131
        }
132

133
        /**
134
         * Returns an url to edit.php with post_type and this filter as the query arguments.
135
         *
136
         * @return string The url to activate this filter.
137
         */
138
        protected function get_filter_url() {
×
UNCOV
139
                $query_args = [
×
140
                        self::FILTER_QUERY_ARG => $this->get_query_val(),
×
141
                        'post_type'            => $this->get_current_post_type(),
×
UNCOV
142
                ];
×
143

144
                return add_query_arg( $query_args, 'edit.php' );
×
145
        }
146

147
        /**
148
         * Returns true when the filter is active.
149
         *
150
         * @return bool Whether the filter is active.
151
         */
152
        protected function is_filter_active() {
×
153
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
154
                if ( isset( $_GET[ self::FILTER_QUERY_ARG ] ) && is_string( $_GET[ self::FILTER_QUERY_ARG ] ) ) {
×
155
                        // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
156
                        return sanitize_text_field( wp_unslash( $_GET[ self::FILTER_QUERY_ARG ] ) ) === $this->get_query_val();
×
157
                }
158
                return false;
×
159
        }
160

161
        /**
162
         * Returns the current post type.
163
         *
164
         * @return string The current post type.
165
         */
166
        protected function get_current_post_type() {
×
167
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
168
                if ( isset( $_GET['post_type'] ) && is_string( $_GET['post_type'] ) ) {
×
169
                        // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
170
                        $post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) );
×
171
                        if ( ! empty( $post_type ) ) {
×
172
                                return $post_type;
×
173
                        }
174
                }
175
                return 'post';
×
176
        }
177

178
        /**
179
         * Returns the post types to which this filter should be added.
180
         *
181
         * @return array The post types to which this filter should be added.
182
         */
183
        protected function get_post_types() {
×
184
                return WPSEO_Post_Type::get_accessible_post_types();
×
185
        }
186

187
        /**
188
         * Checks if the post type is supported.
189
         *
190
         * @param string $post_type Post type to check against.
191
         *
192
         * @return bool True when it is supported.
193
         */
194
        protected function is_supported_post_type( $post_type ) {
×
195
                return in_array( $post_type, $this->get_post_types(), true );
×
196
        }
197
}
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

© 2025 Coveralls, Inc