args = $args; $this->args['steps_path'] = trailingslashit($this->args['steps_path']); $this->set_id($this->args['id']); $this->load_steps($this->args['steps_path']); $this->page = $this->args['page']; $this->set_title($this->args['title']); // TODO: Somehow make these work even if self is only loadedd // on the wizard screen add_action( 'wp_ajax_'.$this->get_id().'_step', array( $this, 'ajax' ) ); add_action( 'admin_init', array( $this, 'styles' ) ); } /* * Accepts a callback function which should use $fv_fp->_get_input_text or similar */ function add_step($step) { $this->steps[] = $step; } function ajax() { if( !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), $this->get_id() ) ) { wp_send_json( array( 'error' => 'Invalid nonce' ) ); } $class_name = (string)$this->get_step( sanitize_text_field( $_POST['step_name'] ) ); $step = new $class_name; $result = call_user_func( array($step,'process') ); wp_send_json( $result ); } function get_id() { return $this->id; } /** * @param string $i Step name to get * * @return string Step name, if it's indeed added to the list of steps */ function get_step($i) { if( is_string($i) && in_array($i, $this->steps, true ) ) { return $i; } } function get_steps() { return $this->steps; } function get_title() { return $this->title; } function load_steps($path) { $files = glob($path.'/step_*.php'); if( count($files) > 0 ) { foreach( $files AS $file ) { include_once($file); } } } function log( $args ) { $args = wp_parse_args( $args, array( 'title' => false, 'message' => false, 'date' => gmdate('r'), 'status' => 'info', 'time' => time() )); $logs = get_option( $this->log_name(), array() ); $logs[] = $args; update_option( $this->log_name(), $logs, false ); } function log_get() { return get_option( $this->log_name(), array() ); } function log_name() { return $this->get_id().'-logs'; } function log_show() { if( count($this->log_get()) ) : ?> Show wizard log (log_get()); ?>)
get_steps()) ) { echo "Error: Step " . esc_html( $class ) . " already loaded!