PluginProbe
Smart Grid-Layout Design for Contact Form 7 / 4.11
Smart Grid-Layout Design for Contact Form 7 v4.11
4.18.0 4.17.0 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 4.0.0 4.0.1 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10 4.11 4.12 4.13 4.14 All 119 releases
cf7-grid-layout / includes / class-cf7-grid-layout.php

class-cf7-grid-layout.php in Smart Grid-Layout Design for Contact Form 7 4.11, at includes/class-cf7-grid-layout.php

366 lines 15.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The file that defines the core plugin class
5 *
6 * A class definition that includes attributes and functions used across both the
7 * public-facing side of the site and the admin area.
8 *
9 * @link http://syllogic.in
10 * @since 1.0.0
11 *
12 * @package Cf7_Grid_Layout
13 * @subpackage Cf7_Grid_Layout/includes
14 */
15
16 /**
17 * The core plugin class.
18 *
19 * This is used to define internationalization, admin-specific hooks, and
20 * public-facing site hooks.
21 *
22 * Also maintains the unique identifier of this plugin as well as the current
23 * version of the plugin.
24 *
25 * @since 1.0.0
26 * @package Cf7_Grid_Layout
27 * @subpackage Cf7_Grid_Layout/includes
28 * @author Aurovrata V. <vrata@syllogic.in>
29 */
30 class Cf7_Grid_Layout {
31
32 /**
33 * The loader that's responsible for maintaining and registering all hooks that power
34 * the plugin.
35 *
36 * @since 1.0.0
37 * @access protected
38 * @var Cf7_Grid_Layout_Loader $loader Maintains and registers all hooks for the plugin.
39 */
40 protected $loader;
41
42 /**
43 * The unique identifier of this plugin.
44 *
45 * @since 1.0.0
46 * @access protected
47 * @var string $plugin_name The string used to uniquely identify this plugin.
48 */
49 protected $plugin_name;
50
51 /**
52 * The current version of the plugin.
53 *
54 * @since 1.0.0
55 * @access protected
56 * @var string $version The current version of the plugin.
57 */
58 protected $version;
59
60 /**
61 * Define the core functionality of the plugin.
62 *
63 * Set the plugin name and the plugin version that can be used throughout the plugin.
64 * Load the dependencies, define the locale, and set the hooks for the admin area and
65 * the public-facing side of the site.
66 *
67 * @since 1.0.0
68 */
69 public function __construct($version) {
70
71 $this->plugin_name = 'cf7-grid-layout';
72 $this->version = $version;
73
74 $this->load_dependencies();
75 $this->set_locale();
76 $this->define_admin_hooks();
77 $this->define_public_hooks();
78 $stored_version = get_option('_cf7sg_version', '1.2.2');
79 if('1.2.2' === $stored_version){
80 $this->upgrade_db();
81 }
82 update_option('_cf7sg_version', $version);
83 }
84 /**
85 *Function to update the DB for v1.2.3 to ensure cf7sg managed forms are properly tagged as such.
86 *
87 *@since 1.2.3
88 */
89 private function upgrade_db(){
90 global $wpdb;
91 $rows = $wpdb->get_results(
92 "SELECT post_id
93 FROM $wpdb->postmeta
94 WHERE meta_key LIKE '_cf7sg_has_tables'"
95 );
96 foreach($rows as $row){
97 update_post_meta($row->post_id, '_cf7sg_managed_form', true);
98 }
99 }
100
101 /**
102 * Load the required dependencies for this plugin.
103 *
104 * Include the following files that make up the plugin:
105 *
106 * - Cf7_Grid_Layout_Loader. Orchestrates the hooks of the plugin.
107 * - Cf7_Grid_Layout_i18n. Defines internationalization functionality.
108 * - Cf7_Grid_Layout_Admin. Defines all hooks for the admin area.
109 * - Cf7_Grid_Layout_Public. Defines all hooks for the public side of the site.
110 *
111 * Create an instance of the loader which will be used to register the hooks
112 * with WordPress.
113 *
114 * @since 1.0.0
115 * @access private
116 */
117 private function load_dependencies() {
118
119 /**
120 * The class responsible for orchestrating the actions and filters of the
121 * core plugin.
122 */
123 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cf7-grid-layout-loader.php';
124 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/wordpress-gurus-debug-api.php';
125 /** @since 5.0 dynamic tags interface */
126 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cf7sg-dynamic-list.php';
127
128 /**
129 * The class responsible for defining internationalization functionality
130 * of the plugin.
131 */
132 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cf7-grid-layout-i18n.php';
133
134 /**
135 * The class responsible for defining all actions that occur in the admin area.
136 */
137 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-cf7-grid-layout-admin.php';
138 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'assets/cf7-admin-table/cf7-admin-table-loader.php';
139 /**
140 * Persist admin notices:
141 * @since 4.0.2
142 */
143 require_once plugin_dir_path( dirname( __FILE__ ) ) . '/assets/persist-admin-notices/persist-admin-notices-dismissal.php';
144 /**
145 * The class responsible for defining all actions that occur in the public-facing
146 * side of the site.
147 */
148 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-cf7-grid-layout-public.php';
149
150 $this->loader = new Cf7_Grid_Layout_Loader();
151
152 }
153
154 /**
155 * Define the locale for this plugin for internationalization.
156 *
157 * Uses the Cf7_Grid_Layout_i18n class in order to set the domain and to register the hook
158 * with WordPress.
159 *
160 * @since 1.0.0
161 * @access private
162 */
163 private function set_locale() {
164
165 $plugin_i18n = new Cf7_Grid_Layout_i18n();
166
167 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
168
169 }
170
171 /**
172 * Register all of the hooks related to the admin area functionality
173 * of the plugin.
174 *
175 * @since 1.0.0
176 * @access private
177 */
178 private function define_admin_hooks() {
179
180 $plugin_admin = new Cf7_Grid_Layout_Admin( $this->get_plugin_name(), $this->get_version() );
181
182 //enqueue styles
183 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
184 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
185 // @since 1.5.0 hack to enqueue js/css for other cf7 extensions.
186 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'popular_extentions_scripts', 999,0);
187 $this->loader->add_action( 'admin_print_scripts', $plugin_admin, 'print_extentions_scripts', 1,0);
188 //add new sub-menu
189 $this->loader->add_action('admin_menu', $plugin_admin, 'add_cf7_sub_menu');
190 $this->loader->add_filter( 'custom_menu_order', $plugin_admin, 'change_cf7_submenu_order' );
191 //modify cf7 post type
192 $this->loader->add_action('register_post_type_args', $plugin_admin, 'modify_cf7_post_type_args' , 20, 2 );
193 //register dynamic dropdown taxonomy with cf7 post
194 $this->loader->add_action('init', $plugin_admin, 'register_dynamic_dropdown_taxonomy' , 20, 2 );
195 //$this->loader->add_action('init', $plugin_admin, 'modify_cf7_post_type' , 20 );
196 //add some metabox to the wpcf7_contact_form post type
197 $this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'edit_page_metabox' );
198 /** @since 4.6.0 hide author metabox by default */
199 $this->loader->add_filter('hidden_meta_boxes', $plugin_admin, 'hide_author_metabox',10,3);
200 //save the post
201 $this->loader->add_action('save_post_wpcf7_contact_form', $plugin_admin, 'save_post', 10,3);
202 /** delete post @since 4.3.0 */
203 $this->loader->add_action('before_delete_post', $plugin_admin, 'delete_post');
204 //ajax load cf7 form content
205 $this->loader->add_action('wp_ajax_get_cf7_content', $plugin_admin, 'get_cf7_content');
206 //hook for adding fields to sumit action metabox
207 $this->loader->add_filter('post_submitbox_misc_actions', $plugin_admin, 'cf7_post_submit_action' ,10);
208 //cusotm sanitation rules for forms
209 $this->loader->add_filter('wp_kses_allowed_html', $plugin_admin, 'custom_kses_rules' ,10, 2);
210 /**
211 * @since 2.1.0 make sure our dependent plugins exists.*/
212 $this->loader->add_action( 'admin_init', $plugin_admin, 'check_plugin_dependency');
213 /**
214 *@since 2.3.0 redirect post.php for form duplicate*/
215 $this->loader->add_filter('admin_init', $plugin_admin, 'duplicate_cf7_form');
216 /** @since 2.6.0*/
217 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'pretty_admin_pointers' );
218 $this->loader->add_action( 'cf7sg_plugin_pointers-edit-wpcf7_contact_form', $plugin_admin, 'edit_pointers',10,2 );
219 /** @since 3.0.0 */
220 $this->loader->add_action( 'cf7sg_plugin_pointers-wpcf7_contact_form', $plugin_admin, 'post_pointers',10,2 );
221 /*
222 CF7 Hooks
223 */
224 //save cf7 form post
225 $this->loader->add_action( 'wpcf7_save_contact_form', $plugin_admin, 'save_factory_metas' , 10, 1);
226 //print submit metabox
227 $this->loader->add_action( 'wpcf7_admin_misc_pub_section', $plugin_admin, 'dynamic_select_choices' , 10, 1);
228 $this->loader->add_action( 'wpcf7_admin_init', $plugin_admin, 'cf7_shortcode_tags' );
229 //modify the default form template
230 $this->loader->add_filter( 'wpcf7_default_template', $plugin_admin, 'default_cf7_form' , 5,2);
231 /** @since 2.6.0*/
232 $this->loader->add_filter( 'wpcf7_messages', $plugin_admin, 'disabled_message' , 5,2);
233 /** @since 3.0.0 */
234 $this->loader->add_filter( 'wpcf7_map_meta_cap', $plugin_admin, 'reset_meta_cap' , 5,1);
235 //make sure users that cannot publish forms are set to pending.
236 $this->loader->add_filter( 'wp_insert_post_data', $plugin_admin, 'pending_for_review',10,2);
237 //add all form capabilities to editor role.
238 $this->loader->add_action( 'admin_init', $plugin_admin, 'enable_cf7_editor_role', 5,0 );
239 /** @since 3.3.0 helper hooks added via action hook */
240 $this->loader->add_action( 'cf7sg_ui_grid_helper_hooks', $plugin_admin, 'print_helper_hooks');
241 /** @since 4.0.0 include default js template */
242 $this->loader->add_action( 'cf7sg_default_custom_js_template', $plugin_admin, 'print_default_js', 1,1);
243 /** @since 4.0.0 enable toggle mail tags */
244 $this->loader->add_filter( 'wpcf7_collect_mail_tags', $plugin_admin, 'setup_cf7_mailtags');
245 /** persist admin notices plugin. @since 4.1.0 */
246 $this->loader->add_action( 'admin_init', 'PAnD', 'init' );
247 $this->loader->add_action( 'admin_init', $plugin_admin, 'init_notices' );
248 $this->loader->add_action( 'admin_notices', $plugin_admin, 'admin_notices' );
249 $this->loader->add_action('wp_ajax_validate_cf7sg_version_update', $plugin_admin, 'validate_cf7sg_version_update');
250 $this->loader->add_filter('upgrader_post_install', $plugin_admin, 'post_plugin_upgrade',10,3);
251 /** @since 4.3.0 enable previews/views of forms */
252 $this->loader->add_action( 'init', $plugin_admin, 'register_form_preview_posttype', 0 );
253 /** @since 4.4 load translation files */
254 $this->loader->add_action( 'cf7pll_load_plugin_translation_resource', $plugin_admin, 'load_translation_files');
255 /** @since 4.11.0 build dynamic list tag generator */
256 $this->loader->add_action( 'cf7sg_display_dynamic_list_tag_manager', $plugin_admin, 'print_dynamic_list_generator', 5, 4);
257 $this->loader->add_action( 'cf7sg_save_dynamic_list_form_classes', $plugin_admin, 'save_dynamic_list_form_classes', 5, 3);
258 $this->loader->add_action( 'cf7sg_dynamic_tag_manager_taxonomy_source', $plugin_admin, 'add_taxonomy_imagegrid_hook');
259 // $this->loader->add_action( 'wpcf7_config_validator_validate', $plugin_admin, 'cf7_form_validation', 10, 1);
260
261 }
262
263 /**
264 * Register all of the hooks related to the public-facing functionality
265 * of the plugin.
266 *
267 * @since 1.0.0
268 * @access private
269 */
270 private function define_public_hooks() {
271
272 $plugin_public = new Cf7_Grid_Layout_Public( $this->get_plugin_name(), $this->get_version() );
273
274 //register front-end scripts for CF7 forms
275 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_styles_and_scripts',9,0 );
276 $this->loader->add_action( 'wp_print_scripts', $plugin_public, 'dequeue_cf7_scripts',100 );
277 $this->loader->add_action( 'wp_print_styles', $plugin_public, 'dequeue_cf7_styles',100 );
278 $this->loader->add_filter( 'do_shortcode_tag', $plugin_public, 'cf7_shortcode_request',5,3 );
279
280 //save grid fields
281 $this->loader->add_action( 'wp_ajax_nopriv_save_grid_fields', $plugin_public, 'save_grid_fields' );
282 $this->loader->add_action( 'wp_ajax_save_grid_fields', $plugin_public, 'save_grid_fields' );
283
284 /* CF7 Hooks */
285 //disable autloading of cf7 plugin scripts
286 //add_filter( 'wpcf7_load_js', '__return_false' );
287 //add_filter( 'wpcf7_load_css', '__return_false' );
288 //add hidden toggle status field when form loads, load after postion 10 to overcome Conditional Fields bug.
289 $this->loader->add_filter( 'wpcf7_form_hidden_fields', $plugin_public, 'add_hidden_fields', 20 );
290 //instroduced a dynamic taxonomy droppdown tag for forms
291 $this->loader->add_action( 'wpcf7_init', $plugin_public, 'register_cf7_shortcode' );
292 //setup individual tag filers
293 $this->loader->add_filter( 'wpcf7_posted_data', $plugin_public, 'setup_grid_values', 5, 1 );
294 //filter cf7 validation
295 $this->loader->add_filter( 'wpcf7_validate', $plugin_public, 'filter_wpcf7_validate', 1, 1);
296 //benchmark validation
297 $this->loader->add_filter( 'wpcf7_validate_dynamic_select*', $plugin_public, 'validate_required', 30, 2 );
298 $this->loader->add_filter( 'wpcf7_validate_benchmark*', $plugin_public, 'validate_required', 30, 2 );
299 /**
300 * @since 2.1 filter mail tags for tables and tabs.*/
301 $this->loader->add_filter( 'wpcf7_mail_tag_replaced', $plugin_public, 'filter_table_tab_mail_tag', 30, 4 );
302 //Post My CF7 Form hooks
303 $this->loader->add_filter('cf7_2_post_echo_field_mapping_script', $plugin_public, 'load_tabs_table_field', 10, 6 );
304 $this->loader->add_action('cf7_2_post_form_posted', $plugin_public, 'save_select2_custom_options', 10, 5 );
305 //load the saved toggled status for saved submissions.
306 $this->loader->add_filter( 'cf7_2_post_form_values', $plugin_public, 'load_saved_toggled_status' );
307 /** track toggles
308 *@since 1.1.0 */
309 $this->loader->add_action('cf7_2_post_form_posted', $plugin_public, 'save_toggle_status', 10, 5 );
310 /** @since 2.4.1 attach array file fields to mails */
311 $this->loader->add_filter( 'wpcf7_mail_components', $plugin_public, 'wpcf7_mail_components' , 999,3);
312 /** @since 4.0.0 enable/disable autop with filter */
313 $this->loader->add_filter( 'wpcf7_autop_or_not', $plugin_public, 'disable_autop_for_grid' ,5,1);
314 /** @since 4.4 prefill preview forms */
315 $this->loader->add_action( 'wpcf7_before_send_mail', $plugin_public, 'on_submit_success');
316 /** @since 4.11.0 abstract out dynamic lsits*/
317 $this->loader->add_action( 'cf7sg_dynamic_select_html_field', $plugin_public, 'build_dynamic_select_field',5,5);
318 $this->loader->add_action( 'cf7sg_dynamic_checkbox_html_field', $plugin_public, 'build_dynamic_checkbox_field',5,5);
319 $this->loader->add_action( 'smart_grid_register_styles', $plugin_public,'register_dynamic_list_styles',10,2);
320 $this->loader->add_action( 'smart_grid_register_scripts', $plugin_public,'register_dynamic_list_scripts',10,2);
321 /** @since 4.11.0 enable custom submission messages using HTML.*/
322 $this->loader->add_action('wpcf7_mail_sent', $plugin_public, 'change_submission_msg');
323 }
324
325 /**
326 * Run the loader to execute all of the hooks with WordPress.
327 *
328 * @since 1.0.0
329 */
330 public function run() {
331 $this->loader->run();
332 }
333
334 /**
335 * The name of the plugin used to uniquely identify it within the context of
336 * WordPress and to define internationalization functionality.
337 *
338 * @since 1.0.0
339 * @return string The name of the plugin.
340 */
341 public function get_plugin_name() {
342 return $this->plugin_name;
343 }
344
345 /**
346 * The reference to the class that orchestrates the hooks with the plugin.
347 *
348 * @since 1.0.0
349 * @return Cf7_Grid_Layout_Loader Orchestrates the hooks of the plugin.
350 */
351 public function get_loader() {
352 return $this->loader;
353 }
354
355 /**
356 * Retrieve the version number of the plugin.
357 *
358 * @since 1.0.0
359 * @return string The version number of the plugin.
360 */
361 public function get_version() {
362 return $this->version;
363 }
364
365 }
366