| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907 |
- <?php
- /**
- * Handles logic for UI settings forms.
- *
- * @since 2.0
- */
- class FLBuilderUISettingsForms {
- /**
- * An array of JS templates for custom form tabs and
- * sections that need to be loaded.
- *
- * @since 2.0
- * @var int $form_templates
- */
- static private $form_templates = array();
- /**
- * @since 2.0
- * @return void
- */
- static public function init() {
- add_action( 'wp', __CLASS__ . '::render_settings_config' );
- add_action( 'wp_enqueue_scripts', __CLASS__ . '::enqueue_settings_config', 11 );
- add_action( 'wp_footer', __CLASS__ . '::init_js_config', 1 );
- add_action( 'wp_footer', __CLASS__ . '::render_js_templates', 11 );
- }
- /**
- * Adds an inline script for general settings config and
- * one for module settings config.
- *
- * @since 2.0.7
- * @return void
- */
- static public function enqueue_settings_config() {
- global $wp_the_query;
- if ( FLBuilderModel::is_builder_active() ) {
- $url = FLBuilderModel::get_edit_url( $wp_the_query->post->ID ) . '&fl_builder_load_settings_config';
- $script = 'var s = document.createElement("script");s.type = "text/javascript";s.src = "%s";document.head.appendChild(s);';
- $config = sprintf( $script, $url );
- $modules = sprintf( $script, $url . '=modules' );
- wp_add_inline_script( 'fl-builder', $config );
- wp_add_inline_script( 'fl-builder-min', $config );
- wp_add_inline_script( 'fl-builder', $modules );
- wp_add_inline_script( 'fl-builder-min', $modules );
- }
- }
- /**
- * Renders the JS config for settings forms for the current page if requested
- * and dies early so it can be loaded from a script tag.
- *
- * @since 2.0.7
- * @return void
- */
- static public function render_settings_config() {
- if ( FLBuilderModel::is_builder_active() && isset( $_GET['fl_builder_load_settings_config'] ) ) {
- $type = sanitize_key( $_GET['fl_builder_load_settings_config'] );
- $handler = 'FLBuilderUISettingsForms::compress_settings_config';
- if ( 'modules' === $type ) {
- $settings = FLBuilderUISettingsForms::get_modules_js_config();
- } else {
- $settings = FLBuilderUISettingsForms::get_js_config();
- }
- if ( @ini_get( 'zlib.output_compression' ) ) { // @codingStandardsIgnoreLine
- @ini_set( 'zlib.output_compression', 'Off' ); // @codingStandardsIgnoreLine
- $handler = null;
- }
- header( 'Content-Type: application/javascript' );
- ob_start( $handler );
- include FL_BUILDER_DIR . 'includes/ui-settings-config.php';
- ob_end_flush();
- die();
- }
- }
- /**
- * Attempts to use the output buffer gzip handler to compress
- * the settings config. We have to do it this way to prevent
- * errors we were running into on some hosts.
- *
- * @since 2.1.0.2
- * @param string $buffer $mode
- * @return string
- */
- static public function compress_settings_config( $buffer, $mode ) {
- @ob_gzhandler( $buffer, null ); // @codingStandardsIgnoreLine
- return $buffer;
- }
- /**
- * Initializes the JS config by calling the get method early on
- * wp_footer (before the UI renders). This needs to be done so
- * changes to the builder's form config arrays are made before the
- * JS templates are printed.
- *
- *
- * @since 2.0.1.1
- * @return void
- */
- static public function init_js_config() {
- self::get_js_config();
- self::get_modules_js_config();
- }
- /**
- * Returns the JS config for all settings forms except
- * modules which are loaded in a separate request.
- *
- * @since 2.0
- * @return array
- */
- static public function get_js_config() {
- return array(
- 'forms' => self::prep_forms_for_js_config( FLBuilderModel::$settings_forms ),
- 'editables' => self::prep_editables_for_js_config(),
- 'nodes' => self::prep_node_settings_for_js_config(),
- 'attachments' => self::prep_attachments_for_js_config(),
- 'settings' => array(
- 'global' => FLBuilderModel::get_global_settings(),
- 'layout' => FLBuilderModel::get_layout_settings(),
- ),
- 'defaults' => array(
- 'row' => FLBuilderModel::get_row_defaults(),
- 'column' => FLBuilderModel::get_col_defaults(),
- 'modules' => FLBuilderModel::get_module_defaults(),
- 'forms' => self::prep_form_defaults_for_js_config( FLBuilderModel::$settings_forms ),
- ),
- );
- }
- /**
- * Returns the JS config for all modules.
- *
- * @since 2.0.7
- * @return array
- */
- static public function get_modules_js_config() {
- return array(
- 'modules' => self::prep_module_forms_for_js_config(),
- );
- }
- /**
- * Returns only the node JS config for settings forms.
- *
- * @since 2.0
- * @return array
- */
- static public function get_node_js_config() {
- return array(
- 'nodes' => self::prep_node_settings_for_js_config(),
- 'attachments' => self::prep_attachments_for_js_config(),
- );
- }
- /**
- * Prepares form defaults for the JS config.
- *
- * @since 2.0
- * @param array $forms
- * @return array
- */
- static private function prep_form_defaults_for_js_config( $forms ) {
- $defaults = array();
- foreach ( $forms as $form_key => $form ) {
- if ( isset( $form['tabs'] ) ) {
- $defaults[ $form_key ] = FLBuilderModel::get_settings_form_defaults( $form_key );
- }
- }
- return $defaults;
- }
- /**
- * Prepares forms for the JS config.
- *
- * @since 2.0
- * @param array $forms
- * @return array
- */
- static private function prep_forms_for_js_config( $forms ) {
- foreach ( $forms as $form_key => &$form ) {
- if ( ! isset( $form['tabs'] ) ) {
- continue;
- }
- foreach ( $form['tabs'] as $tab_key => &$tab ) {
- if ( isset( $tab['template'] ) ) {
- self::$form_templates[ $tab['template']['id'] ] = $tab['template']['file'];
- }
- if ( ! isset( $tab['sections'] ) ) {
- continue;
- }
- foreach ( $tab['sections'] as $section_key => &$section ) {
- if ( isset( $section['file'] ) && FL_BUILDER_DIR . 'includes/service-settings.php' === $section['file'] ) {
- $section['template'] = array(
- 'id' => 'fl-builder-service-settings',
- 'file' => FL_BUILDER_DIR . 'includes/ui-service-settings.php',
- );
- unset( $section['file'] );
- }
- if ( isset( $section['template'] ) ) {
- self::$form_templates[ $section['template']['id'] ] = $section['template']['file'];
- }
- if ( ! isset( $section['fields'] ) ) {
- continue;
- }
- foreach ( $section['fields'] as $field_key => &$field ) {
- self::prep_field_for_js_config( $field, $field_key, $form_key );
- }
- }
- }
- }
- return $forms;
- }
- /**
- * Prepares a field for the JS config.
- *
- * @since 2.0
- * @param array $field
- * @param string $field_key
- * @param string $form_key
- * @return void
- */
- static private function prep_field_for_js_config( &$field, $field_key = '', $form_key = '' ) {
- /**
- * This filter hook replaces pre-2.0 `fl_builder_render_settings_field` one.
- *
- * @param array $field An array of setup data for the field.
- * @param string $field_key The field name/key.
- * @param string $form_key Module/form key.
- */
- $field = apply_filters( 'fl_builder_field_js_config', $field, $field_key, $form_key );
- // Convert class to className for JS compat.
- if ( isset( $field['class'] ) ) {
- $field['className'] = $field['class'];
- }
- // Select fields
- if ( 'select' === $field['type'] ) {
- if ( is_string( $field['options'] ) && is_callable( $field['options'] ) ) {
- $field['options'] = call_user_func( $field['options'] );
- } else {
- $field['options'] = (array) $field['options'];
- }
- }
- }
- /**
- * Gathers and prepares module forms for the JS config.
- *
- * @since 2.0
- * @return array
- */
- static public function prep_module_forms_for_js_config() {
- $module_forms = array();
- foreach ( FLBuilderModel::$modules as $module ) {
- $css = '';
- $js = '';
- if ( file_exists( $module->dir . 'css/settings.css' ) ) {
- $css .= '<link class="fl-builder-settings-css" rel="stylesheet" href="' . $module->url . 'css/settings.css" />';
- }
- if ( file_exists( $module->dir . 'js/settings.js' ) ) {
- $js .= '<script class="fl-builder-settings-js" src="' . $module->url . 'js/settings.js"></script>';
- }
- $module_forms[ $module->slug ] = array(
- 'title' => $module->name,
- 'tabs' => $module->form,
- 'assets' => array(
- 'css' => $css,
- 'js' => $js,
- ),
- );
- }
- return self::prep_forms_for_js_config( $module_forms );
- }
- /**
- * Gathers and prepares inline module editing data for the JS config.
- *
- * @since 2.1
- * @return array
- */
- static public function prep_editables_for_js_config() {
- $editables = array();
- foreach ( FLBuilderModel::$modules as $module ) {
- $fields = FLBuilderModel::get_settings_form_fields( $module->form );
- foreach ( $fields as $key => $field ) {
- if ( 'code' === $field['type'] ) {
- continue;
- }
- if ( ! isset( $field['preview'] ) ) {
- continue;
- }
- if ( ! isset( $field['preview']['type'] ) || 'text' !== $field['preview']['type'] ) {
- continue;
- }
- if ( ! isset( $field['preview']['selector'] ) ) {
- continue;
- }
- if ( ! isset( $editables[ $module->slug ] ) ) {
- $editables[ $module->slug ] = array();
- }
- $editables[ $module->slug ][ $key ] = array(
- 'selector' => $field['preview']['selector'],
- 'field' => array(
- 'name' => $key,
- 'type' => $field['type'],
- ),
- );
- }
- }
- return $editables;
- }
- /**
- * Gathers and prepares node settings for the JS config.
- *
- * @since 2.0
- * @return array
- */
- static public function prep_node_settings_for_js_config() {
- $layout_data = FLBuilderModel::get_layout_data();
- $node_settings = array();
- foreach ( $layout_data as $node_id => $node ) {
- if ( ! is_object( $node ) || ! isset( $node->settings ) || ! is_object( $node->settings ) ) {
- continue;
- }
- $node_settings[ $node_id ] = FLBuilderModel::get_node_settings( $node, false );
- }
- return $node_settings;
- }
- /**
- * Gathers and prepares attachments for the JS config.
- *
- * @since 2.0
- * @return array
- */
- static private function prep_attachments_for_js_config() {
- $layout_data = FLBuilderModel::get_layout_data();
- $attachments = array();
- foreach ( $layout_data as $node ) {
- if ( ! isset( $node->settings ) || ! is_object( $node->settings ) ) {
- continue;
- }
- if ( 'row' === $node->type ) {
- $fields = FLBuilderModel::get_settings_form_fields( FLBuilderModel::$settings_forms['row']['tabs'] );
- } elseif ( 'column' === $node->type ) {
- $fields = FLBuilderModel::get_settings_form_fields( FLBuilderModel::$settings_forms['col']['tabs'] );
- } elseif ( 'module' === $node->type && isset( FLBuilderModel::$modules[ $node->settings->type ] ) ) {
- $fields = FLBuilderModel::get_settings_form_fields( FLBuilderModel::$modules[ $node->settings->type ]->form );
- } else {
- continue;
- }
- foreach ( $node->settings as $key => $value ) {
- // Look for image attachments.
- if ( strstr( $key, '_src' ) ) {
- $base = str_replace( '_src', '', $key );
- if ( isset( $node->settings->$base ) && is_numeric( $node->settings->$base ) ) {
- $id = $node->settings->$base;
- $data = self::prep_attachment_for_js_config( $id );
- if ( $data ) {
- $attachments[ $id ] = $data;
- }
- }
- }
- // Look for video attachments.
- if ( isset( $fields[ $key ] ) && 'video' === $fields[ $key ]['type'] ) {
- if ( is_numeric( $value ) ) {
- $id = $value;
- $data = self::prep_attachment_for_js_config( $id );
- if ( $data ) {
- $attachments[ $id ] = $data;
- }
- }
- }
- }
- }
- return $attachments;
- }
- /**
- * Prepares a single attachment for the JS config.
- *
- * @since 2.0
- * @param int $id
- * @return array|bool
- */
- static private function prep_attachment_for_js_config( $id ) {
- $url = wp_get_attachment_url( $id );
- if ( ! $url ) {
- return false;
- }
- $filename = wp_basename( $url );
- $base_url = str_replace( $filename, '', $url );
- $meta = wp_get_attachment_metadata( $id );
- $sizes = array();
- $possible_sizes = apply_filters( 'image_size_names_choose', array(
- 'thumbnail' => __( 'Thumbnail' ),
- 'medium' => __( 'Medium' ),
- 'large' => __( 'Large' ),
- 'full' => __( 'Full Size' ),
- ) );
- if ( isset( $meta['sizes'] ) ) {
- foreach ( $meta['sizes'] as $size_key => $size ) {
- if ( ! isset( $possible_sizes[ $size_key ] ) ) {
- continue;
- }
- $sizes[ $size_key ] = array(
- 'url' => $base_url . $size['file'],
- 'filename' => $size['file'],
- 'width' => $size['width'],
- 'height' => $size['height'],
- );
- }
- }
- if ( ! isset( $sizes['full'] ) ) {
- $sizes['full'] = array(
- 'url' => $url,
- 'filename' => isset( $meta['file'] ) ? $meta['file'] : $filename,
- 'width' => isset( $meta['width'] ) ? $meta['width'] : '',
- 'height' => isset( $meta['height'] ) ? $meta['height'] : '',
- );
- }
- return array(
- 'id' => $id,
- 'url' => $url,
- 'filename' => $filename,
- 'sizes' => apply_filters( 'fl_builder_photo_sizes_select', $sizes ),
- );
- }
- /**
- * Renders the JS templates for settings forms.
- *
- * @since 2.0
- * @return void
- */
- static public function render_js_templates() {
- if ( ! FLBuilderModel::is_builder_active() ) {
- return;
- }
- include FL_BUILDER_DIR . 'includes/ui-settings-form.php';
- include FL_BUILDER_DIR . 'includes/ui-settings-form-row.php';
- include FL_BUILDER_DIR . 'includes/ui-field.php';
- $fields = glob( FL_BUILDER_DIR . 'includes/ui-field-*.php' );
- $custom = apply_filters( 'fl_builder_custom_fields', array() );
- foreach ( $fields as $path ) {
- $slug = str_replace( array( 'ui-field-', '.php' ), '', basename( $path ) );
- echo '<script type="text/html" id="tmpl-fl-builder-field-' . $slug . '">';
- include $path;
- echo '</script>';
- }
- foreach ( $custom as $type => $path ) {
- echo '<script type="text/html" id="tmpl-fl-builder-field-' . $type . '">';
- include $path;
- echo '</script>';
- }
- foreach ( self::$form_templates as $id => $path ) {
- if ( file_exists( $path ) ) {
- echo '<script type="text/html" id="tmpl-' . $id . '">';
- include $path;
- echo '</script>';
- }
- }
- }
- /**
- * Pre-renders legacy settings tabs, sections and fields for
- * new modules that are currently being sent to the frontend.
- *
- * @since 2.0
- * @param string $type
- * @param object $settings
- * @return array
- */
- static public function pre_render_legacy_module_settings( $type, $settings ) {
- $data = array(
- 'tabs' => array(),
- 'sections' => array(),
- 'fields' => array(),
- 'settings' => $settings,
- 'node_id' => null,
- );
- $custom = apply_filters( 'fl_builder_custom_fields', array() );
- foreach ( FLBuilderModel::$modules[ $type ]->form as $tab_id => $tab ) {
- if ( isset( $tab['file'] ) ) {
- $data['tabs'][] = $tab_id;
- }
- if ( ! isset( $tab['sections'] ) ) {
- continue;
- }
- foreach ( $tab['sections'] as $section_id => $section ) {
- if ( isset( $section['file'] ) ) {
- $data['sections'][] = array(
- 'tab' => $tab_id,
- 'section' => $section_id,
- );
- }
- if ( ! isset( $section['fields'] ) ) {
- continue;
- }
- foreach ( $section['fields'] as $field_id => $field ) {
- $is_core = file_exists( FL_BUILDER_DIR . 'includes/ui-field-' . $field['type'] . '.php' );
- $is_custom = isset( $custom[ $field['type'] ] );
- if ( ! $is_core && ! $is_custom ) {
- $data['fields'][] = $field_id;
- }
- }
- }
- }
- return self::render_legacy_settings( $data, $type, 'module', null );
- }
- /**
- * Renders legacy settings tabs, sections and fields.
- *
- * @since 2.0
- * @param array $data
- * @param string $form
- * @param string $group
- * @param string $lightbox
- * @return array
- */
- static public function render_legacy_settings( $data, $form, $group, $lightbox ) {
- $response = array(
- 'lightbox' => $lightbox,
- 'tabs' => array(),
- 'sections' => array(),
- 'fields' => array(),
- 'extras' => array(),
- );
- // Get the form tabs.
- if ( 'general' === $group ) {
- $tabs = FLBuilderModel::$settings_forms[ $form ]['tabs'];
- } elseif ( 'module' === $group ) {
- $tabs = FLBuilderModel::$modules[ $form ]->form;
- }
- // Get the form fields.
- $fields = FLBuilderModel::get_settings_form_fields( $tabs );
- // Get the settings.
- if ( $data['node_id'] ) {
- $layout_data = FLBuilderModel::get_layout_data();
- $settings = $layout_data[ $data['node_id'] ]->settings;
- } else {
- $settings = isset( $data['settings'] ) ? (object) $data['settings'] : new stdClass();
- }
- // Render legacy custom fields.
- if ( isset( $data['fields'] ) ) {
- foreach ( $data['fields'] as $name ) {
- ob_start();
- self::render_settings_field( $name, (array) $fields[ $name ], $settings );
- $response['fields'][ $name ] = ob_get_clean();
- }
- }
- // Render legacy field extras with the before and after actions.
- foreach ( $fields as $name => $field ) {
- if ( in_array( $name, $response['fields'] ) ) {
- continue;
- }
- $value = isset( $settings->$name ) ? $settings->$name : '';
- $is_multiple = isset( $field['multiple'] ) ? $field['multiple'] : false;
- if ( $is_multiple ) {
- $before = array();
- $after = array();
- foreach ( $value as $repeater_item_value ) {
- ob_start();
- do_action( 'fl_builder_before_control', $name, $repeater_item_value, $field, $settings );
- do_action( 'fl_builder_before_control_' . $field['type'], $name, $value, $field, $settings );
- $before[] = ob_get_clean();
- ob_start();
- do_action( 'fl_builder_after_control_' . $field['type'], $name, $value, $field, $settings );
- do_action( 'fl_builder_after_control', $name, $repeater_item_value, $field, $settings );
- $after[] = ob_get_clean();
- }
- } else {
- ob_start();
- do_action( 'fl_builder_before_control', $name, $value, $field, $settings );
- do_action( 'fl_builder_before_control_' . $field['type'], $name, $value, $field, $settings );
- $before = ob_get_clean();
- ob_start();
- do_action( 'fl_builder_after_control_' . $field['type'], $name, $value, $field, $settings );
- do_action( 'fl_builder_after_control', $name, $value, $field, $settings );
- $after = ob_get_clean();
- }
- if ( ! empty( $before ) || ! empty( $after ) ) {
- $response['extras'][ $name ] = array(
- 'multiple' => $is_multiple,
- 'before' => $before,
- 'after' => $after,
- );
- }
- }
- // Render legacy custom sections.
- if ( isset( $data['sections'] ) ) {
- foreach ( $data['sections'] as $section_data ) {
- $tab = $section_data['tab'];
- $name = $section_data['section'];
- $section = $tabs[ $tab ]['sections'][ $name ];
- if ( file_exists( $section['file'] ) ) {
- if ( ! isset( $response['sections'][ $tab ] ) ) {
- $response['sections'][ $tab ] = array();
- }
- ob_start();
- include $section['file'];
- $response['sections'][ $tab ][ $name ] = ob_get_clean();
- }
- }
- }
- // Render legacy custom tabs.
- if ( isset( $data['tabs'] ) ) {
- foreach ( $data['tabs'] as $name ) {
- $tab = $tabs[ $name ];
- if ( FL_BUILDER_DIR . 'includes/loop-settings.php' === $tab['file'] ) {
- $tab['file'] = FL_BUILDER_DIR . 'includes/ui-loop-settings.php';
- }
- if ( file_exists( $tab['file'] ) ) {
- ob_start();
- include $tab['file'];
- $response['tabs'][ $name ] = ob_get_clean();
- }
- }
- }
- return $response;
- }
- /**
- * Renders a settings via PHP. This method is only around for
- * backwards compatibility with third party settings forms that are
- * still being rendered via AJAX. Going forward, all settings forms
- * should be rendered on the frontend using FLBuilderSettingsForms.render.
- *
- * @since 2.0
- * @param array $form The form data.
- * @param object $settings The settings data.
- * @return array
- */
- static public function render_settings( $form = array(), $settings ) {
- $defaults = array(
- 'class' => '',
- 'attrs' => '',
- 'title' => '',
- 'badges' => array(),
- 'tabs' => array(),
- 'buttons' => array(),
- 'settings' => $settings,
- );
- // Legacy filter for the config.
- $form = apply_filters( 'fl_builder_settings_form_config', array_merge( $defaults, $form ) );
- // Setup the class var to be safe in JS.
- $form['className'] = $form['class'];
- unset( $form['class'] );
- // Get the form ID.
- foreach ( $form['tabs'] as $tab ) {
- $form['id'] = $tab['form_id'];
- break;
- }
- // We don't need to send tab data back.
- unset( $form['tabs'] );
- // Render and return!
- ob_start();
- include FL_BUILDER_DIR . 'includes/ui-legacy-settings.php';
- $html = ob_get_clean();
- return array(
- 'html' => $html,
- );
- }
- /**
- * Renders a settings form via PHP. This method is only around for
- * backwards compatibility with third party settings forms that are
- * still being rendered via AJAX. Going forward, all settings forms
- * should be rendered on the frontend using FLBuilderSettingsForms.render.
- *
- * @since 2.0
- * @param string $type The type of form to render.
- * @param object $settings The settings data.
- * @return array
- */
- static public function render_settings_form( $type = null, $settings = null ) {
- $form = FLBuilderModel::get_settings_form( $type );
- if ( isset( $settings ) && ! empty( $settings ) ) {
- $defaults = FLBuilderModel::get_settings_form_defaults( $type );
- $settings = (object) array_merge( (array) $defaults, (array) $settings );
- } else {
- $settings = FLBuilderModel::get_settings_form_defaults( $type );
- }
- return self::render_settings(array(
- 'title' => $form['title'],
- 'tabs' => $form['tabs'],
- ), $settings);
- }
- /**
- * Renders a settings field via PHP. This method is only around for
- * backwards compatibility with third party settings forms that are
- * still being rendered via AJAX. Going forward, all settings forms
- * should be rendered on the frontend using FLBuilderSettingsForms.render.
- *
- * @since 2.0
- * @param string $name The field name.
- * @param array $field An array of setup data for the field.
- * @param object $settings Form settings data object.
- * @return void
- */
- static public function render_settings_field( $name, $field, $settings = null ) {
- /**
- * Use this filter to modify the config array for a field before it is rendered.
- * @see fl_builder_render_settings_field
- * @link https://kb.wpbeaverbuilder.com/article/117-plugin-filter-reference
- * @since 2.0
- */
- $field = apply_filters( 'fl_builder_render_settings_field', $field, $name, $settings ); // Allow field settings filtering first
- $i = null;
- $is_multiple = isset( $field['multiple'] ) && true === (bool) $field['multiple'];
- $supports_multiple = 'editor' != $field['type'] && 'photo' != $field['type'] && 'service' != $field['type'];
- $settings = ! $settings ? new stdClass() : $settings;
- $preview = isset( $field['preview'] ) ? json_encode( $field['preview'] ) : json_encode( array(
- 'type' => 'refresh',
- ) );
- $row_class = isset( $field['row_class'] ) ? ' ' . $field['row_class'] : '';
- $responsive = false;
- $responsive_fields = array( 'unit' );
- $root_name = $name;
- $global_settings = FLBuilderModel::get_global_settings();
- $value = isset( $settings->$name ) ? $settings->$name : '';
- // Use a default value if not set in the settings.
- if ( ! isset( $settings->$name ) && isset( $field['default'] ) ) {
- $value = $field['default'];
- }
- // Check to see if responsive is enabled for this field.
- if ( $global_settings->responsive_enabled && isset( $field['responsive'] ) && ! $is_multiple && in_array( $field['type'], $responsive_fields ) ) {
- $responsive = $field['responsive'];
- }
- if ( file_exists( FL_BUILDER_DIR . 'includes/ui-field-' . $field['type'] . '.php' ) ) {
- // Render old calls to *core* fields with JS.
- include FL_BUILDER_DIR . 'includes/ui-legacy-field.php';
- } else {
- // Render old calls to *custom* fields with PHP.
- if ( $is_multiple && $supports_multiple ) {
- $values = $value;
- $arr_name = $name;
- $name .= '[]';
- echo '<tbody id="fl-field-' . $root_name . '" class="fl-field fl-builder-field-multiples" data-type="form" data-preview=\'' . $preview . '\'>';
- for ( $i = 0; $i < count( $values ); $i++ ) {
- $value = $values[ $i ];
- echo '<tr class="fl-builder-field-multiple" data-field="' . $arr_name . '">';
- include FL_BUILDER_DIR . 'includes/ui-legacy-custom-field.php';
- echo '<td class="fl-builder-field-actions">';
- echo '<i class="fl-builder-field-move fas fa-arrows-alt"></i>';
- echo '<i class="fl-builder-field-copy far fa-copy"></i>';
- echo '<i class="fl-builder-field-delete fas fa-times"></i>';
- echo '</td>';
- echo '</tr>';
- }
- echo '<tr>';
- if ( empty( $field['label'] ) ) {
- echo '<td colspan="2">';
- } else {
- echo '<td> </td><td>';
- }
- echo '<a href="javascript:void(0);" onclick="return false;" class="fl-builder-field-add fl-builder-button" data-field="' . $arr_name . '">' . sprintf( _x( 'Add %s', 'Field name to add.', 'fl-builder' ), $field['label'] ) . '</a>';
- echo '</td>';
- echo '</tr>';
- echo '</tbody>';
- } else {
- echo '<tr id="fl-field-' . $name . '" class="fl-field' . $row_class . '" data-type="' . $field['type'] . '" data-preview=\'' . $preview . '\'>';
- include FL_BUILDER_DIR . 'includes/ui-legacy-custom-field.php';
- echo '</tr>';
- }
- }
- }
- /**
- * Renders the markup for the icon selector.
- *
- * @since 2.0
- * @return array
- */
- static public function render_icon_selector() {
- $icon_sets = FLBuilderIcons::get_sets();
- ob_start();
- include FL_BUILDER_DIR . 'includes/icon-selector.php';
- $html = ob_get_clean();
- return array(
- 'html' => $html,
- );
- }
- }
- FLBuilderUISettingsForms::init();
|