1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
class GravityView_Admin { |
4
|
|
|
|
5
|
|
|
function __construct() { |
|
|
|
|
6
|
|
|
|
7
|
|
|
if( ! is_admin() ) { return; } |
8
|
|
|
|
9
|
|
|
// If Gravity Forms isn't active or compatibile, stop loading |
10
|
|
|
if( false === GravityView_Compatibility::is_valid() ) { |
11
|
|
|
return; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
$this->include_required_files(); |
15
|
|
|
$this->add_hooks(); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @since 1.15 |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
|
private function include_required_files() { |
23
|
|
|
|
24
|
|
|
// Migrate Class |
25
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-migrate.php' ); |
26
|
|
|
|
27
|
|
|
// Don't load tooltips if on Gravity Forms, otherwise it overrides translations |
28
|
|
|
if( class_exists( 'GFCommon' ) && class_exists( 'GFForms' ) && !GFForms::is_gravity_page() ) { |
|
|
|
|
29
|
|
|
require_once( GFCommon::get_base_path() . '/tooltips.php' ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/admin/metaboxes/class-gravityview-admin-metaboxes.php' ); |
33
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/admin/entry-list.php' ); |
34
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' ); |
35
|
|
|
|
36
|
|
|
/** @since 1.15 **/ |
37
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/admin/class-gravityview-support-port.php' ); |
38
|
|
|
|
39
|
|
|
/** @since 1.6 */ |
40
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-duplicate-view.php' ); |
41
|
|
|
|
42
|
|
|
/** @since 1.17 */ |
43
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/admin/class-gravityview-admin-no-conflict.php' ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @since 1.7.5 |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
private function add_hooks() { |
51
|
|
|
|
52
|
|
|
// Filter Admin messages |
53
|
|
|
add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) ); |
54
|
|
|
add_filter( 'bulk_post_updated_messages', array( $this, 'post_updated_messages' ) ); |
55
|
|
|
|
56
|
|
|
add_filter( 'plugin_action_links_'. plugin_basename( GRAVITYVIEW_FILE ) , array( $this, 'plugin_action_links' ) ); |
57
|
|
|
|
58
|
|
|
add_action( 'plugins_loaded', array( $this, 'backend_actions' ), 100 ); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Function to launch admin objects |
64
|
|
|
* |
65
|
|
|
* @access public |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function backend_actions() { |
69
|
|
|
|
70
|
|
|
/** @define "GRAVITYVIEW_DIR" "../" */ |
71
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/admin/class.field.type.php' ); |
72
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/admin/class.render.settings.php' ); |
73
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-label.php' ); |
74
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-views.php' ); |
75
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-welcome.php' ); |
76
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-add-shortcode.php' ); |
77
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @action `gravityview_include_backend_actions` Triggered after all GravityView admin files are loaded |
81
|
|
|
* |
82
|
|
|
* Nice place to insert extensions' backend stuff |
83
|
|
|
*/ |
84
|
|
|
do_action('gravityview_include_backend_actions'); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Modify plugin action links at plugins screen |
89
|
|
|
* |
90
|
|
|
* @since 1.15 Added check for `gravityview_view_settings` and `gravityview_support_port` capabilities |
91
|
|
|
* @access public |
92
|
|
|
* @static |
93
|
|
|
* @param array $links Array of action links under GravityView on the plugin page |
94
|
|
|
* @return array Action links with Settings and Support included, if the user has the appropriate caps |
95
|
|
|
*/ |
96
|
|
|
public static function plugin_action_links( $links ) { |
97
|
|
|
|
98
|
|
|
$actions = array(); |
99
|
|
|
|
100
|
|
|
if( GVCommon::has_cap( 'gravityview_view_settings' ) ) { |
101
|
|
|
$actions[] = sprintf( '<a href="%s">%s</a>', admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ), esc_html__( 'Settings', 'gravityview' ) ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if( GVCommon::has_cap( 'gravityview_support_port' ) ) { |
105
|
|
|
$actions[] = '<a href="http://docs.gravityview.co">' . esc_html__( 'Support', 'gravityview' ) . '</a>'; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return array_merge( $actions, $links ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get an image of our intrepid explorer friend |
113
|
|
|
* @return string HTML image tag with floaty's cute mug on it |
114
|
|
|
*/ |
115
|
|
|
public static function get_floaty() { |
116
|
|
|
return gravityview_get_floaty(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Filter Admin messages |
121
|
|
|
* |
122
|
|
|
* @param array $messages Existing messages |
123
|
|
|
* @return array Messages with GravityView views! |
124
|
|
|
*/ |
125
|
|
|
function post_updated_messages( $messages, $bulk_counts = NULL ) { |
|
|
|
|
126
|
|
|
global $post; |
|
|
|
|
127
|
|
|
|
128
|
|
|
$post_id = get_the_ID(); |
129
|
|
|
|
130
|
|
|
// By default, there will only be one item being modified. |
131
|
|
|
// When in the `bulk_post_updated_messages` filter, there will be passed a number |
132
|
|
|
// of modified items that will override this array. |
133
|
|
|
$bulk_counts = is_null( $bulk_counts ) ? array( 'updated' => 1 , 'locked' => 1 , 'deleted' => 1 , 'trashed' => 1, 'untrashed' => 1 ) : $bulk_counts; |
|
|
|
|
134
|
|
|
|
135
|
|
|
// If we're starting fresh, a new form was created. |
136
|
|
|
// We should let the user know this is the case. |
137
|
|
|
$start_fresh = get_post_meta( $post_id, '_gravityview_start_fresh', true ); |
138
|
|
|
|
139
|
|
|
$new_form_text = ''; |
140
|
|
|
|
141
|
|
|
if( !empty( $start_fresh ) ) { |
|
|
|
|
142
|
|
|
|
143
|
|
|
// Get the form that was created |
144
|
|
|
$connected_form = gravityview_get_form_id( $post_id ); |
145
|
|
|
|
146
|
|
|
if( !empty( $connected_form ) ) { |
|
|
|
|
147
|
|
|
$form = gravityview_get_form( $connected_form ); |
148
|
|
|
$form_name = esc_attr( $form['title'] ); |
149
|
|
|
$image = self::get_floaty(); |
150
|
|
|
$new_form_text .= '<h3>'.$image.sprintf( __( 'A new form was created for this View: "%s"', 'gravityview' ), $form_name ).'</h3>'; |
151
|
|
|
$new_form_text .= sprintf( __( '%sThere are no entries for the new form, so the View will also be empty.%s To start collecting entries, you can add submissions through %sthe preview form%s and also embed the form on a post or page using this code: %s |
|
|
|
|
152
|
|
|
|
153
|
|
|
You can %sedit the form%s in Gravity Forms and the updated fields will be available here. Don’t forget to %scustomize the form settings%s. |
154
|
|
|
', 'gravityview' ), '<strong>', '</strong>', '<a href="'.site_url( '?gf_page=preview&id='.$connected_form ).'">', '</a>', '<code>[gravityform id="'.$connected_form.'" name="'.$form_name.'"]</code>', '<a href="'.admin_url( 'admin.php?page=gf_edit_forms&id='.$connected_form ).'">', '</a>', '<a href="'.admin_url( 'admin.php?page=gf_edit_forms&view=settings&id='.$connected_form ).'">', '</a>'); |
|
|
|
|
155
|
|
|
$new_form_text = wpautop( $new_form_text ); |
156
|
|
|
|
157
|
|
|
delete_post_meta( $post_id, '_gravityview_start_fresh' ); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$messages['gravityview'] = array( |
162
|
|
|
0 => '', // Unused. Messages start at index 1. |
163
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
164
|
|
|
1 => sprintf(__( 'View updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'), |
|
|
|
|
165
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
166
|
|
|
2 => sprintf(__( 'View updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'), |
|
|
|
|
167
|
|
|
3 => __( 'View deleted.', 'gravityview' ), |
168
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
169
|
|
|
4 => sprintf(__( 'View updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'), |
|
|
|
|
170
|
|
|
/* translators: %s: date and time of the revision */ |
171
|
|
|
5 => isset( $_GET['revision'] ) ? sprintf( __( 'View restored to revision from %s', 'gravityview' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
|
|
|
172
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
173
|
|
|
6 => sprintf(__( 'View published. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text, |
|
|
|
|
174
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
175
|
|
|
7 => sprintf(__( 'View saved. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text, |
|
|
|
|
176
|
|
|
8 => __( 'View submitted.', 'gravityview' ), |
177
|
|
|
9 => sprintf( |
178
|
|
|
/* translators: Date and time the View is scheduled to be published */ |
179
|
|
|
__( 'View scheduled for: %1$s.', 'gravityview' ), |
180
|
|
|
// translators: Publish box date format, see http://php.net/date |
181
|
|
|
date_i18n( __( 'M j, Y @ G:i', 'gravityview' ), strtotime( ( isset( $post->post_date ) ? $post->post_date : NULL ) ) ) |
|
|
|
|
182
|
|
|
) . $new_form_text, |
|
|
|
|
183
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
184
|
|
|
10 => sprintf(__( 'View draft updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'), |
|
|
|
|
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* These apply to `bulk_post_updated_messages` |
188
|
|
|
* @file wp-admin/edit.php |
189
|
|
|
*/ |
190
|
|
|
'updated' => _n( '%s View updated.', '%s Views updated.', $bulk_counts['updated'], 'gravityview' ), |
191
|
|
|
'locked' => _n( '%s View not updated, somebody is editing it.', '%s Views not updated, somebody is editing them.', $bulk_counts['locked'], 'gravityview' ), |
192
|
|
|
'deleted' => _n( '%s View permanently deleted.', '%s Views permanently deleted.', $bulk_counts['deleted'], 'gravityview' ), |
193
|
|
|
'trashed' => _n( '%s View moved to the Trash.', '%s Views moved to the Trash.', $bulk_counts['trashed'], 'gravityview' ), |
194
|
|
|
'untrashed' => _n( '%s View restored from the Trash.', '%s Views restored from the Trash.', $bulk_counts['untrashed'], 'gravityview' ), |
195
|
|
|
); |
196
|
|
|
|
197
|
|
|
return $messages; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Get admin notices |
203
|
|
|
* @deprecated since 1.12 |
204
|
|
|
* @return array |
205
|
|
|
*/ |
206
|
|
|
public static function get_notices() { |
207
|
|
|
return GravityView_Admin_Notices::get_notices(); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Add a notice to be displayed in the admin. |
212
|
|
|
* @deprecated since 1.12 |
213
|
|
|
* @param array $notice Array with `class` and `message` keys. The message is not escaped. |
214
|
|
|
*/ |
215
|
|
|
public static function add_notice( $notice = array() ) { |
216
|
|
|
GravityView_Admin_Notices::add_notice( $notice ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Check if Gravity Forms plugin is active and show notice if not. |
221
|
|
|
* |
222
|
|
|
* @deprecated since 1.12 |
223
|
|
|
* @see GravityView_Compatibility::get_plugin_status() |
224
|
|
|
* @return boolean True: checks have been passed; GV is fine to run; False: checks have failed, don't continue loading |
225
|
|
|
*/ |
226
|
|
|
public static function check_gravityforms() { |
227
|
|
|
return GravityView_Compatibility::check_gravityforms(); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Check if specified plugin is active, inactive or not installed |
232
|
|
|
* |
233
|
|
|
* @deprecated since 1.12 |
234
|
|
|
* @see GravityView_Compatibility::get_plugin_status() |
235
|
|
|
|
236
|
|
|
* @return boolean|string True: plugin is active; False: plugin file doesn't exist at path; 'inactive' it's inactive |
237
|
|
|
*/ |
238
|
|
|
static function get_plugin_status( $location = '' ) { |
|
|
|
|
239
|
|
|
return GravityView_Compatibility::get_plugin_status( $location ); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Is the current admin page a GravityView-related page? |
244
|
|
|
* |
245
|
|
|
* @todo Convert to use WP_Screen |
246
|
|
|
* @param string $hook |
247
|
|
|
* @param null|string $page Optional. String return value of page to compare against. |
248
|
|
|
* |
249
|
|
|
* @return bool|string|void If `false`, not a GravityView page. `true` if $page is passed and is the same as current page. Otherwise, the name of the page (`single`, `settings`, or `views`) |
250
|
|
|
*/ |
251
|
|
|
static function is_admin_page( $hook = '', $page = NULL ) { |
|
|
|
|
252
|
|
|
global $current_screen, $plugin_page, $pagenow, $post; |
|
|
|
|
253
|
|
|
|
254
|
|
|
if( ! is_admin() ) { return false; } |
255
|
|
|
|
256
|
|
|
$is_page = false; |
257
|
|
|
|
258
|
|
|
$is_gv_screen = (!empty($current_screen) && isset($current_screen->post_type) && $current_screen->post_type === 'gravityview'); |
|
|
|
|
259
|
|
|
|
260
|
|
|
$is_gv_post_type_get = (isset($_GET['post_type']) && $_GET['post_type'] === 'gravityview'); |
|
|
|
|
261
|
|
|
|
262
|
|
|
$is_gv_settings_get = isset( $_GET['page'] ) && $_GET['page'] === 'gravityview_settings'; |
|
|
|
|
263
|
|
|
|
264
|
|
|
if( empty( $post ) && $pagenow === 'post.php' && !empty( $_GET['post'] ) ) { |
|
|
|
|
265
|
|
|
$gv_post = get_post( intval( $_GET['post'] ) ); |
|
|
|
|
266
|
|
|
$is_gv_post_type = (!empty($gv_post) && !empty($gv_post->post_type) && $gv_post->post_type === 'gravityview'); |
|
|
|
|
267
|
|
|
} else { |
268
|
|
|
$is_gv_post_type = (!empty($post) && !empty($post->post_type) && $post->post_type === 'gravityview'); |
|
|
|
|
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
if( $is_gv_screen || $is_gv_post_type || $is_gv_post_type || $is_gv_post_type_get || $is_gv_settings_get ) { |
272
|
|
|
|
273
|
|
|
// $_GET `post_type` variable |
|
|
|
|
274
|
|
|
if(in_array($pagenow, array( 'post.php' , 'post-new.php' )) ) { |
|
|
|
|
275
|
|
|
$is_page = 'single'; |
276
|
|
|
} else if ( in_array( $plugin_page, array( 'gravityview_settings', 'gravityview_page_gravityview_settings' ) ) || ( !empty( $_GET['page'] ) && $_GET['page'] === 'gravityview_settings' ) ) { |
|
|
|
|
277
|
|
|
$is_page = 'settings'; |
278
|
|
|
} else { |
279
|
|
|
$is_page = 'views'; |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @filter `gravityview_is_admin_page` Is the current admin page a GravityView-related page? |
285
|
|
|
* @param[in,out] string|bool $is_page If false, no. If string, the name of the page (`single`, `settings`, or `views`) |
286
|
|
|
* @param[in] string $hook The name of the page to check against. Is passed to the method. |
287
|
|
|
*/ |
288
|
|
|
$is_page = apply_filters( 'gravityview_is_admin_page', $is_page, $hook ); |
289
|
|
|
|
290
|
|
|
// If the current page is the same as the compared page |
291
|
|
|
if( !empty( $page ) ) { |
|
|
|
|
292
|
|
|
return $is_page === $page; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
return $is_page; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
new GravityView_Admin; |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Alias for GravityView_Admin::is_admin_page() |
304
|
|
|
* |
305
|
|
|
* @see GravityView_Admin::is_admin_page |
306
|
|
|
* |
307
|
|
|
* @param string $hook |
308
|
|
|
* @param null|string $page Optional. String return value of page to compare against. |
309
|
|
|
* |
310
|
|
|
* @return bool|string|void If `false`, not a GravityView page. `true` if $page is passed and is the same as current page. Otherwise, the name of the page (`single`, `settings`, or `views`) |
311
|
|
|
*/ |
312
|
|
|
function gravityview_is_admin_page($hook = '', $page = NULL) { |
|
|
|
|
313
|
|
|
return GravityView_Admin::is_admin_page( $hook, $page ); |
314
|
|
|
} |
315
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.