Accordion Shortcodes - Version 1.3.1

Version Description

  • Fixes an issue where an empty tag attribute would break the accordion
  • Tags are now checked against a list of valid HTML tags
Download this release

Release Info

Developer philbuchanan
Plugin Icon 128x128 Accordion Shortcodes
Version 1.3.1
Comparing to
See all releases

Code changes from version 1.3 to 1.3.1

Files changed (2) hide show
  1. accordion-shortcodes.php +38 -26
  2. readme.txt +9 -2
accordion-shortcodes.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Accordion Shortcodes
4
  * Description: Adds a few shortcodes to allow for accordion dropdowns.
5
- * Version: 1.3
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
@@ -12,8 +12,8 @@ if (!class_exists('Accordion_Shortcodes')) :
12
 
13
  class Accordion_Shortcodes {
14
 
15
- static $add_script;
16
- static $tag;
17
 
18
  function __construct() {
19
 
@@ -23,53 +23,64 @@ class Accordion_Shortcodes {
23
  load_plugin_textdomain('accordion_shortcodes', false, dirname($basename) . '/languages/');
24
 
25
  # Register JavaScript
26
- add_action('wp_enqueue_scripts', array(__CLASS__, 'register_script'));
27
 
28
  # Add shortcodes
29
- add_shortcode('accordion', array(__CLASS__, 'accordion_shortcode'));
30
- add_shortcode('accordion-item', array(__CLASS__, 'accordion_item_shortcode'));
31
 
32
  # Print script in wp_footer
33
- add_action('wp_footer', array(__CLASS__, 'print_script'));
34
 
35
  # Add link to documentation
36
- add_filter("plugin_action_links_$basename", array(__CLASS__, 'add_documentation_link'));
37
 
38
  }
39
 
40
  # Checks for boolean value
41
- static function parse_boolean($value) {
42
 
43
  return filter_var($value, FILTER_VALIDATE_BOOLEAN);
44
 
45
  }
46
 
47
  # Registers the minified accordion JavaScript file
48
- static function register_script() {
49
 
50
  $min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
51
- wp_register_script('accordion-shortcodes-script', plugins_url('accordion' . $min . '.js', __FILE__), array('jquery'), '1.3', true);
52
 
53
  }
54
 
55
  # Prints the minified accordion JavaScript file in the footer
56
- static function print_script() {
57
 
58
  # Check to see if shortcodes are used on page
59
- if (!self::$add_script) return;
60
 
61
  wp_enqueue_script('accordion-shortcodes-script');
62
 
63
  }
64
 
 
 
 
 
 
 
 
 
 
 
 
65
  # Accordion wrapper shortcode
66
- static function accordion_shortcode($atts, $content = null) {
67
 
68
  # The shortcode is used on the page, so we'll need to load the JavaScript
69
- self::$add_script = true;
70
 
71
  extract(shortcode_atts(array(
72
- 'tag' => 'h3',
73
  'autoclose' => true,
74
  'openfirst' => false,
75
  'openall' => false,
@@ -77,24 +88,25 @@ class Accordion_Shortcodes {
77
  'scroll' => false
78
  ), $atts, 'accordion'));
79
 
 
 
 
80
  # Set settings object (for use in JavaScript)
81
  $script_data = array(
82
- 'autoClose' => self::parse_boolean($autoclose),
83
- 'openFirst' => self::parse_boolean($openfirst),
84
- 'openAll' => self::parse_boolean($openall),
85
- 'clickToClose' => self::parse_boolean($clicktoclose),
86
- 'scroll' => self::parse_boolean($scroll)
87
  );
88
  wp_localize_script('accordion-shortcodes-script', 'accordionSettings', $script_data);
89
 
90
- self::$tag = $tag;
91
-
92
  return '<div class="accordion">' . do_shortcode($content) . '</div>';
93
 
94
  }
95
 
96
  # Accordion item shortcode
97
- static function accordion_item_shortcode($atts, $content = null) {
98
 
99
  extract(shortcode_atts(array(
100
  'title' => '',
@@ -104,13 +116,13 @@ class Accordion_Shortcodes {
104
  return sprintf('<%3$s class="accordion-title">%1$s</%3$s><div class="accordion-content">%2$s</div>',
105
  $title ? $title : '<span style="color:red;">' . __('Please enter a title attribute: [accordion-item title="Item title"]', 'accordion_shortcodes') . '</span>',
106
  do_shortcode($content),
107
- $tag ? $tag : self::$tag
108
  );
109
 
110
  }
111
 
112
  # Add documentation link on plugin page
113
- static function add_documentation_link($links) {
114
 
115
  array_push($links, sprintf('<a href="%s">%s</a>',
116
  'http://wordpress.org/plugins/accordion-shortcodes/',
2
  /**
3
  * Plugin Name: Accordion Shortcodes
4
  * Description: Adds a few shortcodes to allow for accordion dropdowns.
5
+ * Version: 1.3.1
6
  * Author: Phil Buchanan
7
  * Author URI: http://philbuchanan.com
8
  */
12
 
13
  class Accordion_Shortcodes {
14
 
15
+ private $add_script = false;
16
+ private $tag = 'h3';
17
 
18
  function __construct() {
19
 
23
  load_plugin_textdomain('accordion_shortcodes', false, dirname($basename) . '/languages/');
24
 
25
  # Register JavaScript
26
+ add_action('wp_enqueue_scripts', array($this, 'register_script'));
27
 
28
  # Add shortcodes
29
+ add_shortcode('accordion', array($this, 'accordion_shortcode'));
30
+ add_shortcode('accordion-item', array($this, 'accordion_item_shortcode'));
31
 
32
  # Print script in wp_footer
33
+ add_action('wp_footer', array($this, 'print_script'));
34
 
35
  # Add link to documentation
36
+ add_filter("plugin_action_links_$basename", array($this, 'add_documentation_link'));
37
 
38
  }
39
 
40
  # Checks for boolean value
41
+ private function parse_boolean($value) {
42
 
43
  return filter_var($value, FILTER_VALIDATE_BOOLEAN);
44
 
45
  }
46
 
47
  # Registers the minified accordion JavaScript file
48
+ public function register_script() {
49
 
50
  $min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
51
+ wp_register_script('accordion-shortcodes-script', plugins_url('accordion' . $min . '.js', __FILE__), array('jquery'), '1.3.1', true);
52
 
53
  }
54
 
55
  # Prints the minified accordion JavaScript file in the footer
56
+ public function print_script() {
57
 
58
  # Check to see if shortcodes are used on page
59
+ if (!$this -> add_script) return;
60
 
61
  wp_enqueue_script('accordion-shortcodes-script');
62
 
63
  }
64
 
65
+ # Check for valid HTML tag
66
+ private function check_html_tag($tag) {
67
+
68
+ $tag = preg_replace('/\s/', '', $tag);
69
+ $tags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'div');
70
+
71
+ if (in_array($tag, $tags)) return $tag;
72
+ else return 'h3';
73
+
74
+ }
75
+
76
  # Accordion wrapper shortcode
77
+ public function accordion_shortcode($atts, $content = null) {
78
 
79
  # The shortcode is used on the page, so we'll need to load the JavaScript
80
+ $this -> add_script = true;
81
 
82
  extract(shortcode_atts(array(
83
+ 'tag' => '',
84
  'autoclose' => true,
85
  'openfirst' => false,
86
  'openall' => false,
88
  'scroll' => false
89
  ), $atts, 'accordion'));
90
 
91
+ # Set global tag
92
+ if ($tag) $this -> tag = $this -> check_html_tag($tag);
93
+
94
  # Set settings object (for use in JavaScript)
95
  $script_data = array(
96
+ 'autoClose' => $this -> parse_boolean($autoclose),
97
+ 'openFirst' => $this -> parse_boolean($openfirst),
98
+ 'openAll' => $this -> parse_boolean($openall),
99
+ 'clickToClose' => $this -> parse_boolean($clicktoclose),
100
+ 'scroll' => $this -> parse_boolean($scroll)
101
  );
102
  wp_localize_script('accordion-shortcodes-script', 'accordionSettings', $script_data);
103
 
 
 
104
  return '<div class="accordion">' . do_shortcode($content) . '</div>';
105
 
106
  }
107
 
108
  # Accordion item shortcode
109
+ public function accordion_item_shortcode($atts, $content = null) {
110
 
111
  extract(shortcode_atts(array(
112
  'title' => '',
116
  return sprintf('<%3$s class="accordion-title">%1$s</%3$s><div class="accordion-content">%2$s</div>',
117
  $title ? $title : '<span style="color:red;">' . __('Please enter a title attribute: [accordion-item title="Item title"]', 'accordion_shortcodes') . '</span>',
118
  do_shortcode($content),
119
+ $tag ? $this -> check_html_tag($tag) : $this -> tag
120
  );
121
 
122
  }
123
 
124
  # Add documentation link on plugin page
125
+ public function add_documentation_link($links) {
126
 
127
  array_push($links, sprintf('<a href="%s">%s</a>',
128
  'http://wordpress.org/plugins/accordion-shortcodes/',
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate Link: http://philbuchanan.com/
5
  Tags: accordion, accordions, shortcodes
6
  Requires at least: 3.3
7
  Tested up to: 3.9
8
- Stable tag: 1.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -126,13 +126,17 @@ There are a few advanced settings you can add to the opening accordion shortcode
126
 
127
  **tag**: Set the global HTML tag to use for all accordion titles. Set `tag="h2"` on the opening accordion tag like this: `[accordion tag="h2"]`. Default is `h3`.
128
 
129
- You can also set the HTML tag for the titles of each accordion item individually by adding `tag="tagname"` to each `[accordion-item]` shortcode. Make sure to **not** include the angle brackets around the tag name. Example: to use `<h2>` instead of the default `<h3>` tag: `[accordion-item title="Item title" tag="h2"]Item content[/accordion-item]`. Using a tag attribue on an individual accordion item will override the global setting.
130
 
131
  = Issues/Suggestions =
132
 
133
  For bug reports or feature requests or if you'd like to contribute to the plugin you can check everything out on [Github](https://github.com/philbuchanan/Accordion-Shortcodes/).
134
 
135
  == Changelog ==
 
 
 
 
136
  = 1.3 =
137
  * Added global HTML tag setting for accordion item titles
138
 
@@ -186,6 +190,9 @@ For bug reports or feature requests or if you'd like to contribute to the plugin
186
  * Initial release
187
 
188
  == Upgrade Notice ==
 
 
 
189
  = 1.3 =
190
  Added global HTML tag setting for accordion item titles.
191
 
5
  Tags: accordion, accordions, shortcodes
6
  Requires at least: 3.3
7
  Tested up to: 3.9
8
+ Stable tag: 1.3.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
126
 
127
  **tag**: Set the global HTML tag to use for all accordion titles. Set `tag="h2"` on the opening accordion tag like this: `[accordion tag="h2"]`. Default is `h3`.
128
 
129
+ You can also set the HTML tag for the titles of each accordion item individually by adding `tag="tagname"` to each `[accordion-item]` shortcode. Make sure to **not** include the angle brackets around the tag name. Example: to use `<h2>` instead of the default `<h3>` tag: `[accordion-item title="Item title" tag="h2"]Item content[/accordion-item]`. Using a tag attribue on an individual accordion item will override the global setting. The list of valid tags is: h1, h2, h3, h4, h5, h6, p, span and div.
130
 
131
  = Issues/Suggestions =
132
 
133
  For bug reports or feature requests or if you'd like to contribute to the plugin you can check everything out on [Github](https://github.com/philbuchanan/Accordion-Shortcodes/).
134
 
135
  == Changelog ==
136
+ = 1.3.1 =
137
+ * Fixes an issue where an empty tag attribute would break the accordion
138
+ * Tags are now checked against a list of valid HTML tags
139
+
140
  = 1.3 =
141
  * Added global HTML tag setting for accordion item titles
142
 
190
  * Initial release
191
 
192
  == Upgrade Notice ==
193
+ = 1.3.1 =
194
+ IMPORTANT: Tags are now checked against a list of valid HTML tags. If you use a tag other than h1, h2, h3, h4, h5, h6, p, span or div for your titles, please let me know. You will want to avoid this update until I add your tag to the list. This update also fixes an issue where an empty tag attribute would break the accordion.
195
+
196
  = 1.3 =
197
  Added global HTML tag setting for accordion item titles.
198