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
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/admin/metaboxes/class-gravityview-admin-metaboxes.php' ); |
28
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/admin/entry-list.php' ); |
29
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' ); |
30
|
|
|
|
31
|
|
|
/** @since 1.15 **/ |
32
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/admin/class-gravityview-support-port.php' ); |
33
|
|
|
|
34
|
|
|
/** @since 1.6 */ |
35
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-duplicate-view.php' ); |
36
|
|
|
|
37
|
|
|
/** @since 1.17 */ |
38
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/admin/class-gravityview-admin-no-conflict.php' ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @since 1.7.5 |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
private function add_hooks() { |
46
|
|
|
|
47
|
|
|
// Filter Admin messages |
48
|
|
|
add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) ); |
49
|
|
|
add_filter( 'bulk_post_updated_messages', array( $this, 'post_updated_messages' ) ); |
50
|
|
|
|
51
|
|
|
add_filter( 'plugin_action_links_'. plugin_basename( GRAVITYVIEW_FILE ) , array( $this, 'plugin_action_links' ) ); |
52
|
|
|
|
53
|
|
|
add_action( 'plugins_loaded', array( $this, 'backend_actions' ), 100 ); |
54
|
|
|
|
55
|
|
|
add_action( 'gravityview/metaboxes/data-source/before', array( 'GravityView_Admin', 'connected_form_warning' ) ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get text for no views found. |
60
|
|
|
* |
61
|
|
|
* @since 1.18 Moved to GravityView_Admin |
62
|
|
|
* |
63
|
|
|
* @return string HTML message with no container tags. |
64
|
|
|
*/ |
65
|
|
|
public static function no_views_text() { |
66
|
|
|
|
67
|
|
|
if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) { |
|
|
|
|
68
|
|
|
return __( 'No Views found in Trash', 'gravityview' ); |
69
|
|
|
} elseif( ! empty( $_GET['s'] ) ) { |
|
|
|
|
70
|
|
|
return __( 'No Views found.', 'gravityview' ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// Floaty the Astronaut says "oi" |
74
|
|
|
$image = self::get_floaty(); |
75
|
|
|
|
76
|
|
|
if ( GVCommon::has_cap( 'edit_gravityviews' ) ) { |
77
|
|
|
$output = sprintf( esc_attr__( "%sYou don't have any active views. Let’s go %screate one%s!%s\n\nIf you feel like you're lost in space and need help getting started, check out the %sGetting Started%s page.", 'gravityview' ), '<h3>', '<a href="' . admin_url( 'post-new.php?post_type=gravityview' ) . '">', '</a>', '</h3>', '<a href="' . admin_url( 'edit.php?post_type=gravityview&page=gv-getting-started' ) . '">', '</a>' ); |
78
|
|
|
} else { |
79
|
|
|
$output = esc_attr__( 'There are no active Views', 'gravityview' ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $image . wpautop( $output ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Display error HTML in Edit View when the form is in the trash or no longer exists in Gravity Forms |
87
|
|
|
* |
88
|
|
|
* @since 1.19 |
89
|
|
|
* |
90
|
|
|
* @param int $form_id Gravity Forms |
91
|
|
|
* |
92
|
|
|
* @return void |
93
|
|
|
*/ |
94
|
|
|
public static function connected_form_warning( $form_id = 0 ) { |
95
|
|
|
global $pagenow; |
|
|
|
|
96
|
|
|
|
97
|
|
|
if ( empty( $form_id ) || $pagenow === 'post-new.php' ) { |
|
|
|
|
98
|
|
|
return; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$form_info = GFFormsModel::get_form( $form_id, true ); |
102
|
|
|
|
103
|
|
|
$error = ''; |
104
|
|
|
if ( empty( $form_info ) ) { |
105
|
|
|
$error = esc_html__( 'The form connected to this View no longer exists.', 'gravityview' ); |
106
|
|
|
$error .= ' ' . esc_html__( 'Select another form as the data source for this View.', 'gravityview' ); |
107
|
|
|
} elseif ( $form_info->is_trash ) { |
108
|
|
|
$error = esc_html__( 'The connected form is in the trash.', 'gravityview' ); |
109
|
|
|
$error .= ' ' . gravityview_get_link( admin_url( 'admin.php?page=gf_edit_forms&filter=trash' ), esc_html__( 'Restore the form from the trash', 'gravityview' ) ); |
110
|
|
|
$error .= ' ' . esc_html__( 'or select another form.', 'gravityview' ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if( $error ) { |
114
|
|
|
?> |
115
|
|
|
<div class="wp-dialog notice-warning inline error wp-clearfix"> |
116
|
|
|
<?php echo gravityview_get_floaty(); ?> |
|
|
|
|
117
|
|
|
<h3><?php echo $error; ?></h3> |
|
|
|
|
118
|
|
|
</div> |
119
|
|
|
<?php |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Function to launch admin objects |
125
|
|
|
* |
126
|
|
|
* @access public |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
public function backend_actions() { |
130
|
|
|
|
131
|
|
|
/** @define "GRAVITYVIEW_DIR" "../" */ |
132
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/admin/class.field.type.php' ); |
133
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/admin/class.render.settings.php' ); |
134
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/admin/class-gravityview-admin-view-item.php' ); |
135
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/admin/class-gravityview-admin-view-field.php' ); |
136
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/admin/class-gravityview-admin-view-widget.php' ); |
137
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-views.php' ); |
138
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-welcome.php' ); |
139
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-installer.php' ); |
140
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-add-shortcode.php' ); |
141
|
|
|
include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @action `gravityview_include_backend_actions` Triggered after all GravityView admin files are loaded |
145
|
|
|
* |
146
|
|
|
* Nice place to insert extensions' backend stuff |
147
|
|
|
*/ |
148
|
|
|
do_action('gravityview_include_backend_actions'); |
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Modify plugin action links at plugins screen |
153
|
|
|
* |
154
|
|
|
* @since 1.15 Added check for `gravityview_view_settings` and `gravityview_support_port` capabilities |
155
|
|
|
* @access public |
156
|
|
|
* @static |
157
|
|
|
* @param array $links Array of action links under GravityView on the plugin page |
158
|
|
|
* @return array Action links with Settings and Support included, if the user has the appropriate caps |
159
|
|
|
*/ |
160
|
|
|
public static function plugin_action_links( $links ) { |
161
|
|
|
|
162
|
|
|
$actions = array(); |
163
|
|
|
|
164
|
|
|
if( GVCommon::has_cap( 'gravityview_view_settings' ) ) { |
165
|
|
|
$actions[] = sprintf( '<a href="%s">%s</a>', admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ), esc_html__( 'Settings', 'gravityview' ) ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
if( GVCommon::has_cap( 'gravityview_support_port' ) ) { |
169
|
|
|
$actions[] = '<a href="https://docs.gravityview.co">' . esc_html__( 'Support', 'gravityview' ) . '</a>'; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return array_merge( $actions, $links ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Get an image of our intrepid explorer friend |
177
|
|
|
* @return string HTML image tag with floaty's cute mug on it |
178
|
|
|
*/ |
179
|
|
|
public static function get_floaty() { |
180
|
|
|
return gravityview_get_floaty(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Filter Admin messages |
185
|
|
|
* |
186
|
|
|
* @param array $messages Existing messages |
187
|
|
|
* @return array Messages with GravityView views! |
188
|
|
|
*/ |
189
|
|
|
function post_updated_messages( $messages, $bulk_counts = NULL ) { |
|
|
|
|
190
|
|
|
global $post; |
|
|
|
|
191
|
|
|
|
192
|
|
|
$post_id = get_the_ID(); |
193
|
|
|
|
194
|
|
|
// By default, there will only be one item being modified. |
195
|
|
|
// When in the `bulk_post_updated_messages` filter, there will be passed a number |
196
|
|
|
// of modified items that will override this array. |
197
|
|
|
$bulk_counts = is_null( $bulk_counts ) ? array( 'updated' => 1 , 'locked' => 1 , 'deleted' => 1 , 'trashed' => 1, 'untrashed' => 1 ) : $bulk_counts; |
|
|
|
|
198
|
|
|
|
199
|
|
|
// If we're starting fresh, a new form was created. |
200
|
|
|
// We should let the user know this is the case. |
201
|
|
|
$start_fresh = get_post_meta( $post_id, '_gravityview_start_fresh', true ); |
202
|
|
|
|
203
|
|
|
$new_form_text = ''; |
204
|
|
|
|
205
|
|
|
if( !empty( $start_fresh ) ) { |
|
|
|
|
206
|
|
|
|
207
|
|
|
// Get the form that was created |
208
|
|
|
$connected_form = gravityview_get_form_id( $post_id ); |
209
|
|
|
|
210
|
|
|
if( !empty( $connected_form ) ) { |
|
|
|
|
211
|
|
|
$form = gravityview_get_form( $connected_form ); |
212
|
|
|
$form_name = esc_attr( $form['title'] ); |
213
|
|
|
$image = self::get_floaty(); |
214
|
|
|
$new_form_text .= '<h3>'.$image.sprintf( __( 'A new form was created for this View: "%s"', 'gravityview' ), $form_name ).'</h3>'; |
215
|
|
|
$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 |
|
|
|
|
216
|
|
|
|
217
|
|
|
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. |
218
|
|
|
', '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>'); |
|
|
|
|
219
|
|
|
$new_form_text = wpautop( $new_form_text ); |
220
|
|
|
|
221
|
|
|
delete_post_meta( $post_id, '_gravityview_start_fresh' ); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$messages['gravityview'] = array( |
226
|
|
|
0 => '', // Unused. Messages start at index 1. |
227
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
228
|
|
|
1 => sprintf(__( 'View updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'), |
|
|
|
|
229
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
230
|
|
|
2 => sprintf(__( 'View updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'), |
|
|
|
|
231
|
|
|
3 => __( 'View deleted.', 'gravityview' ), |
232
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
233
|
|
|
4 => sprintf(__( 'View updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>'), |
|
|
|
|
234
|
|
|
/* translators: %s: date and time of the revision */ |
235
|
|
|
5 => isset( $_GET['revision'] ) ? sprintf( __( 'View restored to revision from %s', 'gravityview' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
|
|
|
236
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
237
|
|
|
6 => sprintf(__( 'View published. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text, |
|
|
|
|
238
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
239
|
|
|
7 => sprintf(__( 'View saved. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text, |
|
|
|
|
240
|
|
|
8 => __( 'View submitted.', 'gravityview' ), |
241
|
|
|
9 => sprintf( |
242
|
|
|
/* translators: Date and time the View is scheduled to be published */ |
243
|
|
|
__( 'View scheduled for: %1$s.', 'gravityview' ), |
244
|
|
|
// translators: Publish box date format, see http://php.net/date |
245
|
|
|
date_i18n( __( 'M j, Y @ G:i', 'gravityview' ), strtotime( ( isset( $post->post_date ) ? $post->post_date : NULL ) ) ) |
|
|
|
|
246
|
|
|
) . $new_form_text, |
|
|
|
|
247
|
|
|
/* translators: %s and %s are HTML tags linking to the View on the website */ |
248
|
|
|
10 => sprintf(__( 'View draft updated. %sView on website.%s', 'gravityview' ), '<a href="'.get_permalink( $post_id ).'">', '</a>') . $new_form_text, |
|
|
|
|
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* These apply to `bulk_post_updated_messages` |
252
|
|
|
* @file wp-admin/edit.php |
253
|
|
|
*/ |
254
|
|
|
'updated' => _n( '%s View updated.', '%s Views updated.', $bulk_counts['updated'], 'gravityview' ), |
255
|
|
|
'locked' => _n( '%s View not updated, somebody is editing it.', '%s Views not updated, somebody is editing them.', $bulk_counts['locked'], 'gravityview' ), |
256
|
|
|
'deleted' => _n( '%s View permanently deleted.', '%s Views permanently deleted.', $bulk_counts['deleted'], 'gravityview' ), |
257
|
|
|
'trashed' => _n( '%s View moved to the Trash.', '%s Views moved to the Trash.', $bulk_counts['trashed'], 'gravityview' ), |
258
|
|
|
'untrashed' => _n( '%s View restored from the Trash.', '%s Views restored from the Trash.', $bulk_counts['untrashed'], 'gravityview' ), |
259
|
|
|
); |
260
|
|
|
|
261
|
|
|
return $messages; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Get admin notices |
267
|
|
|
* @deprecated since 1.12 |
268
|
|
|
* @return array |
269
|
|
|
*/ |
270
|
|
|
public static function get_notices() { |
271
|
|
|
return GravityView_Admin_Notices::get_notices(); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Add a notice to be displayed in the admin. |
276
|
|
|
* @deprecated since 1.12 |
277
|
|
|
* @param array $notice Array with `class` and `message` keys. The message is not escaped. |
278
|
|
|
*/ |
279
|
|
|
public static function add_notice( $notice = array() ) { |
280
|
|
|
GravityView_Admin_Notices::add_notice( $notice ); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Check if Gravity Forms plugin is active and show notice if not. |
285
|
|
|
* |
286
|
|
|
* @deprecated since 1.12 |
287
|
|
|
* @see GravityView_Compatibility::get_plugin_status() |
288
|
|
|
* @return boolean True: checks have been passed; GV is fine to run; False: checks have failed, don't continue loading |
289
|
|
|
*/ |
290
|
|
|
public static function check_gravityforms() { |
291
|
|
|
return GravityView_Compatibility::check_gravityforms(); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Check if specified plugin is active, inactive or not installed |
296
|
|
|
* |
297
|
|
|
* @deprecated since 1.12 |
298
|
|
|
* @see GravityView_Compatibility::get_plugin_status() |
299
|
|
|
|
300
|
|
|
* @return boolean|string True: plugin is active; False: plugin file doesn't exist at path; 'inactive' it's inactive |
301
|
|
|
*/ |
302
|
|
|
static function get_plugin_status( $location = '' ) { |
|
|
|
|
303
|
|
|
return GravityView_Compatibility::get_plugin_status( $location ); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Is the current admin page a GravityView-related page? |
308
|
|
|
* |
309
|
|
|
* @deprecated See `gravityview()->request->is_admin` or `\GV\Request::is_admin` |
310
|
|
|
* @param string $hook |
311
|
|
|
* @param null|string $page Optional. String return value of page to compare against. |
312
|
|
|
* |
313
|
|
|
* @return bool|string 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`) |
314
|
|
|
*/ |
315
|
|
|
static function is_admin_page( $hook = '', $page = NULL ) { |
|
|
|
|
316
|
|
|
gravityview()->log->warning( 'The \GravityView_Admin::is_admin_page() method is deprecated. Use gravityview()->request->is_admin' ); |
317
|
|
|
return gravityview()->request->is_admin( $hook, $page ); |
|
|
|
|
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
new GravityView_Admin; |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Former alias for GravityView_Admin::is_admin_page() |
325
|
|
|
* |
326
|
|
|
* @param string $hook |
327
|
|
|
* @param null|string $page Optional. String return value of page to compare against. |
328
|
|
|
* |
329
|
|
|
* @deprecated See `gravityview()->request->is_admin` or `\GV\Request::is_admin` |
330
|
|
|
* |
331
|
|
|
* @return bool|string 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`) |
332
|
|
|
*/ |
333
|
|
|
function gravityview_is_admin_page( $hook = '', $page = NULL ) { |
|
|
|
|
334
|
1 |
|
gravityview()->log->warning( 'The gravityview_is_admin_page() function is deprecated. Use gravityview()->request->is_admin' ); |
335
|
1 |
|
return gravityview()->request->is_admin( $hook, $page ); |
|
|
|
|
336
|
|
|
} |
337
|
|
|
|
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.