$_value ) { if ( ! isset($settings[$_key] ) ) { $settings[$_key] = $_value; } } } $this->settings = $settings; $this->settings_default = $settings_default; //Add actions and filters add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); add_action( 'ccj_settings_form', array( $this, 'general_extra_form' ), 11 ); add_filter( 'ccj_settings_default', array( $this, 'general_extra_default' ) ); add_filter( 'ccj_settings_save', array( $this, 'general_extra_save' ) ); add_action( 'before_woocommerce_init', array( $this, 'before_woocommerce_init' ) ); } /** * Add submenu pages */ function admin_menu() { $menu_slug = 'edit.php?post_type=custom-css-js'; add_submenu_page( $menu_slug, __('Settings', 'custom-css-js'), __('Settings', 'custom-css-js'), 'manage_options', 'custom-css-js-config', array( $this, 'config_page' ) ); } /** * Enqueue the scripts and styles */ public function admin_enqueue_scripts( $hook ) { $screen = get_current_screen(); // Only for custom-css-js post type if ( $screen->post_type != 'custom-css-js' ) return false; if ( $hook != 'custom-css-js_page_custom-css-js-config' ) return false; // Some handy variables $a = plugins_url( '/', CCJ_PLUGIN_FILE). 'assets'; $v = CCJ_VERSION; wp_enqueue_script( 'tipsy', $a . '/jquery.tipsy.js', array('jquery'), $v, false ); wp_enqueue_style( 'tipsy', $a . '/tipsy.css', array(), $v ); } /** * Template for the config page */ function config_page() { if ( isset( $_POST['ccj_settings-nonce'] ) ) { check_admin_referer('ccj_settings', 'ccj_settings-nonce'); $data = apply_filters( 'ccj_settings_save', array() ); $settings = get_option('ccj_settings', array()); if ( !isset($settings['add_role'] ) ) $settings['add_role'] = false; if ( !isset($settings['remove_comments'] ) ) $settings['remove_comments'] = false; // If the "add role" option changed if ( $data['add_role'] !== $settings['add_role'] && current_user_can('update_plugins')) { // Add the 'css_js_designer' role if ( $data['add_role'] ) { CustomCSSandJS_Install::create_roles(); } // Remove the 'css_js_designer' role if ( !$data['add_role'] ) { remove_role('css_js_designer'); } flush_rewrite_rules(); } update_option( 'ccj_settings', $data ); } else { $data = $this->settings; } ?>