if ( 'page' === $wpPost->post_type ) { $wp_query->is_page = true; } // phpcs:enable Squiz.NamingConventions.ValidVariableName $post = $wpPost; } /** * Sets the given term as the queried object of the main query. * * @since 4.9.3 * * @param \WP_Term|int $wpTerm The term object or ID. * @param string $taxonomy The taxonomy name. Required if $wpTerm is an ID. * @return void */ public function setWpQueryTerm( $wpTerm, $taxonomy = '' ) { $wpTerm = is_a( $wpTerm, 'WP_Term' ) ? $wpTerm : get_term( $wpTerm, $taxonomy ); if ( ! is_a( $wpTerm, 'WP_Term' ) ) { return; } // phpcs:disable Squiz.NamingConventions.ValidVariableName global $wp_query; $this->originalQuery = $this->deepClone( $wp_query ); $wp_query->queried_object = $wpTerm; $wp_query->queried_object_id = (int) $wpTerm->term_id; $wp_query->is_archive = true; // Set the appropriate taxonomy flag. switch ( $wpTerm->taxonomy ) { case 'category': $wp_query->is_category = true; break; case 'post_tag': $wp_query->is_tag = true; break; default: $wp_query->is_tax = true; break; } // phpcs:enable Squiz.NamingConventions.ValidVariableName } /** * Restores the main query back to the original query. * * @since 4.3.0 * * @return void */ public function restoreWpQuery() { global $wp_query, $post; // phpcs:ignore Squiz.NamingConventions.ValidVariableName if ( is_a( $this->originalQuery, 'WP_Query' ) ) { // Loop over all properties and replace the ones that have changed. // We want to avoid replacing the entire object because it can cause issues with other plugins. foreach ( $this->originalQuery as $key => $value ) { if ( $value !== $wp_query->{$key} ) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName $wp_query->{$key} = $value; // phpcs:ignore Squiz.NamingConventions.ValidVariableName } } } if ( is_a( $this->originalPost, 'WP_Post' ) ) { foreach ( $this->originalPost as $key => $value ) { if ( $value !== $post->{$key} ) { $post->{$key} = $value; } } } $this->originalQuery = null; $this->originalPost = null; } /** * Gets the list of theme features. * * @since 4.4.9 * * @return array List of theme features. */ public function getThemeFeatures() { global $_wp_theme_features; // phpcs:ignore Squiz.NamingConventions.ValidVariableName return isset( $_wp_theme_features ) && is_array( $_wp_theme_features ) ? $_wp_theme_features : []; // phpcs:ignore Squiz.NamingConventions.ValidVariableName } /** * Gets the active theme version. * * @since 4.9.6 * * @param bool $parent Whether to return the parent theme's version. * @return string|null The theme version, or null if parent requested but not found. */ public function getThemeVersion( $parent = false ) { $theme = wp_get_theme(); if ( $parent ) { return ( is_child_theme() && $theme->parent() ) ? $theme->parent()->version : null; } return $theme->version; } /** * Returns whether the active theme is a block-based theme or not. * * @since 4.5.3 * * @return bool Whether the active theme is a block-based theme or not. */ public function isBlockTheme() { if ( function_exists( 'wp_is_block_theme' ) ) { return wp_is_block_theme(); // phpcs:ignore AIOSEO.WpFunctionUse.NewFunctions.wp_is_block_themeFound, @wp-since ignore } return false; } /** * Retrieves the website name. * * @since 4.6.1 * * @return string The website name. */ public function getWebsiteName() { return aioseo()->options->searchAppearance->global->schema->websiteName ? aioseo()->tags->replaceTags( aioseo()->options->searchAppearance->global->schema->websiteName ) : aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'name' ) ); } /** * Checks if WordPress is set to discourage search engines from indexing the site. * * @since 4.9.9 * * @return boolean Whether search engines are discouraged from indexing the site. */ public function isSearchEnginesDiscouraged() { return ! get_option( 'blog_public' ); } /** * Polyfill for {@see wp_attachment_is()} since it uses `str_starts_with()` available only in PHP 8+ or WP 5.9+. * * @since 4.8.5 * * @param string $type Attachment type. Accepts `image`, `audio`, `video`, or a file extension. * @param int|\WP_Post $post Optional. Attachment ID or object. Default is global $post. * @return bool True if an accepted type or a matching file extension, false otherwise. */ public function attachmentIs( $type, $post = null ) { $post = get_post( $post ); $file = $post ? get_attached_file( $post->ID ) : false; if ( ! $type || ! $post || ! $file ) { return false; } if ( false !== stripos( $post->post_mime_type, $type . '/' ) ) { return true; } $check = wp_check_filetype( $file ); if ( empty( $check['ext'] ) ) { return false; } $ext = strtolower( $check['ext'] ); if ( ! in_array( $type, [ 'image', 'audio', 'video' ], true ) ) { return strtolower( $type ) === $ext; } $extensionMap = [ 'image' => [ 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp', 'avif', 'heic' ], 'audio' => wp_get_audio_extensions(), 'video' => wp_get_video_extensions() ]; return in_array( $ext, $extensionMap[ $type ] ?? [], true ); } }