: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$result = ( $bc ) ? bcmul( $number1, $number2, $precision ) /* string */ : ( $number1 * $number2 );
$result = bcdiv( $number1, $number2, $precision ); // String, or NULL if right_operand is 0.
elseif ( $number2 != 0 ) { // phpcs:ignore Universal.Operators.StrictComparisons -- Purposeful loose comparison.
$result = ( $number1 / $number2 );
if ( ! isset( $result ) ) {
$result = bcmod( $number1, $number2 ); // String, or NULL if modulus is 0.
elseif ( $number2 != 0 ) { // phpcs:ignore Universal.Operators.StrictComparisons -- Purposeful loose comparison.
$result = ( $number1 % $number2 );
if ( ! isset( $result ) ) {
$result = bccomp( $number1, $number2, $precision ); // Returns int 0, 1 or -1.
// phpcs:ignore Universal.Operators.StrictComparisons -- Purposeful loose comparison.
$result = ( $number1 == $number2 ) ? 0 : ( ( $number1 > $number2 ) ? 1 : -1 );
if ( isset( $result ) ) {
if ( $compare === false ) {
$result = round( floatval( $result ), $decimals );
// phpcs:ignore Universal.Operators.StrictComparisons -- Purposeful loose comparison.
$result = ( intval( $result ) == $result ) ? intval( $result ) : floatval( $result );
* Trim whitespace and NBSP (Non-breaking space) from string.
* @param string $text String input to trim.
public static function trim_nbsp_from_string( $text ) {
$find = [ ' ', chr( 0xC2 ) . chr( 0xA0 ) ];
$text = str_replace( $find, ' ', $text );
* Check if a string is a valid datetime.
* @param string $datetime String input to check as valid input for DateTime class.
public static function is_valid_datetime( $datetime ) {
return YoastSEO()->helpers->date->is_valid_datetime( $datetime );
* Format the URL to be sure it is okay for using as a redirect url.
* This method will parse the URL and combine them in one string.
* @param string $url URL string.
public static function format_url( $url ) {
$parsed_url = wp_parse_url( $url );
if ( ! empty( $parsed_url['path'] ) ) {
$formatted_url = $parsed_url['path'];
// Prepend a slash if first char != slash.
if ( stripos( $formatted_url, '/' ) !== 0 ) {
$formatted_url = '/' . $formatted_url;
// Append 'query' string if it exists.
if ( ! empty( $parsed_url['query'] ) ) {
$formatted_url .= '?' . $parsed_url['query'];
return apply_filters( 'wpseo_format_admin_url', $formatted_url );
* Retrieves the sitename.
public static function get_site_name() {
return YoastSEO()->helpers->site->get_site_name();
* Check if the current opened page is a Yoast SEO page.
public static function is_yoast_seo_page() {
return YoastSEO()->helpers->current_page->is_yoast_seo_page();
* Check if the current opened page belongs to Yoast SEO Free.
* @param string $current_page The current page the user is on.
public static function is_yoast_seo_free_page( $current_page ) {
$yoast_seo_free_pages = [
return in_array( $current_page, $yoast_seo_free_pages, true );
* Determine if Yoast SEO is in development mode?
* Inspired by JetPack (https://github.com/Automattic/jetpack/blob/master/class.jetpack.php#L1383-L1406).
public static function is_development_mode() {
$development_mode = false;
if ( defined( 'YOAST_ENVIRONMENT' ) && YOAST_ENVIRONMENT === 'development' ) {
$development_mode = true;
elseif ( defined( 'WPSEO_DEBUG' ) ) {
$development_mode = WPSEO_DEBUG;
elseif ( site_url() && strpos( site_url(), '.' ) === false ) {
$development_mode = true;
* Filter the Yoast SEO development mode.
* @param bool $development_mode Is Yoast SEOs development mode active.
return apply_filters( 'yoast_seo_development_mode', $development_mode );
* Retrieve home URL with proper trailing slash.
* @param string $path Path relative to home URL.
* @param string|null $scheme Scheme to apply.
* @return string Home URL with optional path, appropriately slashed if not.
public static function home_url( $path = '', $scheme = null ) {
return YoastSEO()->helpers->url->home( $path, $scheme );
* Checks if the WP-REST-API is available.
* @since 3.7 Introduced the $minimum_version parameter.
* @param string $minimum_version The minimum version the API should be.
* @return bool Returns true if the API is available.
public static function is_api_available( $minimum_version = '2.0' ) {
return ( defined( 'REST_API_VERSION' )
&& version_compare( REST_API_VERSION, $minimum_version, '>=' ) );
* Determine whether or not the metabox should be displayed for a post type.
* @param string|null $post_type Optional. The post type to check the visibility of the metabox for.
* @return bool Whether or not the metabox should be displayed.
protected static function display_post_type_metabox( $post_type = null ) {
if ( ! isset( $post_type ) ) {
$post_type = get_post_type();
if ( ! isset( $post_type ) || ! WPSEO_Post_Type::is_post_type_accessible( $post_type ) ) {
if ( $post_type === 'attachment' && WPSEO_Options::get( 'disable-attachment' ) ) {
return apply_filters( 'wpseo_enable_editor_features_' . $post_type, WPSEO_Options::get( 'display-metabox-pt-' . $post_type ) );
* Determine whether or not the metabox should be displayed for a taxonomy.
* @param string|null $taxonomy Optional. The post type to check the visibility of the metabox for.
* @return bool Whether or not the metabox should be displayed.
protected static function display_taxonomy_metabox( $taxonomy = null ) {
if ( ! isset( $taxonomy ) || ! in_array( $taxonomy, get_taxonomies( [ 'public' => true ], 'names' ), true ) ) {
return WPSEO_Options::get( 'display-metabox-tax-' . $taxonomy );
* Determines whether the metabox is active for the given identifier and type.
* @param string $identifier The identifier to check for.
* @param string $type The type to check for.
* @return bool Whether or not the metabox is active.
public static function is_metabox_active( $identifier, $type ) {
if ( $type === 'post_type' ) {
return self::display_post_type_metabox( $identifier );
if ( $type === 'taxonomy' ) {
return self::display_taxonomy_metabox( $identifier );
* Determines whether the plugin is active for the entire network.
* @return bool Whether the plugin is network-active.
public static function is_plugin_network_active() {
return YoastSEO()->helpers->url->is_plugin_network_active();
* Gets the type of the current post.
* @return string The post type, or an empty string.
public static function get_post_type() {
$wp_screen = get_current_screen();
if ( $wp_screen !== null && ! empty( $wp_screen->post_type ) ) {
return $wp_screen->post_type;
* Gets the type of the current page.
* @return string Returns 'post' if the current page is a post edit page. Taxonomy in other cases.
public static function get_page_type() {
if ( WPSEO_Metabox::is_post_edit( $pagenow ) ) {
* Getter for the Adminl10n array. Applies the wpseo_admin_l10n filter.
* @return array The Adminl10n array.
public static function get_admin_l10n() {
$post_type = self::get_post_type();
$page_type = self::get_page_type();
if ( $page_type === 'post' ) {
$label_object = get_post_type_object( $post_type );
$no_index = WPSEO_Options::get( 'noindex-' . $post_type, false );
$label_object = WPSEO_Taxonomy::get_labels();
$wp_screen = get_current_screen();
if ( $wp_screen !== null && ! empty( $wp_screen->taxonomy ) ) {
$taxonomy_slug = $wp_screen->taxonomy;
$no_index = WPSEO_Options::get( 'noindex-tax-' . $taxonomy_slug, false );
'displayAdvancedTab' => WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) || ! WPSEO_Options::get( 'disableadvanced_meta' ),
'noIndex' => (bool) $no_index,
'isPostType' => (bool) get_post_type(),
'postType' => get_post_type(),
'postTypeNamePlural' => ( $page_type === 'post' ) ? $label_object->label : $label_object->name,
'postTypeNameSingular' => ( $page_type === 'post' ) ? $label_object->labels->singular_name : $label_object->singular_name,
'isBreadcrumbsDisabled' => WPSEO_Options::get( 'breadcrumbs-enable', false ) !== true && ! current_theme_supports( 'yoast-seo-breadcrumbs' ),
// phpcs:ignore Generic.ControlStructures.DisallowYodaConditions -- Bug: squizlabs/PHP_CodeSniffer#2962.
'isPrivateBlog' => ( (string) get_option( 'blog_public' ) ) === '0',
'news_seo_is_active' => ( defined( 'WPSEO_NEWS_FILE' ) ),
$additional_entries = apply_filters( 'wpseo_admin_l10n', [] );
if ( is_array( $additional_entries ) ) {
$wpseo_admin_l10n = array_merge( $wpseo_admin_l10n, $additional_entries );
return $wpseo_admin_l10n;
* Retrieves the analysis worker log level. Defaults to errors only.
* Uses bool YOAST_SEO_DEBUG as flag to enable logging. Off equals ERROR.
* Uses string YOAST_SEO_DEBUG_ANALYSIS_WORKER as log level for the Analysis
* Worker. Defaults to INFO.
* Can be: TRACE, DEBUG, INFO, WARN or ERROR.
* @return string The log level to use.
public static function get_analysis_worker_log_level() {
if ( defined( 'YOAST_SEO_DEBUG' ) && YOAST_SEO_DEBUG ) {
return defined( 'YOAST_SEO_DEBUG_ANALYSIS_WORKER' ) ? YOAST_SEO_DEBUG_ANALYSIS_WORKER : 'INFO';
* Returns the unfiltered home URL.
* In case WPML is installed, returns the original home_url and not the WPML version.
* In case of a multisite setup we return the network_home_url.
* @return string The home url.
public static function get_home_url() {
return YoastSEO()->helpers->url->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.
* @param array $data Allows filtering of the JSON data for debug purposes.
$data = apply_filters( 'wpseo_debug_json_data', $data );
// phpcs:ignore Yoast.Yoast.JsonEncodeAlternative.FoundWithAdditionalParams -- This is the definition of format_json_encode.
return wp_json_encode( $data, $flags );
* Extends the allowed post tags with accessibility-related attributes.
* @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 ) {
if ( isset( $a11y_tags ) === false ) {
// Below are attributes that are needed for backwards compatibility (WP < 5.1).
'aria-describedby' => true,
'aria-describedby' => true,
'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.
* @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 ) {
if ( isset( $input_tags ) === false ) {