ajax = $ajax; $this->library = $library; } /** * Insert schedule * @return void */ public function insert() { $this->ajax->verify_nonce( 'acm/schedule/insert' ); $data = wp_parse_args( $_REQUEST['data'], array() ); $result = $this->library->insert( $data['slug'], $data['name'], $data['interval'] ); if ( is_array( $result ) ) { $errors = $result; } else { $errors = array(); } $success = sprintf( __( 'Schedule "%s" has been added', 'advanced-cron-manager' ), $data['name'] ); $this->ajax->response( $success, $errors ); } /** * Edit schedule * @return void */ public function edit() { $this->ajax->verify_nonce( 'acm/schedule/edit' ); $data = wp_parse_args( $_REQUEST['data'], array() ); $result = $this->library->insert( $data['slug'], $data['name'], $data['interval'], true ); if ( is_array( $result ) ) { $errors = $result; } else { $errors = array(); } $success = sprintf( __( 'Schedule "%s" has been edited', 'advanced-cron-manager' ), $data['name'] ); $this->ajax->response( $success, $errors ); } /** * Remove schedule * @return void */ public function remove() { $schedule_slug = $_REQUEST['schedule']; $this->ajax->verify_nonce( 'acm/schedule/remove/' . $schedule_slug ); $result = $this->library->remove( $schedule_slug ); if ( is_array( $result ) ) { $errors = $result; } else { $errors = array(); } $success = sprintf( __( 'Schedule "%s" has been removed', 'advanced-cron-manager' ), $schedule_slug ); $this->ajax->response( $success, $errors ); } }