l->network_safe_home_url();
}
/**
* Prepares data for outputting as JSON.
*
* @param array $data The data to format.
*
* @return false|string The prepared JSON string.
*/
public static function format_json_encode( $data ) {
$flags = ( JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
if ( self::is_development_mode() ) {
$flags = ( $flags | JSON_PRETTY_PRINT );
/**
* Filter the Yoast SEO development mode.
*
* @api array $data Allows filtering of the JSON data for debug purposes.
*/
$data = apply_filters( 'wpseo_debug_json_data', $data );
}
// phpcs:ignore Yoast.Yoast.AlternativeFunctions.json_encode_wp_json_encodeWithAdditionalParams -- This is the definition of format_json_encode.
return wp_json_encode( $data, $flags );
}
/**
* Extends the allowed post tags with accessibility-related attributes.
*
* @codeCoverageIgnore
*
* @param array $allowed_post_tags The allowed post tags.
*
* @return array The allowed tags including post tags, input tags and select tags.
*/
public static function extend_kses_post_with_a11y( $allowed_post_tags ) {
static $a11y_tags;
if ( isset( $a11y_tags ) === false ) {
$a11y_tags = [
'button' => [
'aria-expanded' => true,
'aria-controls' => true,
],
'div' => [
'tabindex' => true,
],
// Below are attributes that are needed for backwards compatibility (WP < 5.1).
'span' => [
'aria-hidden' => true,
],
'input' => [
'aria-describedby' => true,
],
'select' => [
'aria-describedby' => true,
],
'textarea' => [
'aria-describedby' => true,
],
];
// Add the global allowed attributes to each html element.
$a11y_tags = array_map( '_wp_add_global_attributes', $a11y_tags );
}
return array_merge_recursive( $allowed_post_tags, $a11y_tags );
}
/**
* Extends the allowed post tags with input, select and option tags.
*
* @codeCoverageIgnore
*
* @param array $allowed_post_tags The allowed post tags.
*
* @return array The allowed tags including post tags, input tags, select tags and option tags.
*/
public static function extend_kses_post_with_forms( $allowed_post_tags ) {
static $input_tags;
if ( isset( $input_tags ) === false ) {
$input_tags = [
'input' => [
'accept' => true,
'accesskey' => true,
'align' => true,
'alt' => true,
'autocomplete' => true,
'autofocus' => true,
'checked' => true,
'contenteditable' => true,
'dirname' => true,
'disabled' => true,
'draggable' => true,
'dropzone' => true,
'form' => true,
'formaction' => true,
'formenctype' => true,
'formmethod' => true,
'formnovalidate' => true,
'formtarget' => true,
'height' => true,
'hidden' => true,
'lang' => true,
'list' => true,
'max' => true,
'maxlength' => true,
'min' => true,
'multiple' => true,
'name' => true,
'pattern' => true,
'placeholder' => true,
'readonly' => true,
'required' => true,
'size' => true,
'spellcheck' => true,
'src' => true,
'step' => true,
'tabindex' => true,
'translate' => true,
'type' => true,
'value' => true,
'width' => true,
/*
* Below are attributes that are needed for backwards compatibility (WP < 5.1).
* They are used for the social media image in the metabox.
* These can be removed once we move to the React versions of the social previews.
*/
'data-target' => true,
'data-target-id' => true,
],
'select' => [
'accesskey' => true,
'autofocus' => true,
'contenteditable' => true,
'disabled' => true,
'draggable' => true,
'dropzone' => true,
'form' => true,
'hidden' => true,
'lang' => true,
'multiple' => true,
'name' => true,
'onblur' => true,
'onchange' => true,
'oncontextmenu' => true,
'onfocus' => true,
'oninput' => true,
'oninvalid' => true,
'onreset' => true,
'onsearch' => true,
'onselect' => true,
'onsubmit' => true,
'required' => true,
'size' => true,
'spellcheck' => true,
'tabindex' => true,
'translate' => true,
],
'option' => [
'class' => true,
'disabled' => true,
'id' => true,
'label' => true,
'selected' => true,
'value' => true,
],
];
// Add the global allowed attributes to each html element.
$input_tags = array_map( '_wp_add_global_attributes', $input_tags );
}
return array_merge_recursive( $allowed_post_tags, $input_tags );
}
/**
* Gets an array of enabled features.
*
* @return string[] The array of enabled features.
*/
public static function retrieve_enabled_features() {
/**
* The feature flag integration.
*
* @var Feature_Flag_Integration $feature_flag_integration;
*/
$feature_flag_integration = YoastSEO()->classes->get( Feature_Flag_Integration::class );
return $feature_flag_integration->get_enabled_features();
}
/* ********************* DEPRECATED METHODS ********************* */
/**
* List all the available user roles.
*
* @since 1.8.0
* @deprecated 15.0
* @codeCoverageIgnore
*
* @return array
*/
public static function get_roles() {
_deprecated_function( __METHOD__, '15.0', 'wp_roles()->get_names()' );
$yoast_seo_wp_roles = wp_roles();
$roles = $yoast_seo_wp_roles->get_names();
return $roles;
}
/**
* Checks if the current installation supports MyYoast access tokens.
*
* @deprecated 15.0
* @codeCoverageIgnore
*
* @return bool True if access_tokens are supported.
*/
public static function has_access_token_support() {
_deprecated_function( __METHOD__, 'WPSEO 15.0' );
return false;
}
/**
* Standardize whitespace in a string.
*
* Replace line breaks, carriage returns, tabs with a space, then remove double spaces.
*
* @since 1.8.0
* @deprecated 15.2
* @codeCoverageIgnore
*
* @param string $text String input to standardize.
*
* @return string
*/
public static function standardize_whitespace( $text ) {
_deprecated_function( __METHOD__, 'WPSEO 15.2' );
return YoastSEO()->helpers->string->standardize_whitespace( $text );
}
/**
* First strip out registered and enclosing shortcodes using native WordPress strip_shortcodes function.
* Then strip out the shortcodes with a filthy regex, because people don't properly register their shortcodes.
*
* @since 1.8.0
* @deprecated 15.2
* @codeCoverageIgnore
*
* @param string $text Input string that might contain shortcodes.
*
* @return string String without shortcodes.
*/
public static function strip_shortcode( $text ) {
_deprecated_function( __METHOD__, 'WPSEO 15.2' );
return YoastSEO()->helpers->string->strip_shortcode( $text );
}
/**
* Retrieves the title separator.
*
* @since 3.0.0
* @deprecated 15.2
* @codeCoverageIgnore
*
* @return string
*/
public static function get_title_separator() {
_deprecated_function( __METHOD__, 'WPSEO 15.2', 'Yoast\WP\SEO\Helpers\Options_Helper::get_title_separator' );
return YoastSEO()->helpers->options->get_title_separator();
}
/**
* Flush W3TC cache after successful update/add of taxonomy meta option.
*
* @since 1.8.0
* @deprecated 15.3
* @codeCoverageIgnore
*/
public static function flush_w3tc_cache() {
_deprecated_function( __METHOD__, 'WPSEO 15.3' );
}
/**
* Determines whether or not WooCommerce is active.
*
* @deprecated 15.3
* @codeCoverageIgnore
*
* @return bool Whether or not WooCommerce is active.
*/
public static function is_woocommerce_active() {
_deprecated_function( __METHOD__, 'WPSEO 15.3' );
return YoastSEO()->helpers->woocommerce->is_active();
}
/**
* Outputs a Schema blob.
*
* @deprecated 15.5
* @codeCoverageIgnore
*
* @param array $graph The Schema graph array to output.
* @param string $class_to_add The (optional) class to add to the script tag.
*
* @return bool
*/
public static function schema_output( $graph, $class_to_add = 'yoast-schema-graph' ) {
_deprecated_function( __METHOD__, 'WPSEO 15.5' );
if ( ! is_array( $graph ) || empty( $graph ) ) {
return false;
}
// phpcs:ignore WordPress.Security.EscapeOutput -- Escaping happens in WPSEO_Utils::schema_tag, which should be whitelisted.
echo self::schema_tag( $graph, $class_to_add );
return true;
}
/**
* Returns a script tag with Schema blob.
*
* @deprecated 15.5
* @codeCoverageIgnore
*
* @param array $graph The Schema graph array to output.
* @param string $class_to_add The (optional) class to add to the script tag.
*
* @return false|string A schema blob with script tags.
*/
public static function schema_tag( $graph, $class_to_add = 'yoast-schema-graph' ) {
_deprecated_function( __METHOD__, 'WPSEO 15.5' );
if ( ! is_array( $graph ) || empty( $graph ) ) {
return false;
}
$output = [
'@context' => 'https://schema.org',
'@graph' => $graph,
];
return "' . "\n";
}
/**
* Returns the SVG for the traffic light in the metabox.
*
* @deprecated 15.5
* @codeCoverageIgnore
*
* @return string
*/
public static function traffic_light_svg() {
_deprecated_function( __METHOD__, 'WPSEO 15.5' );
return <<<'SVG'
SVG;
}
/**
* Gets the plugin name from file.
*
* @since 2.3.3
* @deprecated 15.5
* @codeCoverageIgnore
*
* @param string $plugin Plugin path relative to plugins directory.
*
* @return string|bool
*/
public static function get_plugin_name( $plugin ) {
_deprecated_function( __METHOD__, 'WPSEO 15.5' );
$plugin_details = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
if ( $plugin_details['Name'] !== '' ) {
return $plugin_details['Name'];
}
return false;
}
/**
* Returns a base64 URL for the svg for use in the menu.
*
* @since 3.3.0
* @deprecated 15.5
* @codeCoverageIgnore
*
* @param bool $base64 Whether or not to return base64'd output.
*
* @return string
*/
public static function get_icon_svg( $base64 = true ) {
_deprecated_function( __METHOD__, 'WPSEO 15.5' );
$svg = '';
if ( $base64 ) {
//phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- This encoding is intended.
return 'data:image/svg+xml;base64,' . base64_encode( $svg );
}
return $svg;
}
/**
* Checks whether the current user is allowed to access the configuration.
*
* @since 1.8.0
* @deprecated 15.5
* @codeCoverageIgnore
*
* @return bool
*/
public static function grant_access() {
_deprecated_function( __METHOD__, 'WPSEO 15.5' );
if ( ! is_multisite() ) {
return true;
}
$options = get_site_option( 'wpseo_ms' );
if ( empty( $options['access'] ) || $options['access'] === 'admin' ) {
return current_user_can( 'wpseo_manage_options' );
}
return is_super_admin();
}
}