Contact Form 7 Skins - Version 1.0.2

Version Description

  • 2015-05-29 =

  • FIX: wpcf7_add_meta_boxes action removed in Contact Form 7 4.2

  • FIX: Parse the CF7 shortcode ID in single or nested shortcodes

  • FIX: Ensure JavaScript finds active textarea

  • TWEAK: Add cf7skins_form_classes filter hook

Download this release

Release Info

Developer buzztone
Plugin Icon 128x128 Contact Form 7 Skins
Version 1.0.2
Comparing to
See all releases

Code changes from version 1.0.1 to 1.0.2

Files changed (6) hide show
  1. css/admin.css +25 -0
  2. includes/admin.php +28 -0
  3. includes/contact.php +29 -8
  4. index.php +2 -2
  5. js/jquery.admin.js +26 -4
  6. readme.txt +15 -8
css/admin.css CHANGED
@@ -232,6 +232,31 @@
232
  font-style: normal;
233
  }
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  /* Media query based on users screen size */
236
  @media only screen and (max-width: 1160px) {
237
  #cf7s .nav-tab-content .skin {
232
  font-style: normal;
233
  }
234
 
235
+ /* For CF7 >= 4.2 */
236
+ #cf7skins-42 h3 {
237
+ font-size: 14px;
238
+ line-height: 1.4;
239
+ margin: 0;
240
+ padding: 8px 12px;
241
+ cursor: default;
242
+ }
243
+ #cf7skins-42 .handlediv:before {
244
+ right: 12px;
245
+ font: normal 20px/1 'dashicons';
246
+ speak: none;
247
+ display: inline-block;
248
+ padding: 8px 10px;
249
+ top: 0;
250
+ position: relative;
251
+ -webkit-font-smoothing: antialiased;
252
+ -moz-osx-font-smoothing: grayscale;
253
+ text-decoration: none !important;
254
+ content: '\f142';
255
+ }
256
+ #cf7skins-42.closed .handlediv:before {
257
+ content: '\f140';
258
+ }
259
+
260
  /* Media query based on users screen size */
261
  @media only screen and (max-width: 1160px) {
262
  #cf7s .nav-tab-content .skin {
includes/admin.php CHANGED
@@ -21,6 +21,7 @@ class CF7_Skins_Admin {
21
 
22
  // Create the metabox for CF7 Skins
23
  add_action( 'wpcf7_add_meta_boxes', array( &$this, 'add_meta_boxes' ) );
 
24
 
25
  // Push the styles and scripts to the admin header
26
  add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
@@ -117,6 +118,33 @@ class CF7_Skins_Admin {
117
  }
118
 
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  /**
121
  * Display the skins metabox
122
  *
21
 
22
  // Create the metabox for CF7 Skins
23
  add_action( 'wpcf7_add_meta_boxes', array( &$this, 'add_meta_boxes' ) );
24
+ add_action( 'wpcf7_admin_footer', array( &$this, 'add_meta_boxes_42' ) );
25
 
26
  // Push the styles and scripts to the admin header
27
  add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
118
  }
119
 
120
 
121
+ /**
122
+ * Custom skins dialog added in the CF7 Footer for version 4.2
123
+ *
124
+ * @action wpcf7_admin_footer
125
+ * @param $post contact form object
126
+ * @since 1.0.1
127
+ */
128
+ function add_meta_boxes_42( $post ) {
129
+ if (version_compare(WPCF7_VERSION, '4.2') >= 0) {
130
+
131
+ // Create the container id for javascript pointer
132
+ // This is added if using add_meta_box() function
133
+ echo '<div class="wrap">';
134
+ echo '<div id="cf7skins-42" class="postbox">';
135
+ echo '<div title="'. __('Click to toggle', CF7SKINS_TEXTDOMAIN ) .'" class="handlediv"><br></div>';
136
+ echo '<h3 class="hndle"><span>'. __('Skins', CF7SKINS_TEXTDOMAIN ) .'</span></h3>';
137
+ echo '<div class="inside">';
138
+ echo '<div id="cf7s" class="cf7-42">';
139
+ $this->generate_tab( null, null ); // in tab.php
140
+ echo '</div>';
141
+ echo '</div>';
142
+ echo '</div>';
143
+ echo '</div>';
144
+ }
145
+ }
146
+
147
+
148
  /**
149
  * Display the skins metabox
150
  *
includes/contact.php CHANGED
@@ -39,25 +39,45 @@ class CF7_Skins_Contact {
39
 
40
  // Return if current page has no id
41
  if( ! isset( $post->ID ) )
42
- return;
43
 
 
 
 
 
 
 
 
 
 
 
44
  $tag = 'contact-form-7';
45
 
46
  // Return if there is no CF7 shortcode in post content
47
- if ( ! has_shortcode( $post->post_content , $tag ) )
48
- return;
49
 
50
  // Get all the CF7 form shortcodes in the post content
51
- preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER );
 
52
 
 
 
 
53
  // Loop through shortcodes, parse shortcode attributes and get the CF7 form ID
54
  foreach ( $matches as $shortcode ) {
55
- if ( $tag === $shortcode[2] ) {
 
56
  $atts = shortcode_parse_atts( $shortcode[3] );
57
- $ids[] = $atts['id']; // add the CF7 form ID
 
 
 
 
58
  }
 
59
  }
60
-
61
  // Return all the CF7 form ID
62
  if ( isset( $ids ) )
63
  return $ids;
@@ -160,9 +180,10 @@ class CF7_Skins_Contact {
160
 
161
  // CF7 Skins default class
162
  $cf7skins_class = ( $template_class || $skin_class ) ? ' cf7skins' : '';
 
163
 
164
  // Return the modified class
165
- return $class . $cf7skins_class . $template_class . $skin_class;
166
  }
167
 
168
 
39
 
40
  // Return if current page has no id
41
  if( ! isset( $post->ID ) )
42
+ return false;
43
 
44
+ return $this->parse_shortcode_id( $post->post_content );
45
+ }
46
+
47
+
48
+ /**
49
+ * Parse the CF7 shortcode ID in single or nested shortcodes
50
+ * @return (array) of CF7 id(s)
51
+ * @since 1.0.2
52
+ */
53
+ function parse_shortcode_id( $content ) {
54
  $tag = 'contact-form-7';
55
 
56
  // Return if there is no CF7 shortcode in post content
57
+ if ( ! has_shortcode( $content , $tag ) )
58
+ return false;
59
 
60
  // Get all the CF7 form shortcodes in the post content
61
+ // Use similar approach as wp-includes\shortcodes.php has_shortcode() function
62
+ preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
63
 
64
+ if ( empty( $matches ) )
65
+ return false;
66
+
67
  // Loop through shortcodes, parse shortcode attributes and get the CF7 form ID
68
  foreach ( $matches as $shortcode ) {
69
+
70
+ if ( $tag === $shortcode[2] ) {
71
  $atts = shortcode_parse_atts( $shortcode[3] );
72
+ $ids[] = $atts['id']; // Add the CF7 form ID
73
+
74
+ // Nested shortcode
75
+ } elseif ( ! empty( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) { // nested shortcodes
76
+ $shortcode = $this->parse_shortcode_id( $shortcode[5] );
77
  }
78
+
79
  }
80
+
81
  // Return all the CF7 form ID
82
  if ( isset( $ids ) )
83
  return $ids;
180
 
181
  // CF7 Skins default class
182
  $cf7skins_class = ( $template_class || $skin_class ) ? ' cf7skins' : '';
183
+ $cf7skins_classes = apply_filters( 'cf7skins_form_classes', $cf7skins_class );
184
 
185
  // Return the modified class
186
+ return $class . $cf7skins_classes . $template_class . $skin_class;
187
  }
188
 
189
 
index.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Contact Form 7 Skins
4
  * Plugin URI: http://cf7skins.com
5
  * Description: Adds Skins including Templates & Styles to Contact Form 7. Requires Contact Form 7.
6
- * Version: 1.0.1
7
  * Author: Neil Murray
8
  * Author URI: http://cf7skins.com
9
  * License: GPL-2.0+
@@ -44,7 +44,7 @@ if ( ! defined( 'ABSPATH' ) )
44
  *
45
  * @since 0.0.1
46
  */
47
- define( 'CF7SKINS_VERSION', '1.0.1' );
48
  define( 'CF7SKINS_SLUG', 'cf7skins' );
49
  define( 'CF7SKINS_TEXTDOMAIN', 'cf7skins' );
50
  define( 'CF7SKINS_FEATURE_FILTER', false ); // @since 0.4.0
3
  * Plugin Name: Contact Form 7 Skins
4
  * Plugin URI: http://cf7skins.com
5
  * Description: Adds Skins including Templates & Styles to Contact Form 7. Requires Contact Form 7.
6
+ * Version: 1.0.2
7
  * Author: Neil Murray
8
  * Author URI: http://cf7skins.com
9
  * License: GPL-2.0+
44
  *
45
  * @since 0.0.1
46
  */
47
+ define( 'CF7SKINS_VERSION', '1.0.2' );
48
  define( 'CF7SKINS_SLUG', 'cf7skins' );
49
  define( 'CF7SKINS_TEXTDOMAIN', 'cf7skins' );
50
  define( 'CF7SKINS_FEATURE_FILTER', false ); // @since 0.4.0
js/jquery.admin.js CHANGED
@@ -15,6 +15,14 @@
15
  var t = this, post_id;
16
  this.post_id = $("#post_ID").val();
17
 
 
 
 
 
 
 
 
 
18
  $("#cf7s .nav-tab:nth-child(1)").addClass("nav-tab-active");
19
  $("#cf7s .nav-tab-content > div:nth-child(1)").addClass("active");
20
  $("#cf7s .nav-tab").click( function(e) {
@@ -111,6 +119,12 @@
111
  return 'Changes have been made, are you sure you want to leave?';
112
  }
113
  }
 
 
 
 
 
 
114
  },
115
 
116
  tab : function(e) {
@@ -122,13 +136,21 @@
122
  },
123
 
124
  select : function(e) {
125
- var inp, pos, wrap, details, skin;
126
  skin = $(e).attr("data-value"),
127
- inp = $(e).attr("href");
128
  wrap = $(e).closest(".tab-content");
129
  $(inp).val(skin).trigger('change');
130
  details = $(e).closest(".details");
131
 
 
 
 
 
 
 
 
 
132
  // remove and add highlight to the selected skin
133
  $(".skin", wrap).removeClass("skin-selected");
134
  //$(e).closest(".skin").addClass("skin-selected");
@@ -146,7 +168,7 @@
146
  // pos = $("#wpcf7-form").position();
147
  // $("body, html").animate({ scrollTop: pos.top }, 800 );
148
 
149
- $("#wpcf7-form").val( l10n.loading );
150
 
151
  $.post( ajaxurl, {
152
  action: cf7s.load,
@@ -155,7 +177,7 @@
155
  locale: $(e).attr("data-locale"),
156
  nonce: cf7s.nonce
157
  }, function( data ) {
158
- $("#wpcf7-form").val( data ).trigger('change');
159
  });
160
  }
161
  },
15
  var t = this, post_id;
16
  this.post_id = $("#post_ID").val();
17
 
18
+ // Check if hidden input for template/style is inside the form
19
+ if ( $("#cf7s-template").parents("#wpcf7-admin-form-element").length == 1 ) {
20
+ // input is inside form
21
+ } else {
22
+ $("#wpcf7-admin-form-element").append( $("#cf7s-template") );
23
+ $("#wpcf7-admin-form-element").append( $("#cf7s-style") );
24
+ }
25
+
26
  $("#cf7s .nav-tab:nth-child(1)").addClass("nav-tab-active");
27
  $("#cf7s .nav-tab-content > div:nth-child(1)").addClass("active");
28
  $("#cf7s .nav-tab").click( function(e) {
119
  return 'Changes have been made, are you sure you want to leave?';
120
  }
121
  }
122
+
123
+ // Expand collapse skin box for CF7 >= 4.2
124
+ $('#cf7skins-42 .handlediv').click( function(e) {
125
+ e.stopPropagation();
126
+ $(this).parent('.postbox').toggleClass('closed');
127
+ });
128
  },
129
 
130
  tab : function(e) {
136
  },
137
 
138
  select : function(e) {
139
+ var inp, pos, wrap, details, skin, textarea;
140
  skin = $(e).attr("data-value"),
141
+ inp = $(e).attr("href"); // this is the hidden input for storing selected template/style
142
  wrap = $(e).closest(".tab-content");
143
  $(inp).val(skin).trigger('change');
144
  details = $(e).closest(".details");
145
 
146
+ // Default contact form editor id is #wpcf7-form
147
+ // In case if another plugins modify the textarea for cf7 editor, get the first visible textarea in the container
148
+ // Check if CF7 is above or 4.2
149
+ if ( $("#formdiv .half-left")[0] )
150
+ textarea = $("#formdiv .half-left").find('textarea').filter(':visible:first');
151
+ else
152
+ textarea = $("#wpcf7-admin-form-element").find('textarea').filter(':visible:first');
153
+
154
  // remove and add highlight to the selected skin
155
  $(".skin", wrap).removeClass("skin-selected");
156
  //$(e).closest(".skin").addClass("skin-selected");
168
  // pos = $("#wpcf7-form").position();
169
  // $("body, html").animate({ scrollTop: pos.top }, 800 );
170
 
171
+ $(textarea).val( l10n.loading );
172
 
173
  $.post( ajaxurl, {
174
  action: cf7s.load,
177
  locale: $(e).attr("data-locale"),
178
  nonce: cf7s.nonce
179
  }, function( data ) {
180
+ $(textarea).val( data ).trigger('change');
181
  });
182
  }
183
  },
readme.txt CHANGED
@@ -1,24 +1,24 @@
1
  === Contact Form 7 Skins ===
2
  Contributors: buzztone
3
  Tags: contact form 7, form, skin, template, style, html, css
4
- Requires at least: 4.0
5
- Tested up to: 4.2
6
- Stable tag: 1.0.1
7
  Author URI: http://cf7skins.com
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Makes styling of Contact Form 7 forms much easier – even if you don’t have HTML + CSS skills.
12
 
13
  == Description ==
14
 
15
- [CF7 Skins](http://cf7skins.com/) works right within the normal Contact Form 7 interface, making it easier for regular WordPress users to create professional looking Contact Form 7 forms using a range of compatible **Templates** and **Styles**.
16
 
17
- Simply select from a list of compatible Templates that cover many common forms and then choose a Style for your form from a range of professional and beautiful Styles.
18
 
19
  Each Template acts as an easy to follow guide, which can be adapted to your particular requirements. Every Style covers the full range of Contact Form 7 form elements.
20
 
21
- CF7 Skins is highly customizable and easy to learn, even for beginners. CF7 Skins makes building and styling Contact Form 7 forms much easier - even if you don't have HTML and CSS skills.
22
 
23
  = CF7 Skins Features =
24
 
@@ -94,9 +94,16 @@ Many questions have been answered on the [CF7 Skins FAQ](http://kb.cf7skins.com/
94
 
95
  == Changelog ==
96
 
 
 
 
 
 
 
 
97
  = 1.0.1 - 2015-05-06 =
98
 
99
- * FIX: Default CSS was overriding input & textarea Styles
100
 
101
  = 1.0 - 2015-04-01 =
102
 
1
  === Contact Form 7 Skins ===
2
  Contributors: buzztone
3
  Tags: contact form 7, form, skin, template, style, html, css
4
+ Requires at least: 4.1
5
+ Tested up to: 4.2.2
6
+ Stable tag: 1.0.2
7
  Author URI: http://cf7skins.com
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Makes building & styling of Contact Form 7 forms much easier – even if you don’t have HTML + CSS skills.
12
 
13
  == Description ==
14
 
15
+ [CF7 Skins](http://cf7skins.com/) works right within the Contact Form 7 interface, making it easier for regular WordPress users to create professional looking Contact Form 7 forms using a range of compatible **Templates** and **Styles**.
16
 
17
+ Simply select from a list of Templates that cover many common forms and then choose a Style for your form from a range of professional and beautiful Styles.
18
 
19
  Each Template acts as an easy to follow guide, which can be adapted to your particular requirements. Every Style covers the full range of Contact Form 7 form elements.
20
 
21
+ CF7 Skins is highly customizable and easy to learn, even for beginners.
22
 
23
  = CF7 Skins Features =
24
 
94
 
95
  == Changelog ==
96
 
97
+ = 1.0.2 - 2015-05-29 =
98
+
99
+ * FIX: wpcf7_add_meta_boxes action removed in Contact Form 7 4.2
100
+ * FIX: Parse the CF7 shortcode ID in single or nested shortcodes
101
+ * FIX: Ensure JavaScript finds active textarea
102
+ * TWEAK: Add cf7skins_form_classes filter hook
103
+
104
  = 1.0.1 - 2015-05-06 =
105
 
106
+ * FIX: Default CSS overriding input & textarea Styles
107
 
108
  = 1.0 - 2015-04-01 =
109