register_action_type( $action ); } do_action( 'jet-form-builder/actions/register', $this ); } /** * Register new action type * * @param Types\Base $type * * @return void [description] */ public function register_action_type( Types\Base $type ) { if ( $type->dependence() ) { $this->_types[ $type->get_id() ] = $type; } } /** * @param string $type * * @return array */ public function get_actions( $type = '' ) { if ( $type ) { return $this->_types[ $type ]; } return $this->_types; } public function has_action_type( $type ) { return isset( $this->_types[ $type ] ); } /** * Register action types data for the editor * * @param $editor * @param $handle * * @return void [description] */ public function register_types_for_editor( $editor, $handle ) { self::localize_action_types( $this->_types, $handle ); } public static function prepare_actions_data( $source, $handle ) { $prepared_types = array(); foreach ( $source as $type ) { $type_script_name = $type->self_script_name(); $prepared_types[] = array( 'id' => $type->get_id(), 'name' => $type->get_name(), 'self' => $type_script_name, 'callback' => false, // should be rewritten from JS ); $action_localize = $type->action_data(); $action_localize['__messages'] = $type->get_messages_default(); $action_localize['__labels'] = $type->editor_labels(); $action_localize['__help_messages'] = $type->editor_labels_help(); $action_localize['__gateway_attrs'] = $type->visible_attributes_for_gateway_editor(); if ( ! empty( $action_localize ) && $type_script_name ) { wp_localize_script( $handle, $type->self_script_name(), $action_localize ); } } return $prepared_types; } public static function register_action_localize_helper() { wp_enqueue_script( self::ENGINE_HANDLE, JET_FORM_BUILDER_URL . 'assets/js/action-localize-helper.js', array(), JET_FORM_BUILDER_VERSION ); } public static function localize_action_types( $types, $handle = '' ) { $handle = $handle ? $handle : self::ENGINE_HANDLE; wp_localize_script( $handle, 'jetFormActionTypes', self::prepare_actions_data( $types, $handle ) ); } }