Skip to content

Commit

Permalink
4.6.2 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbroes committed May 3, 2024
1 parent 849c2c4 commit 8120c75
Show file tree
Hide file tree
Showing 59 changed files with 8,530 additions and 3,986 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.6.1.1
* Version: 4.6.2
* Text Domain: all-in-one-seo-pack
* Domain Path: /languages
*
Expand Down
32 changes: 32 additions & 0 deletions app/Common/Admin/SiteHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function registerTests( $tests ) {
'label' => 'AIOSEO Site Info',
'test' => [ $this, 'testCheckSiteInfo' ],
];
$tests['direct']['aioseo_google_search_console'] = [
'label' => 'AIOSEO Google Search Console',
'test' => [ $this, 'testCheckGoogleSearchConsole' ],
];
$tests['direct']['aioseo_plugin_update'] = [
'label' => 'AIOSEO Plugin Update',
'test' => [ $this, 'testCheckPluginUpdate' ],
Expand Down Expand Up @@ -166,6 +170,34 @@ public function testCheckSiteInfo() {
);
}

/**
* Checks whether Google Search Console is connected.
*
* @since 4.6.2
*
* @return array The test result.
*/
public function testCheckGoogleSearchConsole() {
$googleSearchConsole = aioseo()->searchStatistics->api->auth->isConnected();

if ( ! $googleSearchConsole ) {
return $this->result(
'aioseo_google_search_console',
'recommended',
__( 'Connect Your Site with Google Search Console', 'all-in-one-seo-pack' ),
__( 'Sync your site with Google Search Console and get valuable insights right inside your WordPress dashboard. Track keyword rankings and search performance for individual posts with actionable insights to help you rank higher in search results!', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
$this->actionLink( admin_url( 'admin.php?page=aioseo-settings&aioseo-scroll=google-search-console-settings&aioseo-highlight=google-search-console-settings#/webmaster-tools?activetool=googleSearchConsole' ), __( 'Connect to Google Search Console', 'all-in-one-seo-pack' ) ) // phpcs:ignore Generic.Files.LineLength.MaxExceeded
);
}

return $this->result(
'aioseo_google_search_console',
'good',
__( 'Google Search Console is Connected', 'all-in-one-seo-pack' ),
__( 'Awesome! Google Search Console is connected to your site. This will help you monitor and maintain your site\'s presence in Google Search results.', 'all-in-one-seo-pack' )
);
}

/**
* Checks whether the required settings for our schema markup are set.
*
Expand Down
10 changes: 7 additions & 3 deletions app/Common/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class Api {
'post' => [ 'callback' => [ 'PostsTerms', 'getPostData' ], 'access' => 'everyone' ],
'post/(?P<postId>[\d]+)/first-attached-image' => [ 'callback' => [ 'PostsTerms', 'getFirstAttachedImage' ], 'access' => 'aioseo_page_social_settings' ],
'user/(?P<userId>[\d]+)/image' => [ 'callback' => [ 'User', 'getUserImage' ], 'access' => 'aioseo_page_social_settings' ],
'tags' => [ 'callback' => [ 'Tags', 'getTags' ], 'access' => 'everyone' ]
'tags' => [ 'callback' => [ 'Tags', 'getTags' ], 'access' => 'everyone' ],
'search-statistics/url/auth' => [ 'callback' => [ 'SearchStatistics', 'getAuthUrl' ], 'access' => [ 'aioseo_search_statistics_settings', 'aioseo_general_settings', 'aioseo_setup_wizard' ] ], // phpcs:ignore Generic.Files.LineLength.MaxExceeded
'search-statistics/url/reauth' => [ 'callback' => [ 'SearchStatistics', 'getReauthUrl' ], 'access' => [ 'aioseo_search_statistics_settings', 'aioseo_general_settings' ] ]
],
'POST' => [
'htaccess' => [ 'callback' => [ 'Tools', 'saveHtaccess' ], 'access' => 'aioseo_tools_settings' ],
Expand Down Expand Up @@ -90,7 +92,8 @@ class Api {
'plugins/install' => [ 'callback' => [ 'Plugins', 'installPlugins' ], 'access' => [ 'install_plugins', 'aioseo_feature_manager_settings' ] ],
'plugins/upgrade' => [ 'callback' => [ 'Plugins', 'upgradePlugins' ], 'access' => [ 'update_plugins', 'aioseo_feature_manager_settings' ] ],
'reset-settings' => [ 'callback' => [ 'Settings', 'resetSettings' ], 'access' => 'aioseo_tools_settings' ],
'settings/export' => [ 'callback' => [ 'Settings', 'exportSettings' ], 'access' => 'aioseo_tools_settings' ],
'search-statistics/sitemap/delete' => [ 'callback' => [ 'SearchStatistics', 'deleteSitemap' ], 'access' => [ 'aioseo_search_statistics_settings', 'aioseo_general_settings' ] ], // phpcs:ignore Generic.Files.LineLength.MaxExceeded
'search-statistics/sitemap/ignore' => [ 'callback' => [ 'SearchStatistics', 'ignoreSitemap' ], 'access' => [ 'aioseo_search_statistics_settings', 'aioseo_general_settings' ] ], // phpcs:ignore Generic.Files.LineLength.MaxExceeded
'settings/hide-setup-wizard' => [ 'callback' => [ 'Settings', 'hideSetupWizard' ], 'access' => 'any' ],
'settings/hide-upgrade-bar' => [ 'callback' => [ 'Settings', 'hideUpgradeBar' ], 'access' => 'any' ],
'settings/import' => [ 'callback' => [ 'Settings', 'importSettings' ], 'access' => 'aioseo_tools_settings' ],
Expand Down Expand Up @@ -141,7 +144,8 @@ class Api {
],
],
'DELETE' => [
'backup' => [ 'callback' => [ 'Tools', 'deleteBackup' ], 'access' => 'aioseo_tools_settings' ]
'backup' => [ 'callback' => [ 'Tools', 'deleteBackup' ], 'access' => 'aioseo_tools_settings' ],
'search-statistics/auth' => [ 'callback' => [ 'SearchStatistics', 'deleteAuth' ], 'access' => [ 'aioseo_search_statistics_settings', 'aioseo_general_settings' ] ]
]
// phpcs:enable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
];
Expand Down
214 changes: 214 additions & 0 deletions app/Common/Api/SearchStatistics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
<?php
namespace AIOSEO\Plugin\Common\Api;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

use AIOSEO\Plugin\Common\SearchStatistics\Api;

/**
* Route class for the API.
*
* @since 4.3.0
* @version 4.6.2 Moved from Pro to Common.
*/
class SearchStatistics {
/**
* Get the authorize URL.
*
* @since 4.3.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function getAuthUrl( $request ) {
$body = $request->get_params();

if ( aioseo()->searchStatistics->api->auth->isConnected() ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'Cannot authenticate. Please re-authenticate.'
], 200 );
}

$returnTo = ! empty( $body['returnTo'] ) ? sanitize_key( $body['returnTo'] ) : '';
$url = add_query_arg( [
'tt' => aioseo()->searchStatistics->api->trustToken->get(),
'sitei' => aioseo()->searchStatistics->api->getSiteIdentifier(),
'version' => aioseo()->version,
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'siteurl' => site_url(),
'return' => urlencode( admin_url( 'admin.php?page=aioseo&return-to=' . $returnTo ) ),
'testurl' => 'https://' . aioseo()->searchStatistics->api->getApiUrl() . '/v1/test/'
], 'https://' . aioseo()->searchStatistics->api->getApiUrl() . '/v1/auth/new/' . aioseo()->searchStatistics->api->auth->type . '/' );

$url = apply_filters( 'aioseo_search_statistics_auth_url', $url );

return new \WP_REST_Response( [
'success' => true,
'url' => $url,
], 200 );
}

/**
* Get the reauthorize URL.
*
* @since 4.3.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function getReauthUrl( $request ) {
$body = $request->get_params();

if ( ! aioseo()->searchStatistics->api->auth->isConnected() ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'Cannot re-authenticate. Please authenticate.',
], 200 );
}

$returnTo = ! empty( $body['returnTo'] ) ? sanitize_key( $body['returnTo'] ) : '';
$url = add_query_arg( [
'tt' => aioseo()->searchStatistics->api->trustToken->get(),
'sitei' => aioseo()->searchStatistics->api->getSiteIdentifier(),
'version' => aioseo()->version,
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'siteurl' => site_url(),
'key' => aioseo()->searchStatistics->api->auth->getKey(),
'token' => aioseo()->searchStatistics->api->auth->getToken(),
'return' => urlencode( admin_url( 'admin.php?page=aioseo&return-to=' . $returnTo ) ),
'testurl' => 'https://' . aioseo()->searchStatistics->api->getApiUrl() . '/v1/test/'
], 'https://' . aioseo()->searchStatistics->api->getApiUrl() . '/v1/auth/reauth/' . aioseo()->searchStatistics->api->auth->type . '/' );

$url = apply_filters( 'aioseo_search_statistics_reauth_url', $url );

return new \WP_REST_Response( [
'success' => true,
'url' => $url,
], 200 );
}

/**
* Delete the authorization.
*
* @since 4.3.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function deleteAuth( $request ) {
$body = $request->get_json_params();

if ( ! aioseo()->searchStatistics->api->auth->isConnected() ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'Cannot deauthenticate. You are not currently authenticated.'
], 200 );
}

$force = ! empty( $body['force'] ) && true === $body['force'];
$deleted = aioseo()->searchStatistics->api->auth->delete( $force );

if ( $deleted || $force ) {
aioseo()->searchStatistics->cancelActions();

return new \WP_REST_Response( [
'success' => true,
'message' => 'Successfully deauthenticated.'
], 200 );
}

return new \WP_REST_Response( [
'success' => false,
'message' => 'Could not deauthenticate, please try again.'
], 200 );
}

/**
* Deletes a sitemap.
*
* @since 4.6.2
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function deleteSitemap( $request ) {
$body = $request->get_json_params();
$sitemap = ! empty( $body['sitemap'] ) ? $body['sitemap'] : '';

if ( empty( $sitemap ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'No sitemap provided.'
], 200 );
}

$args = [
'sitemap' => $sitemap
];

$api = new Api\Request( 'google-search-console/sitemap/delete/', $args, 'POST' );
$response = $api->request();

if ( is_wp_error( $response ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $response['message']
], 200 );
}

aioseo()->internalOptions->searchStatistics->sitemap->list = $response['data'];
aioseo()->internalOptions->searchStatistics->sitemap->lastFetch = time();

return new \WP_REST_Response( [
'success' => true,
'data' => [
'internalOptions' => aioseo()->internalOptions->searchStatistics->sitemap->all(),
'sitemapsWithErrors' => aioseo()->searchStatistics->sitemap->getSitemapsWithErrors()
]
], 200 );
}

/**
* Ignores a sitemap.
*
* @since 4.6.2
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function ignoreSitemap( $request ) {
$body = $request->get_json_params();
$sitemap = ! empty( $body['sitemap'] ) ? $body['sitemap'] : '';

if ( empty( $sitemap ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'No sitemap provided.'
], 200 );
}

$ignoredSitemaps = aioseo()->internalOptions->searchStatistics->sitemap->ignored;
if ( is_array( $sitemap ) ) {
$ignoredSitemaps = array_merge( $ignoredSitemaps, $sitemap );
} else {
$ignoredSitemaps[] = $sitemap;
}

$ignoredSitemaps = array_unique( $ignoredSitemaps ); // Remove duplicates.
$ignoredSitemaps = array_filter( $ignoredSitemaps ); // Remove empty values.

aioseo()->internalOptions->searchStatistics->sitemap->ignored = $ignoredSitemaps;

return new \WP_REST_Response( [
'success' => true,
'data' => [
'internalOptions' => aioseo()->internalOptions->searchStatistics->sitemap->all(),
'sitemapsWithErrors' => aioseo()->searchStatistics->sitemap->getSitemapsWithErrors()
]
], 200 );
}
}
2 changes: 1 addition & 1 deletion app/Common/Meta/SiteVerification.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function meta() {
$metaArray = [];
foreach ( $this->webmasterTools as $key => $metaName ) {
$value = aioseo()->options->webmasterTools->$key;
if ( $value ) {
if ( ! empty( $value ) ) {
$metaArray[ $metaName ] = $value;
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Common/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ public static function savePost( $postId, $data ) {
}

$thePost = self::getPost( $postId );
// Before setting the data, we check if the title/description are the same as the defaults and clear them if so.
$data = self::checkForDefaultFormat( $postId, $thePost, $data );
$data = apply_filters( 'aioseo_save_post', $data, $thePost );

$thePost = apply_filters( 'aioseo_save_post', $thePost );
// Before setting the data, we check if the title/description are the same as the defaults and clear them if so.
$data = self::checkForDefaultFormat( $postId, $thePost, $data );
$thePost = self::sanitizeAndSetDefaults( $postId, $thePost, $data );

// Update traditional post meta so that it can be used by multilingual plugins.
Expand Down
11 changes: 10 additions & 1 deletion app/Common/Options/InternalOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ class InternalOptions {
'searchStatistics' => [
'profile' => [ 'type' => 'array', 'default' => [] ],
'trustToken' => [ 'type' => 'string' ],
'rolling' => [ 'type' => 'string', 'default' => 'last28Days' ]
'rolling' => [ 'type' => 'string', 'default' => 'last28Days' ],
'site' => [
'verified' => [ 'type' => 'boolean', 'default' => false ],
'lastFetch' => [ 'type' => 'number', 'default' => 0 ]
],
'sitemap' => [
'list' => [ 'type' => 'array', 'default' => [] ],
'ignored' => [ 'type' => 'array', 'default' => [] ],
'lastFetch' => [ 'type' => 'number', 'default' => 0 ]
]
]
],
'integrations' => [
Expand Down
30 changes: 18 additions & 12 deletions app/Common/Options/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,14 +565,16 @@ public function translateDefaults() {
* @return void
*/
public function sanitizeAndSave( $options ) {
$sitemapOptions = ! empty( $options['sitemap']['general'] ) ? $options['sitemap']['general'] : null;
$oldSitemapOptions = aioseo()->options->sitemap->general->all();
$deprecatedSitemapOptions = ! empty( $options['deprecated']['sitemap']['general'] )
$sitemapOptions = ! empty( $options['sitemap'] ) ? $options['sitemap'] : null;
$oldSitemapOptions = aioseo()->options->sitemap->all();
$generalSitemapOptions = ! empty( $options['sitemap']['general'] ) ? $options['sitemap']['general'] : null;
$oldGeneralSitemapOptions = aioseo()->options->sitemap->general->all();
$deprecatedGeneralSitemapOptions = ! empty( $options['deprecated']['sitemap']['general'] )
? $options['deprecated']['sitemap']['general']
: null;
$oldDeprecatedSitemapOptions = aioseo()->options->deprecated->sitemap->general->all();
$oldPhoneOption = aioseo()->options->searchAppearance->global->schema->phone;
$phoneNumberOptions = isset( $options['searchAppearance']['global']['schema']['phone'] )
$oldDeprecatedGeneralSitemapOptions = aioseo()->options->deprecated->sitemap->general->all();
$oldPhoneOption = aioseo()->options->searchAppearance->global->schema->phone;
$phoneNumberOptions = isset( $options['searchAppearance']['global']['schema']['phone'] )
? $options['searchAppearance']['global']['schema']['phone']
: null;
$oldHtmlSitemapUrl = aioseo()->options->sitemap->html->pageUrl;
Expand Down Expand Up @@ -645,16 +647,16 @@ public function sanitizeAndSave( $options ) {

// If sitemap settings were changed, static files need to be regenerated.
if (
! empty( $deprecatedSitemapOptions ) &&
! empty( $sitemapOptions )
! empty( $deprecatedGeneralSitemapOptions ) &&
! empty( $generalSitemapOptions )
) {
if (
(
aioseo()->helpers->arraysDifferent( $oldSitemapOptions, $sitemapOptions ) ||
aioseo()->helpers->arraysDifferent( $oldDeprecatedSitemapOptions, $deprecatedSitemapOptions )
aioseo()->helpers->arraysDifferent( $oldGeneralSitemapOptions, $generalSitemapOptions ) ||
aioseo()->helpers->arraysDifferent( $oldDeprecatedGeneralSitemapOptions, $deprecatedGeneralSitemapOptions )
) &&
$sitemapOptions['advancedSettings']['enable'] &&
! $deprecatedSitemapOptions['advancedSettings']['dynamic']
$generalSitemapOptions['advancedSettings']['enable'] &&
! $deprecatedGeneralSitemapOptions['advancedSettings']['dynamic']
) {
aioseo()->sitemap->scheduleRegeneration();
}
Expand All @@ -665,6 +667,10 @@ public function sanitizeAndSave( $options ) {
aioseo()->crawlCleanup->scheduleClearingLogs();
}

if ( ! empty( $sitemapOptions ) ) {
aioseo()->searchStatistics->sitemap->maybeSync( $oldSitemapOptions, $sitemapOptions );
}

// This is required in order for the Pro options to be refreshed before they save data again.
$this->refresh();
}
Expand Down
Loading

0 comments on commit 8120c75

Please sign in to comment.