1
1
<?php
2
+
2
3
/**
3
4
* Class Pods_Export_Code_Admin
4
5
*/
@@ -21,31 +22,30 @@ class Pods_Export_Code_Admin {
21
22
/**
22
23
* @var array
23
24
*/
24
- protected $ exportable_pods = array () ;
25
+ protected $ exportable_pods = [] ;
25
26
26
27
/**
27
28
* Initialize the plugin by loading admin scripts & styles and adding a
28
29
* settings page and menu.
29
30
*
30
31
* @since 1.0.0
31
32
*/
32
- private function __construct () {
33
-
33
+ private function __construct () {
34
34
/*
35
35
* Call $plugin_slug from public plugin class.
36
36
*/
37
- $ plugin = Pods_Export_Code::get_instance ();
37
+ $ plugin = Pods_Export_Code::get_instance ();
38
38
$ this ->plugin_slug = $ plugin ->get_plugin_slug ();
39
39
40
40
// Load admin style sheet and JavaScript.
41
- add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'enqueue_admin_styles ' ) );
42
- add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'enqueue_admin_scripts ' ) );
41
+ add_action ( 'admin_enqueue_scripts ' , [ $ this , 'enqueue_admin_styles ' ] );
42
+ add_action ( 'admin_enqueue_scripts ' , [ $ this , 'enqueue_admin_scripts ' ] );
43
43
44
44
// Hook into the pods admin menu
45
- add_filter ( 'pods_admin_menu ' , array ( $ this , 'add_plugin_admin_menu ' ) );
45
+ add_filter ( 'pods_admin_menu ' , [ $ this , 'add_plugin_admin_menu ' ] );
46
46
47
47
// Ajax handler
48
- add_action ( 'wp_ajax_pods_export_code ' , array ( $ this , 'pods_export_code ' ) );
48
+ add_action ( 'wp_ajax_pods_export_code ' , [ $ this , 'pods_export_code ' ] );
49
49
}
50
50
51
51
/**
@@ -55,8 +55,7 @@ private function __construct () {
55
55
*
56
56
* @return object A single instance of this class.
57
57
*/
58
- public static function get_instance () {
59
-
58
+ public static function get_instance () {
60
59
// If the single instance hasn't been set, set it now.
61
60
if ( null == self ::$ instance ) {
62
61
self ::$ instance = new self ;
@@ -72,17 +71,15 @@ public static function get_instance () {
72
71
*
73
72
* @return null Return early if no settings page is registered.
74
73
*/
75
- public function enqueue_admin_styles () {
76
-
77
- if ( !isset ( $ this ->plugin_screen_hook_suffix ) ) {
74
+ public function enqueue_admin_styles () {
75
+ if ( ! isset ( $ this ->plugin_screen_hook_suffix ) ) {
78
76
return ;
79
77
}
80
78
81
79
$ screen = get_current_screen ();
82
80
if ( $ this ->plugin_screen_hook_suffix == $ screen ->id ) {
83
- wp_enqueue_style ( $ this ->plugin_slug . '-admin-styles ' , plugins_url ( 'assets/css/admin.css ' , __FILE__ ), array () , Pods_Export_Code::VERSION );
81
+ wp_enqueue_style ( $ this ->plugin_slug . '-admin-styles ' , plugins_url ( 'assets/css/admin.css ' , __FILE__ ), [] , Pods_Export_Code::VERSION );
84
82
}
85
-
86
83
}
87
84
88
85
/**
@@ -92,17 +89,15 @@ public function enqueue_admin_styles () {
92
89
*
93
90
* @return null Return early if no settings page is registered.
94
91
*/
95
- public function enqueue_admin_scripts () {
96
-
97
- if ( !isset ( $ this ->plugin_screen_hook_suffix ) ) {
92
+ public function enqueue_admin_scripts () {
93
+ if ( ! isset ( $ this ->plugin_screen_hook_suffix ) ) {
98
94
return ;
99
95
}
100
96
101
97
$ screen = get_current_screen ();
102
98
if ( $ this ->plugin_screen_hook_suffix == $ screen ->id ) {
103
- wp_enqueue_script ( $ this ->plugin_slug . '-admin-script ' , plugins_url ( 'assets/js/admin.js ' , __FILE__ ), array ( 'jquery ' ) , Pods_Export_Code::VERSION );
99
+ wp_enqueue_script ( $ this ->plugin_slug . '-admin-script ' , plugins_url ( 'assets/js/admin.js ' , __FILE__ ), [ 'jquery ' ] , Pods_Export_Code::VERSION );
104
100
}
105
-
106
101
}
107
102
108
103
/**
@@ -112,26 +107,24 @@ public function enqueue_admin_scripts () {
112
107
*
113
108
* @return array
114
109
*/
115
- public function add_plugin_admin_menu ( $ admin_menus ) {
116
-
110
+ public function add_plugin_admin_menu ( $ admin_menus ) {
117
111
// Fresh array to insert our new menu item
118
- $ new_menus = array () ;
112
+ $ new_menus = [] ;
119
113
120
114
// New menu item to insert
121
- $ plugin_menu = array (
115
+ $ plugin_menu = [
122
116
'label ' => 'Export to Code ' ,
123
- 'function ' => array ( $ this , 'display_plugin_admin_page ' ) ,
124
- 'access ' => $ this ->plugin_slug
125
- ) ;
117
+ 'function ' => [ $ this , 'display_plugin_admin_page ' ] ,
118
+ 'access ' => $ this ->plugin_slug ,
119
+ ] ;
126
120
127
121
// Loop through the Pods menu items looking for the target to insert after
128
122
foreach ( $ admin_menus as $ key => $ this_menu_item ) {
129
-
130
123
// Copy all the menu items
131
124
$ new_menus [ $ key ] = $ this_menu_item ;
132
125
133
126
// Insert our menu item after pods components
134
- if ( isset ( $ this_menu_item [ 'access ' ] ) && 'pods_components ' == $ this_menu_item [ 'access ' ] ) {
127
+ if ( isset ( $ this_menu_item ['access ' ] ) && 'pods_components ' == $ this_menu_item ['access ' ] ) {
135
128
$ new_menus [ $ this ->plugin_slug ] = $ plugin_menu ;
136
129
137
130
// ToDo: Proper way to do this?
@@ -147,56 +140,49 @@ public function add_plugin_admin_menu ( $admin_menus ) {
147
140
*
148
141
* @since 1.0.0
149
142
*/
150
- public function display_plugin_admin_page () {
151
-
143
+ public function display_plugin_admin_page () {
152
144
$ this ->set_exportable_pods ();
153
145
if ( count ( $ this ->exportable_pods () ) > 0 ) {
154
146
include_once ( 'views/admin.php ' );
155
- }
156
- else {
147
+ } else {
157
148
include_once ( 'views/admin-no-pods.php ' );
158
149
}
159
-
160
150
}
161
151
162
152
/**
163
153
*
164
154
*/
165
- private function set_exportable_pods () {
155
+ private function set_exportable_pods () {
156
+ $ this ->exportable_pods = [];
166
157
167
- $ this ->exportable_pods = array ();
168
-
169
- $ pods = pods_api ()->load_pods ( array ( 'fields ' => false ) );
158
+ $ pods = pods_api ()->load_pods ( [ 'fields ' => false ] );
170
159
foreach ( $ pods as $ this_pod ) {
171
-
172
160
// We do no support table-based Pods
173
- if ( 'table ' == $ this_pod [ 'storage ' ] ) {
161
+ if ( 'table ' == $ this_pod ['storage ' ] ) {
174
162
continue ;
175
163
}
176
164
177
- $ this ->exportable_pods [ ] = $ this_pod ;
165
+ $ this ->exportable_pods [] = $ this_pod ;
178
166
}
179
-
180
167
}
181
168
182
169
/**
183
170
* @return array
184
171
*/
185
- public function exportable_pods () {
172
+ public function exportable_pods () {
186
173
return $ this ->exportable_pods ;
187
174
}
188
175
189
176
/**
190
177
* AJAX handler
191
178
*/
192
- public function pods_export_code () {
193
-
194
- if ( !isset ( $ _POST [ 'pod_names ' ] ) ) {
179
+ public function pods_export_code () {
180
+ if ( ! isset ( $ _POST ['pod_names ' ] ) ) {
195
181
die ();
196
182
}
197
- $ pod_names = $ _POST [ 'pod_names ' ];
183
+ $ pod_names = $ _POST ['pod_names ' ];
198
184
199
- if ( !is_array ( $ pod_names ) ) {
185
+ if ( ! is_array ( $ pod_names ) ) {
200
186
die ();
201
187
}
202
188
0 commit comments