Contact Form 7 Skins - Version 2.1.3

Version Description

  • 2019-07-03 =

  • TWEAK: Enable export of individual form.

Download this release

Release Info

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

Code changes from version 2.1.2 to 2.1.3

Files changed (4) hide show
  1. includes/export.php +169 -0
  2. includes/settings.php +7 -0
  3. index.php +6 -5
  4. readme.txt +5 -1
includes/export.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * CF7 Skins Export Utility Class.
4
+ *
5
+ * Method:
6
+ * 1. Create a Export button in CF7 Status section.
7
+ * 2. Setup export_wp() parameters by using post status and 'page' post type.
8
+ * 3. Modify SQL query to replace post status with post ID, and 'page' post type with
9
+ * CF7 post type.
10
+ * 4. Setup different export file name.
11
+ *
12
+ * @package cf7skins
13
+ * @author Neil Murray
14
+ *
15
+ * @since 2.1.3
16
+ */
17
+
18
+ class CF7_Skins_Export {
19
+
20
+ var $textdomain;
21
+
22
+ /**
23
+ * Class constructor
24
+ *
25
+ * @since 2.1.3
26
+ */
27
+ function __construct() {
28
+ $this->textdomain = CF7SKINS_TEXTDOMAIN;
29
+
30
+ add_action( 'wpcf7_admin_misc_pub_section', array( $this, 'export_button' ), 1, 1 );
31
+ add_action( 'wpcf7_admin_init', array( $this, 'export_wxr' ) );
32
+
33
+ add_filter( 'query', array( $this, 'export_query' ) );
34
+ add_filter( 'export_wp_filename', array( $this, 'export_filename' ), 1, 3 );
35
+ }
36
+
37
+ /**
38
+ * Add export button in CF7 Status section - not for a new form.
39
+ *
40
+ * @param {String} $post_id current form id
41
+ *
42
+ * @since 2.1.3
43
+ */
44
+ function export_button( $post_id ) {
45
+ if ( $post_id == '-1' ) { // not for a new form
46
+ return;
47
+ }
48
+
49
+ // Create the button, and set onclick to set action value different from 'save'.
50
+ // https://plugins.trac.wordpress.org/browser/contact-form-7/trunk/admin/edit-contact-form.php#L18
51
+ // The 'save' action is used to show the spinner, thus avoid the spinner being shown.
52
+ ?>
53
+ <div style="padding:0 10px 10px 10px; text-align:right">
54
+ <input type="submit" name="cf7skins-export"
55
+ title="<?php _e( 'Export this form and data to WXR format.', $this->textdomain ); ?>"
56
+ class="button" value="<?php _e( 'Export Form', $this->textdomain ); ?>"
57
+ onclick="this.form.action.value = 'export'; return true;"
58
+ />
59
+ </div>
60
+ <?php
61
+ }
62
+
63
+ /**
64
+ * Do export to WXR (WordPress eXtended RSS) after updating form.
65
+ *
66
+ * WordPress WXR Export works based on post_ids array.
67
+ * It loops for the post_ids and generete the WXR content.
68
+ * Unfortunately there is no filter/hook to change it.
69
+ * https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/export.php#L141.
70
+ * The post_ids can be changed by modifying the SQL statement before retrieving the post_ids,
71
+ * https://github.com/WordPress/WordPress/blob/master/wp-includes/wp-db.php#L1871.
72
+ * To help distinguish which one is the export query, we provide custom export parameter
73
+ * by adding post status 'cf7skins_export'. The good news, the post status accepts any status,
74
+ * even if it is not registered, but needs to use 'post/page' post type.
75
+ * https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/export.php#L113
76
+ *
77
+ * @param {Class/Object} $cf7 WPCF7_ContactForm
78
+ *
79
+ * @since 2.1.3
80
+ */
81
+ function export_wxr() {
82
+
83
+ // Return if this is not exporting
84
+ if ( ! isset( $_POST['cf7skins-export'] ) ) {
85
+ return;
86
+ }
87
+
88
+ require_once( ABSPATH . 'wp-admin/includes/export.php' );
89
+
90
+ $args = array();
91
+
92
+ // The post type, will be replaced with 'wpcf7_contact_form' later.
93
+ $args['content'] = 'page';
94
+
95
+ // Post status, will be replaced with ID and current form ID later.
96
+ $args['status'] = 'cf7skins_export';
97
+
98
+ export_wp( $args ); // do export
99
+ die(); // exit after downloading exported file
100
+ }
101
+
102
+ /**
103
+ * Modify the export query.
104
+ *
105
+ * Query: SELECT ID FROM wp_posts WHERE wp_posts.post_type = 'page'
106
+ * AND wp_posts.post_status = 'cf7skins_export'
107
+ *
108
+ * @param {String} $query SQL query
109
+ *
110
+ * @return modified query with cf7 post type and current form id, for example:
111
+ * ... wp_posts.post_type = 'wpcf7_contact_form' AND wp_posts.ID = '1821'
112
+ *
113
+ * @since 2.1.3
114
+ */
115
+ function export_query( $query ) {
116
+
117
+ // Make sure this is requested in CF7 edit form and not a new created form
118
+ if ( isset( $_GET['page'] ) && isset( $_GET['post'] ) ) {
119
+
120
+ $form_id = (int) $_GET['post']; // set form id
121
+
122
+ // Check if this query is our export query.
123
+ // Query contains 'SELECT ID FROM' and 'cf7skins_export' string in it.
124
+ // Take attention for double quotes in query.
125
+ if ( strpos( $query, 'SELECT ID FROM' ) !== false && strpos( $query, 'cf7skins_export' ) ) {
126
+
127
+ // Replace post type from page with wpcf7_contact_form
128
+ $query = str_replace( ".post_type = 'page'", ".post_type = 'wpcf7_contact_form'", $query );
129
+
130
+ // Replace post status with ID and set the value to current form ID
131
+ $query = str_replace( ".post_status = 'cf7skins_export'", ".ID = '{$form_id}'", $query );
132
+ }
133
+ }
134
+
135
+ return $query;
136
+ }
137
+
138
+ /**
139
+ * Modify the exported file name.
140
+ *
141
+ * Default: mysite.wordpress.2019-06-26.xml;
142
+ *
143
+ * @param {String} $wp_filename The name of the file for download.
144
+ * @param {String} $sitename The site name.
145
+ * @param {String} $date Today's date, formatted.
146
+ *
147
+ * @return modified filename cf7skins.mysite.2019-06-26.xml
148
+ *
149
+ * @since 2.1.3
150
+ */
151
+ function export_filename( $wp_filename, $sitename, $date ) {
152
+
153
+ // Only in CF7 edit page, and not for new form.
154
+ // Logic is used twice (see above), consider using a new function?
155
+ if ( isset( $_GET['page'] ) && isset( $_GET['post'] ) ) {
156
+ $wp_filename = 'cf7skins.' . $sitename . $date . '.xml';
157
+ }
158
+
159
+ return $wp_filename;
160
+ }
161
+ }
162
+
163
+ // Get CF7 Skins settings
164
+ $option = get_option( CF7SKINS_OPTIONS );
165
+
166
+ // Run this class if feature is enabled
167
+ if ( isset( $option['export'] ) && !! $option['export'] ) {
168
+ new CF7_Skins_Export();
169
+ }
includes/settings.php CHANGED
@@ -209,6 +209,13 @@ class CF7_Skins_Settings {
209
  'detail' => __( 'Displays plugin log tab.', $this->textdomain ),
210
  ),
211
  */
 
 
 
 
 
 
 
212
  'delete_data' => array(
213
  'section' => 'advanced',
214
  'label' => __( 'Delete Settings', $this->textdomain ),
209
  'detail' => __( 'Displays plugin log tab.', $this->textdomain ),
210
  ),
211
  */
212
+ 'export' => array( /* @since 2.1.3 */
213
+ 'section' => 'advanced',
214
+ 'label' => __( 'Export Form', $this->textdomain ),
215
+ 'type' => 'checkbox',
216
+ 'default' => false,
217
+ 'detail' => __( 'Enable export for individual form.', $this->textdomain ),
218
+ ),
219
  'delete_data' => array(
220
  'section' => 'advanced',
221
  'label' => __( 'Delete Settings', $this->textdomain ),
index.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Contact Form 7 Skins
4
  * Plugin URI: http://cf7skins.com
5
  * Description: Adds drag & drop Visual Editor with Templates & Styles to Contact Form 7. Requires Contact Form 7.
6
- * Version: 2.1.2
7
  * Author: Neil Murray
8
  * Author URI: http://cf7skins.com
9
  * License: GPL-2.0+
@@ -13,7 +13,7 @@
13
  *
14
  * @package cf7skins
15
  * @author Neil Murray
16
- * @copyright Copyright (c) 2014-2018 Neil Murray
17
  */
18
 
19
  /**
@@ -30,7 +30,7 @@ if ( ! defined( 'ABSPATH' ) ) {
30
  *
31
  * @since 0.1.0
32
  */
33
- define( 'CF7SKINS_VERSION', '2.1.2' );
34
  define( 'CF7SKINS_OPTIONS', 'cf7skins' ); // Database option names
35
  define( 'CF7SKINS_TEXTDOMAIN', 'contact-form-7-skins' );
36
  define( 'CF7SKINS_FEATURE_FILTER', false ); // @since 0.4.0
@@ -172,13 +172,14 @@ function cf7skins_plugin_loaded() {
172
 
173
  if ( is_admin() ) {
174
  require_once( CF7SKINS_PATH . 'includes/admin.php' );
175
- require_once( CF7SKINS_PATH . 'includes/admin-visual.php' ); // @since 2.0.0
176
  require_once( CF7SKINS_PATH . 'includes/license.php' );
177
  require_once( CF7SKINS_PATH . 'includes/tab.php' );
178
  require_once( CF7SKINS_PATH . 'includes/settings.php' );
179
  require_once( CF7SKINS_PATH . 'includes/admin-notice.php' );
 
180
  } else {
181
- require_once( CF7SKINS_PATH . 'includes/front-visual.php' ); // @since 2.0.0
182
  }
183
 
184
  if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
3
  * Plugin Name: Contact Form 7 Skins
4
  * Plugin URI: http://cf7skins.com
5
  * Description: Adds drag & drop Visual Editor with Templates & Styles to Contact Form 7. Requires Contact Form 7.
6
+ * Version: 2.1.3
7
  * Author: Neil Murray
8
  * Author URI: http://cf7skins.com
9
  * License: GPL-2.0+
13
  *
14
  * @package cf7skins
15
  * @author Neil Murray
16
+ * @copyright Copyright (c) 2014-2019
17
  */
18
 
19
  /**
30
  *
31
  * @since 0.1.0
32
  */
33
+ define( 'CF7SKINS_VERSION', '2.1.3' );
34
  define( 'CF7SKINS_OPTIONS', 'cf7skins' ); // Database option names
35
  define( 'CF7SKINS_TEXTDOMAIN', 'contact-form-7-skins' );
36
  define( 'CF7SKINS_FEATURE_FILTER', false ); // @since 0.4.0
172
 
173
  if ( is_admin() ) {
174
  require_once( CF7SKINS_PATH . 'includes/admin.php' );
175
+ require_once( CF7SKINS_PATH . 'includes/admin-visual.php' );
176
  require_once( CF7SKINS_PATH . 'includes/license.php' );
177
  require_once( CF7SKINS_PATH . 'includes/tab.php' );
178
  require_once( CF7SKINS_PATH . 'includes/settings.php' );
179
  require_once( CF7SKINS_PATH . 'includes/admin-notice.php' );
180
+ require_once( CF7SKINS_PATH . 'includes/export.php' );
181
  } else {
182
+ require_once( CF7SKINS_PATH . 'includes/front-visual.php' );
183
  }
184
 
185
  if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: contact form 7, drag & drop form editor, contact form 7 template, contact
4
  Requires at least: 4.3
5
  Tested up to: 5.2
6
  Requires PHP: 5.6
7
- Stable tag: 2.1.2
8
  Author URI: https://cf7skins.com
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -122,6 +122,10 @@ Absolutely not. You can create and manage Contact Form 7 forms without any codin
122
 
123
  == Changelog ==
124
 
 
 
 
 
125
  = 2.1.2 - 2019-04-11 =
126
 
127
  * FIX: Encode to UTF-8 when loading HTML
4
  Requires at least: 4.3
5
  Tested up to: 5.2
6
  Requires PHP: 5.6
7
+ Stable tag: 2.1.3
8
  Author URI: https://cf7skins.com
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
122
 
123
  == Changelog ==
124
 
125
+ = 2.1.3 - 2019-07-03 =
126
+
127
+ * TWEAK: Enable export of individual form.
128
+
129
  = 2.1.2 - 2019-04-11 =
130
 
131
  * FIX: Encode to UTF-8 when loading HTML