@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage Evans |
9 | 9 | * @author Old Town Media |
10 | 10 | */ |
11 | -class AdminPage{ |
|
11 | +class AdminPage { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Hooks function. |
@@ -17,12 +17,12 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @see admin_menu, wp_ajax actions |
19 | 19 | */ |
20 | - public function hooks( $file ){ |
|
20 | + public function hooks($file) { |
|
21 | 21 | |
22 | - add_action( 'admin_menu' , array( $this, 'add_menu_item' ) ); |
|
23 | - add_action( 'wp_ajax_handle_test_data', array( $this, 'handle_test_data_callback' ) ); |
|
24 | - add_filter( 'plugin_action_links_' . plugin_basename( $file ) , array( $this, 'add_settings_link' ) ); |
|
25 | - add_action( 'admin_notices', array( $this, 'internet_connected_admin_notice' ) ); |
|
22 | + add_action('admin_menu', array($this, 'add_menu_item')); |
|
23 | + add_action('wp_ajax_handle_test_data', array($this, 'handle_test_data_callback')); |
|
24 | + add_filter('plugin_action_links_' . plugin_basename($file), array($this, 'add_settings_link')); |
|
25 | + add_action('admin_notices', array($this, 'internet_connected_admin_notice')); |
|
26 | 26 | |
27 | 27 | } |
28 | 28 | |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | |
37 | 37 | $page = add_submenu_page( |
38 | 38 | 'tools.php', |
39 | - __( 'Create Test Content', 'otm-test-content' ), |
|
40 | - __( 'Test Content', 'otm-test-content' ), |
|
39 | + __('Create Test Content', 'otm-test-content'), |
|
40 | + __('Test Content', 'otm-test-content'), |
|
41 | 41 | 'manage_options', |
42 | 42 | 'create-test-data', |
43 | - array( $this, 'admin_page' ) |
|
43 | + array($this, 'admin_page') |
|
44 | 44 | ); |
45 | 45 | |
46 | - add_action( 'admin_print_styles-' . $page, array( $this, 'load_scripts' ) ); |
|
46 | + add_action('admin_print_styles-' . $page, array($this, 'load_scripts')); |
|
47 | 47 | |
48 | 48 | } |
49 | 49 | |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | * @param array $links Existing links |
54 | 54 | * @return array Modified links |
55 | 55 | */ |
56 | - public function add_settings_link( $links ) { |
|
56 | + public function add_settings_link($links) { |
|
57 | 57 | |
58 | - $settings_link = '<a href="tools.php?page=create-test-data">' . __( 'Build Test Content', 'otm-test-content' ) . '</a>'; |
|
59 | - array_push( $links, $settings_link ); |
|
58 | + $settings_link = '<a href="tools.php?page=create-test-data">' . __('Build Test Content', 'otm-test-content') . '</a>'; |
|
59 | + array_push($links, $settings_link); |
|
60 | 60 | return $links; |
61 | 61 | |
62 | 62 | } |
@@ -69,28 +69,28 @@ discard block |
||
69 | 69 | * Internet, and the test fails displays a notice informing the user that |
70 | 70 | * images will not pull into test data. |
71 | 71 | */ |
72 | - public function internet_connected_admin_notice(){ |
|
72 | + public function internet_connected_admin_notice() { |
|
73 | 73 | |
74 | 74 | // Get the current admin screen & verify that we're on the right one |
75 | 75 | // before continuing. |
76 | 76 | $screen = get_current_screen(); |
77 | 77 | |
78 | - if ( $screen->base != 'tools_page_create-test-data' ){ |
|
78 | + if ($screen->base != 'tools_page_create-test-data') { |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | 82 | // Define our test point and try to reach out to the URL |
83 | 83 | $test_url = 'http://www.splashbase.co/api/v1/images/'; |
84 | - $response = wp_remote_get( $test_url ); |
|
84 | + $response = wp_remote_get($test_url); |
|
85 | 85 | |
86 | 86 | // Check the response |
87 | - if ( is_array( $response ) ) { |
|
87 | + if (is_array($response)) { |
|
88 | 88 | // We got a response so early return |
89 | 89 | return; |
90 | 90 | } else { |
91 | 91 | // We didn't get a reponse so print the notice out |
92 | 92 | echo '<div class="notice notice-error is-dismissible">'; |
93 | - echo '<p>'.__( 'WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content' ).'</p>'; |
|
93 | + echo '<p>' . __('WordPress could not connect to Splashbase and therefore images will not pull into metaboxes/thumbnails. Turn Airplane Mode off or reconnect to the Internet to get images when creating test data.', 'otm-test-content') . '</p>'; |
|
94 | 94 | echo '</div>'; |
95 | 95 | } |
96 | 96 | |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | /** |
101 | 101 | * Load our script in the admin section and serve in data. |
102 | 102 | */ |
103 | - public function load_scripts(){ |
|
103 | + public function load_scripts() { |
|
104 | 104 | |
105 | - wp_enqueue_script( 'test-content-js', plugins_url( 'assets/admin.js' , dirname( __FILE__ ) ) ); |
|
106 | - wp_enqueue_style( 'test-content-css', plugins_url( 'assets/admin.css' , dirname( __FILE__ ) ) ); |
|
105 | + wp_enqueue_script('test-content-js', plugins_url('assets/admin.js', dirname(__FILE__))); |
|
106 | + wp_enqueue_style('test-content-css', plugins_url('assets/admin.css', dirname(__FILE__))); |
|
107 | 107 | |
108 | 108 | $data = array( |
109 | - 'nonce' => wp_create_nonce( 'handle-test-data' ) |
|
109 | + 'nonce' => wp_create_nonce('handle-test-data') |
|
110 | 110 | ); |
111 | 111 | |
112 | - wp_localize_script( 'test-content-js', 'test_content', $data ); |
|
112 | + wp_localize_script('test-content-js', 'test_content', $data); |
|
113 | 113 | |
114 | 114 | } |
115 | 115 | |
@@ -121,21 +121,21 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function handle_test_data_callback() { |
123 | 123 | |
124 | - $action = $_REQUEST['todo']; |
|
125 | - $nonce = $_REQUEST['nonce']; |
|
124 | + $action = $_REQUEST['todo']; |
|
125 | + $nonce = $_REQUEST['nonce']; |
|
126 | 126 | |
127 | 127 | // Verify that we have a proper logged in user and it's the right person |
128 | - if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'handle-test-data' ) ){ |
|
128 | + if (empty($nonce) || !wp_verify_nonce($nonce, 'handle-test-data')) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | 131 | |
132 | - if ( $action == 'delete' ){ |
|
132 | + if ($action == 'delete') { |
|
133 | 133 | |
134 | - $this->deletion_routing( $_REQUEST ); |
|
134 | + $this->deletion_routing($_REQUEST); |
|
135 | 135 | |
136 | - } elseif ( $action == 'create' ){ |
|
136 | + } elseif ($action == 'create') { |
|
137 | 137 | |
138 | - $this->creation_routing( $_REQUEST ); |
|
138 | + $this->creation_routing($_REQUEST); |
|
139 | 139 | |
140 | 140 | } |
141 | 141 | |
@@ -148,17 +148,17 @@ discard block |
||
148 | 148 | * Choose which type of creation needs to be accomplished and route through |
149 | 149 | * the correct class. |
150 | 150 | */ |
151 | - private function creation_routing( $data ){ |
|
151 | + private function creation_routing($data) { |
|
152 | 152 | |
153 | - if ( $data['type'] == 'post' ){ |
|
153 | + if ($data['type'] == 'post') { |
|
154 | 154 | |
155 | 155 | $create_content = new CreatePost; |
156 | - $create_content->create_post_type_content( $data['slug'], true, 1 ); |
|
156 | + $create_content->create_post_type_content($data['slug'], true, 1); |
|
157 | 157 | |
158 | - } elseif( $data['type'] == 'term' ){ |
|
158 | + } elseif ($data['type'] == 'term') { |
|
159 | 159 | |
160 | 160 | $create_content = new CreateTerm; |
161 | - $create_content->create_terms( $data['slug'], true, 1 ); |
|
161 | + $create_content->create_terms($data['slug'], true, 1); |
|
162 | 162 | |
163 | 163 | } |
164 | 164 | |
@@ -169,17 +169,17 @@ discard block |
||
169 | 169 | * Choose which type of deletion needs to be accomplished and route through |
170 | 170 | * the correct method of Delete. |
171 | 171 | */ |
172 | - private function deletion_routing( $data ){ |
|
172 | + private function deletion_routing($data) { |
|
173 | 173 | |
174 | 174 | $delete_content = new Delete; |
175 | 175 | |
176 | - if ( $data['type'] == 'post' ){ |
|
176 | + if ($data['type'] == 'post') { |
|
177 | 177 | |
178 | - $delete_content->delete_posts( $data['slug'], true ); |
|
178 | + $delete_content->delete_posts($data['slug'], true); |
|
179 | 179 | |
180 | - } elseif ( $data['type'] == 'term' ){ |
|
180 | + } elseif ($data['type'] == 'term') { |
|
181 | 181 | |
182 | - $delete_content->delete_terms( $data['slug'], true ); |
|
182 | + $delete_content->delete_terms($data['slug'], true); |
|
183 | 183 | |
184 | 184 | } |
185 | 185 | |
@@ -189,16 +189,16 @@ discard block |
||
189 | 189 | /** |
190 | 190 | * Print out our admin page to control test data. |
191 | 191 | */ |
192 | - public function admin_page(){ |
|
192 | + public function admin_page() { |
|
193 | 193 | |
194 | 194 | $html = ""; |
195 | 195 | |
196 | 196 | $html .= '<div class="wrap" id="options_editor">' . "\n"; |
197 | 197 | |
198 | - $html .= '<h2>' . __( 'Create Test Data' , 'otm-test-content' ) . '</h2>' . "\n"; |
|
198 | + $html .= '<h2>' . __('Create Test Data', 'otm-test-content') . '</h2>' . "\n"; |
|
199 | 199 | |
200 | 200 | // Loop through all other cpts |
201 | - $post_types = get_post_types( array( 'public' => true ), 'objects' ); |
|
201 | + $post_types = get_post_types(array('public' => true), 'objects'); |
|
202 | 202 | |
203 | 203 | $html .= "<div>"; |
204 | 204 | |
@@ -210,14 +210,14 @@ discard block |
||
210 | 210 | $html .= "</div>"; |
211 | 211 | |
212 | 212 | // Loop through every post type available on the site |
213 | - foreach ( $post_types as $post_type ) { |
|
213 | + foreach ($post_types as $post_type) { |
|
214 | 214 | |
215 | 215 | $skipped_cpts = array( |
216 | 216 | 'attachment' |
217 | 217 | ); |
218 | 218 | |
219 | 219 | // Skip banned cpts |
220 | - if ( in_array( $post_type->name, $skipped_cpts ) ){ |
|
220 | + if (in_array($post_type->name, $skipped_cpts)) { |
|
221 | 221 | continue; |
222 | 222 | } |
223 | 223 | |
@@ -227,17 +227,17 @@ discard block |
||
227 | 227 | $html .= "<h3>"; |
228 | 228 | |
229 | 229 | $html .= "<span class='label'>" . $post_type->labels->name . "</span>"; |
230 | - $html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus'></span> ".__( 'Create Test Data', 'otm-test-content' )."</a>"; |
|
231 | - $html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__( 'Delete Test Data', 'otm-test-content' )."</a>"; |
|
230 | + $html .= " <a href='javascript:void(0);' data-type='post' data-slug='" . $post_type->name . "' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus'></span> " . __('Create Test Data', 'otm-test-content') . "</a>"; |
|
231 | + $html .= " <a href='javascript:void(0);' data-type='post' data-slug='" . $post_type->name . "' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> " . __('Delete Test Data', 'otm-test-content') . "</a>"; |
|
232 | 232 | |
233 | 233 | $html .= "</h3>"; |
234 | 234 | |
235 | 235 | // Create row for each taxonomy associated with the post/page/cpt |
236 | - $taxonomies = get_object_taxonomies( $post_type->name ); |
|
236 | + $taxonomies = get_object_taxonomies($post_type->name); |
|
237 | 237 | |
238 | - if ( !empty( $taxonomies ) ){ |
|
238 | + if (!empty($taxonomies)) { |
|
239 | 239 | |
240 | - foreach( $taxonomies as $tax ){ |
|
240 | + foreach ($taxonomies as $tax) { |
|
241 | 241 | |
242 | 242 | $html .= "<h3>"; |
243 | 243 | |
@@ -246,17 +246,17 @@ discard block |
||
246 | 246 | ); |
247 | 247 | |
248 | 248 | // Skip banned taxonomies |
249 | - if ( in_array( $tax, $skipped_taxonomies ) ){ |
|
249 | + if (in_array($tax, $skipped_taxonomies)) { |
|
250 | 250 | continue; |
251 | 251 | } |
252 | 252 | |
253 | - $taxonomy = get_taxonomy( $tax ); |
|
253 | + $taxonomy = get_taxonomy($tax); |
|
254 | 254 | |
255 | - $html .= "<span class='label term-label'> ".$taxonomy->labels->name."</span>"; |
|
255 | + $html .= "<span class='label term-label'> " . $taxonomy->labels->name . "</span>"; |
|
256 | 256 | |
257 | - $html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category'></span> ".__( 'Create', 'otm-test-content' )." ".$taxonomy->labels->name."</a>"; |
|
257 | + $html .= " <a href='javascript:void(0);' data-type='term' data-slug='" . $tax . "' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category'></span> " . __('Create', 'otm-test-content') . " " . $taxonomy->labels->name . "</a>"; |
|
258 | 258 | |
259 | - $html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__( 'Delete', 'otm-test-content' )." ".$taxonomy->labels->name."</a>"; |
|
259 | + $html .= " <a href='javascript:void(0);' data-type='term' data-slug='" . $tax . "' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> " . __('Delete', 'otm-test-content') . " " . $taxonomy->labels->name . "</a>"; |
|
260 | 260 | |
261 | 261 | $html .= "</h3>"; |
262 | 262 |