plugin install
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Form_Display\Block_Styles;
|
||||
|
||||
use GFCommon;
|
||||
use Gravity_Forms\Gravity_Forms\Form_Display\Block_Styles\Views\Confirmation_View;
|
||||
use Gravity_Forms\Gravity_Forms\Form_Display\Block_Styles\Views\Form_View;
|
||||
use Gravity_Forms\Gravity_Forms\Theme_Layers\API\Fluent\Theme_Layer_Builder;
|
||||
|
||||
class Block_Styles_Handler {
|
||||
|
||||
const NAME = 'block_styles';
|
||||
|
||||
protected $defaults_map;
|
||||
|
||||
public function __construct( $defaults_map ) {
|
||||
$this->defaults_map = $defaults_map;
|
||||
}
|
||||
|
||||
public function defaults_map( $form ) {
|
||||
return call_user_func( $this->defaults_map, $form );
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
$layer = new Theme_Layer_Builder();
|
||||
$layer->set_name( self::NAME )
|
||||
->set_form_css_properties( array( $this, 'form_css_properties' ) )
|
||||
->set_overidden_fields( $this->overriden_fields() )
|
||||
->set_styles( array( $this, 'styles' ) )
|
||||
->register();
|
||||
}
|
||||
|
||||
public function form_css_properties( $form_id, $settings, $block_settings, $form = array() ) {
|
||||
|
||||
if ( rgar( $form, 'styles' ) === false ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$applied_settings = wp_parse_args( $block_settings, $this->defaults_map( $form ) );
|
||||
|
||||
// Bail early if orbital isn't applied.
|
||||
if ( $applied_settings['theme'] !== 'orbital' ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$color_palette = GFCommon::generate_block_styles_palette( $applied_settings );
|
||||
|
||||
return array(
|
||||
/* Global CSS API: Theme */
|
||||
'gf-color-primary' => $color_palette['primary']['color'],
|
||||
'gf-color-primary-rgb' => implode( ', ', $color_palette['primary']['color-rgb'] ),
|
||||
'gf-color-primary-contrast' => $color_palette['primary']['color-contrast'],
|
||||
'gf-color-primary-contrast-rgb' => implode( ', ', $color_palette['primary']['color-contrast-rgb'] ),
|
||||
'gf-color-primary-darker' => $color_palette['primary']['color-darker'],
|
||||
'gf-color-primary-lighter' => $color_palette['primary']['color-lighter'],
|
||||
|
||||
'gf-color-secondary' => $color_palette['secondary']['color'],
|
||||
'gf-color-secondary-rgb' => implode( ', ', $color_palette['secondary']['color-rgb'] ),
|
||||
'gf-color-secondary-contrast' => $color_palette['secondary']['color-contrast'],
|
||||
'gf-color-secondary-contrast-rgb' => implode( ', ', $color_palette['secondary']['color-contrast-rgb'] ),
|
||||
'gf-color-secondary-darker' => $color_palette['secondary']['color-darker'],
|
||||
'gf-color-secondary-lighter' => $color_palette['secondary']['color-lighter'],
|
||||
|
||||
'gf-color-out-ctrl-light' => $color_palette['outside-control-light']['color'],
|
||||
'gf-color-out-ctrl-light-rgb' => implode( ', ', $color_palette['outside-control-light']['color-rgb'] ),
|
||||
'gf-color-out-ctrl-light-darker' => $color_palette['outside-control-light']['color-darker'],
|
||||
'gf-color-out-ctrl-light-lighter' => $color_palette['outside-control-light']['color-lighter'],
|
||||
|
||||
'gf-color-out-ctrl-dark' => $color_palette['outside-control-dark']['color'],
|
||||
'gf-color-out-ctrl-dark-rgb' => implode( ', ', $color_palette['outside-control-dark']['color-rgb'] ),
|
||||
'gf-color-out-ctrl-dark-darker' => $color_palette['outside-control-dark']['color-darker'],
|
||||
'gf-color-out-ctrl-dark-lighter' => $color_palette['outside-control-dark']['color-lighter'],
|
||||
|
||||
'gf-color-in-ctrl' => $color_palette['inside-control']['color'],
|
||||
'gf-color-in-ctrl-rgb' => implode( ', ', $color_palette['inside-control']['color-rgb'] ),
|
||||
'gf-color-in-ctrl-contrast' => $color_palette['inside-control']['color-contrast'],
|
||||
'gf-color-in-ctrl-contrast-rgb' => implode( ', ', $color_palette['inside-control']['color-contrast-rgb'] ),
|
||||
'gf-color-in-ctrl-darker' => $color_palette['inside-control']['color-darker'],
|
||||
'gf-color-in-ctrl-lighter' => $color_palette['inside-control']['color-lighter'],
|
||||
|
||||
'gf-color-in-ctrl-primary' => $color_palette['inside-control-primary']['color'],
|
||||
'gf-color-in-ctrl-primary-rgb' => implode( ', ', $color_palette['inside-control-primary']['color-rgb'] ),
|
||||
'gf-color-in-ctrl-primary-contrast' => $color_palette['inside-control-primary']['color-contrast'],
|
||||
'gf-color-in-ctrl-primary-contrast-rgb' => implode( ', ', $color_palette['inside-control-primary']['color-contrast-rgb'] ),
|
||||
'gf-color-in-ctrl-primary-darker' => $color_palette['inside-control-primary']['color-darker'],
|
||||
'gf-color-in-ctrl-primary-lighter' => $color_palette['inside-control-primary']['color-lighter'],
|
||||
|
||||
'gf-color-in-ctrl-light' => $color_palette['inside-control-light']['color'],
|
||||
'gf-color-in-ctrl-light-rgb' => implode( ', ', $color_palette['inside-control-light']['color-rgb'] ),
|
||||
'gf-color-in-ctrl-light-darker' => $color_palette['inside-control-light']['color-darker'],
|
||||
'gf-color-in-ctrl-light-lighter' => $color_palette['inside-control-light']['color-lighter'],
|
||||
|
||||
'gf-color-in-ctrl-dark' => $color_palette['inside-control-dark']['color'],
|
||||
'gf-color-in-ctrl-dark-rgb' => implode( ', ', $color_palette['inside-control-dark']['color-rgb'] ),
|
||||
'gf-color-in-ctrl-dark-darker' => $color_palette['inside-control-dark']['color-darker'],
|
||||
'gf-color-in-ctrl-dark-lighter' => $color_palette['inside-control-dark']['color-lighter'],
|
||||
|
||||
'gf-radius' => $applied_settings['inputBorderRadius'] . 'px',
|
||||
|
||||
/* Global CSS API: Typography */
|
||||
'gf-font-size-secondary' => $applied_settings['labelFontSize'] . 'px',
|
||||
'gf-font-size-tertiary' => $applied_settings['descriptionFontSize'] . 'px',
|
||||
|
||||
/* Global CSS API: Icons */
|
||||
'gf-icon-ctrl-number' => "url(\"data:image/svg+xml,%3Csvg width='8' height='14' viewBox='0 0 8 14' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M4 0C4.26522 5.96046e-08 4.51957 0.105357 4.70711 0.292893L7.70711 3.29289C8.09763 3.68342 8.09763 4.31658 7.70711 4.70711C7.31658 5.09763 6.68342 5.09763 6.29289 4.70711L4 2.41421L1.70711 4.70711C1.31658 5.09763 0.683417 5.09763 0.292893 4.70711C-0.0976311 4.31658 -0.097631 3.68342 0.292893 3.29289L3.29289 0.292893C3.48043 0.105357 3.73478 0 4 0ZM0.292893 9.29289C0.683417 8.90237 1.31658 8.90237 1.70711 9.29289L4 11.5858L6.29289 9.29289C6.68342 8.90237 7.31658 8.90237 7.70711 9.29289C8.09763 9.68342 8.09763 10.3166 7.70711 10.7071L4.70711 13.7071C4.31658 14.0976 3.68342 14.0976 3.29289 13.7071L0.292893 10.7071C-0.0976311 10.3166 -0.0976311 9.68342 0.292893 9.29289Z' fill='{$color_palette['inside-control-dark']['color-lighter']}'/%3E%3C/svg%3E\")",
|
||||
'gf-icon-ctrl-select' => "url(\"data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M0.292893 0.292893C0.683417 -0.097631 1.31658 -0.097631 1.70711 0.292893L5 3.58579L8.29289 0.292893C8.68342 -0.0976311 9.31658 -0.0976311 9.70711 0.292893C10.0976 0.683417 10.0976 1.31658 9.70711 1.70711L5.70711 5.70711C5.31658 6.09763 4.68342 6.09763 4.29289 5.70711L0.292893 1.70711C-0.0976311 1.31658 -0.0976311 0.683418 0.292893 0.292893Z' fill='{$color_palette['inside-control-dark']['color-lighter']}'/%3E%3C/svg%3E\")",
|
||||
'gf-icon-ctrl-search' => "url(\"data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' width='640' height='640'%3E%3Cpath d='M256 128c-70.692 0-128 57.308-128 128 0 70.691 57.308 128 128 128 70.691 0 128-57.309 128-128 0-70.692-57.309-128-128-128zM64 256c0-106.039 85.961-192 192-192s192 85.961 192 192c0 41.466-13.146 79.863-35.498 111.248l154.125 154.125c12.496 12.496 12.496 32.758 0 45.254s-32.758 12.496-45.254 0L367.248 412.502C335.862 434.854 297.467 448 256 448c-106.039 0-192-85.962-192-192z' fill='{$color_palette['inside-control-dark']['color-lighter']}'/%3E%3C/svg%3E\")",
|
||||
|
||||
/* Global CSS API: Layout & Spacing */
|
||||
'gf-label-space-y-secondary' => 'var(--gf-label-space-y-' . $applied_settings['inputSize'] . '-secondary)',
|
||||
|
||||
/* Global CSS API: Controls - Default For All Types */
|
||||
'gf-ctrl-border-color' => $applied_settings['inputBorderColor'],
|
||||
'gf-ctrl-size' => 'var(--gf-ctrl-size-' . $applied_settings['inputSize'] . ')',
|
||||
|
||||
/* Global CSS API: Control - Label */
|
||||
'gf-ctrl-label-color-primary' => $applied_settings['labelColor'],
|
||||
'gf-ctrl-label-color-secondary' => $applied_settings['labelColor'],
|
||||
|
||||
/* Global CSS API: Control - Choice (Checkbox, Radio, & Consent) */
|
||||
'gf-ctrl-choice-size' => 'var(--gf-ctrl-choice-size-' . $applied_settings['inputSize'] . ')',
|
||||
'gf-ctrl-checkbox-check-size' => 'var(--gf-ctrl-checkbox-check-size-' . $applied_settings['inputSize'] . ')',
|
||||
'gf-ctrl-radio-check-size' => 'var(--gf-ctrl-radio-check-size-' . $applied_settings['inputSize'] . ')',
|
||||
|
||||
/* Global CSS API: Control - Button */
|
||||
'gf-ctrl-btn-font-size' => 'var(--gf-ctrl-btn-font-size-' . $applied_settings['inputSize'] . ')',
|
||||
'gf-ctrl-btn-padding-x' => 'var(--gf-ctrl-btn-padding-x-' . $applied_settings['inputSize'] . ')',
|
||||
'gf-ctrl-btn-size' => 'var(--gf-ctrl-btn-size-' . $applied_settings['inputSize'] . ')',
|
||||
'gf-ctrl-btn-border-color-secondary' => $applied_settings['inputBorderColor'],
|
||||
|
||||
/* Global CSS API: Control - File */
|
||||
'gf-ctrl-file-btn-bg-color-hover' => GFCommon::darken_color( $color_palette['inside-control']['color-darker'], 2 ),
|
||||
|
||||
/* Global CSS API: Field - Page */
|
||||
'gf-field-pg-steps-number-color' => 'rgba(' . implode( ', ', GFCommon::darken_color( $applied_settings['labelColor'], 0, 'rgb' ) ) . ', 0.8)',
|
||||
);
|
||||
}
|
||||
|
||||
private function overriden_fields() {
|
||||
return array(
|
||||
'form' => Form_View::class,
|
||||
'confirmation' => Confirmation_View::class,
|
||||
);
|
||||
}
|
||||
|
||||
public function styles( $form, $ajax, $settings, $block_settings ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Form_Display\Block_Styles\Views;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Settings\Fields\Text;
|
||||
use Gravity_Forms\Gravity_Forms\Theme_Layers\API\View;
|
||||
use \GFFormDisplay;
|
||||
|
||||
class Confirmation_View extends Form_View {
|
||||
|
||||
protected $string_search = "class='gform_confirmation_wrapper";
|
||||
protected $retain_original = true;
|
||||
|
||||
public function get_markup( $content, $form, $value, $lead_id, $form_id ) {
|
||||
$content = $this->add_wrapper_class( $content, $form );
|
||||
$content = $this->add_form_theme_data_attr( $content, $form );
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function add_wrapper_class( $content, $form ) {
|
||||
$theme_slug = GFFormDisplay::get_form_theme_slug( $form );
|
||||
$classes = '';
|
||||
|
||||
switch ( $theme_slug ) {
|
||||
case 'orbital':
|
||||
$classes = 'gform_confirmation_wrapper gform_wrapper gform-theme gform-theme--foundation gform-theme--framework gform-theme--' . $theme_slug;
|
||||
break;
|
||||
case 'gravity-theme':
|
||||
default:
|
||||
$classes = 'gform_confirmation_wrapper gravity-theme gform-theme--no-framework';
|
||||
break;
|
||||
case 'legacy':
|
||||
$classes = 'gform_confirmation_wrapper gform_legacy_markup_wrapper gform_legacy_confirmation_markup_wrapper gform-theme--no-framework';
|
||||
break;
|
||||
}
|
||||
$classes = sprintf( "class='%s", $classes );
|
||||
|
||||
return str_replace( $this->string_search, $classes, $content );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the form theme data attribute to the confirmation wrapper class.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param $content
|
||||
* @param $form
|
||||
*
|
||||
* @return array|string|string[]
|
||||
*/
|
||||
protected function add_form_theme_data_attr( $content, $form ) {
|
||||
$theme_slug = GFFormDisplay::get_form_theme_slug( $form );
|
||||
$theme_attr = sprintf( "data-form-theme='%s' class='gform_confirmation_wrapper", $theme_slug );
|
||||
|
||||
return str_replace( $this->string_search, $theme_attr, $content );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Form_Display\Block_Styles\Views;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Theme_Layers\API\View;
|
||||
use \GFFormDisplay;
|
||||
|
||||
class Form_View extends View {
|
||||
|
||||
protected $string_search = ' gform_wrapper';
|
||||
|
||||
public function should_override( $form, $form_id, $block_settings = array() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_markup( $content, $form, $value, $lead_id, $form_id ) {
|
||||
$content = $this->add_wrapper_class( $content, $form );
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function add_wrapper_class( $content, $form ) {
|
||||
require_once( \GFCommon::get_base_path() . '/form_display.php' );
|
||||
|
||||
$theme_slug = GFFormDisplay::get_form_theme_slug( $form );
|
||||
$classes = '';
|
||||
|
||||
switch ( $theme_slug ) {
|
||||
case 'orbital':
|
||||
$classes = ' gform_wrapper gform-theme gform-theme--foundation gform-theme--framework gform-theme--' . $theme_slug;
|
||||
break;
|
||||
case 'gravity-theme':
|
||||
default:
|
||||
$classes = ' gform_wrapper gravity-theme gform-theme--no-framework';
|
||||
break;
|
||||
case 'legacy':
|
||||
$classes = ' gform_wrapper gform_legacy_markup_wrapper gform-theme--no-framework';
|
||||
break;
|
||||
}
|
||||
|
||||
return str_replace( $this->string_search, $classes, $content );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Form_Display;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Form_Display\Full_Screen\Full_Screen_Handler;
|
||||
use Gravity_Forms\Gravity_Forms\Form_Display\Block_Styles\Block_Styles_Handler;
|
||||
use Gravity_Forms\Gravity_Forms\GF_Service_Container;
|
||||
use Gravity_Forms\Gravity_Forms\GF_Service_Provider;
|
||||
use Gravity_Forms\Gravity_Forms\Query\GF_Query_Service_Provider;
|
||||
use Gravity_Forms\Gravity_Forms\Query\JSON_Handlers\GF_Query_JSON_Handler;
|
||||
use Gravity_Forms\Gravity_Forms\Query\JSON_Handlers\GF_String_JSON_Handler;
|
||||
use \GFCommon;
|
||||
use \GFForms;
|
||||
use \GFFormDisplay;
|
||||
|
||||
/**
|
||||
* Class GF_Form_Display_Service_Provider
|
||||
*
|
||||
* Service provider for the Form_Display Service.
|
||||
*
|
||||
* @package Gravity_Forms\Gravity_Forms\Form_Display;
|
||||
*/
|
||||
class GF_Form_Display_Service_Provider extends GF_Service_Provider {
|
||||
|
||||
const FULL_SCREEN_HANDLER = 'full_screen_handler';
|
||||
const BLOCK_STYLES_HANDLER = 'block_styles_handler';
|
||||
const BLOCK_STYLES_DEFAULTS = 'block_styles_defaults';
|
||||
|
||||
/**
|
||||
* Register services to the container.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param GF_Service_Container $container
|
||||
*/
|
||||
public function register( GF_Service_Container $container ) {
|
||||
require_once( plugin_dir_path( __FILE__ ) . '/full-screen/class-full-screen-handler.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . '/block-styles/views/class-form-view.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . '/block-styles/views/class-confirmation-view.php' );
|
||||
require_once( plugin_dir_path( __FILE__ ) . '/block-styles/block-styles-handler.php' );
|
||||
|
||||
$container->add( self::FULL_SCREEN_HANDLER, function() use ( $container ) {
|
||||
// Use string handler for now to avoid JSON query issues on old platforms.
|
||||
$handler = $container->get( GF_Query_Service_Provider::JSON_STRING_HANDLER );
|
||||
|
||||
return new Full_Screen_Handler( $handler );
|
||||
});
|
||||
|
||||
$container->add( self::BLOCK_STYLES_DEFAULTS, function() {
|
||||
return function( $form = array() ) {
|
||||
|
||||
$form_style_settings = rgar( $form, 'styles' ) ? $form['styles'] : array();
|
||||
$form_styles = GFFormDisplay::get_form_styles( $form_style_settings );
|
||||
|
||||
return array(
|
||||
'theme' => get_option( 'rg_gforms_default_theme', 'gravity-theme' ),
|
||||
'inputSize' => rgar( $form_styles, 'inputSize' ) ? $form_styles['inputSize'] : 'md',
|
||||
'inputBorderRadius' => rgar( $form_styles, 'inputBorderRadius' ) ? $form_styles['inputBorderRadius'] : 3,
|
||||
'inputBorderColor' => rgar( $form_styles, 'inputBorderColor' ) ? $form_styles['inputBorderColor'] : '#686e77',
|
||||
'inputBackgroundColor' => rgar( $form_styles, 'inputBackgroundColor' ) ? $form_styles['inputBackgroundColor'] : '#fff',
|
||||
'inputColor' => rgar( $form_styles, 'inputColor' ) ? $form_styles['inputColor'] : '#112337',
|
||||
// Setting this to empty allows us to set this to what the appropriate default
|
||||
// should be for the theme framework and CSS API. When empty, it defaults to:
|
||||
// buttonPrimaryBackgroundColor
|
||||
'inputPrimaryColor' => rgar( $form_styles, 'inputPrimaryColor' ) ? $form_styles['inputPrimaryColor'] : '', // #204ce5
|
||||
'labelFontSize' => rgar( $form_styles, 'labelFontSize' ) ? $form_styles['labelFontSize'] : 14,
|
||||
'labelColor' => rgar( $form_styles, 'labelColor' ) ? $form_styles['labelColor'] : '#112337',
|
||||
'descriptionFontSize' => rgar( $form_styles, 'descriptionFontSize' ) ? $form_styles['descriptionFontSize'] : 13,
|
||||
'descriptionColor' => rgar( $form_styles, 'descriptionColor' ) ? $form_styles['descriptionColor'] : '#585e6a',
|
||||
'buttonPrimaryBackgroundColor' => rgar( $form_styles, 'buttonPrimaryBackgroundColor' ) ? $form_styles['buttonPrimaryBackgroundColor'] : '#204ce5',
|
||||
'buttonPrimaryColor' => rgar( $form_styles, 'buttonPrimaryColor' ) ? $form_styles['buttonPrimaryColor'] : '#fff',
|
||||
);
|
||||
};
|
||||
}, true );
|
||||
|
||||
$container->add( self::BLOCK_STYLES_HANDLER, function() use ( $container ) {
|
||||
return new Block_Styles_Handler( $container->get( self::BLOCK_STYLES_DEFAULTS ) );
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize any actions or hooks.
|
||||
*
|
||||
* @since
|
||||
*
|
||||
* @param GF_Service_Container $container
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init( GF_Service_Container $container ) {
|
||||
add_filter( 'template_include', function ( $template ) use ( $container ) {
|
||||
return $container->get( self::FULL_SCREEN_HANDLER )->load_full_screen_template( $template );
|
||||
} );
|
||||
|
||||
add_action( 'init', function () use ( $container ) {
|
||||
$container->get( self::BLOCK_STYLES_HANDLER )->handle();
|
||||
}, 0, 0 );
|
||||
|
||||
add_action( 'gform_enqueue_scripts', array( $this, 'register_theme_styles' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'register_theme_styles' ) );
|
||||
}
|
||||
|
||||
public function register_theme_styles() {
|
||||
$base_url = GFCommon::get_base_url();
|
||||
$version = GFForms::$version;
|
||||
$dev_min = defined( 'GF_SCRIPT_DEBUG' ) && GF_SCRIPT_DEBUG ? '' : '.min';
|
||||
|
||||
/**
|
||||
* Allows users to disable all CSS files from being loaded on the Front End.
|
||||
*
|
||||
* @since 2.8
|
||||
*
|
||||
* @param boolean Whether to disable css.
|
||||
*/
|
||||
$disable_css = apply_filters( 'gform_disable_css', get_option( 'rg_gforms_disable_css' ) );
|
||||
|
||||
if ( ! $disable_css ) {
|
||||
wp_register_style( 'gravity_forms_theme_reset', "{$base_url}/assets/css/dist/gravity-forms-theme-reset{$dev_min}.css", array(), $version );
|
||||
wp_register_style( 'gravity_forms_theme_foundation', "{$base_url}/assets/css/dist/gravity-forms-theme-foundation{$dev_min}.css", array(), $version );
|
||||
wp_register_style(
|
||||
'gravity_forms_theme_framework',
|
||||
"{$base_url}/assets/css/dist/gravity-forms-theme-framework{$dev_min}.css",
|
||||
array(
|
||||
'gravity_forms_theme_reset',
|
||||
'gravity_forms_theme_foundation',
|
||||
),
|
||||
$version
|
||||
);
|
||||
wp_register_style( 'gravity_forms_orbital_theme', "{$base_url}/assets/css/dist/gravity-forms-orbital-theme{$dev_min}.css", array( 'gravity_forms_theme_framework' ), $version );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms\Form_Display\Full_Screen;
|
||||
|
||||
use Gravity_Forms\Gravity_Forms\Query\JSON_Handlers\GF_JSON_Handler;
|
||||
|
||||
class Full_Screen_Handler {
|
||||
|
||||
const SETTING_NAME = 'form_full_screen_slug';
|
||||
|
||||
/**
|
||||
* Tokenized storage of forms discovered to avoid duplicate queries.
|
||||
*
|
||||
* @var array $form_found
|
||||
*/
|
||||
private static $form_found = array();
|
||||
|
||||
/**
|
||||
* Tokenized storage of the DB Version to avoid duplicate queries.
|
||||
*
|
||||
* @var string $db_version
|
||||
*/
|
||||
private static $db_version;
|
||||
|
||||
/**
|
||||
* The JSON query handler.
|
||||
*
|
||||
* @var GF_JSON_Handler
|
||||
*/
|
||||
private $json_handler;
|
||||
|
||||
public function __construct( GF_JSON_Handler $handler ) {
|
||||
$this->json_handler = $handler;
|
||||
|
||||
add_filter( 'redirect_canonical', function ( $redirect_url ) use ( $handler ) {
|
||||
|
||||
$form_for_display = apply_filters( 'gform_full_screen_form_for_display', null, '', $handler );
|
||||
|
||||
if ( is_404() && ! empty( $form_for_display ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $redirect_url;
|
||||
}, 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the given database management system version and type support the JSON_CONTAINS function.
|
||||
*
|
||||
* @since 2.7.1
|
||||
*
|
||||
* @param string $version The database management system version number.
|
||||
* @param string $type The database management system type.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function db_supports_json_contains( $version, $type ) {
|
||||
return ( $type === 'MySQL' && version_compare( $version, '5.7.8', '>=' ) ) || ( $type === 'MariaDB' && version_compare( $version, '10.2.25', '>=' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL version for the current server environment.
|
||||
*
|
||||
* @since 2.7
|
||||
* @deprecated 2.7.1
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_mysql_version() {
|
||||
if ( ! is_null( self::$db_version ) ) {
|
||||
return self::$db_version;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// Query to get MySQL version. No prepare() needed since it's a static query.
|
||||
$query = "SHOW VARIABLES LIKE 'version'";
|
||||
$results = $wpdb->get_row( $query );
|
||||
|
||||
if ( empty( $results->Value ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$version = $results->Value;
|
||||
self::$db_version = $version;
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the full screen template if enabled.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @hook template_include 10, 1
|
||||
*
|
||||
* @param string $template The template file passed to template_include.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function load_full_screen_template( $template ) {
|
||||
$form_for_display = $this->get_form_for_display();
|
||||
|
||||
/**
|
||||
* External filter usable by third-party code to modify/return the form ID for display. Useful for
|
||||
* selecting the Form ID based on externally-defined conditions.
|
||||
*
|
||||
* @since 2.7
|
||||
* @since 2.7.4 Added the $json_handler parameter
|
||||
* @since 2.7.4 Set the $template param to null
|
||||
*
|
||||
* @param string $form_for_display The current Form ID found.
|
||||
* @param string $template The current template being loaded by template_load.
|
||||
* @param GF_JSON_Handler $json_handler The JSON handler to query the forms
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
$form_for_display = apply_filters( 'gform_full_screen_form_for_display', null, $template, $this->json_handler );
|
||||
|
||||
if ( ! $form_for_display ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
$form = \GFFormsModel::get_form( $form_for_display );
|
||||
|
||||
add_filter( 'pre_get_document_title', function ( $title ) use ( $form ) {
|
||||
return $form->title;
|
||||
} );
|
||||
|
||||
$new_template = dirname( __FILE__ ) . '/views/class-full-screen-template.php';
|
||||
|
||||
/**
|
||||
* Allows third-party code to define a custom template path to load for full-screen display. Defaults to
|
||||
* our internal view.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param string $new_template The current template being loaded.
|
||||
* @param string $form_for_display The Form ID being loaded.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
$new_template = apply_filters( 'gform_full_screen_template_path', $new_template, $form_for_display );
|
||||
|
||||
// WordPress 5.5 introduced the ability to pass arguments to a template partial. Use that if available.
|
||||
if ( $this->supports_template_arguments() ) {
|
||||
load_template( $new_template, true, array( 'form_id' => $form_for_display ) );
|
||||
|
||||
http_response_code( 200 );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal filter used to globally store the Form ID for the currently-detected form for usage in
|
||||
* the template itself. Used as a workaround to pass arguments to the loaded template partial
|
||||
* in pre-5.5 WordPress.
|
||||
*
|
||||
* NOTE: This isn't a good filter for dynamically modifying the Form ID being loaded. Instead, use
|
||||
* the gform_full_screen_form_for_display filter.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param string $form_for_display The current Form ID detected for display.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
add_filter( 'gform_full_screen_form_id', function () use ( $form_for_display ) {
|
||||
return $form_for_display;
|
||||
}, 10, 0 );
|
||||
|
||||
return $new_template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the applicable Form ID to display for the given $slug.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_form_for_display( $slug = '' ) {
|
||||
if ( ! empty( self::$form_found[ $slug ] ) ) {
|
||||
return self::$form_found[ $slug ];
|
||||
}
|
||||
|
||||
global $wp;
|
||||
|
||||
$post_slug = empty( $slug ) ? $wp->request : $slug;
|
||||
|
||||
// Prevent empty values from hijacking the site homepage.
|
||||
if ( empty( $post_slug ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$form_id = $this->get_form_by_slug( $post_slug );
|
||||
|
||||
if ( ! empty( $form_id ) ) {
|
||||
self::$form_found[ $slug ] = $form_id;
|
||||
}
|
||||
|
||||
return $form_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check WP core version to determine if template arguments are supported.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function supports_template_arguments() {
|
||||
global $wp_version;
|
||||
|
||||
return version_compare( $wp_version, '5.5', '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the JSON Handler to query for a form ID by slug.
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param string $slug The page slug to query by.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_form_by_slug( $slug ) {
|
||||
return $this->json_handler->query( $slug );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
// In WP 5.5+, form ID is passed in $args. Otherwise, we need to grab it from our filter.
|
||||
$form_id = empty( $args['form_id'] ) ? apply_filters( 'gform_full_screen_form_id', 0 ) : $args['form_id'];
|
||||
|
||||
gravity_form( $form_id );
|
||||
Reference in New Issue
Block a user