lugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
if ( ! is_plugin_active_for_network( plugin_basename( RANK_MATH_FILE ) ) ) {
return false;
}
return true;
}
/**
* Helper function to validate & format ISO 8601 duration.
*
* @param string $iso8601 Duration which need to be converted to seconds.
* @return string
*
* @since 1.0.21
*/
public static function get_formatted_duration( $iso8601 ) {
$end = substr( $iso8601, -1 );
if ( ! in_array( $end, [ 'D', 'H', 'M', 'S' ], true ) ) {
return '';
}
// The format starts with the letter P, for "period".
return ( ! Str::starts_with( 'P', $iso8601 ) ) ? 'PT' . $iso8601 : $iso8601;
}
/**
* Get robots default.
*
* @return array
*/
public static function get_robots_defaults() {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : new stdClass();
$robots = Helper::get_settings( 'titles.robots_global', [] );
if ( $screen instanceof WP_Screen ) {
if ( in_array( $screen->base, [ 'post', 'edit' ], true ) && isset( $screen->post_type ) && Helper::get_settings( "titles.pt_{$screen->post_type}_custom_robots" ) ) {
$robots = Helper::get_settings( "titles.pt_{$screen->post_type}_robots", [] );
}
if ( in_array( $screen->base, [ 'term', 'edit-tags' ], true ) && isset( $screen->taxonomy ) && Helper::get_settings( "titles.tax_{$screen->taxonomy}_custom_robots" ) ) {
$robots = Helper::get_settings( "titles.tax_{$screen->taxonomy}_robots", [] );
}
if ( in_array( $screen->base, [ 'profile', 'user-edit' ], true ) && Helper::get_settings( 'titles.author_custom_robots' ) ) {
$robots = Helper::get_settings( 'titles.author_robots', [] );
}
}
if ( is_array( $robots ) && ! in_array( 'noindex', $robots, true ) ) {
$robots[] = 'index';
}
return $robots;
}
/**
* Get advanced robots default.
*
* @return array
*/
public static function get_advanced_robots_defaults() {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : new stdClass();
$advanced_robots = Helper::get_settings( 'titles.advanced_robots_global', [] );
if ( $screen instanceof WP_Screen ) {
if ( 'post' === $screen->base && Helper::get_settings( "titles.pt_{$screen->post_type}_custom_robots" ) ) {
$advanced_robots = Helper::get_settings( "titles.pt_{$screen->post_type}_advanced_robots", [] );
}
if ( 'term' === $screen->base && Helper::get_settings( "titles.tax_{$screen->taxonomy}_custom_robots" ) ) {
$advanced_robots = Helper::get_settings( "titles.tax_{$screen->taxonomy}_advanced_robots", [] );
}
if ( in_array( $screen->base, [ 'profile', 'user-edit' ], true ) && Helper::get_settings( 'titles.author_custom_robots' ) ) {
$advanced_robots = Helper::get_settings( 'titles.author_advanced_robots', [] );
}
}
return $advanced_robots;
}
/**
* Convert timestamp and ISO to date.
*
* @param string $value Value to convert.
* @param boolean $include_timezone Whether to include timezone.
*
* @return string
*/
public static function convert_date( $value, $include_timezone = false ) {
if ( Str::contains( 'T', $value ) ) {
$value = \strtotime( $value );
}
return $include_timezone ? date_i18n( 'Y-m-d H:i-T', $value ) : date_i18n( 'Y-m-d H:i', $value );
}
/**
* Helper function to convert ISO 8601 duration to seconds.
* For example "PT1H12M24S" becomes 5064.
*
* @param string $iso8601 Duration which need to be converted to seconds.
* @return int
*/
public static function duration_to_seconds( $iso8601 ) {
$end = substr( $iso8601, -1 );
if ( ! in_array( $end, [ 'D', 'H', 'M', 'S' ], true ) ) {
$iso8601 = $iso8601 . 'S';
}
$iso8601 = ! Str::starts_with( 'P', $iso8601 ) ? 'PT' . $iso8601 : $iso8601;
preg_match( '/^P([0-9]+D|)?T?([0-9]+H|)?([0-9]+M|)?([0-9]+S|)?$/', $iso8601, $matches );
if ( empty( $matches ) ) {
return false;
}
return array_sum(
[
absint( $matches[1] ) * DAY_IN_SECONDS,
absint( $matches[2] ) * HOUR_IN_SECONDS,
absint( $matches[3] ) * MINUTE_IN_SECONDS,
absint( $matches[4] ),
]
);
}
/**
* Id block editor enabled.
*
* @return bool
*/
public static function is_block_editor() {
// Check WordPress version.
if ( version_compare( get_bloginfo( 'version' ), '5.0.0', '<' ) ) {
return false;
}
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
if ( ! $screen instanceof WP_Screen ) {
return false;
}
if ( method_exists( $screen, 'is_block_editor' ) ) {
return $screen->is_block_editor();
}
if ( 'post' === $screen->base ) {
return self::use_block_editor_for_post_type( $screen->post_type );
}
return false;
}
/**
* Validate Image data. Remove empty values and add default height and width to image
*
* @param array $image The Image data.
* @return array Array of image data
*
* @since 1.0.64
*/
private static function validate_image_data( $image ) {
$image = array_filter( $image );
if ( empty( $image ) ) {
return [];
}
$image[1] = isset( $image[1] ) ? $image[1] : 200;
$image[2] = isset( $image[2] ) ? $image[2] : 200;
return $image;
}
/**
* Return whether a post type is compatible with the block editor.
*
* @param string $post_type The post type.
*
* @return bool Whether the post type can be edited with the block editor.
*/
private static function use_block_editor_for_post_type( $post_type ) {
if ( ! post_type_exists( $post_type ) ) {
return false;
}
if ( ! post_type_supports( $post_type, 'editor' ) ) {
return false;
}
$post_type_object = get_post_type_object( $post_type );
if ( $post_type_object && ! $post_type_object->show_in_rest ) {
return false;
}
/**
* Filter whether a post is able to be edited in the block editor.
*
* @since 5.0.0
*
* @param bool $use_block_editor Whether the post type can be edited or not. Default true.
* @param string $post_type The post type being checked.
*/
return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
}
/**
* Generate classes.
*
* @return string
*/
public static function classnames() {
$args = func_get_args();
$data = array_reduce(
$args,
function( $carry, $arg ) {
if ( is_array( $arg ) ) {
return array_merge( $carry, $arg );
}
$carry[] = $arg;
return $carry;
},
[]
);
$classes = array_map(
function ( $key, $value ) {
$condition = $value;
$return = $key;
if ( is_int( $key ) ) {
$condition = null;
$return = $value;
}
$is_array = is_array( $return );
$is_object = is_object( $return );
$is_stringable_type = ! $is_array && ! $is_object;
$is_stringable_object = $is_object && method_exists( $return, '__toString' );
if ( ! $is_stringable_type && ! $is_stringable_object ) {
return null;
}
if ( is_null( $condition ) ) {
return $return;
}
return $condition ? $return : null;
},
array_keys( $data ),
array_values( $data )
);
$classes = array_filter( $classes );
return implode( ' ', $classes );
}
/**
* An helper function get the home_url without the WPML language parameter.
*
* @param string $path Path relative to the home URL.
* @param string $scheme Scheme to give the home URL context.
*
* @return string
*/
public static function get_home_url( $path = '', $scheme = null ) {
Sitepress::get()->remove_home_url_filter();
$home_url = home_url( $path, $scheme );
Sitepress::get()->restore_home_url_filter();
return $home_url;
}
}
Fatal error: Trait 'RankMath\Helpers\WordPress' not found in /home/mpir1/public_html/wp-content/plugins/seo-by-rank-math/includes/class-helper.php on line 31