options = new ABB_Options(); // Grab an instance of the ABB_Options class if($show_readme_faq) : add_action('abb_after_tabs', array(&$this, 'do_readme_tab')); add_action('abb_after_tab_contents', array(&$this, 'do_readme_tab_content')); endif; } /** * Add the Read Me tab to the plugin settings page */ public function do_readme_tab(){ ?> Read Me FAQ plugin_text_domain) ); $content = $this->get_faq(true); ?> get_faq($for_readme); } /** * Return the plugin FAQ * * @param required boolean $for_readme Whether or not the FAQ is for the plugin readme * @return string */ public function get_faq($for_readme){ $this->for_readme = $for_readme; $questions = array(); $questions[] = $this->get_faq_options(); $questions[] = $this->get_faq_defaults(); $questions[] = $this->get_faq_animation(); $questions[] = $this->get_faq_reset(); return join("\n\n", $questions); } /** * Return the FAQ question "What options are available?" * * @return string */ private function get_faq_options(){ global $wp_settings_sections, $wp_settings_fields; if(!isset($wp_settings_sections[$this->settings_page])) return; $title = sprintf( $this->get_title_format(), __('What options are available?', $this->plugin_text_domain) ); $sections = array(); $i = 0; foreach((array)$wp_settings_sections[$this->settings_page] as $section) : $section_title = sprintf( $this->get_section_format(), $section['title'] ); $options = array(); foreach ((array)$wp_settings_fields[$this->settings_page][$section['id']] as $field) : $description = (isset($field['args']['control_args']['faq_description'])) // Check to see if a specific FAQ description has been declared... ? $field['args']['control_args']['faq_description'] // ...It has - use that : ((isset($field['args']['control_args']['description'])) // ...It has not - check to see if a control descritption has been declared... ? $field['args']['control_args']['description'] // ......It has - use that : __('Sorry, we can\'t find and details about this option.', $this->plugin_text_domain)); // ......It has not - lie to the user to cover up your mistake *whistles onchalantly* $options[].= sprintf( $this->get_option_format(), /** %1$s - The option title */ $field['title'], /** %2$s - The description to show the user */ $description ); endforeach; $sections[$i] = $section_title . join("\n", $options); $sections[$i] = $this->maybe_wrap($sections[$i], ''); $i++; endforeach; $question = $this->compile_question($title, $sections, "\n\n"); return $this->maybe_wrap($question, '
' ,'
'); } /** * Return the FAQ question "" * * @return string */ private function get_faq_defaults(){ global $wp_settings_sections, $wp_settings_fields; if(!isset($wp_settings_sections[$this->settings_page])) return; $title = sprintf( $this->get_title_format(), __('What are the option defaults?', $this->plugin_text_domain) ); $sections = array(); $i = 0; foreach((array)$wp_settings_sections[$this->settings_page] as $section) : $section_title = sprintf( $this->get_section_format(), $section['title'] ); $options = array(); foreach ((array)$wp_settings_fields[$this->settings_page][$section['id']] as $field) : $value = $this->options->get_default($field['id']); if(isset($field['args']['type']) && $field['args']['type'] === 'checkbox') $value = ($value == '1') ? 'Yes' : 'No'; if(isset($field['args']['type']) && $field['args']['type'] === 'select') $value = (isset($this->options->get_select($field['id'])[$value])) ? $this->options->get_select($field['id'])[$value] : $value; $options[].= sprintf( $this->get_option_format(), /** %1$s - The option title */ $field['title'], /** %2$s - The default value */ $value ); endforeach; $sections[$i] = $section_title . join("\n", $options); $sections[$i] = $this->maybe_wrap($sections[$i], ''); $i++; endforeach; $question = $this->compile_question($title, $sections, "\n\n"); return $this->maybe_wrap($question, '
' ,'
'); } /** * Return the FAQ question "Can I prevent the WordPress admin bar show/hide action from being animated?" * * @return string */ private function get_faq_animation(){ $title = sprintf( $this->get_title_format(), __('Can I prevent the WordPress admin bar show/hide action from being animated?', $this->plugin_text_domain) ); $parts = array( __('Yes, simply click on the', $this->plugin_text_domain), '' . __('Animate', $this->plugin_text_domain) . '', __('tab and uncheck the', $this->plugin_text_domain), '' . __('Animate action', $this->plugin_text_domain) . '', __('option.', $this->plugin_text_domain) ); $question = $this->compile_question($title, $parts); return $this->maybe_wrap($question, '
' ,'
'); } /** * Return the FAQ question "Can I restore the default settings?" * * @return string */ private function get_faq_reset(){ $title = sprintf( $this->get_title_format(), __('Can I restore the default settings?', $this->plugin_text_domain) ); $parts = array( __('You certainly can. Simply visit the plugin', $this->plugin_text_domain), $this->get_settings_link(), __('page', $this->plugin_text_domain), '(' . __('Settings » Admin Bar Button', $this->plugin_text_domain) . ')', __('scroll to the bottom and click Restore Defaults. You\'ll be asked to confirm that you wish to do this, and then all of the defaults will be restored.', $this->plugin_text_domain) ); $question = $this->compile_question($title, $parts); return $this->maybe_wrap($question, '
' ,'
'); } private function get_settings_link(){ if($this->for_readme) : $settings_link = '' . __('Settings', $this->plugin_text_domain) . ''; else : $settings_link = sprintf( '%3$s', admin_url('options-general.php?page=' . $this->settings_page), esc_attr__('Admin Bar Button settings', $this->plugin_text_domain), __('Settings', $this->plugin_text_domain) ); endif; return $settings_link; } /** * Return an FAQ question ready for display * * @param required string $title The title of the FAQ question * @param required string $content The content of the FAQ question * @param string $join_on The string to use for joining the $content (if it is an array) * @return string The compiled question */ private function compile_question($title, $content, $join_on = ' '){ if(is_array($content)) $content = join($join_on, $content); $content = $this->maybe_replace_tags(array('', ''), '**', $content); $content = $this->maybe_replace_tags(array('', ''), '*', $content); $question = $title . $this->maybe_wrap($content, '

' ,'

'); return $title . $content; } /** * Return the appropriate format to use when outputting an FAQ question title * * @return string */ private function get_title_format(){ return ($this->for_readme) ? '= %1$s ='."\n\n" : '

%1$s

'; } /** * Return the appropriate format to use when outputting a settings section * * @return string */ private function get_section_format(){ return ($this->for_readme) ? '***%1$s***'."\n\n" : '

%1$s

'; } /** * Return the appropriate format to use when outputting a settings option * * @return string */ private function get_option_format(){ return ($this->for_readme) ? '* **%1$s:** > %2$s' : '
  • %1$s: %2$s
  • '; } /** * Maybe wrap the text in the given tags * * @param required string $text The text to (maybe) wrap * @parma required boolean $for_readme Whether or not the text is for display in the readme * * */ private function maybe_wrap($text, $open_tag, $close_tag){ return ($this->for_readme) ? $text : $open_tag . $text . $close_tag; } private function maybe_replace_tags($search, $replace, $text){ if(!$this->for_readme) return $text; return str_replace($search, $replace, $text); } } ?>