url_path = $url_path; global ${$this->func . '_options'}; ${$this->func . '_options'} = $this->get_settings(); } /** * Add settings pages * * @access public * @since 1.0.0 * @global string ${this->func . '_settings_page'} The settings page slug * @return void */ public function add_settings_page() { global ${$this->func . '_settings_page'}; $menu = apply_filters( $this->func . '_menu', array( 'type' => 'menu', 'parent' => 'options-general.php', 'page_title' => __( 'Section214 Settings', 's214' ), 'show_title' => false, 'menu_title' => __( 'Section214 Settings', 's214' ), 'capability' => 'manage_options', 'icon' => '', 'position' => null ) ); $this->show_title = $menu['show_title']; $this->page_title = $menu['page_title']; if ( $menu['type'] === 'submenu' ) { ${$this->func . '_settings_page'} = add_submenu_page( $menu['parent'], $menu['page_title'], $menu['menu_title'], $menu['capability'], $this->slug . '-settings', array( $this, 'render_settings_page' ) ); } else { ${$this->func . '_settings_page'} = add_menu_page( $menu['page_title'], $menu['menu_title'], $menu['capability'], $this->slug . '-settings', array( $this, 'render_settings_page' ), $menu['icon'], $menu['position'] ); } } /** * Render settings page * * @access public * @since 1.0.0 * @return void */ public function render_settings_page() { $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $this->get_settings_tabs() ) ? $_GET['tab'] : $this->default_tab; $sections = $registered_sections = $this->get_settings_tab_sections( $active_tab ); $key = 'main'; if ( is_array( $sections ) ) { $key = key( $sections ); } $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; ob_start(); ?>
' . $args['desc'] . '
'; echo $this->apply_after_setting_output( $html, $args ); } } /** * Number callback * * @access public * @since 1.0.0 * * @param array $args Arguments passed by the setting * * @return void */ public function number_callback( $args ) { $custom_attributes_html = $this->get_custom_attribute_html( $args ); $class_html = $this->get_class_html( $args ); $value = $this->get_std_input_value( $args ); $name = ' name="' . $this->func . '_settings[' . $args['id'] . ']"'; $max = isset( $args['max'] ) ? $args['max'] : 999999; $min = isset( $args['min'] ) ? $args['min'] : 0; $step = isset( $args['step'] ) ? $args['step'] : 1; $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; $html = ' '; $html = $this->append_description_html( $html, $args ); echo $this->apply_after_setting_output( $html, $args ); } /** * Password callback * * @access public * @since 1.0.0 * * @param array $args Arguments passed by the settings * * @return void */ public function password_callback( $args ) { $custom_attributes_html = $this->get_custom_attribute_html( $args ); $size = $this->get_size_attr( $args ); $class_html = $this->get_class_html( $args, $size . '-text' ); $value = $this->get_std_input_value( $args ); $html = ' '; $html = $this->append_description_html( $html, $args ); echo $this->apply_after_setting_output( $html, $args ); } /** * @param array $args * * @return string */ private function get_size_attr( $args ) { return ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; } /** * Radio callback * * @access public * @since 1.0.0 * * @param array $args Arguments passed by the setting * * @return void */ public function radio_callback( $args ) { $options = $this->get_global_options(); $custom_attributes_html = $this->get_custom_attribute_html( $args ); $class_html = $this->get_class_html( $args ); if ( ! empty( $args['options'] ) ) { $html = ''; foreach ( $args['options'] as $key => $option ) { $checked = false; if ( isset( $options[ $args['id'] ] ) && $options[ $args['id'] ] === $key ) { $checked = true; } elseif ( isset( $args['std'] ) && $args['std'] === $key && ! isset( $options[ $args['id'] ] ) ) { $checked = true; } $html .= ' '; $html .= '' . $args['desc'] . '
'; echo $this->apply_after_setting_output( $html, $args ); } } /** * Select callback * * @access public * @since 1.0.0 * * @param array $args Arguments passed by the setting * * @return void */ public function select_callback( $args ) { $custom_attributes_html = $this->get_custom_attribute_html( $args ); $class_html = $this->get_class_html( $args ); $value = $this->get_std_input_value( $args ); $placeholder = isset( $args['placeholder'] ) ? $args['placeholder'] : ''; $select2 = isset( $args['select2'] ) ? ' class="s214-select2"' : ''; $width = isset( $args['size'] ) ? ' style="width: ' . $args['size'] . '"' : ''; if ( isset( $args['multiple'] ) && $args['multiple'] === true ) { $html = ''; $html .= ''; } else { $html = ''; } foreach ( $args['options'] as $option => $name ) { if ( isset( $args['multiple'] ) && $args['multiple'] === true ) { if ( is_array( $value ) ) { $selected = ( in_array( $option, $value ) ? 'selected="selected"' : '' ); } else { $selected = ''; } } else { if ( is_string( $value ) ) { $selected = selected( $option, $value, false ); } else { $selected = ''; } } $html .= ''; } $html .= ' '; $html = $this->append_description_html( $html, $args ); echo $this->apply_after_setting_output( $html, $args ); } /** * Sysinfo callback * * @since 1.1.0 * * @param array $args Arguements passed by the settings * * @return void */ public function sysinfo_callback( $args ) { $options = $this->get_global_options(); $custom_attributes_html = $this->get_custom_attribute_html( $args ); $class_html = $this->get_class_html( $args ); if ( ! isset( $options[ $args['tab'] ] ) || ( isset( $options[ $args['tab'] ] ) && isset( $_GET['tab'] ) && $_GET['tab'] === $options[ $args['tab'] ] ) ) { $html = ''; $html .= ''; $html .= ''; $html .= '' . __( 'Download System Info File', 's214-settings' ) . ''; $html .= '
'; echo $this->apply_after_setting_output( $html, $args ); } } /** * Text callback * * @since 1.0.0 * * @param array $args Arguments passed by the setting * * @return void */ public function text_callback( $args ) { $custom_attributes_html = $this->get_custom_attribute_html( $args ); $value = $this->get_std_input_value( $args ); $name = ' name="' . $this->func . '_settings[' . $args['id'] . ']"'; $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; $class_html = $this->get_class_html( $args, $size . '-text' ); $html = ' '; $html = $this->append_description_html( $html, $args ); echo $this->apply_after_setting_output( $html, $args ); } /** * Textarea callback * * @since 1.0.0 * * @param array $args Arguments passed by the setting * * @return void */ public function textarea_callback( $args ) { $custom_attributes_html = $this->get_custom_attribute_html( $args ); $class_html = $this->get_class_html( $args, 'large-text' ); $value = $this->get_std_input_value( $args ); $html = ' '; $html = $this->append_description_html( $html, $args ); echo $this->apply_after_setting_output( $html, $args ); } /** * Upload callback * * @since 1.0.0 * * @param array $args Arguments passed by the setting * * @return void */ public function upload_callback( $args ) { $custom_attributes_html = $this->get_custom_attribute_html( $args ); $value = $this->get_std_input_value( $args ); $size = $this->get_size_attr( $args ); $class_html = $this->get_class_html( $args, $size . '-text' ); $html = ' '; $html .= ' '; $html = $this->append_description_html( $html, $args ); echo $this->apply_after_setting_output( $html, $args ); } /** * License field callback * * @access public * @since 1.0.0 * * @param array $args Arguments passed by the setting * * @return void */ public function license_key_callback( $args ) { $custom_attributes_html = $this->get_custom_attribute_html( $args ); $value = $this->get_std_input_value( $args ); $size = $this->get_size_attr( $args ); $class_html = $this->get_class_html( $args, $size . '-text' ); $html = ' '; if ( get_option( $args['options']['is_valid_license_option'] ) ) { $html .= ''; } $html .= ''; wp_nonce_field( $args['id'] . '-nonce', $args['id'] . '-nonce' ); echo $this->apply_after_setting_output( $html, $args ); } /** * Check if we should load admin scripts * * @access public * @since 1.0.0 * * @param string $hook The hook for the current page * * @return bool true if we should load scripts, false otherwise */ public function load_scripts( $hook ) { global ${$this->func . '_settings_page'}; $ret = false; $pages = apply_filters( $this->func . '_admin_pages', array( ${$this->func . '_settings_page'} ) ); if ( in_array( $hook, $pages ) ) { $ret = true; } return (bool) apply_filters( $this->func . 'load_scripts', $ret ); } /** * Add tooltips * * @access public * @since 1.2.0 * * @param string $html The current field HTML * @param array $args Arguments passed to the field * * @return string $html The updated field HTML */ function add_setting_tooltip( $html, $args ) { if ( ! empty( $args['tooltip_title'] ) && ! empty( $args['tooltip_desc'] ) ) { $tooltip = ''; $html .= $tooltip; } return $html; } private $url_path; public function enqueue_scripts( $hook ) { if ( ! apply_filters( $this->func . '_load_admin_scripts', $this->load_scripts( $hook ), $hook ) ) { return; } global $wp_scripts; // Use minified libraries if SCRIPT_DEBUG is turned off $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; //$url_path = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, dirname( __FILE__ ) ); //$url_path = $this->plugin->get_plugin_url() . 'classes/wpdesk'; $url_path = $this->url_path . '/vendor/wpdesk/wp-settings/source'; $select2_cdn = 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/'; $cm_cdn = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.14.2/'; $jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.11.4'; wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_script( 'jquery-ui-tooltip' ); wp_enqueue_media(); wp_enqueue_style( 'jquery-ui-style', '//code.jquery.com/ui/' . $jquery_version . '/themes/smoothness/jquery-ui' . $suffix . '.css', array(), $jquery_version ); wp_enqueue_script( 'media-upload' ); wp_enqueue_style( 'thickbox' ); wp_enqueue_script( 'thickbox' ); wp_enqueue_style( 's14-select2', $select2_cdn . 'css/select2' . $suffix . '.css', array(), '4.0.5' ); wp_enqueue_script( 's14-select2', $select2_cdn . 'js/select2' . $suffix . '.js', array( 'jquery' ), '4.0.5' ); wp_enqueue_style( $this->slug . '-cm', $cm_cdn . 'codemirror.css', array(), '5.10' ); wp_enqueue_script( $this->slug . '-cm', $cm_cdn . 'codemirror.js', array( 'jquery' ), '5.14.2' ); wp_enqueue_script( $this->slug . '-cm-html', $cm_cdn . 'mode/htmlmixed/htmlmixed.js', array( 'jquery', $this->slug . '-cm' ), '5.14.2' ); wp_enqueue_script( $this->slug . '-cm-xml', $cm_cdn . 'mode/xml/xml.js', array( 'jquery', $this->slug . '-cm' ), '5.14.2' ); wp_enqueue_script( $this->slug . '-cm-js', $cm_cdn . 'mode/javascript/javascript.js', array( 'jquery', $this->slug . '-cm' ), '5.14.2' ); wp_enqueue_script( $this->slug . '-cm-css', $cm_cdn . 'mode/css/css.js', array( 'jquery', $this->slug . '-cm' ), '5.14.2' ); wp_enqueue_script( $this->slug . '-cm-php', $cm_cdn . 'mode/php/php.js', array( 'jquery', $this->slug . '-cm' ), '5.14.2' ); wp_enqueue_script( $this->slug . '-cm-clike', $cm_cdn . 'mode/clike/clike.js', array( 'jquery', $this->slug . '-cm' ), '5.14.2' ); wp_enqueue_style( $this->slug, $url_path . '/assets/css/admin' . $suffix . '.css', array(), $this->version ); wp_enqueue_style( $this->slug . '-settings', $url_path . '/assets/css/admin-settings' . $suffix . '.css', array(), $this->version ); wp_enqueue_script( $this->slug . '-js', $url_path . '/assets/js/admin-settings' . $suffix . '.js', array( 'jquery' ), $this->version ); wp_localize_script( $this->slug . '-js', 's214_settings_vars', apply_filters( $this->func . 'localize_script', array( 'func' => $this->func, 'image_media_button' => __( 'Insert Image', 'wpdesk-plugin' ), 'image_media_title' => __( 'Select Image', 'wpdesk-plugin' ), ) ) ); } /** * Date callback * * @access public * @since 1.0.0 * * @param array $args Arguments passed by the setting * * @global array ${$this->func . '_options'} The Beacon options * @return void */ public function date_callback( $args ) { global ${$this->func . '_options'}; $custom_attributes_html = $this->get_custom_attribute_html( $args ); if ( isset( ${$this->func . '_options'}[ $args['id'] ] ) ) { $value = ${$this->func . '_options'}[ $args['id'] ]; } else { $value = isset( $args['std'] ) ? $args['std'] : ''; } $name = ' name="' . $this->func . '_settings[' . $args['id'] . ']"'; $max = isset( $args['max'] ) ? $args['max'] : 999999; $min = isset( $args['min'] ) ? $args['min'] : 0; $step = isset( $args['step'] ) ? $args['step'] : 1; $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'date'; $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; $class_html = $this->get_class_html( $args, $size . '-text' ); $html = ' '; $html .= ''; echo apply_filters( $this->func . '_after_setting_output', $html, $args ); } /** * select 2 columns * * @access public * @since 1.0.0 * * @param array $args Arguments passed by the setting * * @global array ${$this->func . '_options'} The Beacon options * @return void */ public function select_2_columns_callback( $args ) { global ${$this->func . '_options'}; $custom_attributes_html = $this->get_custom_attribute_html( $args ); $class_html = $this->get_class_html( $args, 'select-2-columns' ); if ( isset( ${$this->func . '_options'}[ $args['id'] ] ) ) { $value = ${$this->func . '_options'}[ $args['id'] ]; } else { $value = isset( $args['std'] ) ? $args['std'] : ''; } $value_array = explode( ',', $value ); $placeholder = isset( $args['placeholder'] ) ? $args['placeholder'] : ''; $width = isset( $args['size'] ) ? ' style="width: ' . $args['size'] . '"' : ''; $available_header = isset( $args['available_header'] ) ? $args['available_header'] : ''; $selected_header = isset( $args['selected_header'] ) ? $args['selected_header'] : ''; $html = ''; $html_list_available = '