Skip to content

Commit

Permalink
4.7.8 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbroes committed Jan 16, 2025
1 parent f065a31 commit 50bc931
Show file tree
Hide file tree
Showing 91 changed files with 2,686 additions and 1,348 deletions.
2 changes: 1 addition & 1 deletion all_in_one_seo_pack.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: SEO for WordPress. Features like XML Sitemaps, SEO for custom post types, SEO for blogs, business sites, ecommerce sites, and much more. More than 100 million downloads since 2007.
* Author: All in One SEO Team
* Author URI: https://aioseo.com/
* Version: 4.7.7
* Version: 4.7.8
* Text Domain: all-in-one-seo-pack
* Domain Path: /languages
* License: GPL-3.0+
Expand Down
2 changes: 1 addition & 1 deletion app/Common/Admin/PostSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct() {
// Add metabox.
add_action( 'add_meta_boxes', [ $this, 'addPostSettingsMetabox' ] );

// Add metabox to terms on init hook.
// Add metabox (upsell) to terms on init hook.
add_action( 'init', [ $this, 'init' ], 1000 );

// Save metabox.
Expand Down
4 changes: 2 additions & 2 deletions app/Common/Breadcrumbs/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function temporarilyAddTerm( $terms, $objectIds, $taxonomies ) {
return $terms;
}

$term = get_term( $this->primaryTerm[ $taxonomy ] );
$term = aioseo()->helpers->getTerm( $this->primaryTerm[ $taxonomy ] );
if ( is_a( $term, 'WP_Term' ) ) {
$terms[] = $term;
}
Expand All @@ -134,6 +134,6 @@ public function changePrimaryTerm( $term, $taxonomy ) {
return $term;
}

return get_term( $this->primaryTerm[ $taxonomy ], $taxonomy );
return aioseo()->helpers->getTerm( $this->primaryTerm[ $taxonomy ], $taxonomy );
}
}
4 changes: 2 additions & 2 deletions app/Common/Breadcrumbs/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function getTermTaxonomyParentCrumbs( $term ) {
$termHierarchy = $this->getTermHierarchy( $term->term_id, $term->taxonomy );
if ( ! empty( $termHierarchy ) ) {
foreach ( $termHierarchy as $parentTermId ) {
$parentTerm = get_term( $parentTermId, $term->taxonomy );
$parentTerm = aioseo()->helpers->getTerm( $parentTermId, $term->taxonomy );
$crumbs[] = $this->getTermTaxonomyCrumb( $parentTerm, 'parent' );
}
}
Expand Down Expand Up @@ -432,7 +432,7 @@ public function getPostTaxonomyCrumbs( $post, $taxonomy = null ) {
$termHierarchy = $this->getPostTaxTermHierarchy( $post, $taxonomy );
if ( ! empty( $termHierarchy['terms'] ) ) {
foreach ( $termHierarchy['terms'] as $termId ) {
$term = get_term( $termId, $termHierarchy['taxonomy'] );
$term = aioseo()->helpers->getTerm( $termId, $termHierarchy['taxonomy'] );
$crumbs[] = $this->makeCrumb( $term->name, get_term_link( $term, $termHierarchy['taxonomy'] ), 'taxonomy', $term, 'parent' );
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/Common/Main/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public function declareAioseoFollowingConsentApi() {
if ( empty( $addon->installed ) || empty( $addon->basename ) ) {
continue;
}

add_filter( 'wp_consent_api_registered_' . $addon->basename, '__return_true' );
if ( isset( $addon->basename ) ) {
add_filter( 'wp_consent_api_registered_' . $addon->basename, '__return_true' );
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/Common/Main/Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@ private function addWritingAssistantTables() {
`content_analysis_hash` VARCHAR(40) DEFAULT NULL,
`content_analysis` text DEFAULT NULL,
`created` datetime NOT NULL,
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated` datetime NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY ndx_aioseo_writing_assistant_posts_post_id (post_id),
KEY ndx_aioseo_writing_assistant_posts_keyword_id (keyword_id)
Expand All @@ -1763,7 +1763,7 @@ private function addWritingAssistantTables() {
`keywords` mediumtext NULL,
`competitors` mediumtext NULL,
`created` datetime NOT NULL,
`updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated` datetime NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY ndx_aioseo_writing_assistant_keywords_uuid (uuid),
KEY ndx_aioseo_writing_assistant_keywords_keyword (keyword)
Expand Down
2 changes: 1 addition & 1 deletion app/Common/Meta/Description.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getDescription( $post = null, $default = false ) {
}

if ( is_category() || is_tag() || is_tax() ) {
$term = $post ? $post : get_queried_object();
$term = $post ? $post : aioseo()->helpers->getTerm();

return $this->getTermDescription( $term, $default );
}
Expand Down
11 changes: 9 additions & 2 deletions app/Common/Meta/Included.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function isIncluded() {
* @return bool Whether the queried object is public.
*/
protected function isQueriedObjectPublic() {
$queriedObject = get_queried_object();
$queriedObject = get_queried_object(); // Don't use the getTerm helper here.

if ( is_a( $queriedObject, 'WP_Post' ) ) {
return aioseo()->helpers->isPostTypePublic( $queriedObject->post_type );
Expand All @@ -55,6 +55,13 @@ protected function isQueriedObjectPublic() {
}

if ( is_a( $queriedObject, 'WP_Term' ) ) {
if ( aioseo()->helpers->isWooCommerceProductAttribute( $queriedObject->taxonomy ) ) {
// Check if the attribute has archives enabled.
$taxonomy = get_taxonomy( $queriedObject->taxonomy );

return $taxonomy->public;
}

return aioseo()->helpers->isTaxonomyPublic( $queriedObject->taxonomy );
}

Expand Down Expand Up @@ -130,7 +137,7 @@ protected function isTaxExcludedGlobal() {
}
}

$term = get_queried_object();
$term = aioseo()->helpers->getTerm();
if ( in_array( (int) $term->term_id, $ids, true ) ) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions app/Common/Meta/Robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function post( $post = null ) {
*/
public function term( $term = null ) {
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
$term = is_a( $term, 'WP_Term' ) ? $term : get_queried_object();
$term = is_a( $term, 'WP_Term' ) ? $term : aioseo()->helpers->getTerm();

// Misbehaving themes/plugins can manipulate the loop and make archives return a post as the queried object.
if ( ! is_a( $term, 'WP_Term' ) ) {
Expand All @@ -253,7 +253,7 @@ public function term( $term = null ) {
*/
private function archives() {
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
$postType = get_queried_object();
$postType = aioseo()->helpers->getTerm();
if ( ! empty( $postType->name ) && $dynamicOptions->searchAppearance->archives->has( $postType->name ) ) {
$this->globalValues( [ 'archives', $postType->name ], true );
}
Expand Down
2 changes: 1 addition & 1 deletion app/Common/Meta/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getTitle( $post = null, $default = false ) {
}

if ( is_category() || is_tag() || is_tax() ) {
$term = $post ? $post : get_queried_object();
$term = $post ? $post : aioseo()->helpers->getTerm();

return $this->getTermTitle( $term, $default );
}
Expand Down
2 changes: 1 addition & 1 deletion app/Common/Models/WritingAssistantPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WritingAssistantPost extends Model {
public static function getContentAnalysis( $postId ) {
$post = self::getPost( $postId );

return is_object( $post->content_analysis ) ? (array) $post->content_analysis : [];
return ! empty( $post->content_analysis ) && is_object( $post->content_analysis ) ? (array) $post->content_analysis : [];
}

/**
Expand Down
6 changes: 5 additions & 1 deletion app/Common/Schema/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ private function postNonHierarchical( $post ) {
* @return array The breadcrumb trail.
*/
public function term( $term ) {
if ( 'product_attributes' === $term->taxonomy ) {
$term = get_term( $term->term_id );
}

$breadcrumbs = [];
do {
array_unshift(
Expand All @@ -214,7 +218,7 @@ public function term( $term ) {
);

if ( $term->parent ) {
$term = get_term( $term->parent, $term->taxonomy );
$term = aioseo()->helpers->getTerm( $term->parent, $term->taxonomy );
} else {
$term = false;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Common/Schema/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function post() {
* @return array The context data.
*/
public function term() {
$term = get_queried_object();
$term = aioseo()->helpers->getTerm();
if ( ! $term ) {
return [
'name' => '',
Expand Down
2 changes: 1 addition & 1 deletion app/Common/SearchStatistics/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function worker() {
$api = new Api\Request( 'google-search-console/sitemap/sync/', [ 'sitemaps' => aioseo()->sitemap->helpers->getSitemapUrls() ] );
$response = $api->request();

if ( is_wp_error( $response ) ) {
if ( is_wp_error( $response ) || empty( $response['data'] ) ) {
// If it failed to communicate with the server, try again in a few hours.
aioseo()->actionScheduler->scheduleSingle( $this->action, wp_rand( HOUR_IN_SECONDS, 2 * HOUR_IN_SECONDS ), [], true );

Expand Down
74 changes: 71 additions & 3 deletions app/Common/Sitemap/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,21 @@ public function get() {
}

// Check if requested index is a registered taxonomy.
if ( in_array( aioseo()->sitemap->indexName, aioseo()->sitemap->helpers->includedTaxonomies(), true ) ) {
if (
in_array( aioseo()->sitemap->indexName, aioseo()->sitemap->helpers->includedTaxonomies(), true ) &&
'product_attributes' !== aioseo()->sitemap->indexName
) {
return $this->terms( aioseo()->sitemap->indexName );
}

if (
aioseo()->helpers->isWooCommerceActive() &&
in_array( aioseo()->sitemap->indexName, aioseo()->sitemap->helpers->includedTaxonomies(), true ) &&
'product_attributes' === aioseo()->sitemap->indexName
) {
return $this->productAttributes();
}

return [];
}

Expand Down Expand Up @@ -361,7 +372,7 @@ public function getTermLastModified( $term ) {

// If the term is an ID, get the term object.
if ( is_numeric( $term ) ) {
$term = get_term( $term );
$term = aioseo()->helpers->getTerm( $term );
}

// First, check the count of the term. If it's 0, then we're dealing with a parent term that does not have
Expand Down Expand Up @@ -802,7 +813,7 @@ public function bpMember() {
->orderBy( '`a`.`date_recorded` DESC' );

$items = $query->run()
->result();
->result();

foreach ( $items as $item ) {
$entry = [
Expand Down Expand Up @@ -833,4 +844,61 @@ public function bpMember() {

return apply_filters( 'aioseo_sitemap_posts', $entries, $postType );
}

/**
* Returns all entries for the WooCommerce Product Attributes sitemap.
* Note: This sitemap does not support pagination.
*
* @since 4.7.8
*
* @param bool $count Whether to return the count of the entries. This is used to determine the indexes.
* @return array The sitemap entries.
*/
public function productAttributes( $count = false ) {
$aioseoTermsTable = aioseo()->core->db->prefix . 'aioseo_terms';
$wcAttributeTaxonomiesTable = aioseo()->core->db->prefix . 'woocommerce_attribute_taxonomies';
$termTaxonomyTable = aioseo()->core->db->prefix . 'term_taxonomy';

$selectClause = $count ? 'COUNT(*) as childProductAttributes' : 'tt.term_id, at.frequency, at.priority';
$whereClause = aioseo()->pro ? 'AND (at.robots_noindex IS NULL OR at.robots_noindex = 0)' : '';
$limitClause = $count ? '' : 'LIMIT 50000';

$result = aioseo()->core->db->execute(
"SELECT {$selectClause}
FROM {$termTaxonomyTable} AS tt
JOIN {$wcAttributeTaxonomiesTable} AS wat ON tt.taxonomy = CONCAT('pa_', wat.attribute_name)
LEFT JOIN {$aioseoTermsTable} AS at ON tt.term_id = at.term_id
WHERE wat.attribute_public = 1
{$whereClause}
AND tt.count > 0
{$limitClause};",
true
)->result();

if ( $count ) {
return ! empty( $result[0]->childProductAttributes ) ? (int) $result[0]->childProductAttributes : 0;
}

if ( empty( $result ) ) {
return [];
}

$entries = [];
foreach ( $result as $term ) {
$term = (object) $term;
$termId = (int) $term->term_id;

$entry = [
'loc' => get_term_link( $termId ),
'lastmod' => $this->getTermLastModified( $termId ),
'changefreq' => aioseo()->sitemap->priority->frequency( 'taxonomies', $term, 'product_attributes' ),
'priority' => aioseo()->sitemap->priority->priority( 'taxonomies', $term, 'product_attributes' ),
'images' => aioseo()->sitemap->image->term( $term )
];

$entries[] = apply_filters( 'aioseo_sitemap_product_attributes', $entry, $termId );
}

return $entries;
}
}
25 changes: 23 additions & 2 deletions app/Common/Sitemap/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ public function includedTaxonomies() {
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
$publicTaxonomies = aioseo()->helpers->getPublicTaxonomies( true );
foreach ( $taxonomies as $taxonomy ) {
if (
aioseo()->helpers->isWooCommerceActive() &&
aioseo()->helpers->isWooCommerceProductAttribute( $taxonomy )
) {
$taxonomies = aioseo()->helpers->unsetValue( $taxonomies, $taxonomy );
if ( ! in_array( 'product_attributes', $taxonomies, true ) ) {
$taxonomies[] = 'product_attributes';
}
continue;
}

// Check if taxonomy is no longer registered.
if ( ! in_array( $taxonomy, $publicTaxonomies, true ) || ! $dynamicOptions->searchAppearance->taxonomies->has( $taxonomy ) ) {
$taxonomies = aioseo()->helpers->unsetValue( $taxonomies, $taxonomy );
Expand Down Expand Up @@ -350,7 +361,12 @@ public function lastModifiedAdditionalPage( $page ) {
* @return string The excluded IDs.
*/
public function excludedPosts() {
return $this->excludedObjectIds( 'excludePosts' );
static $excludedPosts = null;
if ( null === $excludedPosts ) {
$excludedPosts = $this->excludedObjectIds( 'excludePosts' );
}

return $excludedPosts;
}

/**
Expand All @@ -361,7 +377,12 @@ public function excludedPosts() {
* @return string The excluded IDs.
*/
public function excludedTerms() {
return $this->excludedObjectIds( 'excludeTerms' );
static $excludedTerms = null;
if ( null === $excludedTerms ) {
$excludedTerms = $this->excludedObjectIds( 'excludeTerms' );
}

return $excludedTerms;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Common/Sitemap/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function localizeEntry( $entry, $entryId, $objectName, $objectType ) {
$elementId = $entryId;
$elementType = 'post_' . $objectName;
if ( 'term' === $objectType ) {
$term = get_term( $entryId, $objectName );
$term = aioseo()->helpers->getTerm( $entryId, $objectName );
$elementId = $term->term_taxonomy_id;
$elementType = 'tax_' . $objectName;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ private function isExcludedTerm( $termId ) {
}

// Now, we must also check for noindex.
$term = get_term( $termId );
$term = aioseo()->helpers->getTerm( $termId );
if ( ! is_a( $term, 'WP_Term' ) ) {
return true;
}
Expand Down
11 changes: 11 additions & 0 deletions app/Common/Sitemap/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ public function indexes() {
$indexes[] = $this->buildIndex( 'date', $result[0]->amountOfUrls );
}

if (
aioseo()->helpers->isWooCommerceActive() &&
in_array( 'product_attributes', aioseo()->sitemap->helpers->includedTaxonomies(), true )
) {
$productAttributes = aioseo()->sitemap->content->productAttributes( true );

if ( ! empty( $productAttributes ) ) {
$indexes[] = $this->buildIndex( 'product_attributes', $productAttributes );
}
}

if ( isset( aioseo()->standalone->buddyPress->sitemap ) ) {
$indexes = array_merge( $indexes, aioseo()->standalone->buddyPress->sitemap->indexes() );
}
Expand Down
3 changes: 3 additions & 0 deletions app/Common/Sitemap/Xsl.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function generate() {
$labels = array_column( wp_list_filter( $bpFakePostTypes, [ 'name' => $sitemapInfo[1] ] ), 'label' );
$sitemapName = ! empty( $labels[0] ) ? $labels[0] : $sitemapName;
break;
case 'product_attributes':
$sitemapName = __( 'Product Attributes', 'all-in-one-seo-pack' );
break;
default:
if ( post_type_exists( $sitemapInfo[1] ) ) {
$postTypeObject = get_post_type_object( $sitemapInfo[1] );
Expand Down
Loading

0 comments on commit 50bc931

Please sign in to comment.