page; } /** * @return bool */ public function isEditorEnabled() { global $current_user; wp_get_current_user(); /** @var $settings - get use group access rules */ $settings = $this->get( 'groups_access_rules' ); $show = true; foreach ( $current_user->roles as $role ) { if ( isset( $settings[ $role ]['show'] ) && 'no' === $settings[ $role ]['show'] ) { $show = false; break; } } return $show; } /** * */ public function setTabs() { $this->tabs = array(); if ( $this->showConfigurationTabs() ) { $this->tabs['vc-general'] = esc_html__( 'General Settings', 'js_composer' ); if ( ! vc_is_as_theme() || apply_filters( 'vc_settings_page_show_design_tabs', false ) ) { $this->tabs['vc-color'] = esc_html__( 'Design Options', 'js_composer' ); $this->tabs['vc-custom_css'] = esc_html__( 'Custom CSS', 'js_composer' ); } } if ( ! vc_is_network_plugin() || ( vc_is_network_plugin() && is_network_admin() ) ) { if ( ! vc_is_updater_disabled() ) { $this->tabs['vc-updater'] = esc_html__( 'Product License', 'js_composer' ); } } // TODO: may allow to disable automapper if ( ! is_network_admin() && ! vc_automapper_is_disabled() ) { $this->tabs['vc-automapper'] = vc_automapper()->title(); } } /** * @return mixed|void */ public function getTabs() { if ( ! isset( $this->tabs ) ) { $this->setTabs(); } return apply_filters( 'vc_settings_tabs', $this->tabs ); } /** * @return bool */ public function showConfigurationTabs() { return ! vc_is_network_plugin() || ! is_network_admin(); } /** * Render * * @param $tab * @throws \Exception */ public function renderTab( $tab ) { require_once vc_path_dir( 'CORE_DIR', 'class-vc-page.php' ); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); if ( ( ( '1' === vc_get_param( 'build_css' ) || 'true' === vc_get_param( 'build_css' ) ) ) || ( ( '1' === vc_get_param( 'settings-updated' ) || 'true' === vc_get_param( 'settings-updated' ) ) ) ) { $this->buildCustomCss(); // TODO: remove this - no needs to re-save always } $tabs = $this->getTabs(); foreach ( $tabs as $key => $value ) { if ( ! vc_user_access()->part( 'settings' )->can( $key . '-tab' )->get() ) { unset( $tabs[ $key ] ); } } do_action( 'vc-settings-render-tab-' . $tab ); $page = new Vc_Page(); $page->setSlug( $tab )->setTitle( isset( $tabs[ $tab ] ) ? $tabs[ $tab ] : '' )->setTemplatePath( apply_filters( 'vc_settings-render-tab-' . $tab, 'pages/vc-settings/tab.php' ) ); vc_include_template( 'pages/vc-settings/index.php', array( 'pages' => $tabs, 'active_page' => $page, 'vc_settings' => $this, ) ); } /** * Init settings page && menu item * vc_filter: vc_settings_tabs - hook to override settings tabs */ public function initAdmin() { $this->setTabs(); self::$color_settings = array( array( 'vc_color' => array( 'title' => esc_html__( 'Main accent color', 'js_composer' ) ) ), array( 'vc_color_hover' => array( 'title' => esc_html__( 'Hover color', 'js_composer' ) ) ), array( 'vc_color_call_to_action_bg' => array( 'title' => esc_html__( 'Call to action background color', 'js_composer' ) ) ), array( 'vc_color_google_maps_bg' => array( 'title' => esc_html__( 'Google maps background color', 'js_composer' ) ) ), array( 'vc_color_post_slider_caption_bg' => array( 'title' => esc_html__( 'Post slider caption background color', 'js_composer' ) ) ), array( 'vc_color_progress_bar_bg' => array( 'title' => esc_html__( 'Progress bar background color', 'js_composer' ) ) ), array( 'vc_color_separator_border' => array( 'title' => esc_html__( 'Separator border color', 'js_composer' ) ) ), array( 'vc_color_tab_bg' => array( 'title' => esc_html__( 'Tabs navigation background color', 'js_composer' ) ) ), array( 'vc_color_tab_bg_active' => array( 'title' => esc_html__( 'Active tab background color', 'js_composer' ) ) ), ); self::$defaults = array( 'vc_color' => '#f7f7f7', 'vc_color_hover' => '#F0F0F0', 'margin' => '35px', 'gutter' => '15', 'responsive_max' => '768', 'compiled_js_composer_less' => '', ); if ( 'restore_color' === vc_post_param( 'vc_action' ) && vc_user_access()->check( 'wp_verify_nonce', vc_post_param( '_wpnonce' ), vc_settings()->getOptionGroup() . '_color' . '-options' ) ->validateDie()->wpAny( 'manage_options' )->validateDie()->part( 'settings' )->can( 'vc-color-tab' )->validateDie()->get() ) { $this->restoreColor(); } /** * @since 4.5 used to call update file once option is changed */ add_action( 'update_option_wpb_js_compiled_js_composer_less', array( $this, 'buildCustomColorCss', ) ); /** * @since 4.5 used to call update file once option is changed */ add_action( 'update_option_wpb_js_custom_css', array( $this, 'buildCustomCss', ) ); /** * @since 4.5 used to call update file once option is changed */ add_action( 'add_option_wpb_js_compiled_js_composer_less', array( $this, 'buildCustomColorCss', ) ); /** * @since 4.5 used to call update file once option is changed */ add_action( 'add_option_wpb_js_custom_css', array( $this, 'buildCustomCss', ) ); /** * Tab: General Settings */ $tab = 'general'; $this->addSection( $tab ); $this->addField( $tab, esc_html__( 'Disable responsive content elements', 'js_composer' ), 'not_responsive_css', array( $this, 'sanitize_not_responsive_css_callback', ), array( $this, 'not_responsive_css_field_callback', ) ); $this->addField( $tab, esc_html__( 'Google fonts subsets', 'js_composer' ), 'google_fonts_subsets', array( $this, 'sanitize_google_fonts_subsets_callback', ), array( $this, 'google_fonts_subsets_callback', ) ); /** * Tab: Design Options */ $tab = 'color'; $this->addSection( $tab ); // Use custom checkbox $this->addField( $tab, esc_html__( 'Use custom design options', 'js_composer' ), 'use_custom', array( $this, 'sanitize_use_custom_callback', ), array( $this, 'use_custom_callback', ) ); foreach ( self::$color_settings as $color_set ) { foreach ( $color_set as $key => $data ) { $this->addField( $tab, $data['title'], $key, array( $this, 'sanitize_color_callback', ), array( $this, 'color_callback', ), array( 'id' => $key, ) ); } } // Margin $this->addField( $tab, esc_html__( 'Elements bottom margin', 'js_composer' ), 'margin', array( $this, 'sanitize_margin_callback', ), array( $this, 'margin_callback', ) ); // Gutter $this->addField( $tab, esc_html__( 'Grid gutter width', 'js_composer' ), 'gutter', array( $this, 'sanitize_gutter_callback', ), array( $this, 'gutter_callback', ) ); // Responsive max width $this->addField( $tab, esc_html__( 'Mobile screen width', 'js_composer' ), 'responsive_max', array( $this, 'sanitize_responsive_max_callback', ), array( $this, 'responsive_max_callback', ) ); $this->addField( $tab, false, 'compiled_js_composer_less', array( $this, 'sanitize_compiled_js_composer_less_callback', ), array( $this, 'compiled_js_composer_less_callback', ) ); /** * Tab: Custom CSS */ $tab = 'custom_css'; $this->addSection( $tab ); $this->addField( $tab, esc_html__( 'Paste your CSS code', 'js_composer' ), 'custom_css', array( $this, 'sanitize_custom_css_callback', ), array( $this, 'custom_css_field_callback', ) ); /** * Custom Tabs */ foreach ( $this->getTabs() as $tab => $title ) { do_action( 'vc_settings_tab-' . preg_replace( '/^vc\-/', '', $tab ), $this ); } /** * Tab: Updater */ $tab = 'updater'; $this->addSection( $tab ); } /** * Creates new section. * * @param $tab - tab key name as tab section * @param $title - Human title * @param $callback - function to build section header. */ public function addSection( $tab, $title = null, $callback = null ) { add_settings_section( $this->option_group . '_' . $tab, $title, ( null !== $callback ? $callback : array( $this, 'setting_section_callback_function', ) ), $this->page . '_' . $tab ); } /** * Create field in section. * * @param $tab * @param $title * @param $field_name * @param $sanitize_callback * @param $field_callback * @param array $args * * @return $this */ public function addField( $tab, $title, $field_name, $sanitize_callback, $field_callback, $args = array() ) { register_setting( $this->option_group . '_' . $tab, self::$field_prefix . $field_name, $sanitize_callback ); add_settings_field( self::$field_prefix . $field_name, $title, $field_callback, $this->page . '_' . $tab, $this->option_group . '_' . $tab, $args ); return $this; // chaining } /** * */ public function restoreColor() { foreach ( self::$color_settings as $color_sett ) { foreach ( $color_sett as $key => $value ) { delete_option( self::$field_prefix . $key ); } } delete_option( self::$field_prefix . 'margin' ); delete_option( self::$field_prefix . 'gutter' ); delete_option( self::$field_prefix . 'responsive_max' ); delete_option( self::$field_prefix . 'use_custom' ); delete_option( self::$field_prefix . 'compiled_js_composer_less' ); delete_option( self::$field_prefix . 'less_version' ); } /** * @param $option_name * * @param bool $defaultValue * * @return mixed */ public static function get( $option_name, $defaultValue = false ) { return get_option( self::$field_prefix . $option_name, $defaultValue ); } /** * @param $option_name * @param $value * * @return bool */ public static function set( $option_name, $value ) { return update_option( self::$field_prefix . $option_name, $value ); } /** * Set up the enqueue for the CSS & JavaScript files. * */ public function adminLoad() { wp_register_script( 'wpb_js_composer_settings', vc_asset_url( 'js/dist/settings.min.js' ), array(), WPB_VC_VERSION, true ); wp_enqueue_style( 'js_composer_settings', vc_asset_url( 'css/js_composer_settings.min.css' ), false, WPB_VC_VERSION ); wp_enqueue_script( 'backbone' ); wp_enqueue_script( 'shortcode' ); wp_enqueue_script( 'underscore' ); wp_enqueue_script( 'jquery-ui-accordion' ); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'wpb_js_composer_settings' ); $this->locale = array( 'are_you_sure_reset_css_classes' => esc_html__( 'Are you sure you want to reset to defaults?', 'js_composer' ), 'are_you_sure_reset_color' => esc_html__( 'Are you sure you want to reset to defaults?', 'js_composer' ), 'saving' => esc_html__( 'Saving...', 'js_composer' ), 'save' => esc_html__( 'Save Changes', 'js_composer' ), 'saved' => esc_html__( 'Design Options successfully saved.', 'js_composer' ), 'save_error' => esc_html__( 'Design Options could not be saved', 'js_composer' ), 'form_save_error' => esc_html__( 'Problem with AJAX request execution, check internet connection and try again.', 'js_composer' ), 'are_you_sure_delete' => esc_html__( 'Are you sure you want to delete this shortcode?', 'js_composer' ), 'are_you_sure_delete_param' => esc_html__( "Are you sure you want to delete the shortcode's param?", 'js_composer' ), 'my_shortcodes_category' => esc_html__( 'My shortcodes', 'js_composer' ), 'error_shortcode_name_is_required' => esc_html__( 'Shortcode name is required.', 'js_composer' ), 'error_enter_valid_shortcode_tag' => esc_html__( 'Please enter valid shortcode tag.', 'js_composer' ), 'error_enter_required_fields' => esc_html__( 'Please enter all required fields for params.', 'js_composer' ), 'new_shortcode_mapped' => esc_html__( 'New shortcode mapped from string!', 'js_composer' ), 'shortcode_updated' => esc_html__( 'Shortcode updated!', 'js_composer' ), 'error_content_param_not_manually' => esc_html__( 'Content param can not be added manually, please use checkbox.', 'js_composer' ), 'error_param_already_exists' => esc_html__( 'Param %s already exists. Param names must be unique.', 'js_composer' ), 'error_wrong_param_name' => esc_html__( 'Please use only letters, numbers and underscore for param name', 'js_composer' ), 'error_enter_valid_shortcode' => esc_html__( 'Please enter valid shortcode to parse!', 'js_composer' ), ); wp_localize_script( 'wpb_js_composer_settings', 'vcData', apply_filters( 'vc_global_js_data', array( 'version' => WPB_VC_VERSION, 'debug' => false, ) ) ); wp_localize_script( 'wpb_js_composer_settings', 'i18nLocaleSettings', $this->locale ); } /** * */ public function custom_css_field_callback() { $value = get_option( self::$field_prefix . 'custom_css' ); if ( empty( $value ) ) { $value = ''; } echo ''; echo '
' . esc_textarea( $value ) . ''; echo '
' . esc_html__( 'Add custom CSS code to the plugin without modifying files.', 'js_composer' ) . '
'; } /** * Not responsive checkbox callback function */ public function not_responsive_css_field_callback() { $checked = get_option( self::$field_prefix . 'not_responsive_css' ); if ( empty( $checked ) ) { $checked = false; } ?>' . esc_html__( 'Change default vertical spacing between content elements (Example: 20px).', 'js_composer' ) . '
'; } /** * */ public function gutter_callback() { $field = 'gutter'; $value = get_option( self::$field_prefix . $field ); $value = $value ? $value : $this->getDefault( $field ); echo ' px'; echo '' . esc_html__( 'Change default horizontal spacing between columns, enter new value in pixels.', 'js_composer' ) . '
'; } /** * */ public function responsive_max_callback() { $field = 'responsive_max'; $value = get_option( self::$field_prefix . $field ); $value = $value ? $value : $this->getDefault( $field ); echo ' px'; echo '' . esc_html__( 'By default content elements "stack" one on top other when screen size is smaller than 768px. Change the value to change "stacking" size.', 'js_composer' ) . '
'; } /** * */ public function compiled_js_composer_less_callback() { $field = 'compiled_js_composer_less'; echo ''; // VALUE must be empty } /** * @param $key * * @return string */ public function getDefault( $key ) { return ! empty( self::$defaults[ $key ] ) ? self::$defaults[ $key ] : ''; } /** * Callback function for settings section * * @param $tab */ public function setting_section_callback_function( $tab ) { if ( 'wpb_js_composer_settings_color' === $tab['id'] ) { echo '' . esc_html__( 'Here you can tweak default WPBakery Page Builder content elements visual appearance. By default WPBakery Page Builder is using neutral light-grey theme. Changing "Main accent color" will affect all content elements if no specific "content block" related color is set.', 'js_composer' ) . '