@@ -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 | * file |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @see admin_menu, wp_ajax actions |
28 | 28 | */ |
29 | - public function hooks( $file ){ |
|
29 | + public function hooks($file) { |
|
30 | 30 | |
31 | 31 | $this->file = $file; |
32 | 32 | |
33 | - add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); |
|
34 | - add_action( 'admin_menu' , array( $this, 'add_menu_item' ) ); |
|
35 | - add_action( 'wp_ajax_handle_test_data', array( $this, 'handle_test_data_callback' ) ); |
|
36 | - add_filter( 'plugin_action_links_' . plugin_basename( $file ) , array( $this, 'add_settings_link' ) ); |
|
37 | - add_action( 'admin_notices', array( $this, 'internet_connected_admin_notice' ) ); |
|
33 | + add_action('plugins_loaded', array($this, 'load_textdomain')); |
|
34 | + add_action('admin_menu', array($this, 'add_menu_item')); |
|
35 | + add_action('wp_ajax_handle_test_data', array($this, 'handle_test_data_callback')); |
|
36 | + add_filter('plugin_action_links_' . plugin_basename($file), array($this, 'add_settings_link')); |
|
37 | + add_action('admin_notices', array($this, 'internet_connected_admin_notice')); |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @see load_plugin_textdomain |
46 | 46 | */ |
47 | 47 | public function load_textdomain() { |
48 | - load_plugin_textdomain( 'otm-test-content', FALSE, basename( dirname( $this->file ) ) . '/languages/' ); |
|
48 | + load_plugin_textdomain('otm-test-content', FALSE, basename(dirname($this->file)) . '/languages/'); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | |
59 | 59 | $page = add_submenu_page( |
60 | 60 | 'tools.php', |
61 | - __( 'Create Test Content', 'otm-test-content' ), |
|
62 | - __( 'Test Content', 'otm-test-content' ), |
|
61 | + __('Create Test Content', 'otm-test-content'), |
|
62 | + __('Test Content', 'otm-test-content'), |
|
63 | 63 | 'manage_options', |
64 | 64 | 'create-test-data', |
65 | - array( $this, 'admin_page' ) |
|
65 | + array($this, 'admin_page') |
|
66 | 66 | ); |
67 | 67 | |
68 | - add_action( 'admin_print_styles-' . $page, array( $this, 'load_scripts' ) ); |
|
68 | + add_action('admin_print_styles-' . $page, array($this, 'load_scripts')); |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | * @param array $links Existing links |
76 | 76 | * @return array Modified links |
77 | 77 | */ |
78 | - public function add_settings_link( $links ) { |
|
78 | + public function add_settings_link($links) { |
|
79 | 79 | |
80 | - $settings_link = '<a href="tools.php?page=create-test-data">' . __( 'Build Test Content', 'otm-test-content' ) . '</a>'; |
|
81 | - array_push( $links, $settings_link ); |
|
80 | + $settings_link = '<a href="tools.php?page=create-test-data">' . __('Build Test Content', 'otm-test-content') . '</a>'; |
|
81 | + array_push($links, $settings_link); |
|
82 | 82 | return $links; |
83 | 83 | |
84 | 84 | } |
@@ -91,24 +91,24 @@ discard block |
||
91 | 91 | * Internet, and the test fails displays a notice informing the user that |
92 | 92 | * images will not pull into test data. |
93 | 93 | */ |
94 | - public function internet_connected_admin_notice(){ |
|
94 | + public function internet_connected_admin_notice() { |
|
95 | 95 | |
96 | 96 | // Get the current admin screen & verify that we're on the right one |
97 | 97 | // before continuing. |
98 | 98 | $screen = get_current_screen(); |
99 | 99 | |
100 | - if ( $screen->base != 'tools_page_create-test-data' ){ |
|
100 | + if ($screen->base != 'tools_page_create-test-data') { |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // Check the response |
105 | - if ( $this->test_splashbase_api() ) { |
|
105 | + if ($this->test_splashbase_api()) { |
|
106 | 106 | // We got a response so early return |
107 | 107 | return; |
108 | 108 | } else { |
109 | 109 | // We didn't get a reponse so print the notice out |
110 | 110 | echo '<div class="notice notice-error is-dismissible">'; |
111 | - 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>'; |
|
111 | + 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>'; |
|
112 | 112 | echo '</div>'; |
113 | 113 | } |
114 | 114 | |
@@ -131,30 +131,30 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return boolean Status of connection to Splashbase. |
133 | 133 | */ |
134 | - private function test_splashbase_api(){ |
|
134 | + private function test_splashbase_api() { |
|
135 | 135 | |
136 | 136 | /* |
137 | 137 | * Test #1 - Check Internet connection in general |
138 | 138 | */ |
139 | 139 | // Attempt to open a socket connection to Google |
140 | - $connected = @fsockopen( "www.google.com", 80 ); |
|
140 | + $connected = @fsockopen("www.google.com", 80); |
|
141 | 141 | |
142 | - if ( !$connected ){ |
|
142 | + if (!$connected) { |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | 146 | // Close out our 1st test |
147 | - fclose( $connected ); |
|
147 | + fclose($connected); |
|
148 | 148 | |
149 | 149 | |
150 | 150 | /* |
151 | 151 | * Test #2 - Check for Airplane Mode plugin status |
152 | 152 | */ |
153 | - if ( class_exists( 'Airplane_Mode_Core' ) ){ |
|
153 | + if (class_exists('Airplane_Mode_Core')) { |
|
154 | 154 | // Is airplane mode active? |
155 | - $airplane_mode = get_site_option( 'airplane-mode' ); |
|
155 | + $airplane_mode = get_site_option('airplane-mode'); |
|
156 | 156 | |
157 | - if ( $airplane_mode === 'on' ){ |
|
157 | + if ($airplane_mode === 'on') { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | } |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | * Test #3 - Check Splashbase itself |
165 | 165 | */ |
166 | 166 | $test_url = 'http://www.splashbase.co/api/v1/images/'; |
167 | - $response = wp_remote_get( $test_url ); |
|
167 | + $response = wp_remote_get($test_url); |
|
168 | 168 | |
169 | - if ( !is_array( $response ) ){ |
|
169 | + if (!is_array($response)) { |
|
170 | 170 | return false; |
171 | 171 | } |
172 | 172 | |
@@ -179,19 +179,19 @@ discard block |
||
179 | 179 | /** |
180 | 180 | * Load our script in the admin section and serve in data. |
181 | 181 | */ |
182 | - public function load_scripts(){ |
|
182 | + public function load_scripts() { |
|
183 | 183 | |
184 | - wp_enqueue_script( 'test-content-js', plugins_url( 'assets/admin.js' , dirname( __FILE__ ) ) ); |
|
185 | - wp_enqueue_style( 'test-content-css', plugins_url( 'assets/admin.css' , dirname( __FILE__ ) ) ); |
|
184 | + wp_enqueue_script('test-content-js', plugins_url('assets/admin.js', dirname(__FILE__))); |
|
185 | + wp_enqueue_style('test-content-css', plugins_url('assets/admin.css', dirname(__FILE__))); |
|
186 | 186 | |
187 | 187 | $data = array( |
188 | - 'nonce' => wp_create_nonce( 'handle-test-data' ), |
|
189 | - 'createdStr' => __( 'Created', 'otm-test-content' ), |
|
190 | - 'deletedStr' => __( 'Deleting', 'otm-test-content' ), |
|
191 | - 'creatingStr' => __( 'Creating', 'otm-test-content' ), |
|
188 | + 'nonce' => wp_create_nonce('handle-test-data'), |
|
189 | + 'createdStr' => __('Created', 'otm-test-content'), |
|
190 | + 'deletedStr' => __('Deleting', 'otm-test-content'), |
|
191 | + 'creatingStr' => __('Creating', 'otm-test-content'), |
|
192 | 192 | ); |
193 | 193 | |
194 | - wp_localize_script( 'test-content-js', 'test_content', $data ); |
|
194 | + wp_localize_script('test-content-js', 'test_content', $data); |
|
195 | 195 | |
196 | 196 | } |
197 | 197 | |
@@ -203,21 +203,21 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public function handle_test_data_callback() { |
205 | 205 | |
206 | - $action = $_REQUEST['todo']; |
|
207 | - $nonce = $_REQUEST['nonce']; |
|
206 | + $action = $_REQUEST['todo']; |
|
207 | + $nonce = $_REQUEST['nonce']; |
|
208 | 208 | |
209 | 209 | // Verify that we have a proper logged in user and it's the right person |
210 | - if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'handle-test-data' ) ){ |
|
210 | + if (empty($nonce) || !wp_verify_nonce($nonce, 'handle-test-data')) { |
|
211 | 211 | return; |
212 | 212 | } |
213 | 213 | |
214 | - if ( $action == 'delete' ){ |
|
214 | + if ($action == 'delete') { |
|
215 | 215 | |
216 | - $this->deletion_routing( $_REQUEST ); |
|
216 | + $this->deletion_routing($_REQUEST); |
|
217 | 217 | |
218 | - } elseif ( $action == 'create' ){ |
|
218 | + } elseif ($action == 'create') { |
|
219 | 219 | |
220 | - $this->creation_routing( $_REQUEST ); |
|
220 | + $this->creation_routing($_REQUEST); |
|
221 | 221 | |
222 | 222 | } |
223 | 223 | |
@@ -230,17 +230,17 @@ discard block |
||
230 | 230 | * Choose which type of creation needs to be accomplished and route through |
231 | 231 | * the correct class. |
232 | 232 | */ |
233 | - private function creation_routing( $data ){ |
|
233 | + private function creation_routing($data) { |
|
234 | 234 | |
235 | - if ( $data['type'] == 'post' ){ |
|
235 | + if ($data['type'] == 'post') { |
|
236 | 236 | |
237 | 237 | $create_content = new CreatePost; |
238 | - $create_content->create_post_type_content( $data['slug'], true, 1 ); |
|
238 | + $create_content->create_post_type_content($data['slug'], true, 1); |
|
239 | 239 | |
240 | - } elseif( $data['type'] == 'term' ){ |
|
240 | + } elseif ($data['type'] == 'term') { |
|
241 | 241 | |
242 | 242 | $create_content = new CreateTerm; |
243 | - $create_content->create_terms( $data['slug'], true, 1 ); |
|
243 | + $create_content->create_terms($data['slug'], true, 1); |
|
244 | 244 | |
245 | 245 | } |
246 | 246 | |
@@ -251,17 +251,17 @@ discard block |
||
251 | 251 | * Choose which type of deletion needs to be accomplished and route through |
252 | 252 | * the correct method of Delete. |
253 | 253 | */ |
254 | - private function deletion_routing( $data ){ |
|
254 | + private function deletion_routing($data) { |
|
255 | 255 | |
256 | 256 | $delete_content = new Delete; |
257 | 257 | |
258 | - if ( $data['type'] == 'post' ){ |
|
258 | + if ($data['type'] == 'post') { |
|
259 | 259 | |
260 | - $delete_content->delete_posts( $data['slug'], true ); |
|
260 | + $delete_content->delete_posts($data['slug'], true); |
|
261 | 261 | |
262 | - } elseif ( $data['type'] == 'term' ){ |
|
262 | + } elseif ($data['type'] == 'term') { |
|
263 | 263 | |
264 | - $delete_content->delete_terms( $data['slug'], true ); |
|
264 | + $delete_content->delete_terms($data['slug'], true); |
|
265 | 265 | |
266 | 266 | } |
267 | 267 | |
@@ -271,35 +271,35 @@ discard block |
||
271 | 271 | /** |
272 | 272 | * Print out our admin page to control test data. |
273 | 273 | */ |
274 | - public function admin_page(){ |
|
274 | + public function admin_page() { |
|
275 | 275 | |
276 | 276 | $html = ""; |
277 | 277 | |
278 | 278 | $html .= '<div class="wrap" id="options_editor">' . "\n"; |
279 | 279 | |
280 | - $html .= '<h2>' . __( 'Create Test Data' , 'otm-test-content' ) . '</h2>' . "\n"; |
|
280 | + $html .= '<h2>' . __('Create Test Data', 'otm-test-content') . '</h2>' . "\n"; |
|
281 | 281 | |
282 | 282 | // Loop through all other cpts |
283 | - $post_types = get_post_types( array( 'public' => true ), 'objects' ); |
|
283 | + $post_types = get_post_types(array('public' => true), 'objects'); |
|
284 | 284 | |
285 | 285 | $html .= "<div>"; |
286 | 286 | |
287 | 287 | $html .= "<div class='test-data-cpt'>"; |
288 | 288 | $html .= "<h3>"; |
289 | - $html .= "<span class='label'>".__( 'Quantity', 'otm-test-content' )."</span>"; |
|
290 | - $html .= "<input type='number' value='0' id='quantity-adjustment'> <small><i>".__( 'Set to 0 to keep random', 'otm-test-content' )."</i></small>"; |
|
289 | + $html .= "<span class='label'>" . __('Quantity', 'otm-test-content') . "</span>"; |
|
290 | + $html .= "<input type='number' value='0' id='quantity-adjustment'> <small><i>" . __('Set to 0 to keep random', 'otm-test-content') . "</i></small>"; |
|
291 | 291 | $html .= "</h3>"; |
292 | 292 | $html .= "</div>"; |
293 | 293 | |
294 | 294 | // Loop through every post type available on the site |
295 | - foreach ( $post_types as $post_type ) { |
|
295 | + foreach ($post_types as $post_type) { |
|
296 | 296 | |
297 | 297 | $skipped_cpts = array( |
298 | 298 | 'attachment' |
299 | 299 | ); |
300 | 300 | |
301 | 301 | // Skip banned cpts |
302 | - if ( in_array( $post_type->name, $skipped_cpts ) ){ |
|
302 | + if (in_array($post_type->name, $skipped_cpts)) { |
|
303 | 303 | continue; |
304 | 304 | } |
305 | 305 | |
@@ -309,17 +309,17 @@ discard block |
||
309 | 309 | $html .= "<h3>"; |
310 | 310 | |
311 | 311 | $html .= "<span class='label'>" . $post_type->labels->name . "</span>"; |
312 | - $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>"; |
|
313 | - $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>"; |
|
312 | + $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>"; |
|
313 | + $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>"; |
|
314 | 314 | |
315 | 315 | $html .= "</h3>"; |
316 | 316 | |
317 | 317 | // Create row for each taxonomy associated with the post/page/cpt |
318 | - $taxonomies = get_object_taxonomies( $post_type->name ); |
|
318 | + $taxonomies = get_object_taxonomies($post_type->name); |
|
319 | 319 | |
320 | - if ( !empty( $taxonomies ) ){ |
|
320 | + if (!empty($taxonomies)) { |
|
321 | 321 | |
322 | - foreach( $taxonomies as $tax ){ |
|
322 | + foreach ($taxonomies as $tax) { |
|
323 | 323 | |
324 | 324 | $html .= "<h3 class='term-box'>"; |
325 | 325 | |
@@ -328,17 +328,17 @@ discard block |
||
328 | 328 | ); |
329 | 329 | |
330 | 330 | // Skip banned taxonomies |
331 | - if ( in_array( $tax, $skipped_taxonomies ) ){ |
|
331 | + if (in_array($tax, $skipped_taxonomies)) { |
|
332 | 332 | continue; |
333 | 333 | } |
334 | 334 | |
335 | - $taxonomy = get_taxonomy( $tax ); |
|
335 | + $taxonomy = get_taxonomy($tax); |
|
336 | 336 | |
337 | - $html .= "<span class='label'>".$taxonomy->labels->name."</span>"; |
|
337 | + $html .= "<span class='label'>" . $taxonomy->labels->name . "</span>"; |
|
338 | 338 | |
339 | - $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>"; |
|
339 | + $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>"; |
|
340 | 340 | |
341 | - $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>"; |
|
341 | + $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>"; |
|
342 | 342 | |
343 | 343 | $html .= "</h3>"; |
344 | 344 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @subpackage Evans |
15 | 15 | * @author Old Town Media |
16 | 16 | */ |
17 | -class TestContent{ |
|
17 | +class TestContent { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Title function. |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param int $num_words Number of words to return. |
27 | 27 | * @return string Random title string. |
28 | 28 | */ |
29 | - public static function title( $num_words = '' ){ |
|
29 | + public static function title($num_words = '') { |
|
30 | 30 | |
31 | 31 | $title = ''; |
32 | 32 | |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | ); |
68 | 68 | |
69 | 69 | // If we didn't choose a count, make one |
70 | - if ( empty( $num_words ) ){ |
|
71 | - $num_words = rand( 2, 10 ); |
|
70 | + if (empty($num_words)) { |
|
71 | + $num_words = rand(2, 10); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // Pull random words |
75 | - for( $i = 1; $i <= $num_words; $i++ ){ |
|
76 | - $title .= $random_words[ rand( 0, 31 ) ] . " "; |
|
75 | + for ($i = 1; $i <= $num_words; $i++) { |
|
76 | + $title .= $random_words[rand(0, 31)] . " "; |
|
77 | 77 | } |
78 | 78 | |
79 | - return substr( $title, 0, -1 ); |
|
79 | + return substr($title, 0, -1); |
|
80 | 80 | |
81 | 81 | } |
82 | 82 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return string Paragraph(s) of text. |
91 | 91 | */ |
92 | - public static function paragraphs(){ |
|
92 | + public static function paragraphs() { |
|
93 | 93 | |
94 | 94 | $content = ''; |
95 | 95 | |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | </table>' |
337 | 337 | ); |
338 | 338 | |
339 | - for( $i = 1; $i < 6; $i++ ){ |
|
340 | - $content .= $random_content_types[rand( 0, 10 )]; |
|
339 | + for ($i = 1; $i < 6; $i++) { |
|
340 | + $content .= $random_content_types[rand(0, 10)]; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | return $content; |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * |
353 | 353 | * @return string Plain text paragraphs. |
354 | 354 | */ |
355 | - public static function plain_text(){ |
|
355 | + public static function plain_text() { |
|
356 | 356 | |
357 | 357 | $paragraphs = array( |
358 | 358 | 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean tincidunt luctus eros, a tincidunt massa aliquet sit amet. Sed faucibus, eros non lacinia porttitor, risus odio efficitur sapien, id porta urna massa ac est. Cras efficitur lacinia magna eget tempus. Fusce ex felis, finibus consectetur mi at, finibus rhoncus augue. In ut tortor lacinia, rutrum mauris vel, maximus tortor. Praesent ac arcu nec eros pharetra tristique. Morbi congue leo sed ipsum fermentum vulputate. Ut nulla eros, porta varius pulvinar eget, bibendum quis dolor. Morbi sed diam eu dui semper ornare nec quis nisl.', |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | 'Fusce semper erat tortor, at pulvinar risus luctus suscipit. Phasellus quis enim nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas semper dapibus odio, nec pellentesque sem laoreet sit amet. Maecenas ut enim tellus. Fusce malesuada mattis sem, porta interdum ex fermentum quis. Ut eget quam mi. In molestie volutpat feugiat. Nulla vel viverra nunc. Integer lobortis nisl vitae placerat egestas. Curabitur tristique nulla at libero blandit, a eleifend augue tempus.', |
368 | 368 | ); |
369 | 369 | |
370 | - return $paragraphs[ rand( 0, 9 ) ]; |
|
370 | + return $paragraphs[rand(0, 9)]; |
|
371 | 371 | |
372 | 372 | } |
373 | 373 | |
@@ -383,45 +383,45 @@ discard block |
||
383 | 383 | * @param int $post_id Post ID. |
384 | 384 | * @return mixed Attachment ID or WP Error. |
385 | 385 | */ |
386 | - public static function image( $post_id ){ |
|
386 | + public static function image($post_id) { |
|
387 | 387 | $file_array = array(); |
388 | 388 | |
389 | 389 | // Get the image from the API |
390 | 390 | $url = self::get_image_link(); |
391 | 391 | |
392 | 392 | // If the returned string is empty or it's not a string, try again. |
393 | - if ( empty( $url ) || !is_string( $url ) ){ |
|
393 | + if (empty($url) || !is_string($url)) { |
|
394 | 394 | |
395 | 395 | // Try again |
396 | 396 | $url = self::get_image_link(); |
397 | 397 | |
398 | 398 | // If it fails again, just give up |
399 | - if ( empty( $url ) || !is_string( $url ) ){ |
|
399 | + if (empty($url) || !is_string($url)) { |
|
400 | 400 | return; |
401 | 401 | } |
402 | 402 | |
403 | 403 | } |
404 | 404 | |
405 | 405 | // Download the file |
406 | - $tmp = \download_url( $url ); |
|
406 | + $tmp = \download_url($url); |
|
407 | 407 | |
408 | - preg_match( '/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches ); |
|
408 | + preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $url, $matches); |
|
409 | 409 | |
410 | - $file_array['name'] = basename( $matches[0] ); |
|
410 | + $file_array['name'] = basename($matches[0]); |
|
411 | 411 | $file_array['tmp_name'] = $tmp; |
412 | 412 | |
413 | 413 | // Check for download errors |
414 | - if ( is_wp_error( $tmp ) ) { |
|
415 | - unlink( $file_array[ 'tmp_name' ] ); |
|
414 | + if (is_wp_error($tmp)) { |
|
415 | + unlink($file_array['tmp_name']); |
|
416 | 416 | return $tmp->get_error_message(); |
417 | 417 | } |
418 | 418 | |
419 | 419 | // Pull the image into the media library |
420 | - $image_id = media_handle_sideload( $file_array, $post_id ); |
|
420 | + $image_id = media_handle_sideload($file_array, $post_id); |
|
421 | 421 | |
422 | 422 | // Check for handle sideload errors. |
423 | - if ( is_wp_error( $image_id ) ) { |
|
424 | - unlink( $file_array['tmp_name'] ); |
|
423 | + if (is_wp_error($image_id)) { |
|
424 | + unlink($file_array['tmp_name']); |
|
425 | 425 | return $image_id->get_error_message(); |
426 | 426 | } |
427 | 427 | |
@@ -437,31 +437,31 @@ discard block |
||
437 | 437 | * |
438 | 438 | * @return string Image URL. |
439 | 439 | */ |
440 | - private static function get_image_link(){ |
|
440 | + private static function get_image_link() { |
|
441 | 441 | |
442 | 442 | // cURL an image API for a completely random photo |
443 | - $curl = curl_init( "http://www.splashbase.co/api/v1/images/random?images_only=true" ); |
|
443 | + $curl = curl_init("http://www.splashbase.co/api/v1/images/random?images_only=true"); |
|
444 | 444 | |
445 | - curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE ); |
|
445 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); |
|
446 | 446 | |
447 | - $curl_response = curl_exec( $curl ); |
|
447 | + $curl_response = curl_exec($curl); |
|
448 | 448 | |
449 | 449 | // If our cURL failed |
450 | - if ( $curl_response === false ) { |
|
451 | - $info = curl_getinfo( $curl ); |
|
452 | - curl_close( $curl ); |
|
453 | - die( 'error occured during curl exec. Additional info: ' . var_export( $info ) ); |
|
450 | + if ($curl_response === false) { |
|
451 | + $info = curl_getinfo($curl); |
|
452 | + curl_close($curl); |
|
453 | + die('error occured during curl exec. Additional info: ' . var_export($info)); |
|
454 | 454 | } |
455 | 455 | |
456 | - curl_close( $curl ); |
|
456 | + curl_close($curl); |
|
457 | 457 | |
458 | 458 | // Decode the data |
459 | - $response = json_decode( $curl_response, true ); |
|
459 | + $response = json_decode($curl_response, true); |
|
460 | 460 | |
461 | 461 | // Check to make sure that the return contains a valid image extensions |
462 | 462 | preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $response['url'], $matches); |
463 | 463 | |
464 | - if ( !empty( $matches ) ){ |
|
464 | + if (!empty($matches)) { |
|
465 | 465 | return $response['url']; |
466 | 466 | } |
467 | 467 | |
@@ -476,10 +476,10 @@ discard block |
||
476 | 476 | * @param string $format PHP Date format. |
477 | 477 | * @return mixed Date in the format requested. |
478 | 478 | */ |
479 | - public static function date( $format ){ |
|
479 | + public static function date($format) { |
|
480 | 480 | |
481 | - $num_days = rand( 1, 60 ); |
|
482 | - return date( $format, strtotime( " +$num_days days" ) ); |
|
481 | + $num_days = rand(1, 60); |
|
482 | + return date($format, strtotime(" +$num_days days")); |
|
483 | 483 | |
484 | 484 | } |
485 | 485 | |
@@ -491,19 +491,19 @@ discard block |
||
491 | 491 | * |
492 | 492 | * @return string Time string |
493 | 493 | */ |
494 | - public static function time(){ |
|
494 | + public static function time() { |
|
495 | 495 | |
496 | 496 | $times = array( |
497 | 497 | '8:00 am', |
498 | 498 | '5:00PM', |
499 | 499 | '13:00', |
500 | 500 | '2015', |
501 | - date( 'G:i', strtotime( " +".rand( 4, 24 )." hours" ) ), |
|
502 | - date( 'g:i', strtotime( " +".rand( 4, 24 )." hours" ) ), |
|
503 | - date( 'G:i A', strtotime( " +".rand( 4, 24 )." hours" ) ) |
|
501 | + date('G:i', strtotime(" +" . rand(4, 24) . " hours")), |
|
502 | + date('g:i', strtotime(" +" . rand(4, 24) . " hours")), |
|
503 | + date('G:i A', strtotime(" +" . rand(4, 24) . " hours")) |
|
504 | 504 | ); |
505 | 505 | |
506 | - return $times[ rand( 0, 6 ) ]; |
|
506 | + return $times[rand(0, 6)]; |
|
507 | 507 | |
508 | 508 | } |
509 | 509 | |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | * |
516 | 516 | * @return string Timezone |
517 | 517 | */ |
518 | - public static function timezone(){ |
|
518 | + public static function timezone() { |
|
519 | 519 | |
520 | 520 | $timezones = array( |
521 | 521 | 'America/Denver', |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | 'UTC' |
534 | 534 | ); |
535 | 535 | |
536 | - return $timezones[ rand( 0, 12 ) ]; |
|
536 | + return $timezones[rand(0, 12)]; |
|
537 | 537 | |
538 | 538 | } |
539 | 539 | |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | * |
547 | 547 | * @return string Phone #. |
548 | 548 | */ |
549 | - public static function phone(){ |
|
549 | + public static function phone() { |
|
550 | 550 | |
551 | 551 | $phone_numbers = array( |
552 | 552 | '7203893101', |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | '+43 780 0047112' |
563 | 563 | ); |
564 | 564 | |
565 | - return $phone_numbers[ rand( 0, 10 ) ]; |
|
565 | + return $phone_numbers[rand(0, 10)]; |
|
566 | 566 | |
567 | 567 | } |
568 | 568 | |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @return string Email address. |
576 | 576 | */ |
577 | - public static function email(){ |
|
577 | + public static function email() { |
|
578 | 578 | |
579 | 579 | $email_addresses = array( |
580 | 580 | '[email protected]', |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | '[email protected]' |
588 | 588 | ); |
589 | 589 | |
590 | - return $email_addresses[ rand( 0, 7 ) ]; |
|
590 | + return $email_addresses[rand(0, 7)]; |
|
591 | 591 | |
592 | 592 | } |
593 | 593 | |
@@ -601,12 +601,12 @@ discard block |
||
601 | 601 | * |
602 | 602 | * @return string URL. |
603 | 603 | */ |
604 | - public static function link(){ |
|
604 | + public static function link() { |
|
605 | 605 | |
606 | 606 | $links = array( |
607 | 607 | 'http://google.com', |
608 | 608 | 'https://www.twitter.com', |
609 | - site_url( '/?iam=anextravariable' ), |
|
609 | + site_url('/?iam=anextravariable'), |
|
610 | 610 | 'github.com', |
611 | 611 | 'http://filebase.com', |
612 | 612 | 'www.oldtownmediainc.com', |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | 'https://www.eff.org' |
615 | 615 | ); |
616 | 616 | |
617 | - return $links[ rand( 0, 7 ) ]; |
|
617 | + return $links[rand(0, 7)]; |
|
618 | 618 | |
619 | 619 | } |
620 | 620 | |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | * |
626 | 626 | * @return string URL. |
627 | 627 | */ |
628 | - public static function oembed(){ |
|
628 | + public static function oembed() { |
|
629 | 629 | |
630 | 630 | $links = array( |
631 | 631 | 'https://www.youtube.com/watch?v=A85-YQsm6pY', |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | 'https://www.instagram.com/p/-eyLo0RMfX', |
637 | 637 | ); |
638 | 638 | |
639 | - return $links[ rand( 0, 5 ) ]; |
|
639 | + return $links[rand(0, 5)]; |
|
640 | 640 | |
641 | 641 | } |
642 | 642 | |
@@ -650,10 +650,10 @@ discard block |
||
650 | 650 | * @param string $type Video service to get link from |
651 | 651 | * @return string URL. |
652 | 652 | */ |
653 | - public static function video( $type ){ |
|
653 | + public static function video($type) { |
|
654 | 654 | |
655 | 655 | // Switch through our video types. Expecting to add more in the future |
656 | - switch( $type ){ |
|
656 | + switch ($type) { |
|
657 | 657 | |
658 | 658 | // YouTube videos |
659 | 659 | case 'youtube' : |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | |
695 | 695 | } |
696 | 696 | |
697 | - return $links[ rand( 0, 8 ) ]; |
|
697 | + return $links[rand(0, 8)]; |
|
698 | 698 | |
699 | 699 | } |
700 | 700 |