Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nonce param to do_sync links #3933

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add nonce param to do_sync links
  • Loading branch information
felipeelia committed Jun 11, 2024
commit ff70faac0094bc83e06751a18962572116fde4f7
12 changes: 2 additions & 10 deletions includes/classes/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ protected function process_auto_activate_sync_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync=features' );
} else {
$url = admin_url( 'admin.php?page=elasticpress-sync&do_sync=features' );
}
$url = Utils\get_sync_url( 'features' );

$feature = Features::factory()->get_registered_feature( $auto_activate_sync );

Expand Down Expand Up @@ -250,11 +246,7 @@ protected function process_upgrade_sync_notice() {
return false;
}

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync=upgrade' );
} else {
$url = admin_url( 'admin.php?page=elasticpress-sync&do_sync=upgrade' );
}
$url = Utils\get_sync_url( 'upgrade' );

if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) {
$html = esc_html__( 'Dashboard sync is disabled. The new version of ElasticPress requires that you delete all data and start a fresh sync using WP-CLI.', 'elasticpress' );
Expand Down
4 changes: 2 additions & 2 deletions includes/partials/install-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$setup_url = admin_url( 'network/admin.php?page=elasticpress-settings' );
$sync_url = admin_url( 'network/admin.php?page=elasticpress-sync&do_sync=install' );
$dashboard_url = admin_url( 'network/admin.php?page=elasticpress' );
} else {
$setup_url = admin_url( 'admin.php?page=elasticpress-settings' );
$sync_url = admin_url( 'admin.php?page=elasticpress-sync&do_sync=install' );
$dashboard_url = admin_url( 'admin.php?page=elasticpress' );
}

$sync_url = \ElasticPress\Utils\get_sync_url( 'install' );

$skip_install_url = add_query_arg(
[
'ep-skip-install' => 1,
Expand Down
10 changes: 7 additions & 3 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,17 @@ function get_asset_info( $slug, $attribute = null ) {
* Return the Sync Page URL.
*
* @since 4.4.0
* @param boolean $do_sync Whether the link should or should not start a resync.
* @param boolean|string $do_sync Whether the link should or should not start a resync. Pass a string to store the reason of the resync.
* @return string
*/
function get_sync_url( bool $do_sync = false ) : string {
function get_sync_url( $do_sync = false ) : string {
$page = 'admin.php?page=elasticpress-sync';
if ( $do_sync ) {
$page .= '&do_sync&ep_sync_nonce=' . wp_create_nonce( 'ep_sync_nonce' );
$page .= '&do_sync';
if ( is_string( $do_sync ) ) {
$page .= '=' . rawurlencode( $do_sync );
}
$page .= '&ep_sync_nonce=' . wp_create_nonce( 'ep_sync_nonce' );
}
return ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ?
network_admin_url( $page ) :
Expand Down
Loading