class-cf7-2-post.php
11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both the
* public-facing side of the site and the admin area.
*
* @link http://syllogic.in
* @since 1.0.0
*
* @package Cf7_2_Post
* @subpackage Cf7_2_Post/includes
*/
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since 1.0.0
* @package Cf7_2_Post
* @subpackage Cf7_2_Post/includes
* @author Aurovrata V. <vrata@syllogic.in>
*/
class Cf7_2_Post {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var Cf7_2_Post_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct($version) {
$this->plugin_name = 'post-my-contact-form-7';
$this->version = $version;
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - Cf7_2_Post_Loader. Orchestrates the hooks of the plugin.
* - Cf7_2_Post_i18n. Defines internationalization functionality.
* - Cf7_2_Post_Admin. Defines all hooks for the admin area.
* - Cf7_2_Post_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies() {
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cf7-2-post-factory.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cf7-2-post-loader.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/wordpress-gurus-debug-api.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cf7-2-post-i18n.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-cf7-2-post-admin.php';
if( !in_array( 'cf7-grid-layout/cf7-grid-layout.php', get_option('active_plugins', array()) )){
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'assets/cf7-admin-table/cf7-admin-table-loader.php';
}
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-cf7-2-post-public.php';
$this->loader = new Cf7_2_Post_Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the Cf7_2_Post_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new Cf7_2_Post_i18n();
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_admin_hooks() {
$plugin_admin = new Cf7_2_Post_Admin( $this->get_plugin_name(), $this->get_version() );
/* WP hooks */
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
//no cahing metas
$this->loader->add_action('admin_head', $plugin_admin, 'disable_browser_page_cache', 1);
//modify the CF7 post type
$this->loader->add_action('init', $plugin_admin, 'modify_cf7_post_type',20);
//$this->loader->add_filter( 'custom_menu_order', $plugin_admin, 'change_cf7_submenu_order' );
//modify the cf7 list table columns
$this->loader->add_filter('manage_wpcf7_contact_form_posts_columns' , $plugin_admin, 'modify_cf7_list_columns',30,1);
$this->loader->add_action('manage_wpcf7_contact_form_posts_custom_column', $plugin_admin, 'populate_custom_column',10,2);
//register dynamic posts
$this->loader->add_action('init',$plugin_admin, 'register_dynamic_posts',20);
//make sure our dependent plugins exists.
$this->loader->add_action( 'admin_init', $plugin_admin, 'check_plugin_dependency');
//hide the cf7->post page form the submenu
$this->loader->add_action( 'admin_print_footer_scripts', $plugin_admin, 'inject_footer_script');
//quick-edit
$this->loader->add_action( 'quick_edit_custom_box', $plugin_admin, 'quick_edit_box', 20, 2 );
$this->loader->add_action( 'save_post_wpcf7_contact_form', $plugin_admin, 'save_quick_edit', 10, 2 );
//hide mapping submenu page.
//$this->loader->add_filter( 'custom_menu_order', $plugin_admin, 'hide_mapping_menu', 10);
/**
* add metabox to mapped posts.
* @since 3.3.0
*/
$this->loader->add_action('cf72post_register_mapped_post', $plugin_admin, 'cf72post_metabox');
/* CF7 Hooks */
//delete post
$this->loader->add_action( 'wpcf7_post_delete',$plugin_admin, 'delete_cf7_post',10,1);
//add the 'save' button tag
$this->loader->add_action( 'wpcf7_admin_init', $plugin_admin, 'cf7_shortcode_tags', 55,0 );
/** @since 4.0.0 add save-darft message*/
$this->loader->add_action( 'wpcf7_messages', $plugin_admin, 'draft_message' );
/**
* hook to modify custom post in dashboard
* @since 3.4.0
*/
$cf7_2_post_type = c2p_mapped_post_types();
foreach($cf7_2_post_type as $post_id=>$type){
$post_type = key($type);
$this->loader->add_filter('manage_' . $post_type . '_posts_columns', $plugin_admin, 'modify_cf72post_columns', 999,1);
$this->loader->add_action('manage_' . $post_type . '_posts_custom_column', $plugin_admin, 'populate_custom_column', 999,2);
//on save cf7 post type
$this->loader->add_action( 'save_post_'. $post_type, $plugin_admin,'save_quick_custompost', 10, 2 );
switch($type[$post_type]){
case 'factory': /*add a metabox to the post edit page*/
$this->loader->add_action( 'add_meta_boxes_'. $post_type, $plugin_admin,'custom_post_metabox' );
break;
default:
break;
}
}
/** @since 4.1.0 mail tag for post links */
$this->loader->add_filter( 'wpcf7_collect_mail_tags', $plugin_admin, 'email_tags' );
/** @since 5.0 */
$this->loader->add_filter( 'wpcf7_editor_panels', $plugin_admin, 'add_mapping_panel');
$this->loader->add_action( 'admin_init', $plugin_admin, 'set_c2p_panel_tab');
/** @since 5.0.0 hook the smart grid form saving action to fix double save_post hook call
* calls to save_post_mapping moved to 'admin_init' hook above.
*/
//show helper metabox.
$this->loader->add_action( 'add_meta_boxes_wpcf7_contact_form', $plugin_admin,'add_helper_metabox' );
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_public_hooks() {
$plugin_public = new Cf7_2_Post_Public( $this->get_plugin_name(), $this->get_version() );
/* WP hooks */
//$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_scripts');
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_styles' );
$this->loader->add_filter( 'do_shortcode_tag', $plugin_public, 'load_cf7_script', 4,3 ); //4: add before cf7 grid.
//no cahing metas
$this->loader->add_action('wp_head', $plugin_public, 'disable_browser_page_cache', 1);
/*CF7 Hooks*/
//use before_send_mail to ensure mapping post form validation
$this->loader->add_action( 'wpcf7_before_send_mail', $plugin_public, 'save_cf7_2_post', 100);
//skip mail for draft forms
$this->loader->add_filter('wpcf7_skip_mail', $plugin_public, 'skip_cf7_mail');
//instroduced a 'save button tag for forms
$this->loader->add_action( 'wpcf7_init', $plugin_public, 'save_button_shortcode_handler' );
//skip validation for saved forms
$this->loader->add_filter( 'wpcf7_validate', $plugin_public, 'save_skips_wpcf7_validate', 100, 2 );
$this->loader->add_filter( 'wpcf7_validate_file', $plugin_public, 'save_skips_file_validation', 100, 2 );
$this->loader->add_filter( 'wpcf7_validate_file*', $plugin_public, 'save_skips_file_validation', 100, 2 );
//add the author map for logged in user @since 3.9.0.
$this->loader->add_filter( 'wpcf7_form_hidden_fields', $plugin_public, 'add_hidden_fields', 100, 2 );
//filter message for draft saved forms.
$this->loader->add_filter('wpcf7_display_message', $plugin_public, 'draft_message', 100, 2 );
/** @since 4.1.8 filter selectable field types, fix for CF7 v5.2.1 changes. */
$this->loader->add_filter('wpcf7_posted_data_select', $plugin_public, 'array_to_single', 1, 3 );
$this->loader->add_filter('wpcf7_posted_data_select*', $plugin_public, 'array_to_single', 1, 3 );
$this->loader->add_filter('wpcf7_posted_data_dynamic-select', $plugin_public, 'array_to_single', 1, 3 );
$this->loader->add_filter('wpcf7_posted_data_dynamic-select*', $plugin_public, 'array_to_single', 1, 3 );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 1.0.0
* @return string The name of the plugin.
*/
public function get_plugin_name() {
return $this->plugin_name;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @since 1.0.0
* @return Cf7_2_Post_Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @since 1.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
}