• 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
/inc/wpseo-functions.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Internals
6
 */
7

UNCOV
8
if ( ! defined( 'WPSEO_VERSION' ) ) {
×
UNCOV
9
        header( 'Status: 403 Forbidden' );
×
UNCOV
10
        header( 'HTTP/1.1 403 Forbidden' );
×
UNCOV
11
        exit();
×
12
}
13

UNCOV
14
if ( ! function_exists( 'yoast_breadcrumb' ) ) {
×
15
        /**
16
         * Template tag for breadcrumbs.
17
         *
18
         * @param string $before  What to show before the breadcrumb.
19
         * @param string $after   What to show after the breadcrumb.
20
         * @param bool   $display Whether to display the breadcrumb (true) or return it (false).
21
         *
22
         * @return string
23
         */
24
        function yoast_breadcrumb( $before = '', $after = '', $display = true ) {
25
                $breadcrumbs_enabled = current_theme_supports( 'yoast-seo-breadcrumbs' );
×
26
                if ( ! $breadcrumbs_enabled ) {
×
27
                        $breadcrumbs_enabled = WPSEO_Options::get( 'breadcrumbs-enable', false );
×
28
                }
29

30
                if ( $breadcrumbs_enabled ) {
×
31
                        return WPSEO_Breadcrumbs::breadcrumb( $before, $after, $display );
×
32
                }
33
        }
34
}
35

UNCOV
36
if ( ! function_exists( 'yoast_get_primary_term_id' ) ) {
×
37
        /**
38
         * Get the primary term ID.
39
         *
40
         * @param string           $taxonomy Optional. The taxonomy to get the primary term ID for. Defaults to category.
41
         * @param int|WP_Post|null $post     Optional. Post to get the primary term ID for.
42
         *
43
         * @return bool|int
44
         */
45
        function yoast_get_primary_term_id( $taxonomy = 'category', $post = null ) {
46
                $post = get_post( $post );
×
47

48
                $primary_term = new WPSEO_Primary_Term( $taxonomy, $post->ID );
×
49
                return $primary_term->get_primary_term();
×
50
        }
51
}
52

UNCOV
53
if ( ! function_exists( 'yoast_get_primary_term' ) ) {
×
54
        /**
55
         * Get the primary term name.
56
         *
57
         * @param string           $taxonomy Optional. The taxonomy to get the primary term for. Defaults to category.
58
         * @param int|WP_Post|null $post     Optional. Post to get the primary term for.
59
         *
60
         * @return string Name of the primary term.
61
         */
62
        function yoast_get_primary_term( $taxonomy = 'category', $post = null ) {
63
                $primary_term_id = yoast_get_primary_term_id( $taxonomy, $post );
×
64

65
                $term = get_term( $primary_term_id );
×
66
                if ( ! is_wp_error( $term ) && ! empty( $term ) ) {
×
67
                        return $term->name;
×
68
                }
69

70
                return '';
×
71
        }
72
}
73

74
/**
75
 * Replace `%%variable_placeholders%%` with their real value based on the current requested page/post/cpt.
76
 *
77
 * @param string $text The string to replace the variables in.
78
 * @param object $args The object some of the replacement values might come from,
79
 *                     could be a post, taxonomy or term.
80
 * @param array  $omit Variables that should not be replaced by this function.
81
 *
82
 * @return string
83
 */
84
function wpseo_replace_vars( $text, $args, $omit = [] ) {
UNCOV
85
        $replacer = new WPSEO_Replace_Vars();
×
86

UNCOV
87
        return $replacer->replace( $text, $args, $omit );
×
88
}
89

90
/**
91
 * Register a new variable replacement.
92
 *
93
 * This function is for use by other plugins/themes to easily add their own additional variables to replace.
94
 * This function should be called from a function on the 'wpseo_register_extra_replacements' action hook.
95
 * The use of this function is preferred over the older 'wpseo_replacements' filter as a way to add new replacements.
96
 * The 'wpseo_replacements' filter should still be used to adjust standard WPSEO replacement values.
97
 * The function can not be used to replace standard WPSEO replacement value functions and will thrown a warning
98
 * if you accidently try.
99
 * To avoid conflicts with variables registered by WPSEO and other themes/plugins, try and make the
100
 * name of your variable unique. Variable names also can not start with "%%cf_" or "%%ct_" as these are reserved
101
 * for the standard WPSEO variable variables 'cf_<custom-field-name>', 'ct_<custom-tax-name>' and
102
 * 'ct_desc_<custom-tax-name>'.
103
 * The replacement function will be passed the undelimited name (i.e. stripped of the %%) of the variable
104
 * to replace in case you need it.
105
 *
106
 * Example code:
107
 * <code>
108
 * <?php
109
 * function retrieve_var1_replacement( $var1 ) {
110
 *        return 'your replacement value';
111
 * }
112
 *
113
 * function register_my_plugin_extra_replacements() {
114
 *        wpseo_register_var_replacement( '%%myvar1%%', 'retrieve_var1_replacement', 'advanced', 'this is a help text for myvar1' );
115
 *        wpseo_register_var_replacement( 'myvar2', array( 'class', 'method_name' ), 'basic', 'this is a help text for myvar2' );
116
 * }
117
 * add_action( 'wpseo_register_extra_replacements', 'register_my_plugin_extra_replacements' );
118
 * ?>
119
 * </code>
120
 *
121
 * @since 1.5.4
122
 *
123
 * @param string $replacevar_name  The name of the variable to replace, i.e. '%%var%%'.
124
 *                                 Note: the surrounding %% are optional, name can only contain [A-Za-z0-9_-].
125
 * @param mixed  $replace_function Function or method to call to retrieve the replacement value for the variable.
126
 *                                 Uses the same format as add_filter/add_action function parameter and
127
 *                                 should *return* the replacement value. DON'T echo it.
128
 * @param string $type             Type of variable: 'basic' or 'advanced', defaults to 'advanced'.
129
 * @param string $help_text        Help text to be added to the help tab for this variable.
130
 *
131
 * @return bool Whether the replacement function was successfully registered.
132
 */
133
function wpseo_register_var_replacement( $replacevar_name, $replace_function, $type = 'advanced', $help_text = '' ) {
134
        return WPSEO_Replace_Vars::register_replacement( $replacevar_name, $replace_function, $type, $help_text );
×
135
}
136

137
/**
138
 * WPML plugin support: Set titles for custom types / taxonomies as translatable.
139
 *
140
 * It adds new keys to a wpml-config.xml file for a custom post type title, metadesc,
141
 * title-ptarchive and metadesc-ptarchive fields translation.
142
 * Documentation: http://wpml.org/documentation/support/language-configuration-files/
143
 *
144
 * @global $sitepress
145
 *
146
 * @param array $config WPML configuration data to filter.
147
 *
148
 * @return array
149
 */
150
function wpseo_wpml_config( $config ) {
151
        global $sitepress;
×
152

153
        if ( ( is_array( $config ) && isset( $config['wpml-config']['admin-texts']['key'] ) ) && ( is_array( $config['wpml-config']['admin-texts']['key'] ) && $config['wpml-config']['admin-texts']['key'] !== [] ) ) {
×
154
                $admin_texts = $config['wpml-config']['admin-texts']['key'];
×
155
                foreach ( $admin_texts as $k => $val ) {
×
156
                        if ( $val['attr']['name'] === 'wpseo_titles' ) {
×
157
                                $translate_cp = array_keys( $sitepress->get_translatable_documents() );
×
158
                                if ( is_array( $translate_cp ) && $translate_cp !== [] ) {
×
159
                                        foreach ( $translate_cp as $post_type ) {
×
160
                                                $admin_texts[ $k ]['key'][]['attr']['name'] = 'title-' . $post_type;
×
161
                                                $admin_texts[ $k ]['key'][]['attr']['name'] = 'metadesc-' . $post_type;
×
162
                                                $admin_texts[ $k ]['key'][]['attr']['name'] = 'title-ptarchive-' . $post_type;
×
163
                                                $admin_texts[ $k ]['key'][]['attr']['name'] = 'metadesc-ptarchive-' . $post_type;
×
164

165
                                                $translate_tax = $sitepress->get_translatable_taxonomies( false, $post_type );
×
166
                                                if ( is_array( $translate_tax ) && $translate_tax !== [] ) {
×
167
                                                        foreach ( $translate_tax as $taxonomy ) {
×
168
                                                                $admin_texts[ $k ]['key'][]['attr']['name'] = 'title-tax-' . $taxonomy;
×
169
                                                                $admin_texts[ $k ]['key'][]['attr']['name'] = 'metadesc-tax-' . $taxonomy;
×
170
                                                        }
171
                                                }
172
                                        }
173
                                }
174
                                break;
×
175
                        }
176
                }
177
                $config['wpml-config']['admin-texts']['key'] = $admin_texts;
×
178
        }
179

180
        return $config;
×
181
}
182

UNCOV
183
add_filter( 'icl_wpml_config_array', 'wpseo_wpml_config' );
×
184

UNCOV
185
if ( ! function_exists( 'ctype_digit' ) ) {
×
186
        /**
187
         * Emulate PHP native ctype_digit() function for when the ctype extension would be disabled *sigh*.
188
         * Only emulates the behaviour for when the input is a string, does not handle integer input as ascii value.
189
         *
190
         * @param string $text String input to validate.
191
         *
192
         * @return bool
193
         */
194
        function ctype_digit( $text ) {
UNCOV
195
                $return = false;
×
UNCOV
196
                if ( ( is_string( $text ) && $text !== '' ) && preg_match( '`^\d+$`', $text ) === 1 ) {
×
UNCOV
197
                        $return = true;
×
198
                }
199

UNCOV
200
                return $return;
×
201
        }
202
}
203

204
/**
205
 * Makes sure the taxonomy meta is updated when a taxonomy term is split.
206
 *
207
 * @link https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ Article explaining the taxonomy term splitting in WP 4.2.
208
 *
209
 * @param string $old_term_id      Old term id of the taxonomy term that was splitted.
210
 * @param string $new_term_id      New term id of the taxonomy term that was splitted.
211
 * @param string $term_taxonomy_id Term taxonomy id for the taxonomy that was affected.
212
 * @param string $taxonomy         The taxonomy that the taxonomy term was splitted for.
213
 *
214
 * @return void
215
 */
216
function wpseo_split_shared_term( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
217
        $tax_meta = get_option( 'wpseo_taxonomy_meta', [] );
×
218

219
        if ( ! empty( $tax_meta[ $taxonomy ][ $old_term_id ] ) ) {
×
220
                $tax_meta[ $taxonomy ][ $new_term_id ] = $tax_meta[ $taxonomy ][ $old_term_id ];
×
221
                unset( $tax_meta[ $taxonomy ][ $old_term_id ] );
×
222
                update_option( 'wpseo_taxonomy_meta', $tax_meta );
×
223
        }
224
}
225

UNCOV
226
add_action( 'split_shared_term', 'wpseo_split_shared_term', 10, 4 );
×
227

228
/**
229
 * Get all WPSEO related capabilities.
230
 *
231
 * @since 8.3
232
 * @return array
233
 */
234
function wpseo_get_capabilities() {
UNCOV
235
        if ( ! did_action( 'wpseo_register_capabilities' ) ) {
×
236
                do_action( 'wpseo_register_capabilities' );
×
237
        }
UNCOV
238
        return WPSEO_Capability_Manager_Factory::get()->get_capabilities();
×
239
}
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