✨feature: Add split-direction (push/pull) process
This commit is contained in:
@@ -53,6 +53,8 @@ class Admin {
|
||||
add_action( 'admin_menu', array( $this, 'register_menu' ) );
|
||||
add_action( 'admin_post_site_sync_save_settings', array( $this, 'handle_save_settings' ) );
|
||||
add_action( 'admin_post_site_sync_manual', array( $this, 'handle_manual_sync' ) );
|
||||
add_action( 'admin_post_site_sync_manual_push', array( $this, 'handle_manual_push' ) );
|
||||
add_action( 'admin_post_site_sync_manual_pull', array( $this, 'handle_manual_pull' ) );
|
||||
add_action( 'admin_post_site_sync_handshake', array( $this, 'handle_handshake' ) );
|
||||
add_action( 'admin_post_site_sync_reset_state', array( $this, 'handle_reset_state' ) );
|
||||
add_action( 'admin_post_site_sync_clear_logs', array( $this, 'handle_clear_logs' ) );
|
||||
@@ -165,6 +167,23 @@ class Admin {
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Directions', 'site-sync' ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<label>
|
||||
<input type="checkbox" name="enable_push" value="1" <?php checked( $settings['enable_push'] ); ?>>
|
||||
<?php esc_html_e( 'Include outbound push (send this site\'s changes).', 'site-sync' ); ?>
|
||||
</label>
|
||||
<br>
|
||||
<label>
|
||||
<input type="checkbox" name="enable_pull" value="1" <?php checked( $settings['enable_pull'] ); ?>>
|
||||
<?php esc_html_e( 'Include inbound pull (receive peer changes).', 'site-sync' ); ?>
|
||||
</label>
|
||||
<p class="description"><?php esc_html_e( 'Uncheck to disable that direction during scheduled and combined manual syncs.', 'site-sync' ); ?></p>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button( __( 'Save Settings', 'site-sync' ) ); ?>
|
||||
@@ -178,6 +197,17 @@ class Admin {
|
||||
<input type="hidden" name="action" value="site_sync_manual">
|
||||
<?php submit_button( __( 'Sync Now', 'site-sync' ), 'secondary' ); ?>
|
||||
</form>
|
||||
<p><?php esc_html_e( 'Or run one direction at a time:', 'site-sync' ); ?></p>
|
||||
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" style="margin-right:12px; display:inline-block;">
|
||||
<?php wp_nonce_field( 'site_sync_manual_push', 'site_sync_manual_push_nonce' ); ?>
|
||||
<input type="hidden" name="action" value="site_sync_manual_push">
|
||||
<?php submit_button( __( 'Push Only', 'site-sync' ), 'secondary', 'submit', false ); ?>
|
||||
</form>
|
||||
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" style="display:inline-block;">
|
||||
<?php wp_nonce_field( 'site_sync_manual_pull', 'site_sync_manual_pull_nonce' ); ?>
|
||||
<input type="hidden" name="action" value="site_sync_manual_pull">
|
||||
<?php submit_button( __( 'Pull Only', 'site-sync' ), 'secondary', 'submit', false ); ?>
|
||||
</form>
|
||||
|
||||
<h2><?php esc_html_e( 'Maintenance', 'site-sync' ); ?></h2>
|
||||
<p><?php esc_html_e( 'Reset checkpoints to force a full resend on the next sync. Use if the destination was emptied or fell out of sync.', 'site-sync' ); ?></p>
|
||||
@@ -302,6 +332,8 @@ class Admin {
|
||||
'post_meta_keys' => isset( $_POST['post_meta_keys'] ) ? wp_unslash( $_POST['post_meta_keys'] ) : '',
|
||||
'sync_interval' => isset( $_POST['sync_interval'] ) ? wp_unslash( $_POST['sync_interval'] ) : '',
|
||||
'enabled' => isset( $_POST['enabled'] ),
|
||||
'enable_push' => isset( $_POST['enable_push'] ),
|
||||
'enable_pull' => isset( $_POST['enable_pull'] ),
|
||||
);
|
||||
// phpcs:enable
|
||||
|
||||
@@ -349,6 +381,60 @@ class Admin {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the manual push-only action from the admin form submission.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle_manual_push(): void {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to do this.', 'site-sync' ) );
|
||||
}
|
||||
|
||||
check_admin_referer( 'site_sync_manual_push', 'site_sync_manual_push_nonce' );
|
||||
|
||||
$settings = $this->settings->get_settings();
|
||||
do_action( 'site_sync/manual_push', $settings );
|
||||
|
||||
$redirect = add_query_arg(
|
||||
array(
|
||||
'page' => 'site-sync',
|
||||
'site_sync_status' => 'manual_push_run',
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
);
|
||||
|
||||
wp_safe_redirect( $redirect );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the manual pull-only action from the admin form submission.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle_manual_pull(): void {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'You do not have permission to do this.', 'site-sync' ) );
|
||||
}
|
||||
|
||||
check_admin_referer( 'site_sync_manual_pull', 'site_sync_manual_pull_nonce' );
|
||||
|
||||
$settings = $this->settings->get_settings();
|
||||
do_action( 'site_sync/manual_pull', $settings );
|
||||
|
||||
$redirect = add_query_arg(
|
||||
array(
|
||||
'page' => 'site-sync',
|
||||
'site_sync_status' => 'manual_pull_run',
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
);
|
||||
|
||||
wp_safe_redirect( $redirect );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders admin notices for Site Sync actions based on query parameters.
|
||||
*
|
||||
@@ -373,6 +459,20 @@ class Admin {
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $_GET['site_sync_status'] ) && 'manual_push_run' === $_GET['site_sync_status'] ) {
|
||||
printf(
|
||||
'<div class="notice notice-info is-dismissible"><p>%s</p></div>',
|
||||
esc_html__( 'Manual push triggered.', 'site-sync' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $_GET['site_sync_status'] ) && 'manual_pull_run' === $_GET['site_sync_status'] ) {
|
||||
printf(
|
||||
'<div class="notice notice-info is-dismissible"><p>%s</p></div>',
|
||||
esc_html__( 'Manual pull triggered.', 'site-sync' )
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $_GET['site_sync_status'] ) && 'handshake_ok' === $_GET['site_sync_status'] ) {
|
||||
printf(
|
||||
'<div class="notice notice-success is-dismissible"><p>%s</p></div>',
|
||||
|
||||
Reference in New Issue
Block a user