handle_admin_notices(); parent::__construct(); } protected function handle_admin_notices() { if ( ! is_admin() ) { return; } $action = 'admin_notices'; if ( $this->is_completed() ) { add_action( $action, array( $this, 'admin_notice_upgrade_is_completed' ) ); } if ( $this->is_running() ) { add_action( $action, array( $this, 'admin_notice_upgrade_is_running' ) ); } } public function is_running() { $task_runner = $this->get_task_runner(); return $task_runner->is_running(); } public function is_completed() { if ( isset( $this->completed ) ) { return $this->completed; } $this->completed = $this->get_flag( 'completed' ); return $this->completed; } public function get_task_runner_class() { return 'PPW_Password_Recovery'; } public function get_query_limit() { return 100; } public function on_runner_complete( $did_tasks = false ) { // Implement log here if ( $did_tasks ) { $this->add_flag( 'completed' ); } } public function start_run() { $updater = $this->get_task_runner(); if ( $updater->is_running() ) { return; } $restore_password_callbacks = $this->get_restore_password_callbacks(); if ( empty( $restore_password_callbacks ) ) { $this->on_runner_complete(); return; } foreach ( $restore_password_callbacks as $callback ) { $updater->push_to_queue( array( 'callback' => $callback, ) ); } $updater->save()->dispatch(); } public function get_restore_password_callbacks() { $callbacks[] = array( 'PPW_Password_Recovery_Manager', 'restore_passwords' ); return $callbacks; } public static function restore_passwords() { return ( new PPW_Password_Services() )->restore_wp_post_password(); } public function admin_notice_upgrade_is_running() { $continue_action = $this->get_continue_action_url(); $message = '

' . __( 'Password recovery process is running in the background.', 'password-protect-page' ) . '

' . '

' . sprintf( 'Taking a while? Click here to run it now', $continue_action ) . '

'; echo '
' . wp_kses_post( $message ) . '
'; } public function admin_notice_upgrade_is_completed() { $this->delete_flag( 'completed' ); $message = $this->get_success_message(); if ( ! empty( $message ) ) { echo '
' . wp_kses_post( $message ) . '
'; } } public function get_action() { return 'password_recovery_process'; } public function get_plugin_name() { return 'ppw'; } public function get_plugin_label() { return __( PPW_PLUGIN_NAME, 'password-protect-page' ); } public function get_name() { return 'ppw-password-recovery'; } public function get_success_message() { return '

' . sprintf( __( '%s Password recovery process is now complete.. Thank you for your patience!', 'password-protect-page' ), $this->get_updater_label() ) . '

'; } public function get_updater_label() { return sprintf( '%s –', __( 'Password Protect WordPress', 'password-protect-page' ) ); } }