initial
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Collection;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Configurator;
|
||||
|
||||
/**
|
||||
* Config items for app registration, including helper methods.
|
||||
*
|
||||
* @since 2.7.1
|
||||
*/
|
||||
class GF_App_Config extends GF_Config {
|
||||
|
||||
/**
|
||||
* The name of the app, in slug form.
|
||||
*
|
||||
* @var string $app_name
|
||||
*/
|
||||
private $app_name;
|
||||
|
||||
/**
|
||||
* The condition for enqueuing the app data.
|
||||
*
|
||||
* @var bool|callable $display_condition
|
||||
*/
|
||||
private $display_condition;
|
||||
|
||||
/**
|
||||
* The CSS assets to enqueue.
|
||||
*
|
||||
* @var array $css_asset
|
||||
*/
|
||||
private $css_asset;
|
||||
|
||||
/**
|
||||
* The relative path to the chunk in JS.
|
||||
*
|
||||
* @var string $chunk
|
||||
*/
|
||||
private $chunk;
|
||||
|
||||
/**
|
||||
* The root element to use to load the app.
|
||||
*
|
||||
* @var string $root_element
|
||||
*/
|
||||
private $root_element;
|
||||
|
||||
/**
|
||||
* Set the data for this app config.
|
||||
*
|
||||
* @since 2.7.1
|
||||
*
|
||||
* @param $data
|
||||
*/
|
||||
public function set_data( $data ) {
|
||||
$this->name = $data['object_name'];
|
||||
$this->script_to_localize = $data['script_name'];
|
||||
$this->app_name = $data['app_name'];
|
||||
|
||||
$this->display_condition = $data['enqueue'];
|
||||
$this->chunk = $data['chunk'];
|
||||
$this->root_element = $data['root_element'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we should enqueue this data.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function should_enqueue() {
|
||||
return is_admin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Config data.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data() {
|
||||
return array(
|
||||
'apps' => array(
|
||||
$this->app_name => array(
|
||||
'should_display' => is_callable( $this->display_condition ) ? call_user_func( $this->display_condition ) : $this->display_condition,
|
||||
'chunk_path' => $this->chunk,
|
||||
'root_element' => $this->root_element,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
|
||||
use GFCommon;
|
||||
|
||||
/**
|
||||
* Collection to hold GF_Config items and provide their structured data when needed.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @package Gravity_Forms\Gravity_Forms\Config
|
||||
*/
|
||||
class GF_Config_Collection {
|
||||
|
||||
/**
|
||||
* @var GF_Config[] $configs
|
||||
*/
|
||||
private $configs = array();
|
||||
|
||||
/**
|
||||
* Add a config to the collection.
|
||||
*
|
||||
* @param GF_Config $config
|
||||
*/
|
||||
public function add_config( GF_Config $config ) {
|
||||
$this->configs[] = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle outputting the config data.
|
||||
*
|
||||
* If $localize is true, data is actually localized via `wp_localize_script`, otherwise
|
||||
* data is simply returned as an array.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param bool $localize Whether to localize the data, or simply return it.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function handle( $localize = true, $args = null ) {
|
||||
|
||||
$scripts = $this->get_configs_by_script();
|
||||
$data_to_localize = array();
|
||||
|
||||
foreach ( $scripts as $script => $items ) {
|
||||
$item_data = $this->localize_data_for_script( $script, $items, $localize, $args );
|
||||
$data_to_localize = array_merge( $data_to_localize, $item_data );
|
||||
}
|
||||
|
||||
return $data_to_localize;
|
||||
}
|
||||
|
||||
public function handle_ajax() {
|
||||
|
||||
// Check nonce.
|
||||
$nonce_result = check_ajax_referer( 'gform_config_ajax', 'gform_ajax_nonce', false );
|
||||
|
||||
if ( ! $nonce_result ) {
|
||||
GFCommon::send_json_error( esc_html__( 'Unable to verify nonce. Please refresh the page and try again.', 'gravityforms' ) );
|
||||
}
|
||||
|
||||
$args = json_decode( rgpost( 'args' ), true );
|
||||
$config_path = wp_strip_all_tags( rgpost( 'config_path' ) );
|
||||
$query_string = rgpost( 'query_string' );
|
||||
|
||||
// Making the query string available for use with form filters.
|
||||
if ( ! empty( $query_string ) && is_string( $query_string ) ) {
|
||||
parse_str( $query_string, $query );
|
||||
unset( $query['gf_page'] ); // Removing so it doesn't conflict with gf_ajax_page=preview.
|
||||
$_GET = array_merge( $_GET, $query );
|
||||
}
|
||||
|
||||
$configs = $this->get_configs_by_path( $config_path, $args );
|
||||
|
||||
if ( ! $configs ) {
|
||||
GFCommon::send_json_error( sprintf( esc_html__( 'Unable to find config: %s', 'gravityforms' ), esc_html( $config_path ) ) );
|
||||
}
|
||||
|
||||
$data = $this->get_merged_data_for_object( $configs, $args );
|
||||
GFCommon::send_json_success( $data );
|
||||
}
|
||||
/**
|
||||
* Localize the data for the given script.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param string $script The script to localize.
|
||||
* @param array $items The associative array of configs to process for this script.
|
||||
* @param bool $localize Whether to actually localize the data, or simply return it.
|
||||
* @param array $args The arguments to pass to the config objects.
|
||||
*
|
||||
* @return array Returns the localized data.
|
||||
*/
|
||||
private function localize_data_for_script( $script, $items, $localize = true, $args = null ) {
|
||||
$data = array();
|
||||
|
||||
foreach ( $items as $name => $configs ) {
|
||||
|
||||
$localized_data = $this->get_merged_data_for_object( $configs, $args );
|
||||
|
||||
/**
|
||||
* Allows users to filter the data localized for a given script/resource.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param array $localized_data The current localize data
|
||||
* @param string $script The script being localized
|
||||
* @param array $configs An array of $configs being applied to this script
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
$localized_data = apply_filters( 'gform_localized_script_data_' . $name, $localized_data, $script, $configs );
|
||||
|
||||
$data[ $name ] = $localized_data;
|
||||
|
||||
if ( $localize ) {
|
||||
wp_localize_script( $script, $name, $localized_data );
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the merged data object for the applicable configs. Will process each config by its
|
||||
* $priority property, overriding or merging values as needed.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param GF_Config[] $configs
|
||||
*/
|
||||
private function get_merged_data_for_object( $configs, $args ) {
|
||||
// Squash warnings for PHP < 7.0 when running tests.
|
||||
@usort( $configs, array( $this, 'sort_by_priority' ) );
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $configs as $config ) {
|
||||
|
||||
$config->set_args( $args );
|
||||
|
||||
// Config is set to overwrite data - simply return its value without attempting to merge.
|
||||
if ( $config->should_overwrite() ) {
|
||||
$data = $config->get_data();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Config should be merged - loop through each key and attempt to recursively merge the values.
|
||||
foreach ( $config->get_data() as $key => $value ) {
|
||||
$existing = isset( $data[ $key ] ) ? $data[ $key ] : null;
|
||||
|
||||
if ( is_null( $existing ) || ! is_array( $existing ) || ! is_array( $value ) ) {
|
||||
$data[ $key ] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[ $key ] = array_merge_recursive( $existing, $value );
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the appropriate configs, organized by the script they belong to.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_configs_by_script() {
|
||||
$data_to_localize = array();
|
||||
|
||||
foreach ( $this->configs as $config ) {
|
||||
if ( ( ! defined( 'GFORMS_DOING_MOCK' ) || ! GFORMS_DOING_MOCK ) && ! $config->should_enqueue() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data_to_localize[ $config->script_to_localize() ][ $config->name() ][] = $config;
|
||||
}
|
||||
|
||||
return $data_to_localize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of configs that match the specified config path.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param string $config_path The path of the config to be returned.
|
||||
* @param array $args The arguments to pass to the config objects.
|
||||
*
|
||||
* @return array Returns an array of configs that are associated with the specified config path.
|
||||
*/
|
||||
private function get_configs_by_path( $config_path, $args )
|
||||
{
|
||||
$configs = array();
|
||||
foreach ( $this->configs as $config ) {
|
||||
if ( $config->enable_ajax( $config_path, $args ) ) {
|
||||
$configs[] = $config;
|
||||
}
|
||||
}
|
||||
return $configs;
|
||||
}
|
||||
|
||||
/**
|
||||
* usort() callback to sort the configs by their $priority.
|
||||
*
|
||||
* @param GF_Config $a
|
||||
* @param GF_Config $b
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function sort_by_priority( GF_Config $a, GF_Config $b ) {
|
||||
if ( $a->priority() === $b->priority() ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $a->priority() < $b->priority() ? - 1 : 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config;
|
||||
|
||||
/**
|
||||
* Parses a given data array to return either Live or Mock values, depending on the
|
||||
* environment and context.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @package Gravity_Forms\Gravity_Forms\Config
|
||||
*/
|
||||
class GF_Config_Data_Parser {
|
||||
|
||||
/**
|
||||
* Parse the given $data array and get the correct values for the context.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function parse( $data ) {
|
||||
$return = array();
|
||||
|
||||
foreach( $data as $key => $value ) {
|
||||
$return[ $key ] = $this->get_correct_value( $value );
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loop through each array key and get the correct value. Is called recursively for
|
||||
* nested arrays.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
private function get_correct_value( $value ) {
|
||||
|
||||
// Value isn't array - we've reached the final level for this branch.
|
||||
if ( ! is_array( $value ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
// Value is an array with our defined value and default keys. Return either live or mock data.
|
||||
if ( array_key_exists( 'default', $value ) && array_key_exists( 'value', $value ) ) {
|
||||
return $this->is_mock() ? $value['default'] : $value['value'];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
// Value is an array - recursively call this method to dig into each level and return the correct value.
|
||||
foreach( $value as $key => $value ) {
|
||||
$data[ $key ] = $this->get_correct_value( $value );
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the current environmental context is a Mock context.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_mock() {
|
||||
return defined( 'GFORMS_DOING_MOCK' ) && GFORMS_DOING_MOCK;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Config\Items\GF_Config_Admin;
|
||||
use Gravity_Forms\Gravity_Forms\Config\Items\GF_Config_Block_Editor;
|
||||
use Gravity_Forms\Gravity_Forms\Config\Items\GF_Config_Global;
|
||||
use Gravity_Forms\Gravity_Forms\Config\Items\GF_Config_I18n;
|
||||
use Gravity_Forms\Gravity_Forms\Config\Items\GF_Config_Legacy_Check;
|
||||
use Gravity_Forms\Gravity_Forms\Config\Items\GF_Config_Legacy_Check_Multi;
|
||||
use Gravity_Forms\Gravity_Forms\Config\Items\GF_Config_Multifile;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\GF_Service_Container;
|
||||
use Gravity_Forms\Gravity_Forms\GF_Service_Provider;
|
||||
|
||||
/**
|
||||
* Class GF_Config_Service_Provider
|
||||
*
|
||||
* Service provider for the Config Service.
|
||||
*
|
||||
* @package Gravity_Forms\Gravity_Forms\Config
|
||||
*/
|
||||
class GF_Config_Service_Provider extends GF_Service_Provider {
|
||||
|
||||
// Organizational services
|
||||
const CONFIG_COLLECTION = 'config_collection';
|
||||
const DATA_PARSER = 'data_parser';
|
||||
|
||||
// Config services
|
||||
const I18N_CONFIG = 'i18n_config';
|
||||
const ADMIN_CONFIG = 'admin_config';
|
||||
const LEGACY_CONFIG = 'legacy_config';
|
||||
const LEGACY_MULTI_CONFIG = 'legacy_multi_config';
|
||||
const MULTIFILE_CONFIG = 'multifile_config';
|
||||
const GLOBAL_CONFIG = 'global_config';
|
||||
|
||||
/**
|
||||
* Array mapping config class names to their container ID.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $configs = array(
|
||||
self::I18N_CONFIG => GF_Config_I18n::class,
|
||||
self::ADMIN_CONFIG => GF_Config_Admin::class,
|
||||
self::LEGACY_CONFIG => GF_Config_Legacy_Check::class,
|
||||
self::LEGACY_MULTI_CONFIG => GF_Config_Legacy_Check_Multi::class,
|
||||
self::MULTIFILE_CONFIG => GF_Config_Multifile::class,
|
||||
);
|
||||
|
||||
/**
|
||||
* Register services to the container.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param GF_Service_Container $container
|
||||
*/
|
||||
public function register( GF_Service_Container $container ) {
|
||||
|
||||
// Include required files.
|
||||
require_once( plugin_dir_path( __FILE__ ) . 'class-gf-config-collection.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . 'class-gf-config.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . 'class-gf-config-data-parser.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . 'class-gf-app-config.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . 'items/class-gf-config-global.php' );
|
||||
|
||||
// Add to container
|
||||
$container->add( self::CONFIG_COLLECTION, function () {
|
||||
return new GF_Config_Collection();
|
||||
} );
|
||||
|
||||
$container->add( self::DATA_PARSER, function () {
|
||||
return new GF_Config_Data_Parser();
|
||||
} );
|
||||
|
||||
$container->add( self::GLOBAL_CONFIG, function () {
|
||||
return new GF_Config_Global();
|
||||
} );
|
||||
|
||||
// Add configs to container.
|
||||
$this->register_config_items( $container );
|
||||
$this->register_configs_to_collection( $container );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the config has been localized.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static $is_localized = false;
|
||||
|
||||
/**
|
||||
* Initiailize any actions or hooks.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param GF_Service_Container $container
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init( GF_Service_Container $container ) {
|
||||
|
||||
// Need to pass $this to callbacks; save as variable.
|
||||
$self = $this;
|
||||
|
||||
add_action( 'wp_enqueue_scripts', function () use ( $container ) {
|
||||
// Only localize during wp_enqueue_scripts if none of the other more specific events have been fired.
|
||||
if ( ! self::$is_localized ) {
|
||||
$container->get( self::CONFIG_COLLECTION )->handle();
|
||||
}
|
||||
}, 9999 );
|
||||
|
||||
add_action( 'admin_enqueue_scripts', function () use ( $container ) {
|
||||
// Only localize during admin_enqueue_scripts if none of the other more specific events have been fired.
|
||||
if ( ! self::$is_localized ) {
|
||||
$container->get( self::CONFIG_COLLECTION )->handle();
|
||||
}
|
||||
}, 9999 );
|
||||
|
||||
add_action( 'gform_output_config', function ( $form_ids = null ) use ( $container ) {
|
||||
$container->get( self::CONFIG_COLLECTION )->handle( true, $form_ids );
|
||||
self::$is_localized = true;
|
||||
} );
|
||||
|
||||
add_action( 'gform_post_enqueue_scripts', function ( $found_forms, $found_blocks, $post ) use ( $container ) {
|
||||
$form_ids = array_column( $found_forms, 'formId' );
|
||||
$container->get( self::CONFIG_COLLECTION )->handle( true, array( 'form_ids' => $form_ids ) );
|
||||
self::$is_localized = true;
|
||||
}, 10, 3);
|
||||
|
||||
add_action( 'gform_preview_init', function ( $form_id ) use ( $container ) {
|
||||
$form_ids = array( $form_id );
|
||||
$container->get( self::CONFIG_COLLECTION )->handle( true, array( 'form_ids' => $form_ids ) );
|
||||
self::$is_localized = true;
|
||||
}, 10, 2);
|
||||
|
||||
add_action('wp_ajax_gform_get_config', function () use ( $container ) {
|
||||
$container->get( self::CONFIG_COLLECTION )->handle_ajax();
|
||||
});
|
||||
|
||||
add_action('wp_ajax_nopriv_gform_get_config', function () use ( $container ) {
|
||||
$container->get( self::CONFIG_COLLECTION )->handle_ajax();
|
||||
});
|
||||
|
||||
add_action( 'rest_api_init', function () use ( $container, $self ) {
|
||||
// check if we are in a test environment, if so register the mock data endpoint.
|
||||
if ( defined( 'GF_SCRIPT_DEBUG' ) && GF_SCRIPT_DEBUG ) {
|
||||
register_rest_route( 'gravityforms/v2', '/tests/mock-data', array( // nosemgrep audit.php.wp.security.rest-route.permission-callback.return-true
|
||||
'methods' => 'GET',
|
||||
'callback' => array( $self, 'config_mocks_endpoint' ),
|
||||
'permission_callback' => function () {
|
||||
return true;
|
||||
},
|
||||
) );
|
||||
}
|
||||
} );
|
||||
|
||||
// Add global config data to admin and theme.
|
||||
add_filter( 'gform_localized_script_data_gform_admin_config', function ( $data ) use ( $self ) {
|
||||
return $self->add_global_config_data( $data );
|
||||
} );
|
||||
|
||||
add_filter( 'gform_localized_script_data_gform_theme_config', function ( $data ) use ( $self ) {
|
||||
return $self->add_global_config_data( $data );
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* For each config defined in $configs, instantiate and add to container.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param GF_Service_Container $container
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function register_config_items( GF_Service_Container $container ) {
|
||||
require_once( plugin_dir_path( __FILE__ ) . '/items/class-gf-config-i18n.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . '/items/class-gf-config-admin.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . '/items/class-gf-config-legacy-check.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . '/items/class-gf-config-legacy-check-multi.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . '/items/class-gf-config-multifile.php' );
|
||||
|
||||
$parser = $container->get( self::DATA_PARSER );
|
||||
|
||||
foreach ( $this->configs as $name => $class ) {
|
||||
$container->add( $name, function () use ( $class, $parser ) {
|
||||
return new $class( $parser );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register each config defined in $configs to the GF_Config_Collection.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param GF_Service_Container $container
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_configs_to_collection( GF_Service_Container $container ) {
|
||||
$collection = $container->get( self::CONFIG_COLLECTION );
|
||||
|
||||
foreach ( $this->configs as $name => $config ) {
|
||||
$config_class = $container->get( $name );
|
||||
$collection->add_config( $config_class );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for the Config Mocks REST endpoint.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function config_mocks_endpoint() {
|
||||
define( 'GFORMS_DOING_MOCK', true );
|
||||
$container = \GFForms::get_service_container();
|
||||
$data = $container->get( self::CONFIG_COLLECTION )->handle( false );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add global data to both admin and theme configs so that it is available everywhere
|
||||
* within the system.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_global_config_data( $data ) {
|
||||
$container = \GFForms::get_service_container();
|
||||
$global = $container->get( self::GLOBAL_CONFIG )->data();
|
||||
|
||||
return array_merge( $data, $global );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config;
|
||||
|
||||
/**
|
||||
* Base class for providing advanced functionality when localizing Config Data
|
||||
* for usage in Javascript.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @package Gravity_Forms\Gravity_Forms\Config
|
||||
*/
|
||||
abstract class GF_Config {
|
||||
|
||||
/**
|
||||
* The Data Parser
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @var GF_Config_Data_Parser
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
/**
|
||||
* The data for this config object.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* The object name for this config.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The ID of the script to localize the data to.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $script_to_localize;
|
||||
|
||||
/**
|
||||
* The priority of this config - can be used to control the order in
|
||||
* which configs are processed in the Collection.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $priority = 0;
|
||||
|
||||
/**
|
||||
* Whether the config should enqueue it's data. Can also be handled by overriding the
|
||||
* ::should_enqueue() method.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $should_enqueue = true;
|
||||
|
||||
/**
|
||||
* Whether this config should overwrite previous values in the object.
|
||||
*
|
||||
* If set to "true", the object will be overwritten by the values provided here.
|
||||
* If set to "false", the object will have its values merged with those defined here, recursively.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $overwrite = false;
|
||||
|
||||
/**
|
||||
* An args array. Use in the data() method to retrieve data specific to the specified args. For example, form specific configs will have an array of form ids specified in args.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $args = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param GF_Config_Data_Parser $parser
|
||||
*/
|
||||
public function __construct( GF_Config_Data_Parser $parser ) {
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to handle defining the data array for this config.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function data();
|
||||
|
||||
/**
|
||||
* Override this method to add enable ajax loading for a specific config path.
|
||||
* To enable loading data() via ajax, check if $config_path is one of the paths that are provided by the config. If so, return true.
|
||||
*
|
||||
* Example:
|
||||
* public function enable_ajax( $config_path, $args ) {
|
||||
* return str_starts_with( $config_path, 'gform_theme_config/common/form/product_meta' );
|
||||
* }
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param string $config_path The full path to the config item when stored in the browser's window object, for example: "gform_theme_config/common/form/product_meta"
|
||||
* @param array $args The args used to load the config data. This will be empty for generic config items. For form specific items will be in the format: array( 'form_ids' => array(123,222) ).
|
||||
*
|
||||
* @return bool Return true to load the config data associated with the provided $config_path. Return false otherwise.
|
||||
*/
|
||||
public function enable_ajax( $config_path, $args ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the config should enqueue its data. If should_enqueue() is a method,
|
||||
* call it and return the result. If not, simply return the (boolean) value of the property.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_enqueue() {
|
||||
if ( is_callable( $this->should_enqueue ) ) {
|
||||
return call_user_func( $this->should_enqueue );
|
||||
}
|
||||
|
||||
return $this->should_enqueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data for the config, passing it through a filter.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_data() {
|
||||
if ( ( ! defined( 'GFORMS_DOING_MOCK' ) || ! GFORMS_DOING_MOCK ) && ! $this->should_enqueue() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows developers to modify the raw config data being sent to the Config Parser. Useful for
|
||||
* adding in custom default/mock values for a given entry in the data, as well as modifying
|
||||
* things like callbacks for dynamic data before it's parsed and localized.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $script_to_localize
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
$data = apply_filters( 'gform_config_data_' . $this->name(), $this->data(), $this->script_to_localize() );
|
||||
|
||||
return $this->parser->parse( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the config's object.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the $priority for the config.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function priority() {
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the script to localize.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function script_to_localize() {
|
||||
return $this->script_to_localize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the config should override previous values.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_overwrite() {
|
||||
return $this->overwrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the $form_ids arrays.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param array $args Args array to be set
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_args( $args ) {
|
||||
$this->args = $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sanitized array of form ids from the args.
|
||||
*
|
||||
* @since 2.9.31
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_form_ids_arg() {
|
||||
$form_ids = rgar( $this->args, 'form_ids' );
|
||||
if ( empty( $form_ids ) || ! is_array( $form_ids ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return array_filter( array_map( 'absint', $form_ids ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the config data against a hash to ensure it has not been tampered with.
|
||||
* This method is called via AJAX, initiated by the gform.config.isValid() JS method.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function validate_ajax() {
|
||||
|
||||
// Check nonce
|
||||
$nonce_result = check_ajax_referer( 'gform_config_ajax', 'gform_ajax_nonce', false );
|
||||
|
||||
if ( ! $nonce_result ) {
|
||||
wp_send_json_error( esc_html__( 'Unable to verify nonce. Please refresh the page and try again.', 'gravityforms' ) );
|
||||
}
|
||||
|
||||
$config = json_decode( rgpost( 'config' ), true );
|
||||
$hash = rgar( $config, 'hash' );
|
||||
if ( ! $hash ) {
|
||||
wp_send_json_error( esc_html__( 'Invalid config.', 'gravityforms' ) );
|
||||
}
|
||||
|
||||
// Remove hash from config before validating.
|
||||
unset( $config['hash'] );
|
||||
|
||||
// Compare hash to config.
|
||||
if ( $hash !== self::hash( $config ) ) {
|
||||
wp_send_json_error( esc_html__( 'Config validation failed. Hash does not match', 'gravityforms' ) );
|
||||
}
|
||||
|
||||
// Send success response.
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashes the config data.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param array $config
|
||||
*
|
||||
* @return string Returns the hash of the config data.
|
||||
*/
|
||||
public static function hash( $config ) {
|
||||
return wp_hash( json_encode( $config ) );
|
||||
}
|
||||
}
|
||||
|
||||
// AJAX hash validation for config data.
|
||||
add_action('wp_ajax_gform_validate_config', array( 'Gravity_Forms\Gravity_Forms\Config\GF_Config', 'validate_ajax' ) );
|
||||
add_action('wp_ajax_nopriv_gform_validate_config', array( 'Gravity_Forms\Gravity_Forms\Config\GF_Config', 'validate_ajax' ) );
|
||||
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config\Items;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Collection;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Configurator;
|
||||
|
||||
/**
|
||||
* Config items for Admin I18N
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
class GF_Config_Admin extends GF_Config {
|
||||
|
||||
protected $name = 'gform_admin_config';
|
||||
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
|
||||
|
||||
/**
|
||||
* Whether we should enqueue this data.
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function should_enqueue() {
|
||||
return is_admin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Config data.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data() {
|
||||
$data = array(
|
||||
'data' => array(
|
||||
'is_block_editor' => \GFCommon::is_block_editor_page(),
|
||||
'gf_page' => \GFForms::get_page(),
|
||||
),
|
||||
'i18n' => array(
|
||||
'form_admin' => array(
|
||||
'toggle_feed_inactive' => esc_html__( 'Inactive', 'gravityforms' ),
|
||||
'toggle_feed_active' => esc_html__( 'Active', 'gravityforms' ),
|
||||
),
|
||||
'shortcode_ui' => array(
|
||||
'edit_form' => esc_html__( 'Edit Form', 'gravityforms' ),
|
||||
'insert_form' => esc_html__( 'Insert Form', 'gravityforms' ),
|
||||
),
|
||||
'dialog' => array(
|
||||
'cancel' => esc_html__( 'Cancel', 'gravityforms' ),
|
||||
'close' => esc_html__( 'Close', 'gravityforms' ),
|
||||
'ok' => esc_html__( 'OK', 'gravityforms' ),
|
||||
),
|
||||
),
|
||||
'bulk_actions' => $this->get_bulk_action_config(),
|
||||
);
|
||||
|
||||
$data = $this->add_entry_list_data( $data );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function get_bulk_action_config() {
|
||||
return array(
|
||||
'nonce' => wp_create_nonce( 'gf_bulk_action' ),
|
||||
'threshold' => \Gravity_Forms\Gravity_Forms\Bulk_Actions\Endpoints\GF_Bulk_Action_Endpoint_Start::get_background_threshold(),
|
||||
'backgroundActions' => \Gravity_Forms\Gravity_Forms\Bulk_Actions\Endpoints\GF_Bulk_Action_Endpoint_Start::BACKGROUND_ACTIONS,
|
||||
'pollInterval' => 1500,
|
||||
'labels' => array(
|
||||
'delete' => array(
|
||||
'title' => esc_html__( 'Bulk Delete', 'gravityforms' ),
|
||||
'starting' => esc_html__( 'Starting bulk delete...', 'gravityforms' ),
|
||||
'progress' => esc_html__( 'Deleting Gravity Forms entries...', 'gravityforms' ),
|
||||
'complete' => esc_html__( 'Completed deleting entries!', 'gravityforms' ),
|
||||
'error' => esc_html__( 'Error starting bulk delete.', 'gravityforms' ),
|
||||
),
|
||||
'trash' => array(
|
||||
'title' => esc_html__( 'Bulk Trash', 'gravityforms' ),
|
||||
'starting' => esc_html__( 'Starting bulk trash...', 'gravityforms' ),
|
||||
'progress' => esc_html__( 'Trashing Gravity Forms entries...', 'gravityforms' ),
|
||||
'complete' => esc_html__( 'Completed moving entries to trash!', 'gravityforms' ),
|
||||
'error' => esc_html__( 'Error starting bulk trash.', 'gravityforms' ),
|
||||
),
|
||||
'spam' => array(
|
||||
'title' => esc_html__( 'Bulk Mark as Spam', 'gravityforms' ),
|
||||
'starting' => esc_html__( 'Starting bulk spam marking...', 'gravityforms' ),
|
||||
'progress' => esc_html__( 'Marking Gravity Forms entries as spam...', 'gravityforms' ),
|
||||
'complete' => esc_html__( 'Completed marking entries as spam!', 'gravityforms' ),
|
||||
'error' => esc_html__( 'Error starting bulk spam.', 'gravityforms' ),
|
||||
),
|
||||
'restore' => array(
|
||||
'title' => esc_html__( 'Bulk Restore', 'gravityforms' ),
|
||||
'starting' => esc_html__( 'Starting bulk restore...', 'gravityforms' ),
|
||||
'progress' => esc_html__( 'Restoring Gravity Forms entries...', 'gravityforms' ),
|
||||
'complete' => esc_html__( 'Completed restoring entries!', 'gravityforms' ),
|
||||
'error' => esc_html__( 'Error starting bulk restore.', 'gravityforms' ),
|
||||
),
|
||||
'unspam' => array(
|
||||
'title' => esc_html__( 'Bulk Unmark as Spam', 'gravityforms' ),
|
||||
'starting' => esc_html__( 'Starting bulk unspam...', 'gravityforms' ),
|
||||
'progress' => esc_html__( 'Restoring Gravity Forms entries from spam...', 'gravityforms' ),
|
||||
'complete' => esc_html__( 'Completed unmarking entries as spam!', 'gravityforms' ),
|
||||
'error' => esc_html__( 'Error starting bulk unspam.', 'gravityforms' ),
|
||||
),
|
||||
'delete_entries' => array(
|
||||
'title' => esc_html__( 'Bulk Delete Entries', 'gravityforms' ),
|
||||
'starting' => esc_html__( 'Starting bulk entry deletion...', 'gravityforms' ),
|
||||
'progress' => esc_html__( 'Deleting Gravity Forms entries...', 'gravityforms' ),
|
||||
'complete' => esc_html__( 'Completed deleting entries!', 'gravityforms' ),
|
||||
'error' => esc_html__( 'Error starting bulk entry deletion.', 'gravityforms' ),
|
||||
),
|
||||
'mark_read' => array(
|
||||
'title' => esc_html__( 'Bulk Mark as Read', 'gravityforms' ),
|
||||
'starting' => esc_html__( 'Starting bulk mark as read...', 'gravityforms' ),
|
||||
'progress' => esc_html__( 'Marking Gravity Forms entries as read...', 'gravityforms' ),
|
||||
'complete' => esc_html__( 'Completed marking entries as read!', 'gravityforms' ),
|
||||
'error' => esc_html__( 'Error starting bulk mark as read.', 'gravityforms' ),
|
||||
),
|
||||
'mark_unread' => array(
|
||||
'title' => esc_html__( 'Bulk Mark as Unread', 'gravityforms' ),
|
||||
'starting' => esc_html__( 'Starting bulk mark as unread...', 'gravityforms' ),
|
||||
'progress' => esc_html__( 'Marking Gravity Forms entries as unread...', 'gravityforms' ),
|
||||
'complete' => esc_html__( 'Completed marking entries as unread!', 'gravityforms' ),
|
||||
'error' => esc_html__( 'Error starting bulk mark as unread.', 'gravityforms' ),
|
||||
),
|
||||
),
|
||||
'messages' => array(
|
||||
'inProgress' => esc_html__( 'Bulk action in progress...', 'gravityforms' ),
|
||||
'continueInBackground' => esc_html__( 'Continue in Background', 'gravityforms' ),
|
||||
'cancel' => esc_html__( 'Cancel', 'gravityforms' ),
|
||||
'cancelling' => esc_html__( 'Cancelling...', 'gravityforms' ),
|
||||
'operationCancelled' => esc_html__( 'Operation cancelled.', 'gravityforms' ),
|
||||
'viewDetails' => esc_html__( 'View Details', 'gravityforms' ),
|
||||
'close' => esc_html__( 'Close', 'gravityforms' ),
|
||||
'processedCount' => esc_html__( '%1$d of %2$d items processed.', 'gravityforms' ),
|
||||
'goToPage' => esc_html__( 'Go to %s', 'gravityforms' ),
|
||||
),
|
||||
'pageLabels' => array(
|
||||
'entry_list' => esc_html__( 'Entries', 'gravityforms' ),
|
||||
'form_list' => esc_html__( 'Forms', 'gravityforms' ),
|
||||
),
|
||||
'entryActions' => \Gravity_Forms\Gravity_Forms\Bulk_Actions\Endpoints\GF_Bulk_Action_Endpoint_Start::BACKGROUND_ACTIONS_ENTRY,
|
||||
'formActions' => \Gravity_Forms\Gravity_Forms\Bulk_Actions\Endpoints\GF_Bulk_Action_Endpoint_Start::BACKGROUND_ACTIONS_FORM,
|
||||
);
|
||||
}
|
||||
|
||||
private function add_entry_list_data( $data ) {
|
||||
if ( \GFForms::get_page() !== 'entry_list' ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$form_id = absint( rgget( 'id' ) );
|
||||
if ( ! $form_id ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data['form_id'] = $form_id;
|
||||
|
||||
$filter = rgget( 'filter' );
|
||||
$search = rgget( 's' );
|
||||
$field_id = rgget( 'field_id' ) === 'entry_id' ? 'id' : rgget( 'field_id' );
|
||||
$operator = rgget( 'operator' );
|
||||
$search_criteria = array();
|
||||
|
||||
if ( $filter === 'trash' || $filter === 'spam' ) {
|
||||
$search_criteria['status'] = $filter;
|
||||
} elseif ( $filter === 'star' ) {
|
||||
$search_criteria['field_filters'][] = array( 'key' => 'is_starred', 'value' => true );
|
||||
} elseif ( $filter === 'unread' ) {
|
||||
$search_criteria['field_filters'][] = array( 'key' => 'is_read', 'value' => false );
|
||||
} else {
|
||||
$search_criteria['status'] = 'active';
|
||||
}
|
||||
|
||||
if ( $search && $field_id ) {
|
||||
$search_criteria['field_filters'][] = array(
|
||||
'key' => $field_id,
|
||||
'value' => $search,
|
||||
'operator' => $operator ? $operator : 'contains',
|
||||
);
|
||||
}
|
||||
|
||||
$data['search_criteria'] = $search_criteria;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config\Items;
|
||||
|
||||
/**
|
||||
* Acts as a container for any Global Config data we need to send to both
|
||||
* the admin and theme side of the ecosystem.
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
class GF_Config_Global {
|
||||
|
||||
/**
|
||||
* The data to send to both configs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function data() {
|
||||
return array(
|
||||
'hmr_dev' => defined( 'GF_ENABLE_HMR' ) && GF_ENABLE_HMR,
|
||||
'public_path' => trailingslashit( \GFCommon::get_base_url() ) . 'assets/js/dist/',
|
||||
'config_nonce' => wp_create_nonce( 'gform_config_ajax' ),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config\Items;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Collection;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Configurator;
|
||||
|
||||
/**
|
||||
* Config items for Theme I18N
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
class GF_Config_I18n extends GF_Config {
|
||||
|
||||
protected $name = 'gform_i18n';
|
||||
protected $script_to_localize = 'gform_gravityforms';
|
||||
|
||||
/**
|
||||
* Config data.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data() {
|
||||
return array(
|
||||
'datepicker' => array(
|
||||
'days' => array(
|
||||
'monday' => esc_html__( 'Mo', 'gravityforms' ),
|
||||
'tuesday' => esc_html__( 'Tu', 'gravityforms' ),
|
||||
'wednesday' => esc_html__( 'We', 'gravityforms' ),
|
||||
'thursday' => esc_html__( 'Th', 'gravityforms' ),
|
||||
'friday' => esc_html__( 'Fr', 'gravityforms' ),
|
||||
'saturday' => esc_html__( 'Sa', 'gravityforms' ),
|
||||
'sunday' => esc_html__( 'Su', 'gravityforms' ),
|
||||
),
|
||||
'months' => array(
|
||||
'january' => esc_html__( 'January', 'gravityforms' ),
|
||||
'february' => esc_html__( 'February', 'gravityforms' ),
|
||||
'march' => esc_html__( 'March', 'gravityforms' ),
|
||||
'april' => esc_html__( 'April', 'gravityforms' ),
|
||||
'may' => esc_html_x('May', 'Full month name', 'gravityforms'),
|
||||
'june' => esc_html__( 'June', 'gravityforms' ),
|
||||
'july' => esc_html__( 'July', 'gravityforms' ),
|
||||
'august' => esc_html__( 'August', 'gravityforms' ),
|
||||
'september' => esc_html__( 'September', 'gravityforms' ),
|
||||
'october' => esc_html__( 'October', 'gravityforms' ),
|
||||
'november' => esc_html__( 'November', 'gravityforms' ),
|
||||
'december' => esc_html__( 'December', 'gravityforms' ),
|
||||
),
|
||||
'firstDay' => array(
|
||||
'value' => absint( get_option( 'start_of_week' ) ),
|
||||
'default' => 1,
|
||||
),
|
||||
'iconText' => esc_html__( 'Select date', 'gravityforms' ),
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config\Items;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Collection;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Configurator;
|
||||
|
||||
/**
|
||||
* Config items for Multi Legacy Check (mostly just data from a filter).
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
class GF_Config_Legacy_Check_Multi extends GF_Config {
|
||||
|
||||
protected $name = 'gf_legacy_multi';
|
||||
protected $script_to_localize = 'gform_gravityforms';
|
||||
|
||||
/**
|
||||
* Config data.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data() {
|
||||
/**
|
||||
* Allows users to filter the legacy checks for any form on the page.
|
||||
*
|
||||
* @since 2.5
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
return apply_filters( 'gform_gf_legacy_multi', array() );
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config\Items;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config_Collection;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Configurator;
|
||||
|
||||
/**
|
||||
* Config items for Theme Legacy Checks.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
class GF_Config_Legacy_Check extends GF_Config {
|
||||
|
||||
protected $name = 'gf_legacy';
|
||||
protected $script_to_localize = 'gform_layout_editor';
|
||||
|
||||
/**
|
||||
* Determine if the config should enqueue its data.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_enqueue() {
|
||||
return \GFCommon::is_form_editor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Config data.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data() {
|
||||
$form = \RGFormsModel::get_form_meta( rgget( 'id' ) );
|
||||
|
||||
return array(
|
||||
'is_legacy' => array(
|
||||
'value' => \GFCommon::is_legacy_markup_enabled( $form ),
|
||||
'default' => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Config\Items;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
|
||||
use Gravity_Forms\Gravity_Forms\Config\GF_Configurator;
|
||||
|
||||
/**
|
||||
* Config items for Multifile Strings
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
class GF_Config_Multifile extends GF_Config {
|
||||
|
||||
protected $script_to_localize = 'gform_gravityforms';
|
||||
protected $name = 'gform_gravityforms';
|
||||
|
||||
/**
|
||||
* Config data.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function data() {
|
||||
return array(
|
||||
'strings' => array(
|
||||
'invalid_file_extension' => wp_strip_all_tags( __( 'This type of file is not allowed. Must be one of the following: ', 'gravityforms' ) ),
|
||||
'file_uploaded' => wp_strip_all_tags( __( 'File uploaded', 'gravityforms' ) ),
|
||||
'delete_file' => wp_strip_all_tags( __( 'Delete this file', 'gravityforms' ) ),
|
||||
'in_progress' => wp_strip_all_tags( __( 'in progress', 'gravityforms' ) ),
|
||||
'file_exceeds_limit' => wp_strip_all_tags( __( 'File exceeds size limit', 'gravityforms' ) ),
|
||||
'illegal_extension' => wp_strip_all_tags( __( 'This type of file is not allowed.', 'gravityforms' ) ),
|
||||
'max_reached' => wp_strip_all_tags( __( 'Maximum number of files reached', 'gravityforms' ) ),
|
||||
'unknown_error' => wp_strip_all_tags( __( 'There was a problem while saving the file on the server', 'gravityforms' ) ),
|
||||
'currently_uploading' => wp_strip_all_tags( __( 'Please wait for the uploading to complete', 'gravityforms' ) ),
|
||||
'cancel' => wp_strip_all_tags( __( 'Cancel', 'gravityforms' ) ),
|
||||
'cancel_upload' => wp_strip_all_tags( __( 'Cancel this upload', 'gravityforms' ) ),
|
||||
'cancelled' => wp_strip_all_tags( __( 'Cancelled', 'gravityforms' ) ),
|
||||
'error' => wp_strip_all_tags( __( 'Error', 'gravityforms' ) ),
|
||||
'message' => wp_strip_all_tags( __( 'Message', 'gravityforms' ) ),
|
||||
),
|
||||
'vars' => array(
|
||||
'images_url' => \GFCommon::get_base_url() . '/images',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user