| 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 |
|
| 126 |
/** |
| 127 |
* The class responsible for defining internationalization functionality |
| 128 |
* of the plugin. |
| 129 |
*/ |
| 130 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cf7-grid-layout-i18n.php'; |
| 131 |
|
| 132 |
/** |
| 133 |
* The class responsible for defining all actions that occur in the admin area. |
| 134 |
*/ |
| 135 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-cf7-grid-layout-admin.php'; |
| 136 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'assets/cf7-admin-table/cf7-admin-table-loader.php'; |
| 137 |
/** |
| 138 |
* The class responsible for defining all actions that occur in the public-facing |
| 139 |
* side of the site. |
| 140 |
*/ |
| 141 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-cf7-grid-layout-public.php'; |
| 142 |
|
| 143 |
$this->loader = new Cf7_Grid_Layout_Loader(); |
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Define the locale for this plugin for internationalization. |
| 149 |
* |
| 150 |
* Uses the Cf7_Grid_Layout_i18n class in order to set the domain and to register the hook |
| 151 |
* with WordPress. |
| 152 |
* |
| 153 |
* @since 1.0.0 |
| 154 |
* @access private |
| 155 |
*/ |
| 156 |
private function set_locale() { |
| 157 |
|
| 158 |
$plugin_i18n = new Cf7_Grid_Layout_i18n(); |
| 159 |
|
| 160 |
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Register all of the hooks related to the admin area functionality |
| 166 |
* of the plugin. |
| 167 |
* |
| 168 |
* @since 1.0.0 |
| 169 |
* @access private |
| 170 |
*/ |
| 171 |
private function define_admin_hooks() { |
| 172 |
|
| 173 |
$plugin_admin = new Cf7_Grid_Layout_Admin( $this->get_plugin_name(), $this->get_version() ); |
| 174 |
|
| 175 |
//enqueue styles |
| 176 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
| 177 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 178 |
// @since 1.5.0 hack to enqueue js/css for other cf7 extensions. |
| 179 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'popular_extentions_scripts', 999,0); |
| 180 |
$this->loader->add_action( 'admin_print_scripts', $plugin_admin, 'print_extentions_scripts', 1,0); |
| 181 |
//add new sub-menu |
| 182 |
$this->loader->add_action('admin_menu', $plugin_admin, 'add_cf7_sub_menu'); |
| 183 |
$this->loader->add_filter( 'custom_menu_order', $plugin_admin, 'change_cf7_submenu_order' ); |
| 184 |
//modify cf7 post type |
| 185 |
$this->loader->add_action('register_post_type_args', $plugin_admin, 'modify_cf7_post_type_args' , 20, 2 ); |
| 186 |
//register dynamic dropdown taxonomy with cf7 post |
| 187 |
$this->loader->add_action('init', $plugin_admin, 'register_dynamic_dropdown_taxonomy' , 20, 2 ); |
| 188 |
//$this->loader->add_action('init', $plugin_admin, 'modify_cf7_post_type' , 20 ); |
| 189 |
//add some metabox to the wpcf7_contact_form post type |
| 190 |
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'main_editor_meta_box' ); |
| 191 |
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'info_meta_box' ); |
| 192 |
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'helper_meta_box'); |
| 193 |
//save the post |
| 194 |
$this->loader->add_action('save_post_wpcf7_contact_form', $plugin_admin, 'save_post', 10,3); |
| 195 |
//ajax load cf7 form content |
| 196 |
$this->loader->add_action('wp_ajax_get_cf7_content', $plugin_admin, 'get_cf7_content'); |
| 197 |
//hook for adding fields to sumit action metabox |
| 198 |
$this->loader->add_filter('post_submitbox_misc_actions', $plugin_admin, 'cf7_post_submit_action' ,10); |
| 199 |
//cusotm sanitation rules for forms |
| 200 |
$this->loader->add_filter('wp_kses_allowed_html', $plugin_admin, 'custom_kses_rules' ,10, 2); |
| 201 |
/** |
| 202 |
* @since 2.1.0 make sure our dependent plugins exists.*/ |
| 203 |
$this->loader->add_action( 'admin_init', $plugin_admin, 'check_plugin_dependency'); |
| 204 |
/** |
| 205 |
*@since 2.3.0 redirect post.php for form duplicate*/ |
| 206 |
$this->loader->add_filter('admin_init', $plugin_admin, 'duplicate_cf7_form'); |
| 207 |
/** @since 2.6.0*/ |
| 208 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'pretty_admin_pointers' ); |
| 209 |
$this->loader->add_action( 'cf7sg_plugin_pointers-edit-wpcf7_contact_form', $plugin_admin, 'edit_pointers' ); |
| 210 |
/** @since 3.0.0 */ |
| 211 |
$this->loader->add_action( 'cf7sg_plugin_pointers-wpcf7_contact_form', $plugin_admin, 'post_pointers' ); |
| 212 |
/* |
| 213 |
CF7 Hooks |
| 214 |
*/ |
| 215 |
//save cf7 form post |
| 216 |
$this->loader->add_action( 'wpcf7_save_contact_form', $plugin_admin, 'save_factory_metas' , 10, 1); |
| 217 |
//print submit metabox |
| 218 |
$this->loader->add_action( 'wpcf7_admin_misc_pub_section', $plugin_admin, 'dynamic_select_choices' , 10, 1); |
| 219 |
$this->loader->add_action( 'wpcf7_admin_init', $plugin_admin, 'cf7_shortcode_tags' ); |
| 220 |
//modify the default form template |
| 221 |
$this->loader->add_filter( 'wpcf7_default_template', $plugin_admin, 'default_cf7_form' , 5,2); |
| 222 |
/** @since 2.6.0*/ |
| 223 |
$this->loader->add_filter( 'wpcf7_messages', $plugin_admin, 'disabled_message' , 5,2); |
| 224 |
/** @since 3.0.0 */ |
| 225 |
$this->loader->add_filter( 'wpcf7_map_meta_cap', $plugin_admin, 'reset_meta_cap' , 5,1); |
| 226 |
//make sure users that cannot publish forms are set to pending. |
| 227 |
$this->loader->add_filter( 'wp_insert_post_data', $plugin_admin, 'pending_for_review'); |
| 228 |
//add all form capabilities to editor role. |
| 229 |
$this->loader->add_action( 'admin_init', $plugin_admin, 'enable_cf7_editor_role', 5,0 ); |
| 230 |
/** @since 3.3.0 helper hooks added via action hook */ |
| 231 |
$this->loader->add_action( 'cf7sg_ui_grid_helper_hooks', $plugin_admin, 'print_helper_hooks'); |
| 232 |
|
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* Register all of the hooks related to the public-facing functionality |
| 237 |
* of the plugin. |
| 238 |
* |
| 239 |
* @since 1.0.0 |
| 240 |
* @access private |
| 241 |
*/ |
| 242 |
private function define_public_hooks() { |
| 243 |
|
| 244 |
$plugin_public = new Cf7_Grid_Layout_Public( $this->get_plugin_name(), $this->get_version() ); |
| 245 |
|
| 246 |
//register front-end scripts for CF7 forms |
| 247 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_styles' ); |
| 248 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_scripts' ); |
| 249 |
$this->loader->add_action( 'wp_print_scripts', $plugin_public, 'dequeue_cf7_scripts',100 ); |
| 250 |
$this->loader->add_action( 'wp_print_styles', $plugin_public, 'dequeue_cf7_styles',100 ); |
| 251 |
$this->loader->add_filter( 'do_shortcode_tag', $plugin_public, 'cf7_shortcode_request',5,3 ); |
| 252 |
|
| 253 |
//save grid fields |
| 254 |
$this->loader->add_action( 'wp_ajax_nopriv_save_grid_fields', $plugin_public, 'save_grid_fields' ); |
| 255 |
$this->loader->add_action( 'wp_ajax_save_grid_fields', $plugin_public, 'save_grid_fields' ); |
| 256 |
|
| 257 |
/* CF7 Hooks */ |
| 258 |
//disable autloading of cf7 plugin scripts |
| 259 |
//add_filter( 'wpcf7_load_js', '__return_false' ); |
| 260 |
//add_filter( 'wpcf7_load_css', '__return_false' ); |
| 261 |
//add hidden toggle status field when form loads, load after postion 10 to overcome Conditional Fields bug. |
| 262 |
$this->loader->add_filter( 'wpcf7_form_hidden_fields', $plugin_public, 'add_hidden_fields', 20 ); |
| 263 |
//instroduced a dynamic taxonomy droppdown tag for forms |
| 264 |
$this->loader->add_action( 'wpcf7_init', $plugin_public, 'register_cf7_shortcode' ); |
| 265 |
//setup individual tag filers |
| 266 |
$this->loader->add_filter( 'wpcf7_posted_data', $plugin_public, 'setup_grid_values', 5, 1 ); |
| 267 |
//filter cf7 validation |
| 268 |
$this->loader->add_filter( 'wpcf7_validate', $plugin_public, 'filter_wpcf7_validate', 30, 2 ); |
| 269 |
//benchmark validation |
| 270 |
$this->loader->add_filter( 'wpcf7_validate_dynamic_select*', $plugin_public, 'validate_required', 30, 2 ); |
| 271 |
$this->loader->add_filter( 'wpcf7_validate_benchmark*', $plugin_public, 'validate_required', 30, 2 ); |
| 272 |
/** |
| 273 |
* @since 2.1 filter mail tags for tables and tabs.*/ |
| 274 |
$this->loader->add_filter( 'wpcf7_mail_tag_replaced', $plugin_public, 'filter_table_tab_mail_tag', 30, 4 ); |
| 275 |
//Post My CF7 Form hooks |
| 276 |
$this->loader->add_filter('cf7_2_post_echo_field_mapping_script', $plugin_public, 'load_tabs_table_field', 10, 6 ); |
| 277 |
$this->loader->add_action('cf7_2_post_form_posted', $plugin_public, 'save_select2_custom_options', 10, 5 ); |
| 278 |
//load the saved toggled status for saved submissions. |
| 279 |
$this->loader->add_filter( 'cf7_2_post_form_values', $plugin_public, 'load_saved_toggled_status' ); |
| 280 |
/** track toggles |
| 281 |
*@since 1.1.0 */ |
| 282 |
$this->loader->add_action('cf7_2_post_form_posted', $plugin_public, 'save_toggle_status', 10, 5 ); |
| 283 |
/** @since 2.4.1 attache array file fields to mails */ |
| 284 |
$this->loader->add_filter( 'wpcf7_mail_components', $plugin_public, 'wpcf7_mail_components' , 999,3); |
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* Run the loader to execute all of the hooks with WordPress. |
| 290 |
* |
| 291 |
* @since 1.0.0 |
| 292 |
*/ |
| 293 |
public function run() { |
| 294 |
$this->loader->run(); |
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* The name of the plugin used to uniquely identify it within the context of |
| 299 |
* WordPress and to define internationalization functionality. |
| 300 |
* |
| 301 |
* @since 1.0.0 |
| 302 |
* @return string The name of the plugin. |
| 303 |
*/ |
| 304 |
public function get_plugin_name() { |
| 305 |
return $this->plugin_name; |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 310 |
* |
| 311 |
* @since 1.0.0 |
| 312 |
* @return Cf7_Grid_Layout_Loader Orchestrates the hooks of the plugin. |
| 313 |
*/ |
| 314 |
public function get_loader() { |
| 315 |
return $this->loader; |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Retrieve the version number of the plugin. |
| 320 |
* |
| 321 |
* @since 1.0.0 |
| 322 |
* @return string The version number of the plugin. |
| 323 |
*/ |
| 324 |
public function get_version() { |
| 325 |
return $this->version; |
| 326 |
} |
| 327 |
|
| 328 |
} |
| 329 |
|