.
*
* @package Redux_Framework
* @subpackage Core
* @author Redux Framework Team
* @version 3.1.8
*/
// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) exit;
// Fix for the GT3 page builder: http://www.gt3themes.com/wordpress-gt3-page-builder-plugin/
/** @global string $pagenow */
if(has_action('ecpt_field_options_')) {
global $pagenow;
if ( $pagenow === 'admin.php' ) {
/** @noinspection PhpUndefinedCallbackInspection */
remove_action( 'admin_init', 'pb_admin_init' );
}
}
// Don't duplicate me!
if( !class_exists( 'ReduxFramework' ) ) {
// General helper functions
include_once(dirname(__FILE__).'/inc/class.redux_helpers.php');
/**
* Main ReduxFramework class
*
* @since 1.0.0
*/
class ReduxFramework {
// ATTENTION DEVS
// Please update the build number with each push, no matter how small.
// This will make for easier support when we ask users what version they are using.
public static $_version = '3.1.9.2';
public static $_dir;
public static $_url;
public static $_properties;
public static $_is_plugin = true;
static function init() {
// Windows-proof constants: replace backward by forward slashes. Thanks to: @peterbouwmeester
self::$_dir = trailingslashit( Redux_Helpers::cleanFilePath( dirname( __FILE__ ) ) );
$wp_content_dir = trailingslashit( Redux_Helpers::cleanFilePath( WP_CONTENT_DIR ) );
$wp_content_dir = trailingslashit( str_replace( '//', '/', $wp_content_dir ) );
$relative_url = str_replace( $wp_content_dir, '', self::$_dir );
$wp_content_url = Redux_Helpers::cleanFilePath( ( is_ssl() ? str_replace( 'http://', 'https://', WP_CONTENT_URL ) : WP_CONTENT_URL ) );
self::$_url = trailingslashit( $wp_content_url ) . $relative_url;
// See if Redux is a plugin or not
if ( strpos( Redux_Helpers::cleanFilePath( __FILE__ ), Redux_Helpers::cleanFilePath(get_stylesheet_directory()) ) !== false) {
self::$_is_plugin = false;
}
}// ::init()
public $framework_url = 'http://www.reduxframework.com/';
public $instance = null;
public $admin_notices = array();
public $page = '';
public $args = array(
'opt_name' => '', // Must be defined by theme/plugin
'google_api_key' => '', // Must be defined to add google fonts to the typography module
'last_tab' => '', // force a specific tab to always show on reload
'menu_icon' => '', // menu icon
'menu_title' => '', // menu title/text
'page_icon' => 'icon-themes',
'page_title' => '', // option page title
'page_slug' => '_options',
'page_permissions' => 'manage_options',
'menu_type' => 'menu', // ('menu'|'submenu')
'page_parent' => 'themes.php', // requires menu_type = 'submenu
'page_priority' => null,
'allow_sub_menu' => true, // allow submenus to be added if menu_type == menu
'save_defaults' => true, // Save defaults to the DB on it if empty
'footer_credit' => '',
'async_typography' => false,
'admin_bar' => true, // Show the panel pages on the admin bar
'help_tabs' => array(),
'help_sidebar' => '', // __( '', 'aakanksha' );
'database' => '', // possible: options, theme_mods, theme_mods_expanded, transient
'customizer' => false, // setting to true forces get_theme_mod_expanded
'global_variable' => '', // Changes global variable from $GLOBALS['YOUR_OPT_NAME'] to whatever you set here. false disables the global variable
'output' => true, // Dynamically generate CSS
'compiler' => true, // Initiate the compiler hook
'output_tag' => true, // Print Output Tag
'transient_time' => '',
'default_show' => false, // If true, it shows the default value
'default_mark' => '', // What to print by the field's title if the value shown is default
'update_notice' => true,
'hints' => array(
'icon' => 'icon-question-sign',
'icon_position' => 'right',
'icon_color' => 'lightgray',
'icon_size' => 'normal',
'tip_style' => array(
'color' => 'light',
'shadow' => true,
'rounded' => false,
'style' => '',
),
'tip_position' => array(
'my' => 'top_left',
'at' => 'bottom_right',
),
'tip_effect' => array(
'show' => array(
'effect' => 'slide',
'duration' => '500',
),
'hide' => array(
'effect' => 'fade',
'duration' => '500',
),
),
),
'show_import_export' => true,
'dev_mode' => false,
/**
* 'system_info'
* @deprecated
*/
'system_info' => false, // REMOVE
);
public $sections = array(); // Sections and fields
public $errors = array(); // Errors
public $warnings = array(); // Warnings
public $options = array(); // Option values
public $options_defaults = null; // Option defaults
public $localize_data = array(); // Information that needs to be localized
public $folds = array(); // The itms that need to fold.
public $path = '';
public $output = array(); // Fields with CSS output selectors
public $outputCSS = null; // CSS that get auto-appended to the header
public $compilerCSS = null; // CSS that get sent to the compiler hook
public $customizerCSS = null; // CSS that goes to the customizer
public $fieldsValues = array(); //all fields values in an id=>value array so we can check dependencies
public $fieldsHidden = array(); //all fields that didn't pass the dependency test and are hidden
public $toHide = array(); // Values to hide on page load
public $typography = null; //values to generate google font CSS
public $import_export = null;
public $debug = null;
private $show_hints = false;
/**
* Class Constructor. Defines the args for the theme options class
* @since 1.0.0
* @param array $sections Panel sections.
* @param array $args Class constructor arguments.
* @param array $extra_tabs Extra panel tabs. // REMOVE
* @return \ReduxFramework
*/
public function __construct( $sections = array(), $args = array(), $extra_tabs = array() ) {
global $wp_version;
// Set values
$this->args = wp_parse_args( $args, $this->args );
if ( empty( $this->args['transient_time'] ) ) {
$this->args['transient_time'] = 60 * MINUTE_IN_SECONDS;
}
if ( empty( $this->args['footer_credit'] ) ) {
$this->args['footer_credit'] = '' . sprintf( __( 'Options panel created using %1$s', 'aakanksha' ), ''.__( 'Redux Framework', 'aakanksha' ).' v'.self::$_version ) . '';
}
if ( empty( $this->args['menu_title'] ) ) {
$this->args['menu_title'] = __( 'Options', 'aakanksha' );
}
if ( empty( $this->args['page_title'] ) ) {
$this->args['page_title'] = __( 'Options', 'aakanksha' );
}
/**
* filter 'redux/args/{opt_name}'
* @param array $args ReduxFramework configuration
*/
$this->args = apply_filters( "redux/args/{$this->args['opt_name']}", $this->args );
/**
* filter 'redux/options/{opt_name}/args'
* @param array $args ReduxFramework configuration
*/
$this->args = apply_filters( "redux/options/{$this->args['opt_name']}/args", $this->args );
if ( !empty( $this->args['opt_name'] ) ) {
/**
SHIM SECTION
Old variables and ways of doing things that need correcting. ;)
**/
// Variable name change
if ( !empty( $this->args['page_cap'] ) ) {
$this->args['page_permissions'] = $this->args['page_cap'];
unset( $this->args['page_cap'] );
}
if ( !empty( $this->args['page_position'] ) ) {
$this->args['page_priority'] = $this->args['page_position'];
unset( $this->args['page_position'] );
}
if ( !empty( $this->args['page_type'] ) ) {
$this->args['menu_type'] = $this->args['page_type'];
unset( $this->args['page_type'] );
}
// Get rid of extra_tabs! Not needed.
if( is_array( $extra_tabs ) && !empty( $extra_tabs ) ) {
foreach( $extra_tabs as $tab ) {
array_push($this->sections, $tab);
}
}
// Move to the first loop area!
/**
* filter 'redux-sections'
* @deprecated
* @param array $sections field option sections
*/
$this->sections = apply_filters('redux-sections', $sections); // REMOVE LATER
/**
* filter 'redux-sections-{opt_name}'
* @deprecated
* @param array $sections field option sections
*/
$this->sections = apply_filters("redux-sections-{$this->args['opt_name']}", $this->sections); // REMOVE LATER
/**
* filter 'redux/options/{opt_name}/sections'
* @param array $sections field option sections
*/
$this->sections = apply_filters("redux/options/{$this->args['opt_name']}/sections", $this->sections);
/**
* Construct hook
* action 'redux/construct'
* @param object $this ReduxFramework
*/
do_action( 'redux/construct', $this );
// Set the default values
$this->_default_cleanup();
$this->_internationalization();
// Register extra extensions
$this->_register_extensions();
// Grab database values
$this->get_options();
$this->_tracking();
// Set option with defaults
//add_action( 'init', array( &$this, '_set_default_options' ), 101 );
// Options page
add_action( 'admin_menu', array( $this, '_options_page' ) );
// Admin Bar menu
add_action( 'admin_bar_menu', array( $this, '_admin_bar_menu' ) , 999 );
// Register setting
add_action( 'admin_init', array( $this, '_register_settings' ) );
// Display admin notices in dev_mode
if (true == $this->args['dev_mode']) {
include_once(self::$_dir . 'inc/debug.php');
$this->debug = new ReduxDebugObject($this);
if (true == $this->args['update_notice']) {
add_action( 'admin_init', array( $this, '_update_check' ) );
}
}
// Display admin notices
add_action( 'admin_notices', array( $this, '_admin_notices' ) );
// Check for dismissed admin notices.
add_action( 'admin_init', array( $this, '_dismiss_admin_notice' ), 9 );
// Enqueue the admin page CSS and JS
if ( isset( $_GET['page'] ) && $_GET['page'] == $this->args['page_slug'] ) {
add_action( 'admin_enqueue_scripts', array( $this, '_enqueue' ) );
}
// Any dynamic CSS output, let's run
add_action( 'wp_head', array( &$this, '_enqueue_output' ), 150 );
// Add tracking. PLEASE leave this in tact! It helps us gain needed statistics of uses. Opt-in of course.
//add_action( 'init', array( &$this, '_tracking' ), 200 );
// Start internationalization
//add_action( 'init', array( &$this, '_internationalization' ), 100 );
require_once(self::$_dir . 'inc/fields/import_export/import_export.php');
$this->import_export = new Redux_import_export($this);
}
/**
* Loaded hook
*
* action 'redux/loaded'
* @param object $this ReduxFramework
*/
do_action( 'redux/loaded', $this );
} // __construct()
public function _update_check() {
// Get the raw framework.php from github
$gitpage = wp_remote_get(
'https://raw.github.com/ReduxFramework/redux-framework/master/ReduxCore/framework.php',
array(
'headers' => array(
'Accept-Encoding' => ''
),
'sslverify' => true,
'timeout' => 300
));
// Is the response code the corect one?
if (!is_wp_error($gitpage)) {
if (isset($gitpage['body'])) {
// Get the page text.
$body = $gitpage['body'];
// Find version line in framework.php
$needle = 'public static $_version =';
$pos = strpos($body, $needle);
// If it's there, continue. We don't want errors if $pos = 0.
if ($pos > 0) {
// Look for the semi-colon at the end of the version line
$semi = strpos($body,";", $pos);
// Error avoidance. If the semi-colon is there, continue.
if ($semi > 0 ) {
// Extract the version line
$text = substr($body, $pos, ($semi - $pos));
// Find the first quote around the veersion number.
$quote = strpos($body,"'", $pos);
// Extract the version number
$ver = substr($body, $quote, ($semi - $quote) );
// Strip off quotes.
$ver = str_replace("'",'',$ver);
// Set up admin notice on new version
if (1 == strcmp($ver, self::$_version)) {
$this->admin_notices[] = array(
'type' => 'updated',
'msg' => 'A new build of Redux is now available!
Your version: ' . self::$_version . ' New version: ' . $ver . '
Get it now |',
'id' => 'dev_notice_' . $ver,
'dismiss' => true,
);
}
}
}
}
}
}
public function _admin_notices() {
global $current_user, $pagenow;
// Check for an active admin notice array
if (!empty($this->admin_notices)) {
// Enum admin notices
foreach( $this->admin_notices as $notice ) {
if (true == $notice['dismiss']) {
// Get user ID
$userid = $current_user->ID;
if ( !get_user_meta( $userid, 'ignore_' . $notice['id'] ) ) {
// Check if we are on admin.php. If we are, we have
// to get the current page slug and tab, so we can
// feed it back to Wordpress. Why> admin.php cannot
// be accessed without the page parameter. We add the
// tab to return the user to the last panel they were
// on.
if ($pagenow == 'admin.php') {
// Get the current page. To avoid errors, we'll set
// the redux page slug if the GET is empty.
$pageName = empty($_GET['page']) ? '&page=' . $this->args['page_slug'] : '&page=' . $_GET['page'];
// Ditto for the current tab.
$curTab = empty($_GET['tab']) ? '&tab=0' : '&tab=' . $_GET['tab'];
}
// Print the notice with the dismiss link
echo '
', 'aakanksha')
);
$screen->add_help_tab( $tab );
}
// Sidebar text
if( $this->args['help_sidebar'] != '' ) {
// Specify users text from arguments
$screen->set_help_sidebar( $this->args['help_sidebar'] );
} else {
// If sidebar text is empty and hints are active, display text
// about hints.
if (true == $this->show_hints) {
$screen->set_help_sidebar( '
Redux Framework
Hint Tooltip Preferences
' );
}
}
/**
* action 'redux-load-page-{opt_name}'
* @deprecated
* @param object $screen WP_Screen
*/
do_action( "redux-load-page-{$this->args['opt_name']}", $screen ); // REMOVE
/**
* action 'redux/page/{opt_name}/load'
* @param object $screen WP_Screen
*/
do_action( "redux/page/{$this->args['opt_name']}/load", $screen );
} // _load_page()
/**
* Do action redux-admin-head for options page
*
* @since 1.0.0
* @access public
* @return void
*/
public function admin_head() {
/**
* action 'redux-admin-head-{opt_name}'
* @deprecated
* @param object $this ReduxFramework
*/
do_action( "redux-admin-head-{$this->args['opt_name']}", $this ); // REMOVE
/**
* action 'redux/page/{opt_name}/header'
* @param object $this ReduxFramework
*/
do_action( "redux/page/{$this->args['opt_name']}/header", $this );
} // admin_head()
/**
* Return footer text
*
* @since 2.0.0
* @access public
* @return string $this->args['footer_credit']
*/
public function admin_footer_text( ) {
return $this->args['footer_credit'];
} // admin_footer_text()
/**
* Return default output string for use in panel
*
* @since 3.1.5
* @access public
* @return string default_output
*/
public function get_default_output_string($field) {
$default_output = "";
if ( !isset( $field['default'] ) ) {
$field['default'] = "";
}
if (!is_array($field['default'])) {
if ( !empty( $field['options'][$field['default']] ) ) {
if (!empty($field['options'][$field['default']]['alt'])) {
$default_output .= $field['options'][$field['default']]['alt'] . ', ';
} else {
// TODO: This serialize fix may not be the best solution. Look into it. PHP 5.4 error without serialize
$default_output .= serialize($field['options'][$field['default']]).", ";
}
} else if ( !empty( $field['options'][$field['default']] ) ) {
$default_output .= $field['options'][$field['default']].", ";
} else if ( !empty( $field['default'] ) ) {
$default_output .= $field['default'] . ', ';
}
} else {
foreach( $field['default'] as $defaultk => $defaultv ) {
if (!empty($field['options'][$defaultv]['alt'])) {
$default_output .= $field['options'][$defaultv]['alt'] . ', ';
} else if ( !empty( $field['options'][$defaultv] ) ) {
$default_output .= $field['options'][$defaultv].", ";
} else if ( !empty( $field['options'][$defaultk] ) ) {
$default_output .= $field['options'][$defaultk].", ";
} else if ( !empty( $defaultv ) ) {
$default_output .= $defaultv.', ';
}
}
}
if ( !empty( $default_output ) ) {
$default_output = __( 'Default', 'aakanksha' ) . ": " . substr($default_output, 0, -2);
}
if (!empty($default_output)) {
$default_output = ''.$default_output.'';
}
return $default_output;
} // get_default_output_string()
public function get_header_html( $field ) {
global $current_user;
// Set to empty string to avoid wanrings.
$hint = '';
$th = "";
if( isset( $field['title'] ) && isset( $field['type'] ) && $field['type'] !== "info" && $field['type'] !== "group" && $field['type'] !== "section" ) {
$default_mark = ( !empty($field['default']) && isset($this->options[$field['id']]) && $this->options[$field['id']] == $field['default'] && !empty( $this->args['default_mark'] ) && isset( $field['default'] ) ) ? $this->args['default_mark'] : '';
// If a hint is specified in the field, process it.
if (isset($field['hint']) && !'' == $field['hint']) {
// Set show_hints flag to true, so helptab will be displayed.
$this->show_hints = true;
// Get user pref for displaying hints.
$metaVal = get_user_meta( $current_user->ID, 'ignore_hints', true);
if ('true' == $metaVal || empty($metaVal)) {
// Set hand cursor for clickable hints
$pointer = '';
if ('click' == $this->args['hints']['tip_effect']['show']['event']) {
$pointer = 'pointer';
}
$size = '16px';
if ('large' == $this->args['hints']['icon_size']) {
$size = '18px';
}
// In case docs are ignored.
$titleParam = isset($field['hint']['title']) ? $field['hint']['title'] : '';
$contentParam = isset($field['hint']['content']) ? $field['hint']['content'] : '';
// Set hint html with appropriate position css
$hint = '
';
}
if ( $this->args['default_show'] === true && isset( $field['default'] ) && isset($this->options[$field['id']]) && $this->options[$field['id']] != $field['default'] && $field['type'] !== "info" && $field['type'] !== "group" && $field['type'] !== "section" && $field['type'] !== "editor" && $field['type'] !== "ace_editor" ) {
$th .= $this->get_default_output_string($field);
}
return $th;
}
/**
* Register Option for use
*
* @since 1.0.0
* @access public
* @return void
*/
public function _register_settings() {
// TODO - REMOVE
// Not used by new sample-config, but in here for legacy builds
// This is bad and can break things. Hehe.
if( !function_exists( 'wp_get_current_user' ) ) {
include(ABSPATH . "wp-includes/pluggable.php");
}
register_setting( $this->args['opt_name'] . '_group', $this->args['opt_name'], array( &$this,'_validate_options' ) );
if( is_null( $this->sections ) ) return;
$this->options_defaults = $this->_default_values();
$runUpdate = false;
foreach( $this->sections as $k => $section ) {
if( isset($section['type'] ) && $section['type'] == 'divide' ) {
continue;
}
if ( empty( $section['id'] ) ) {
$section['id'] = sanitize_html_class( $section['title'] );
}
// DOVY! Replace $k with $section['id'] when ready
/**
* filter 'redux-section-{index}-modifier-{opt_name}'
* @param array $section section configuration
*/
$section = apply_filters( "redux-section-{$k}-modifier-{$this->args['opt_name']}", $section );
/**
* filter 'redux/options/{opt_name}/section/{section.id}'
* @param array $section section configuration
*/
$section = apply_filters( "redux/options/{$this->args['opt_name']}/section/{$section['id']}", $section );
$heading = isset($section['heading']) ? $section['heading'] : $section['title'];
if (isset($section['permissions'])) {
if ( !current_user_can($section['permissions']) ) {
continue;
}
}
add_settings_section( $this->args['opt_name'] . $k . '_section', $heading, array( &$this, '_section_desc' ), $this->args['opt_name'] . $k . '_section_group' );
if( isset( $section['fields'] ) ) {
foreach( $section['fields'] as $fieldk => $field ) {
if ( !isset( $field['type'] ) ) {
continue; // You need a type!
}
// TODO AFTER GROUP WORKS - Remove IF statement
if ( $field['type'] == "group" && isset( $_GET['page'] ) && $_GET['page'] == $this->args['page_slug'] ) {
//if ( $this->args['dev_mode'] ) {
$this->admin_notices[] = array(
'type' => 'error',
'msg' => 'The group field has been removed while we retool it for improved performance.',
'id' => 'group_err',
'dismiss' => true,
);
//}
continue; // Disabled for now
}
if (isset($field['permissions'])) {
if ( !current_user_can($field['permissions']) ) {
continue;
}
}
if (!isset($field['id'])) {
echo '
No field ID is set.
';
print_r($field);
echo "
";
continue;
}
$th = $this->get_header_html( $field );
$field['name'] = $this->args['opt_name'] . '[' . $field['id'] . ']';
// Set the default value if present
$this->options_defaults[$field['id']] = isset( $this->options_defaults[$field['id']] ) ? $this->options_defaults[$field['id']] : '';
// Set the defaults to the value if not present
$doUpdate = false;
// Check fields for values in the default parameter
if ( !isset( $this->options[$field['id']] ) && isset( $field['default'] )) {
$this->options_defaults[$field['id']] = $this->options[$field['id']] = $field['default'];
$doUpdate = true;
// Check fields that hae no default value, but an options value with settings to
// be saved by default
} elseif ( !isset( $this->options[$field['id']] ) && isset( $field['options'] )) {
// If sorter field, check for options as save them as defaults
if ($field['type'] == 'sorter' || $field['type'] == 'sortable') {
$this->options_defaults[$field['id']] = $this->options[$field['id']] = $field['options'];
$doUpdate = true;
}
}
if (true == $doUpdate) {
if ( $this->args['save_defaults'] ) { // Only save that to the DB if allowed to
$runUpdate = true;
}
}
if (!isset($field['class'])) { // No errors please
$field['class'] = "";
}
/**
* filter 'redux-field-{field.id}modifier-{opt_name}'
* @deprecated
* @param array $field field config
*/
$field = apply_filters( "redux-field-{$field['id']}modifier-{$this->args['opt_name']}", $field ); // REMOVE LATER
/**
* filter 'redux/options/{opt_name}/field/{field.id}'
* @param array $field field config
*/
$field = apply_filters( "redux/options/{$this->args['opt_name']}/field/{$field['id']}", $field );
if ( !empty( $this->folds[$field['id']]['parent'] ) ) { // This has some fold items, hide it by default
$field['class'] .= " fold";
}
if ( !empty( $this->folds[$field['id']]['children'] ) ) { // Sets the values you shoe fold children on
$field['class'] .= " foldParent";
}
if ( !empty( $field['compiler'] ) ) {
$field['class'] .= " compiler";
}
if ( isset( $field['unit'] ) && !isset( $field['units'] ) ) {
$field['units'] = $field['unit'];
unset( $field['unit'] );
}
$this->sections[$k]['fields'][$fieldk] = $field;
if( isset( $this->args['display_source'] ) ) {
$th .= '
';
}
}
/**
* Field HTML OUTPUT.
* Gets option from options array, then calls the specific field type class - allows extending by other devs
* @since 1.0.0
* @param array $field
* @param string $v
* @return void
*/
public function _field_input( $field, $v = null ) {
if( isset( $field['callback'] ) && function_exists( $field['callback'] ) ) {
$value = ( isset( $this->options[$field['id']] ) ) ? $this->options[$field['id']] : '';
/**
* action 'redux-before-field-{opt_name}'
* @deprecated
* @param array $field field data
* @param string $value field.id
*/
do_action( "redux-before-field-{$this->args['opt_name']}", $field, $value ); // REMOVE
/**
* action 'redux/field/{opt_name}/{field.type}/callback/before'
* @param array $field field data
* @param string $value field.id
*/
do_action( "redux/field/{$this->args['opt_name']}/{$field['type']}/callback/before", $field, $value );
/**
* action 'redux/field/{opt_name}/callback/before'
* @param array $field field data
* @param string $value field.id
*/
do_action( "redux/field/{$this->args['opt_name']}/callback/before", $field, $value );
call_user_func( $field['callback'], $field, $value );
/**
* action 'redux-after-field-{opt_name}'
* @deprecated
* @param array $field field data
* @param string $value field.id
*/
do_action( "redux-after-field-{$this->args['opt_name']}", $field, $value ); // REMOVE
/**
* action 'redux/field/{opt_name}/{field.type}/callback/after'
* @param array $field field data
* @param string $value field.id
*/
do_action( "redux/field/{$this->args['opt_name']}/{$field['type']}/callback/after", $field, $value );
/**
* action 'redux/field/{opt_name}/callback/after'
* @param array $field field data
* @param string $value field.id
*/
do_action( "redux/field/{$this->args['opt_name']}/callback/after", $field, $value );
return;
}
if( isset( $field['type'] ) ) {
$field_class = "ReduxFramework_{$field['type']}";
if( !class_exists( $field_class ) ) {
// $class_file = apply_filters( 'redux/field/class/'.$field['type'], self::$_dir . 'inc/fields/' . $field['type'] . '/field_' . $field['type'] . '.php', $field ); // REMOVE
/**
* filter 'redux/{opt_name}/field/class/{field.type}'
* @param string field class file path
* @param array $field field data
*/
$class_file = apply_filters( "redux/{$this->args['opt_name']}/field/class/{$field['type']}", self::$_dir . "inc/fields/{$field['type']}/field_{$field['type']}.php", $field );
if( $class_file ) {
/** @noinspection PhpIncludeInspection */
if (file_exists($class_file)) {
require_once($class_file);
}
}
}
if( class_exists( $field_class ) ) {
$value = isset($this->options[$field['id']])?$this->options[$field['id']]:'';
if ( $v !== null ) {
$value = $v;
}
/**
* action 'redux-before-field-{opt_name}'
* @deprecated
* @param array $field field data
* @param string $value field id
*/
do_action( "redux-before-field-{$this->args['opt_name']}", $field, $value); // REMOVE
/**
* action 'redux/field/{opt_name}/{field.type}/render/before'
* @param array $field field data
* @param string $value field id
*/
do_action( "redux/field/{$this->args['opt_name']}/{$field['type']}/render/before", $field, $value );
/**
* action 'redux/field/{$this->args['opt_name']}/render/before'
* @param array $field field data
* @param string $value field id
*/
do_action( "redux/field/{$this->args['opt_name']}/render/before", $field, $value );
if ( !isset( $field['name_suffix'] ) ) {
$field['name_suffix'] = "";
}
$render = new $field_class( $field, $value, $this );
ob_start();
/** @noinspection PhpUndefinedMethodInspection */
$render->render();
/*
echo "
";
print_r($value);
echo "
";
*/
/**
* filter 'redux-field-{opt_name}'
* @deprecated
* @param string rendered field markup
* @param array $field field data
*/
$_render = apply_filters( "redux-field-{$this->args['opt_name']}", ob_get_contents(), $field ); // REMOVE
/**
* filter 'redux/field/{opt_name}/{field.type}/render/after'
* @param string rendered field markup
* @param array $field field data
*/
$_render = apply_filters( "redux/field/{$this->args['opt_name']}/{$field['type']}/render/after", $_render, $field );
/**
* filter 'redux/field/{opt_name}/render/after'
* @param string rendered field markup
* @param array $field field data
*/
$_render = apply_filters( "redux/field/{$this->args['opt_name']}/render/after", $_render, $field );
ob_end_clean();
//save the values into a unique array in case we need it for dependencies
$this->fieldsValues[$field['id']] = (isset($value['url']) && is_array($value) )?$value['url']:$value;
//create default data und class string and checks the dependencies of an object
$class_string = '';
$data_string = '';
extract($this->check_dependencies($field));
/**
* action 'redux/field/{opt_name}/{field.type}/fieldset/before/{opt_name}'
* @param array $field field data
* @param string $value field id
*/
do_action( "redux/field/{$this->args['opt_name']}/{$field['type']}/fieldset/before/{$this->args['opt_name']}", $field, $value );
/**
* action 'redux/field/{opt_name}/fieldset/before/{opt_name}'
* @param array $field field data
* @param string $value field id
*/
do_action( "redux/field/{$this->args['opt_name']}/fieldset/before/{$this->args['opt_name']}", $field, $value );
if (!isset($field['fields']) || empty($field['fields'])) {
echo '';
}
/**
* action 'redux-after-field-{opt_name}'
* @deprecated
* @param array $field field data
* @param string $value field id
*/
do_action( "redux-after-field-{$this->args['opt_name']}", $field, $value ); // REMOVE
/**
* action 'redux/field/{opt_name}/{field.type}/fieldset/after/{opt_name}'
* @param array $field field data
* @param string $value field id
*/
do_action( "redux/field/{$this->args['opt_name']}/{$field['type']}/fieldset/after/{$this->args['opt_name']}", $field, $value );
/**
* action 'redux/field/{opt_name}/fieldset/after/{opt_name}'
* @param array $field field data
* @param string $value field id
*/
do_action( "redux/field/{$this->args['opt_name']}/fieldset/after/{$this->args['opt_name']}", $field, $value );
}
}
} // _field_input()
/**
* Can Output CSS
* Check if a field meets its requirements before outputting to CSS
* @param $field
* @return bool
*/
public function _can_output_css($field) {
if (!empty($field['required'])) {
$data['check-field'] = $field['required'][0];
$data['check-comparison'] = $field['required'][1];
$data['check-value'] = $field['required'][2];
$return = false;
$global_var = $GLOBALS[$this->args['global_variable']];
if (isset($global_var[$data['check-field']])) {
$value1 = $global_var[$data['check-field']];
$value2 = $data['check-value'];
switch ($data['check-comparison']) {
case '=':
case 'equals':
if(is_array($value2)){
if(in_array($value1, $value2))
$return = true;
}else{
if ($value1 == $value2)
$return = true;
}
break;
case '!=':
case 'not':
if(is_array($value2)){
if(!in_array($value1, $value2))
$return = true;
}else{
if ($value1 != $value2)
$return = true;
}
break;
case '>':
case 'greater':
case 'is_larger':
if ($value1 > $value2)
$return = true;
break;
case '>=':
case 'greater_equal':
case 'is_larger_equal':
if ($value1 >= $value2)
$return = true;
break;
case '<':
case 'less':
case 'is_smaller':
if ($value1 < $value2)
$return = true;
break;
case '<=':
case 'less_equal':
case 'is_smaller_equal':
if ($value1 <= $value2)
$return = true;
break;
case 'contains':
if (strpos($value1, $value2) !== false)
$return = true;
break;
case 'doesnt_contain':
case 'not_contain':
if (strpos($value1, $value2) === false)
$return = true;
break;
case 'is_empty_or':
if (empty($value1) || $value1 == $value2)
$return = true;
break;
case 'not_empty_and':
if (!empty($value1) && $value1 != $value2)
$return = true;
break;
}
return $return;
}
}
return true;
} // _can_output_css
/**
* Checks dependencies between objects based on the $field['required'] array
*
* If the array is set it needs to have exactly 3 entries.
* The first entry describes which field should be monitored by the current field. eg: "content"
* The second entry describes the comparison parameter. eg: "equals, not, is_larger, is_smaller ,contains"
* The third entry describes the value that we are comparing against.
*
* Example: if the required array is set to array('content','equals','Hello World'); then the current
* field will only be displayed if the field with id "content" has exactly the value "Hello World"
*
* @param array $field
* @return array $params
*/
public function check_dependencies($field) {
$params = array('data_string' => "", 'class_string' => "");
if (!empty($field['required'])) {
$data['check-field'] = $field['required'][0];
$data['check-comparison'] = $field['required'][1];
$data['check-value'] = $field['required'][2];
$params['data_string'] = $this->create_data_string($data);
$return = false;
//required field must not be hidden. otherwise hide this one by default
if ( !in_array( $data['check-field'], $this->fieldsHidden ) ) {
if (isset($this->fieldsValues[$data['check-field']])) {
//$value1 = isset($this->fieldsValues[$data['check-field']]['url'])?isset($this->fieldsValues[$data['check-field']]['url']):$this->fieldsValues[$data['check-field']];
$value1 = $this->fieldsValues[$data['check-field']];
$value2 = $data['check-value'];
switch ($data['check-comparison']) {
case '=':
case 'equals':
if(is_array($value2)){
if(in_array($value1, $value2))
$return = true;
}else{
if ($value1 == $value2)
$return = true;
}
break;
case '!=':
case 'not':
if(is_array($value2)){
if(!in_array($value1, $value2))
$return = true;
}else{
if ($value1 != $value2)
$return = true;
}
break;
case '>':
case 'greater':
case 'is_larger':
if ($value1 > $value2)
$return = true;
break;
case '>=':
case 'greater_equal':
case 'is_larger_equal':
if ($value1 >= $value2)
$return = true;
break;
case '<':
case 'less':
case 'is_smaller':
if ($value1 < $value2)
$return = true;
break;
case '<=':
case 'less_equal':
case 'is_smaller_equal':
if ($value1 <= $value2)
$return = true;
break;
case 'contains':
if (strpos($value1, $value2) !== false)
$return = true;
break;
case 'doesnt_contain':
case 'not_contain':
if (strpos($value1, $value2) === false)
$return = true;
break;
case 'is_empty_or':
if (empty($value1) || $value1 == $value2)
$return = true;
break;
case 'not_empty_and':
if (!empty($value1) && $value1 != $value2)
$return = true;
break;
}
}
}
if (!$return) {
$params['class_string'] = ' hiddenFold ';
$this->fieldsHidden[] = $field['id'];
}else{
$params['class_string'] = ' showFold ';
}
}
return $params;
}
/**
* converts an array into a html data string
*
* @param array $data example input: array('id'=>'true')
* @return string $data_string example output: data-id='true'
*/
public function create_data_string($data = array()){
$data_string = "";
foreach($data as $key=>$value){
if(is_array($value)) $value = implode("|",$value);
$data_string .= " data-$key='$value' ";
}
return $data_string;
}
} // ReduxFramework
/**
* action 'redux/init'
* @param null
*/
do_action( 'redux/init', ReduxFramework::init() );
//add_action( 'plugins_loaded', ReduxFramework::init(), 0 );
} // class_exists('ReduxFramework')