mePage ) { if ( $wpmlHomePage['id'] === $postId ) { return true; } } return false; } /** * Returns the WPML url format. * * @since 4.2.8 * * @return string The format. */ public function getWpmlUrlFormat() { global $sitepress; if ( ! $this->isWpmlActive() || empty( $sitepress ) || ! method_exists( $sitepress, 'get_setting' ) ) { return ''; } switch ( $sitepress->get_setting( 'language_negotiation_type' ) ) { case WPML_LANGUAGE_NEGOTIATION_TYPE_DIRECTORY: case 1: return 'directory'; case WPML_LANGUAGE_NEGOTIATION_TYPE_DOMAIN: case 2: return 'domain'; case WPML_LANGUAGE_NEGOTIATION_TYPE_PARAMETER: case 3: return 'parameter'; default: return ''; } } /** * Returns the TranslatePress slugs code and slug. * * @since 4.7.3 * * @return array The slugs. */ public function getTranslatePressUrlSlugs() { if ( ! $this->isTranslatePressActive() ) { return []; } $settings = maybe_unserialize( get_option( 'trp_settings', [] ) ); return isset( $settings['url-slugs'] ) ? $settings['url-slugs'] : []; } /** * Checks whether the WooCommerce Follow Up Emails plugin is active. * * @since 4.2.2 * * @return bool Whether the plugin is active. */ public function isWooCommerceFollowupEmailsActive() { $isActive = defined( 'FUE_VERSION' ) || is_plugin_active( 'woocommerce-follow-up-emails/woocommerce-follow-up-emails.php' ); return $isActive; } /** * Checks if the current page is an AMP page. * This function is only effective if called after the `wp` action. * * @since 4.2.3 * * @param string $pluginName The name of the AMP plugin to check for (optional). * @return bool Whether the current page is an AMP page. */ public function isAmpPage( $pluginName = '' ) { // Official AMP plugin. if ( 'amp' === $pluginName ) { // If we're checking for the AMP page plugin specifically, return early if it's not active. // Otherwise, we'll return true if AMP for WP is enabled because the helper method doesn't distinguish between the two. if ( ! defined( 'AMP__VERSION' ) ) { return false; } $options = get_option( 'amp-options' ); if ( ! empty( $options['theme_support'] ) && 'standard' === strtolower( $options['theme_support'] ) ) { return true; } } return $this->isAmpPageHelper(); } /** * Helper function for {@see isAmpPage()}. * Checks if the current page is an AMP page. * * @since 4.2.4 * * @return bool Whether the current page is an AMP page. */ private function isAmpPageHelper() { // First check for the existence of any AMP plugin functions. Bail early if none are found, and prevent false positives. if ( ! function_exists( 'amp_is_request' ) && ! function_exists( 'is_amp_endpoint' ) && ! function_exists( 'ampforwp_is_amp_endpoint' ) && ! function_exists( 'is_amp_wp' ) ) { // If none of the AMP plugin functions are found, return false and allow compatibility with custom implementations. return apply_filters( 'aioseo_is_amp_page', false ); } // AMP plugin requires the `wp` action to be called to function properly, otherwise, it will throw warnings. // https://github.com/awesomemotive/aioseo/issues/6056 if ( did_action( 'wp' ) ) { // Check for the "AMP" plugin. if ( function_exists( 'amp_is_request' ) ) { return (bool) amp_is_request(); } // Check for the "AMP" plugin (`is_amp_endpoint()` is deprecated). if ( function_exists( 'is_amp_endpoint' ) ) { return (bool) is_amp_endpoint(); } // Check for the "AMP for WP – Accelerated Mobile Pages" plugin. if ( function_exists( 'ampforwp_is_amp_endpoint' ) ) { return (bool) ampforwp_is_amp_endpoint(); } // Check for the "AMP WP" plugin. if ( function_exists( 'is_amp_wp' ) ) { return (bool) is_amp_wp(); } } return false; } /** * If we're in a LearnPress lesson page, return the lesson ID. * * @since 4.3.1 * * @return int|false */ public function getLearnPressLesson() { // phpcs:disable Squiz.NamingConventions.ValidVariableName global $lp_course_item; if ( $lp_course_item && method_exists( $lp_course_item, 'get_id' ) ) { return $lp_course_item->get_id(); } // phpcs:enable Squiz.NamingConventions.ValidVariableName return false; } /** * Set a flag to indicate Divi whether it is processing internal content or not. * * @since 4.4.3 * * @param null|bool $flag The flag value. * @return null|bool The previous flag value to reset it later. */ public function setDiviInternalRendering( $flag ) { if ( ! defined( 'ET_BUILDER_VERSION' ) ) { return null; } // phpcs:disable Squiz.NamingConventions.ValidVariableName global $et_pb_rendering_column_content; $originalValue = $et_pb_rendering_column_content; $et_pb_rendering_column_content = $flag; // phpcs:enable Squiz.NamingConventions.ValidVariableName return $originalValue; } /** * Checks whether the current request is being done by a crawler from Yandex. * * @since 4.4.0 * * @return bool Whether the current request is being done by a crawler from Yandex. */ public function isYandexUserAgent() { if ( ! isset( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } return preg_match( '#.*Yandex.*#', (string) sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ); } /** * Checks whether the taxonomy is a WooCommerce product attribute. * * @since 4.7.8 * * @param mixed $taxonomy The taxonomy. * @return bool Whether the taxonomy is a WooCommerce product attribute. */ public function isWooCommerceProductAttribute( $taxonomy ) { $name = is_object( $taxonomy ) ? $taxonomy->name : ( is_array( $taxonomy ) ? $taxonomy['name'] : $taxonomy ); return ! empty( $name ) && 'pa_' === substr( $name, 0, 3 ); } /** * Returns whether a plugin is active or not using abstraction. * * @since 4.8.1 * * @param string $slug The plugin slug. * @return bool Whether the plugin is active. */ public function isPluginActive( $slug ) { $mapped = [ 'buddypress' => 'buddypress/bp-loader.php', 'bbpress' => 'bbpress/bbpress.php' ]; static $output = []; if ( isset( $output[ $slug ] ) ) { return $output[ $slug ]; } $mapped[ $slug ] = $mapped[ $slug ] ?? $slug; $output[ $slug ] = function_exists( 'is_plugin_active' ) && is_plugin_active( $mapped[ $slug ] ); return $output[ $slug ]; } }