prefix = '#action_'; $this->registered = array( 'assign_post' ); } function hooks(){ add_filter( 'acui_restricted_fields', array( $this, 'restricted_fields' ) ); add_action( 'acui_documentation_after_plugins_activated', array( $this, 'documentation' ) ); foreach( $this->registered as $registered_action ){ add_action( 'acui_action_' . $registered_action, array( $this, $registered_action ), 10, 6 ); } add_action( 'post_acui_import_single_user', array( $this, 'run' ), 10, 8 ); } function check_prefix( $header ){ return ( substr( $header, 0, strlen( $this->prefix ) ) === $this->prefix ); } function remove_prefix( $header ){ return substr( $header, strlen( $this->prefix ) ); } function restricted_fields( $fields ){ $actions = array(); foreach( $this->registered as $registered_action ) $actions[] = $this->prefix . $registered_action; return array_merge( $fields, $actions ); } function run( $headers, $data, $user_id, $role, $positions, $form_data, $is_frontend, $is_cron ){ $actions = $this->get_actions_from_headers( $headers ); if( empty( $actions ) ) return; foreach( $actions as $pos => $action ){ do_action( 'acui_action_' . $action, $user_id, $role, $data[ $pos ], $form_data, $is_frontend, $is_cron ); } } function get_actions_from_headers( $headers ){ $actions = array(); foreach( $headers as $pos => $header ){ if( $this->is_action( $header ) ) $actions[ $pos ] = $this->remove_prefix( $header ); } return $actions; } function is_action( $header ){ if( !$this->check_prefix( $header ) ) return false; return in_array( $this->remove_prefix( $header ), $this->registered ); } function documentation(){ ?> intval( $post_id ), 'post_author' => $user_id, ) ); } } } $acui_actions = new ACUI_Actions(); $acui_actions->hooks();