Settings > Simple Tooltips Version: 2.1.3 Author: Justin Saad Author URI: http://www.clevelandwebdeveloper.com License: GPL2 */ $plugin_label = "Simple Tooltips"; $plugin_slug = "simple_tooltips"; class simple_tooltips { public function __construct(){ global $plugin_label, $plugin_slug; $this->plugin_slug = $plugin_slug; $this->plugin_label = $plugin_label; $this->custom_tooltips = array(); //enqueue color picker add_action( 'admin_enqueue_scripts', array($this, 'enqueue_color_picker') ); //plugin row links add_filter( 'plugin_row_meta', array($this,'plugin_row_links'), 10, 2 ); add_shortcode('simple_tooltip', array($this, 'addShortcodeHandler')); if(is_admin()){ add_action('admin_menu', array($this, 'add_plugin_page')); add_action('admin_init', array($this, 'page_init')); //add Settings link to plugin page add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array($this, 'add_plugin_action_links') ); //custom jquery for admin page add_action('admin_footer', array($this,'motech_tooltips_admin_jquery')); } add_filter( 'tiny_mce_version', array($this, 'my_refresh_mce')); //add_action('init', array($this, 'add_custom_button')); add_action('init', array($this, 'load_tooltips')); //loads on wordpress init add_action('init', array($this, 'add_custom_button')); } function enqueue_color_picker( $hook_suffix ) { // first check that $hook_suffix is appropriate for your admin page wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'my-script-handle', plugins_url('motech-color-picker.js', __FILE__ ), array( 'wp-color-picker' ), false, true ); } public function add_plugin_page(){ // This page will be under "Settings" add_options_page('Settings Admin', $this->plugin_label, 'manage_options', $this->plugin_slug.'-setting-admin', array($this, 'create_admin_page')); } public function print_section_info(){ //section summary info goes here print 'Set the default settings for your tooltips. For instructions on how to use the tooltips, visit the plugin page »'; } public function get_donate_button(){ ?>
Ways to say thanks
A lot of effort went into the development of this plugin. You can say 'Thank You' by doing any of the following
  • Donate a few dollars to my company The Motech Network to help with future development and updates.
  • Follow me on Twitter
  • Follow me on Google+
  • Connect with me on LinkedIn
  • Rate it on WordPress.org
  • Blog about it & link to the plugin page
  • Check out my other WordPress plugins
  • Email me to say thanks. If you can let me know where my plugins are being used 'in the wild' I always appreciate that.
Thanks in advance for your support.
-Justin
get_donate_button() ?>

plugin_label ?>

plugin_slug.'_option_group'); do_settings_sections($this->plugin_slug.'-setting-admin'); ?>
plugin_slug.'_setting_section', 'Configuration', array($this, 'print_section_info'), $this->plugin_slug.'-setting-admin' ); //add color picker text input field $field_slug = "background_color"; $field_label = "Background Color:"; $field_id = $this->plugin_slug.'_'.$field_slug; register_setting($this->plugin_slug.'_option_group', $field_id); add_settings_field( $field_id, $field_label, array($this, 'create_a_text_input'), //callback function for text input $this->plugin_slug.'-setting-admin', $this->plugin_slug.'_setting_section', array( // The array of arguments to pass to the callback. "id" => $field_id, //sends field id to callback "desc" => 'Choose your tooltip background color above', //description of the field (optional) "default" => '#000000', //sets the default field value (optional), when grabbing this option value later on remember to use get_option(option_name, default_value) so it will return default value if no value exists yet "class" => "motech-color-field" //designate this as color field ) ); //add color picker text input field $field_slug = "text_color"; $field_label = "Text Color:"; $field_id = $this->plugin_slug.'_'.$field_slug; register_setting($this->plugin_slug.'_option_group', $field_id); add_settings_field( $field_id, $field_label, array($this, 'create_a_text_input'), //callback function for text input $this->plugin_slug.'-setting-admin', $this->plugin_slug.'_setting_section', array( // The array of arguments to pass to the callback. "id" => $field_id, //sends field id to callback "desc" => 'Choose your tooltip text color above', //description of the field (optional) "default" => '#ffffff', //sets the default field value (optional), when grabbing this option value later on remember to use get_option(option_name, default_value) so it will return default value if no value exists yet "class" => "motech-color-field" //designate this as color field ) ); //add text input field $field_slug = "max_width"; $field_label = "Max Width:"; $field_id = $this->plugin_slug.'_'.$field_slug; register_setting($this->plugin_slug.'_option_group', $field_id); add_settings_field( $field_id, $field_label, array($this, 'create_a_text_input'), //callback function for text input $this->plugin_slug.'-setting-admin', $this->plugin_slug.'_setting_section', array( // The array of arguments to pass to the callback. "id" => $field_id, //sends field id to callback "desc" => 'Set the maximum pixel width of the tooltip bubble. Default is 250.', //description of the field (optional) "default" => '250', //sets the default field value (optional), when grabbing this option value later on remember to use get_option(option_name, default_value) so it will return default value if no value exists yet ) ); //add text input field $field_slug = "opacity"; $field_label = "Opacity:"; $field_id = $this->plugin_slug.'_'.$field_slug; register_setting($this->plugin_slug.'_option_group', $field_id); add_settings_field( $field_id, $field_label, array($this, 'create_a_text_input'), //callback function for text input $this->plugin_slug.'-setting-admin', $this->plugin_slug.'_setting_section', array( // The array of arguments to pass to the callback. "id" => $field_id, //sends field id to callback "desc" => 'Set the opacity of the tooltip bubble. This should be a number
between 0 and 1. 0 makes the bubble invisible and 1 makes
the bubble totally solid. Default is .95', //description of the field (optional) "default" => '.95', //sets the default field value (optional), when grabbing this option value later on remember to use get_option(option_name, default_value) so it will return default value if no value exists yet ) ); //add select input field $field_slug = "position"; $field_label = "Position:"; $field_id = $this->plugin_slug.'_'.$field_slug; $options = array( array("label" => "Center", "value" => "center"), array("label" => "Left", "value" => "left"), array("label" => "Right", "value" => "right"), ); register_setting($this->plugin_slug.'_option_group', $field_id); add_settings_field( $field_id, $field_label, array($this, 'create_a_select_input'), //callback function for radio input $this->plugin_slug.'-setting-admin', $this->plugin_slug.'_setting_section', array( // The array of arguments to pass to the callback. "id" => $field_id, //sends select field id to callback "desc" => 'The tooltip\'s position, relative to the trigger element.', //description of the select field (optional) "default" => 'center', //sets the default field value (optional), when grabbing this field value later on remember to use get_option(option_name, default_value) so it will return default value if no value exists yet "select_options" => $options //sets select option data ) ); //add checkbox field $field_slug = "disable_on_mobile"; $field_label = "Disable On Mobile"; $field_id = $this->plugin_slug.'_'.$field_slug; register_setting($this->plugin_slug.'_option_group', $field_id); add_settings_field( $field_id, $field_label, array($this, 'create_a_checkbox'), //callback function for checkbox $this->plugin_slug.'-setting-admin', $this->plugin_slug.'_setting_section', array( // The array of arguments to pass to the callback. "id" => $field_id, //sends field id to callback "desc" => 'Check this box to disable tooltips on mobile devices.', //description of the field (optional) "default" => '0' //sets the default field value (optional), when grabbing this option value later on remember to use get_option(option_name, default_value) so it will return default value if no value exists yet ) ); //add text input field $field_slug = "menu_selectors"; $field_label = "Menu Selectors (Advanced):"; $field_id = $this->plugin_slug.'_'.$field_slug; register_setting($this->plugin_slug.'_option_group', $field_id); add_settings_field( $field_id, $field_label, array($this, 'create_a_text_input'), //callback function for text input $this->plugin_slug.'-setting-admin', $this->plugin_slug.'_setting_section', array( // The array of arguments to pass to the callback. "id" => $field_id, //sends field id to callback "desc" => 'This is for advanced users. If you want to use the tooltips on your WordPress menus, you can enable this by entering in the css selectors for your menus. For example, if your menu has the class "nav_menu", enter in ".nav_menu" to enable tooltips for all menus where class="nav_menu". You can enter multiple selectors in a comma seperated list. If you don\'t know what this means, or you don\'t want tooltips on your menus, just leave it empty. Get Help »', //description of the field (optional) "default" => '', //sets the default field value (optional), when grabbing this option value later on remember to use get_option(option_name, default_value) so it will return default value if no value exists yet ) ); } //end of page_init function /** * This following set of functions handle all input field creation * */ function create_a_checkbox($args) { $html = ''; // Here, we will take the desc argument of the array and add it to a label next to the checkbox $html .= ''; echo $html; } // end create_a_checkbox function create_a_text_input($args) { //grab placeholder if there is one if(isset($args["placeholder"])) { $placeholder_html = "placeholder=\"".$args['placeholder']."\""; } else { $placeholder_html = ""; } if(!empty($args["class"])){ $class = $args["class"]; }else{ $class = ""; } // Render the output echo ''; if(isset($args["desc"])) { echo "

".$args["desc"]."

"; } } // end create_a_text_input function create_a_textarea_input($args) { //grab placeholder if there is one if($args[placeholder]) { $placeholder_html = "placeholder=\"".$args[placeholder]."\""; } // Render the output echo ''; if($args[desc]) { echo "

".$args[desc]."

"; } } function create_a_radio_input($args) { $radio_options = $args[radio_options]; $html = ""; if($args[desc]) { $html .= $args[desc] . "
"; } foreach($radio_options as $radio_option) { $html .= ''; $html .= '
'; } echo $html; } // end create_a_radio_input callback function create_a_select_input($args) { $select_options = $args["select_options"]; $html = ""; if(!empty($args["desc"])) { $html .= $args["desc"] . "
"; } $html .= ''; echo $html; } // end create_a_select_input callback //add plugin action links logic function add_plugin_action_links( $links ) { return array_merge( array( 'settings' => 'Settings' ), $links ); } function load_tooltips() { if (!is_admin()) { wp_enqueue_script('simple_tooltips_base', plugins_url( 'zebra_tooltips.js' , __FILE__ ), array('jquery'), false, true); wp_enqueue_style('simple_tooltips_style', plugins_url( 'zebra_tooltips.css' , __FILE__ )); add_action('wp_footer', array($this, 'tooltip_data'), 100); } } function tooltip_data() { ?> ' . __('Find me on LinkedIn' ) . '' ), array( '' . __('Follow me on Twitter') . '' ) ); return $links; } function my_refresh_mce($ver) { $ver += 6; return $ver; } function add_custom_button() { if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) return; if ( get_user_option('rich_editing') == 'true') { add_filter('mce_external_plugins', array($this, 'add_custom_tinymce_plugin')); add_filter('mce_buttons', array($this, 'register_custom_button')); } } function register_custom_button($buttons) { array_push($buttons, "|", get_class($this)); return $buttons; } function add_custom_tinymce_plugin($plugin_array) { //use this in a plugin $plugin_array[get_class($this)] = plugins_url( 'editor_plugin.js' , __FILE__ ); //use this in a theme //$plugin_array[get_class($this)] = get_bloginfo('template_url').'/editor_plugin.js'; return $plugin_array; } // add the shortcode handler function addShortcodeHandler($atts, $trigger = null) { extract(shortcode_atts(array( "content" => "", "style" => "", "bubblewidth" => "", "bubbleopacity" => "", "bubblebgcolor" => "", "bubbleposition" => "", "bubblecolor" => "", ), $atts)); /* if ($height > 0 ) { $spacer_css = "padding-top: " . $height . ";"; } elseif($height < 0) { $spacer_css = "margin-top: " . $height . ";"; } return '';*/ $custom_tooltips = $this->custom_tooltips; $new_custom_tooltip = array(); $special_class = ""; if($bubblewidth != "") { $new_custom_tooltip["bubblewidth"] = $bubblewidth; //add to array $special_class .= " bubblewidth_".$bubblewidth; $custom_tooltip_active = 1; } if($bubblebgcolor != "") { $new_custom_tooltip["bubblebgcolor"] = $bubblebgcolor; $special_class .= " bubblebgcolor_" . $bubblebgcolor; $custom_tooltip_active = 1; } if($bubbleopacity != "") { $new_custom_tooltip["bubbleopacity"] = $bubbleopacity; $special_class .= " bubbleopacity_" . $bubbleopacity; $custom_tooltip_active = 1; } if($bubbleposition != "") { $new_custom_tooltip["bubbleposition"] = $bubbleposition; $special_class .= " bubbleposition_" . $bubbleposition; $custom_tooltip_active = 1; } if($bubblecolor != "") { $new_custom_tooltip["bubblecolor"] = $bubblecolor; $special_class .= " bubblecolor_" . $bubblecolor; $custom_tooltip_active = 1; } if((isset($custom_tooltip_active)) && ($custom_tooltip_active == 1)) { $custom_tooltips[] = $new_custom_tooltip; $this->custom_tooltips = $custom_tooltips; $special_class .= " custom_m_bubble"; } $html = ''; $html .= ''.do_shortcode($trigger).''; return $html; } function motech_tooltips_admin_jquery() { if (isset($_GET['page']) && $_GET['page'] == $this->plugin_slug.'-setting-admin') { //if we are on our admin page ?>