pluginloc = strlen($loc)? $loc: __FILE__; $this->options = claps_default_options(); $basename = plugin_basename($this->pluginloc); if (is_admin()){ add_action('admin_enqueue_scripts', array($this, 'claps_enqueue_admin')); add_action('admin_init',array($this, 'claps_register_settings')); add_action('admin_menu', array($this, 'claps_admin_menu')); add_filter('plugin_action_links_'.$basename, array($this, 'claps_settings_link')); add_action('wp_dashboard_setup', array($this, 'claps_add_dashboard')); // add_action('dashboard_glance_items', [ $this, 'claps_glance_item' ]); // add_action('add_meta_boxes', array($this, 'claps_add_post_meta_box')); //manage the stored variable and option values when registering or deactivating register_activation_hook($loc, array($this, 'claps_load_options' )); register_deactivation_hook($loc, array($this, 'claps_unset_options' )); register_uninstall_hook ($loc, array($this, 'claps_uninstall')); } else { add_action('wp_enqueue_scripts', array($this, 'claps_enqueue_main')); } // add_action('wp_ajax_claps_fetch_styles', 'claps_fetch_styles'); // add_action('wp_ajax_nopriv_claps_fetch_styles', 'claps_fetch_styles'); //Load a function that runs after all plugins are registered //add_action('plugins_loaded', array($this, 'claps_late_loader')); } // -------------------- Add styles and scripts -------------------- /** * @param $hook - the admin_enqueue_scripts action provides the $hook_suffix for the current admin page. * This is used to load the scripts only for the admin pages associated with the plugin * HOOK: "toplevel_page_leads5050-code" * HOOK: "hub5050-insights_page_ract-ranking" */ function claps_enqueue_main($hook){ wp_enqueue_style( 'claps-main', plugins_url('css/collapse-magic.css', __FILE__), [], CLAPS_VERSION ); wp_enqueue_script( 'claps-main', plugins_url('js/collapse-magic.js', __FILE__), ['jquery'], CLAPS_VERSION, true ); } function claps_enqueue_admin(){ wp_enqueue_style( 'claps-admin-css', plugins_url('css/collapse-magic-admin.css', __FILE__), [], CLAPS_VERSION ); wp_enqueue_script( 'claps-admin-js', plugins_url('js/collapse-magic-admin.js', __FILE__), ['jquery'], CLAPS_VERSION, true ); } /** * Late loading function for actions that runs after all plugins are loaded */ function claps_late_loader(){ //do something here } // -------------------- Options, Variables and Menu - Admin Settings Form Definition -------------------- function claps_admin_menu() { //Add a menu to the Settings menu group add_submenu_page( 'options-general.php', 'Collapse Magic', 'Collapse Magic', 'manage_options', 'claps_menu_page', array($this, 'claps_options_page') ); } /** * @param $links - When the 'plugin_action_links_(plugin file name)' filter is called, it is passed one parameter: * namely the links to show on the plugins overview page in an array * https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name) * * @return mixed */ function claps_settings_link($links) { $url = get_admin_url().'options-general.php?page=claps_menu_page'; $settings_link = '' . __("Settings", "collapse-magic") . ''; array_unshift( $links, $settings_link ); return $links; } /** * Note - whatever output is returned from option_validate will be included into the option_name option, even * if this is totally unrelated to the values listed in the form * @return void */ function claps_register_settings() { register_setting('claps_group', 'claps_options', array($this, 'claps_validate')); } /** * Validate and transform the values submitted to the options form. * The input is the result from the form POST operation. The output will replace the option_name value that was * used in the call to the validation routine. * @param array $input - options results from the form submission * @return array|false - validated and transformed options results */ function claps_validate($input){ $output = []; if ( is_array($input) ){ foreach ( $this->options as $att => $arr ) { if ( $att=='switches' && is_array($arr) ) { foreach ( $arr as $type => $state ) { $output[$att][ $type ] = ( isset( $input[$att][ $type ] ) && $input[$att][ $type ] ) ? 1 : 0; } } elseif($att=='data' && is_array($arr)) { foreach ( $arr as $type => $state ) { if ( isset($input[$att][$type]) && strlen($input[$att][$type]) ){ if ( $type=='icon' || $type=='swapicon' ){ $cnv = mb_convert_encoding($input[$att][$type], 'HTML-ENTITIES', 'UTF-8'); $output[$att][$type] = claps_validate_dec_entity($cnv)? sanitize_text_field($cnv): '⇅'; } else { $output[$att][$type] = sanitize_text_field( $input[$att][$type] ); } } else { $output[$att][$type] = $this->options[$att][$type]; } } } elseif($att=='style' && is_array($arr)) { foreach ( $arr as $type => $state ) { if (claps_validate_height_value($input[$att][$type])) { $output[$att][$type] = sanitize_text_field($input[$att][$type]); } else { $output[$att][$type] = $this->options[$att][$type]; } } } } } return $output; } function claps_options_page() { $allowed_tags = array( 'input' => array( 'type' => true, 'id' => true, 'name' => true, 'class' => true, 'value' => true, 'min' => true, 'size' => true, ), 'select' => array( 'name' => true, 'class' => true, ), 'option' => array( 'value' => true, 'selected' => true, ), ); $options = claps_get_options(); if(current_user_can('manage_options')) { echo '
'.var_export($options, true).''; echo '
'.var_export($options, true).''; echo '