optin = $optin; $this->beta = $beta; $this->adapter = $adapter; } /** * Returns an array of events this subscriber wants to listen to. * * @return array */ public static function get_subscribed_events(): array { return [ 'backwpup_page_settings_save' => 'update_setting', 'init' => 'init', ]; } /** * Update the beta opt-in setting * * @return void */ public function update_setting(): void { if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'backwpup_page' ) ) { return; } if ( $this->adapter->is_pro() ) { if ( $this->optin->is_enabled() ) { $this->optin->disable(); } return; } if ( get_site_option( 'backwpup_onboarding', false ) ) { return; } $value = isset( $_POST['beta'] ) ? 1 : 0; $current = $this->optin->is_enabled() ? 1 : 0; // Only fire the event if the value actually changed. if ( $value !== $current ) { /** * Fires when the beta opt-in setting is changed. * * The parameter passed to the action is the new value of the beta opt-in setting (int). */ do_action( 'backwpup_beta_optin_change', $value ); } if ( 0 === $value ) { if ( $this->optin->is_enabled() ) { $this->optin->disable(); } return; } if ( 1 === $value ) { $this->optin->enable(); } } /** * Initialize the beta functionality * * @return void */ public function init(): void { if ( $this->adapter->is_pro() ) { return; } $this->beta->set_update_message( __( 'This update is a beta version.', 'backwpup' ) ); $this->beta->init(); } }