Completed
Push — develop ( dae086...f9d8a0 )
by Zack
18:24
created
includes/class-admin-installer.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	public function register_noconflict( $items ) {
55 55
 
56
-		$items[] = 'gravityview-admin-installer';
56
+		$items[ ] = 'gravityview-admin-installer';
57 57
 
58 58
 		return $items;
59 59
 	}
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
 			return;
71 71
 		}
72 72
 
73
-		add_filter( 'plugins_api', function ( $data, $action, $args ) use ( $downloads_data ) {
73
+		add_filter( 'plugins_api', function( $data, $action, $args ) use ( $downloads_data ) {
74 74
 			foreach ( $downloads_data as $extension ) {
75
-				if ( empty( $extension['info'] ) || empty( $args->slug ) || $args->slug !== $extension['info']['slug'] ) {
75
+				if ( empty( $extension[ 'info' ] ) || empty( $args->slug ) || $args->slug !== $extension[ 'info' ][ 'slug' ] ) {
76 76
 					continue;
77 77
 				}
78 78
 
79
-				return (object) array(
80
-					'slug'          => $extension['info']['slug'],
81
-					'name'          => $extension['info']['title'],
82
-					'version'       => $extension['licensing']['version'],
83
-					'download_link' => $extension['files'][0]['file'],
79
+				return (object)array(
80
+					'slug'          => $extension[ 'info' ][ 'slug' ],
81
+					'name'          => $extension[ 'info' ][ 'title' ],
82
+					'version'       => $extension[ 'licensing' ][ 'version' ],
83
+					'download_link' => $extension[ 'files' ][ 0 ][ 'file' ],
84 84
 				);
85 85
 			}
86 86
 
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
 
143 143
 		foreach ( $all_plugins as $path => $plugin ) {
144 144
 
145
-			if ( empty( $plugin['TextDomain'] ) ) {
145
+			if ( empty( $plugin[ 'TextDomain' ] ) ) {
146 146
 				continue;
147 147
 			}
148 148
 
149
-			$wp_plugins[ $plugin['TextDomain'] ] = array(
149
+			$wp_plugins[ $plugin[ 'TextDomain' ] ] = array(
150 150
 				'path'      => $path,
151
-				'version'   => $plugin['Version'],
151
+				'version'   => $plugin[ 'Version' ],
152 152
 				'activated' => is_plugin_active( $path )
153 153
 			);
154 154
 		}
@@ -230,13 +230,13 @@  discard block
 block discarded – undo
230 230
 
231 231
 		$downloads_data = json_decode( wp_remote_retrieve_body( $response ), true );
232 232
 
233
-		if ( empty( $downloads_data['products'] ) ) {
233
+		if ( empty( $downloads_data[ 'products' ] ) ) {
234 234
 			return array();
235 235
 		}
236 236
 
237
-		$this->set_downloads_data( $downloads_data['products'] );
237
+		$this->set_downloads_data( $downloads_data[ 'products' ] );
238 238
 
239
-		return $downloads_data['products'];
239
+		return $downloads_data[ 'products' ];
240 240
 	}
241 241
 
242 242
 	/**
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 
310 310
 				foreach ( $downloads_data as $extension ) {
311 311
 
312
-					if ( empty( $extension['info'] ) ) {
312
+					if ( empty( $extension[ 'info' ] ) ) {
313 313
 						continue;
314 314
 					}
315 315
 
@@ -338,29 +338,29 @@  discard block
 block discarded – undo
338 338
 
339 339
         $details = $this->get_download_display_details( $download, $wp_plugins );
340 340
 
341
-        $download_info = $details['download_info'];
341
+        $download_info = $details[ 'download_info' ];
342 342
 
343 343
 		?>
344
-        <div class="item <?php echo esc_attr( $details['item_class'] ); ?>">
344
+        <div class="item <?php echo esc_attr( $details[ 'item_class' ] ); ?>">
345 345
             <div class="addon-inner">
346
-                <a href="<?php echo esc_url( $download_info['link'] ); ?>" rel="external noreferrer noopener" title="<?php esc_html_e( 'Visit the plugin page', 'gravityview' ); ?>"><img class="thumbnail" src="<?php echo esc_attr( $download_info['thumbnail'] ); ?>" alt="" /></a>
347
-                <h3><?php echo esc_html( \GV\Utils::get( $download_info, 'installer_title', $download_info['title'] ) ); ?></h3>
346
+                <a href="<?php echo esc_url( $download_info[ 'link' ] ); ?>" rel="external noreferrer noopener" title="<?php esc_html_e( 'Visit the plugin page', 'gravityview' ); ?>"><img class="thumbnail" src="<?php echo esc_attr( $download_info[ 'thumbnail' ] ); ?>" alt="" /></a>
347
+                <h3><?php echo esc_html( \GV\Utils::get( $download_info, 'installer_title', $download_info[ 'title' ] ) ); ?></h3>
348 348
                 <div>
349
-                    <?php if( $details['status_label'] ) { ?>
350
-                    <div class="status <?php echo esc_attr( $details['status'] ); ?>" title="<?php printf( esc_attr__( 'Plugin status: %s', 'gravityview' ), esc_html( $details['status_label'] ) ); ?>">
351
-                        <span class="dashicons dashicons-admin-plugins"></span> <span class="status-label"><?php echo esc_html( $details['status_label'] ); ?></span>
349
+                    <?php if ( $details[ 'status_label' ] ) { ?>
350
+                    <div class="status <?php echo esc_attr( $details[ 'status' ] ); ?>" title="<?php printf( esc_attr__( 'Plugin status: %s', 'gravityview' ), esc_html( $details[ 'status_label' ] ) ); ?>">
351
+                        <span class="dashicons dashicons-admin-plugins"></span> <span class="status-label"><?php echo esc_html( $details[ 'status_label' ] ); ?></span>
352 352
                     </div>
353 353
 			        <?php } ?>
354 354
 
355
-                    <a data-status="<?php echo esc_attr( $details['status'] ); ?>" data-plugin-path="<?php echo esc_attr( $details['plugin_path'] ); ?>" href="<?php echo esc_url( $details['href'] ); ?>" class="button <?php echo esc_attr( $details['button_class'] ); ?>" title="<?php echo esc_attr( $details['button_title'] ); ?>">
356
-                        <span class="title"><?php echo esc_html( $details['button_label'] ); ?></span>
357
-                        <?php if( $details['spinner'] ) { ?><span class="spinner"></span><?php } ?>
355
+                    <a data-status="<?php echo esc_attr( $details[ 'status' ] ); ?>" data-plugin-path="<?php echo esc_attr( $details[ 'plugin_path' ] ); ?>" href="<?php echo esc_url( $details[ 'href' ] ); ?>" class="button <?php echo esc_attr( $details[ 'button_class' ] ); ?>" title="<?php echo esc_attr( $details[ 'button_title' ] ); ?>">
356
+                        <span class="title"><?php echo esc_html( $details[ 'button_label' ] ); ?></span>
357
+                        <?php if ( $details[ 'spinner' ] ) { ?><span class="spinner"></span><?php } ?>
358 358
                     </a>
359 359
                 </div>
360 360
 
361 361
                 <div class="addon-excerpt"><?php
362 362
 
363
-                    $excerpt = \GV\Utils::get( $download_info, 'installer_excerpt', $download_info['excerpt'] );
363
+                    $excerpt = \GV\Utils::get( $download_info, 'installer_excerpt', $download_info[ 'excerpt' ] );
364 364
 
365 365
                     // Allow some pure HTML tags, but remove everything else from the excerpt.
366 366
                     $tags = array( '<strong>', '</strong>', '<em>', '</em>', '<code>', '</code>' );
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	 */
401 401
 	private function get_download_display_details( $download, $wp_plugins ) {
402 402
 
403
-		$download_info = wp_parse_args( (array) $download['info'], array(
403
+		$download_info = wp_parse_args( (array)$download[ 'info' ], array(
404 404
 			'thumbnail' => '',
405 405
 			'title' => '',
406 406
 			'textdomain' => '',
@@ -411,9 +411,9 @@  discard block
 block discarded – undo
411 411
 			'installer_excerpt' => null, // May not be defined
412 412
 		) );
413 413
 
414
-		$wp_plugin = \GV\Utils::get( $wp_plugins, $download_info['textdomain'], false );
414
+		$wp_plugin = \GV\Utils::get( $wp_plugins, $download_info[ 'textdomain' ], false );
415 415
 
416
-		$has_access = ! empty( $download['files'] );
416
+		$has_access = ! empty( $download[ 'files' ] );
417 417
 		$spinner = true;
418 418
 		$href = $plugin_path = '#';
419 419
 		$status = $item_class = $button_title = $button_class = '';
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 		$required_license = $galactic_only ? __( 'Galactic', 'gravityview' ) : __( 'Interstellar', 'gravityview' );
424 424
 
425 425
 		// The license is not active - no matter what level, this should not work
426
-		if( ! $is_active  && empty( $base_price ) ) {
426
+		if ( ! $is_active && empty( $base_price ) ) {
427 427
 			$spinner      = false;
428 428
 			$button_class = 'disabled disabled-license';
429 429
 			$button_label = sprintf( __( 'Active %s License is Required.', 'gravityview' ), $required_license );
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 			$status_label = '';
436 436
 			$button_label = sprintf( __( 'Purchase Now for %s', 'gravityview' ), '$' . $base_price );
437 437
 			$button_class = 'button-primary button-large';
438
-			$href         = $download_info['link'];
438
+			$href         = $download_info[ 'link' ];
439 439
 			$item_class   = 'featured';
440 440
 		}
441 441
 
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 			$href = add_query_arg(
455 455
 				array(
456 456
 					'action'   => 'install-plugin',
457
-					'plugin'   => $download_info['slug'],
458
-					'_wpnonce' => wp_create_nonce( 'install-plugin_' . $download_info['slug'] ),
457
+					'plugin'   => $download_info[ 'slug' ],
458
+					'_wpnonce' => wp_create_nonce( 'install-plugin_' . $download_info[ 'slug' ] ),
459 459
 				),
460 460
 				self_admin_url( 'update.php' )
461 461
 			);
@@ -467,26 +467,26 @@  discard block
 block discarded – undo
467 467
 		}
468 468
 
469 469
 		// Access and the plugin is installed but not active
470
-		else if ( false === $wp_plugin['activated'] ) {
470
+		else if ( false === $wp_plugin[ 'activated' ] ) {
471 471
 
472 472
 			$status = 'inactive';
473 473
 			$status_label = __( 'Inactive', 'gravityview' );
474 474
 			$button_label = __( 'Activate', 'gravityview' );
475
-			$plugin_path = $wp_plugin['path'];
475
+			$plugin_path = $wp_plugin[ 'path' ];
476 476
 
477 477
 		}
478 478
 
479 479
 		// Access and the plugin is installed and active
480 480
 		else {
481 481
 
482
-			$plugin_path = $wp_plugin['path'];
482
+			$plugin_path = $wp_plugin[ 'path' ];
483 483
 			$status = 'active';
484 484
 			$status_label = __( 'Active', 'gravityview' );
485 485
 			$button_label = __( 'Deactivate', 'gravityview' );
486 486
 
487 487
 		}
488 488
 
489
-		return compact( 'download_info','plugin_path', 'status', 'status_label', 'button_title', 'button_class', 'button_label', 'href', 'spinner', 'item_class', 'required_license', 'is_active' );
489
+		return compact( 'download_info', 'plugin_path', 'status', 'status_label', 'button_title', 'button_class', 'button_label', 'href', 'spinner', 'item_class', 'required_license', 'is_active' );
490 490
     }
491 491
 
492 492
 	/**
@@ -501,11 +501,11 @@  discard block
 block discarded – undo
501 501
 	    $base_price = \GV\Utils::get( $download, 'pricing/amount', 0 );
502 502
 		$base_price = \GFCommon::to_number( $base_price );
503 503
 
504
-		unset( $download['pricing']['amount'] );
504
+		unset( $download[ 'pricing' ][ 'amount' ] );
505 505
 
506 506
 		// Price options array, not single price
507
-		if ( ! $base_price && ! empty( $download['pricing'] ) ) {
508
-			$base_price = array_shift( $download['pricing'] );
507
+		if ( ! $base_price && ! empty( $download[ 'pricing' ] ) ) {
508
+			$base_price = array_shift( $download[ 'pricing' ] );
509 509
 		}
510 510
 
511 511
 		return floatval( $base_price );
@@ -519,13 +519,13 @@  discard block
 block discarded – undo
519 519
 	public function activate_download() {
520 520
 		$data = \GV\Utils::_POST( 'data', array() );
521 521
 
522
-		if ( empty( $data['path'] ) ) {
522
+		if ( empty( $data[ 'path' ] ) ) {
523 523
 			return;
524 524
 		}
525 525
 
526
-		$result = activate_plugin( $data['path'] );
526
+		$result = activate_plugin( $data[ 'path' ] );
527 527
 
528
-		if ( is_wp_error( $result ) || ! is_plugin_active( $data['path'] ) ) {
528
+		if ( is_wp_error( $result ) || ! is_plugin_active( $data[ 'path' ] ) ) {
529 529
 			wp_send_json_error( array(
530 530
                 'error' => sprintf( __( 'Plugin activation failed: %s', 'gravityview' ), $result->get_error_message() )
531 531
             ) );
@@ -542,13 +542,13 @@  discard block
 block discarded – undo
542 542
 	public function deactivate_download() {
543 543
 		$data = \GV\Utils::_POST( 'data', array() );
544 544
 
545
-		if ( empty( $data['path'] ) ) {
545
+		if ( empty( $data[ 'path' ] ) ) {
546 546
 			return;
547 547
 		}
548 548
 
549
-		deactivate_plugins( $data['path'] );
549
+		deactivate_plugins( $data[ 'path' ] );
550 550
 
551
-		if( is_plugin_active( $data['path'] ) ) {
551
+		if ( is_plugin_active( $data[ 'path' ] ) ) {
552 552
             wp_send_json_error( array(
553 553
                 'error' => sprintf( __( 'Plugin deactivation failed.', 'gravityview' ) )
554 554
             ) );
Please login to merge, or discard this patch.