Completed
Push — develop ( 9eea7d...b20d13 )
by Zack
17:43
created
includes/class-admin-installer.php 1 patch
Spacing   +57 added lines, -57 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
 	}
@@ -68,21 +68,21 @@  discard block
 block discarded – undo
68 68
 
69 69
 	    $downloads_data = get_site_transient( self::DOWNLOADS_DATA_TRANSIENT );
70 70
 
71
-	    if ( ! $downloads_data && ! isset( $_GET['cache'] ) ) {
71
+	    if ( ! $downloads_data && ! isset( $_GET[ 'cache' ] ) ) {
72 72
 			return;
73 73
 		}
74 74
 
75
-		add_filter( 'plugins_api', function ( $data, $action, $args ) use ( $downloads_data ) {
75
+		add_filter( 'plugins_api', function( $data, $action, $args ) use ( $downloads_data ) {
76 76
 			foreach ( $downloads_data as $extension ) {
77
-				if ( empty( $extension['info'] ) || empty( $args->slug ) || $args->slug !== $extension['info']['slug'] ) {
77
+				if ( empty( $extension[ 'info' ] ) || empty( $args->slug ) || $args->slug !== $extension[ 'info' ][ 'slug' ] ) {
78 78
 					continue;
79 79
 				}
80 80
 
81
-				return (object) array(
82
-					'slug'          => $extension['info']['slug'],
83
-					'name'          => $extension['info']['title'],
84
-					'version'       => $extension['licensing']['version'],
85
-					'download_link' => $extension['files'][0]['file'],
81
+				return (object)array(
82
+					'slug'          => $extension[ 'info' ][ 'slug' ],
83
+					'name'          => $extension[ 'info' ][ 'title' ],
84
+					'version'       => $extension[ 'licensing' ][ 'version' ],
85
+					'download_link' => $extension[ 'files' ][ 0 ][ 'file' ],
86 86
 				);
87 87
 			}
88 88
 
@@ -149,13 +149,13 @@  discard block
 block discarded – undo
149 149
 
150 150
 		foreach ( $all_plugins as $path => $plugin ) {
151 151
 
152
-			if ( empty( $plugin['TextDomain'] ) ) {
152
+			if ( empty( $plugin[ 'TextDomain' ] ) ) {
153 153
 				continue;
154 154
 			}
155 155
 
156
-			$wp_plugins[ $plugin['TextDomain'] ] = array(
156
+			$wp_plugins[ $plugin[ 'TextDomain' ] ] = array(
157 157
 				'path'      => $path,
158
-				'version'   => $plugin['Version'],
158
+				'version'   => $plugin[ 'Version' ],
159 159
 				'activated' => is_plugin_active( $path )
160 160
 			);
161 161
 		}
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 
210 210
 		$downloads_data = get_site_transient( self::DOWNLOADS_DATA_TRANSIENT );
211 211
 
212
-		if ( $downloads_data && ! isset( $_GET['cache'] ) ) {
212
+		if ( $downloads_data && ! isset( $_GET[ 'cache' ] ) ) {
213 213
 			return $downloads_data;
214 214
 		}
215 215
 
216
-		if( \GV\Plugin::is_network_activated() ) {
216
+		if ( \GV\Plugin::is_network_activated() ) {
217 217
 			$home_url = network_home_url();
218 218
 		} else {
219 219
 			$home_url = home_url();
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
 
242 242
 		$downloads_data = json_decode( wp_remote_retrieve_body( $response ), true );
243 243
 
244
-		if ( empty( $downloads_data['products'] ) ) {
244
+		if ( empty( $downloads_data[ 'products' ] ) ) {
245 245
 			return array();
246 246
 		}
247 247
 
248
-		$this->set_downloads_data( $downloads_data['products'] );
248
+		$this->set_downloads_data( $downloads_data[ 'products' ] );
249 249
 
250
-		return $downloads_data['products'];
250
+		return $downloads_data[ 'products' ];
251 251
 	}
252 252
 
253 253
 	/**
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 
308 308
             <h2><?php esc_html_e( 'The following plugins extend GravityView and Gravity Forms functionality:', 'gravityview' ); ?></h2>
309 309
 
310
-			<a class="button button-secondary gv-admin-installer-refresh-link" href="<?php echo add_query_arg(array( 'cache' => 1 ) ); ?>"><i class="dashicons dashicons-update" style="margin-top: .2em"></i> <?php esc_html_e( 'Refresh', 'gravityview' ); ?></a>
310
+			<a class="button button-secondary gv-admin-installer-refresh-link" href="<?php echo add_query_arg( array( 'cache' => 1 ) ); ?>"><i class="dashicons dashicons-update" style="margin-top: .2em"></i> <?php esc_html_e( 'Refresh', 'gravityview' ); ?></a>
311 311
 
312 312
 			<hr class="wp-header-end" />
313 313
 
@@ -324,11 +324,11 @@  discard block
 block discarded – undo
324 324
 
325 325
 				$this->render_section( 'extensions', esc_html__( 'GravityView Extensions', 'gravityview' ), $downloads_data, $wp_plugins );
326 326
 
327
-				$this->render_section(  'plugins', esc_html__( 'Gravity Forms Add-Ons', 'gravityview' ), $downloads_data, $wp_plugins );
327
+				$this->render_section( 'plugins', esc_html__( 'Gravity Forms Add-Ons', 'gravityview' ), $downloads_data, $wp_plugins );
328 328
 
329
-				$this->render_section(  'labs', esc_html__( 'GravityView Labs', 'gravityview' ), $downloads_data, $wp_plugins );
329
+				$this->render_section( 'labs', esc_html__( 'GravityView Labs', 'gravityview' ), $downloads_data, $wp_plugins );
330 330
 
331
-				$this->render_section(  'friends', esc_html__( 'Friends of GravityView', 'gravityview' ), $downloads_data, $wp_plugins );
331
+				$this->render_section( 'friends', esc_html__( 'Friends of GravityView', 'gravityview' ), $downloads_data, $wp_plugins );
332 332
 				?>
333 333
             </div>
334 334
         </div>
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 				continue;
356 356
 			}
357 357
 
358
-			if ( empty( $download['info'] ) ) {
358
+			if ( empty( $download[ 'info' ] ) ) {
359 359
 				continue;
360 360
 			}
361 361
 
@@ -383,31 +383,31 @@  discard block
 block discarded – undo
383 383
 
384 384
         $details = $this->get_download_display_details( $download, $wp_plugins );
385 385
 
386
-        $download_info = $details['download_info'];
386
+        $download_info = $details[ 'download_info' ];
387 387
 
388 388
 		?>
389
-        <div class="item <?php echo esc_attr( $details['item_class'] ); ?>">
389
+        <div class="item <?php echo esc_attr( $details[ 'item_class' ] ); ?>">
390 390
             <div class="addon-inner">
391
-                <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>
392
-                <h3><?php echo esc_html( \GV\Utils::get( $download_info, 'installer_title', $download_info['title'] ) ); ?></h3>
391
+                <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>
392
+                <h3><?php echo esc_html( \GV\Utils::get( $download_info, 'installer_title', $download_info[ 'title' ] ) ); ?></h3>
393 393
                 <div>
394
-                    <?php if( ! empty( $details['status_label'] ) ) { ?>
395
-                    <div class="status <?php echo esc_attr( $details['status'] ); ?>" title="<?php printf( esc_attr__( 'Plugin status: %s', 'gravityview' ), esc_html( $details['status_label'] ) ); ?>">
396
-                        <span class="dashicons dashicons-admin-plugins"></span> <span class="status-label"><?php echo esc_html( $details['status_label'] ); ?></span>
394
+                    <?php if ( ! empty( $details[ 'status_label' ] ) ) { ?>
395
+                    <div class="status <?php echo esc_attr( $details[ 'status' ] ); ?>" title="<?php printf( esc_attr__( 'Plugin status: %s', 'gravityview' ), esc_html( $details[ 'status_label' ] ) ); ?>">
396
+                        <span class="dashicons dashicons-admin-plugins"></span> <span class="status-label"><?php echo esc_html( $details[ 'status_label' ] ); ?></span>
397 397
                     </div>
398 398
 			        <?php } ?>
399 399
 
400
-					<?php if ( 'gravityview' !== $download_info['slug'] ) { ?>
401
-                    <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'] ); ?>">
402
-                        <span class="title"><?php echo esc_html( $details['button_label'] ); ?></span>
403
-                        <?php if( $details['spinner'] ) { ?><span class="spinner"></span><?php } ?>
400
+					<?php if ( 'gravityview' !== $download_info[ 'slug' ] ) { ?>
401
+                    <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' ] ); ?>">
402
+                        <span class="title"><?php echo esc_html( $details[ 'button_label' ] ); ?></span>
403
+                        <?php if ( $details[ 'spinner' ] ) { ?><span class="spinner"></span><?php } ?>
404 404
                     </a>
405 405
 					<?php } ?>
406 406
                 </div>
407 407
 
408 408
                 <div class="addon-excerpt"><?php
409 409
 
410
-                    $excerpt = \GV\Utils::get( $download_info, 'installer_excerpt', $download_info['excerpt'] );
410
+                    $excerpt = \GV\Utils::get( $download_info, 'installer_excerpt', $download_info[ 'excerpt' ] );
411 411
 
412 412
                     // Allow some pure HTML tags, but remove everything else from the excerpt.
413 413
                     $tags = array( '<strong>', '</strong>', '<em>', '</em>', '<code>', '</code>' );
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
 	 */
450 450
 	private function get_download_display_details( $download, $wp_plugins ) {
451 451
 
452
-		$download_info = wp_parse_args( (array) $download['info'], array(
452
+		$download_info = wp_parse_args( (array)$download[ 'info' ], array(
453 453
 			'thumbnail' => '',
454 454
 			'title' => '',
455 455
 			'textdomain' => '',
@@ -461,9 +461,9 @@  discard block
 block discarded – undo
461 461
 			'installer_excerpt' => null, // May not be defined
462 462
 		) );
463 463
 
464
-		$wp_plugin = \GV\Utils::get( $wp_plugins, $download_info['textdomain'], false );
464
+		$wp_plugin = \GV\Utils::get( $wp_plugins, $download_info[ 'textdomain' ], false );
465 465
 
466
-		$has_access = ! empty( $download['files'] );
466
+		$has_access = ! empty( $download[ 'files' ] );
467 467
 		$spinner = true;
468 468
 		$href = $plugin_path = '#';
469 469
 		$status = $item_class = $button_title = $button_class = '';
@@ -473,11 +473,11 @@  discard block
 block discarded – undo
473 473
 		$required_license = $galactic_only ? __( 'All Access', 'gravityview' ) : __( 'Core + Extensions', 'gravityview' );
474 474
 
475 475
 		// The license is not active - no matter what level, this should not work
476
-		if( ! $is_active  && empty( $base_price ) ) {
476
+		if ( ! $is_active && empty( $base_price ) ) {
477 477
 			$spinner      = false;
478 478
 			$status_label = '';
479 479
 			$button_label = sprintf( __( 'Active %s License is Required.', 'gravityview' ), $required_license );
480
-			$href         = $download_info['link'];
480
+			$href         = $download_info[ 'link' ];
481 481
 			$button_class = 'button-primary';
482 482
 		}
483 483
 
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 			$status_label = '';
488 488
 			$button_label = sprintf( __( 'Purchase Now for %s', 'gravityview' ), '$' . $base_price );
489 489
 			$button_class = 'button-primary button-large';
490
-			$href         = $download_info['link'];
490
+			$href         = $download_info[ 'link' ];
491 491
 			$item_class   = 'featured';
492 492
 		}
493 493
 
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 			$href         = 'https://gravityview.co/pricing/?utm_source=admin-installer&utm_medium=admin&utm_campaign=Admin%20Notice&utm_content=' . $required_license;
501 501
 		}
502 502
 
503
-        elseif ( ! empty( $download_info['coming_soon'] ) ) {
503
+        elseif ( ! empty( $download_info[ 'coming_soon' ] ) ) {
504 504
 	        $spinner      = false;
505 505
 	        $status       = 'notinstalled';
506 506
 	        $status_label = __( 'Coming Soon', 'gravityview' );
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
 			$href = add_query_arg(
516 516
 				array(
517 517
 					'action'   => 'install-plugin',
518
-					'plugin'   => $download_info['slug'],
519
-					'_wpnonce' => wp_create_nonce( 'install-plugin_' . $download_info['slug'] ),
518
+					'plugin'   => $download_info[ 'slug' ],
519
+					'_wpnonce' => wp_create_nonce( 'install-plugin_' . $download_info[ 'slug' ] ),
520 520
 				),
521 521
 				self_admin_url( 'update.php' )
522 522
 			);
@@ -532,12 +532,12 @@  discard block
 block discarded – undo
532 532
 			$status = 'inactive';
533 533
 			$status_label = __( 'Inactive', 'gravityview' );
534 534
 			$button_label = __( 'Activate', 'gravityview' );
535
-			$plugin_path = $wp_plugin['path'];
535
+			$plugin_path = $wp_plugin[ 'path' ];
536 536
 			$button_class = 'button-secondary';
537 537
 		}
538 538
 		// The plugin is installed and active
539
-		elseif ( ! empty( $wp_plugin['path'] ) ) {
540
-			$plugin_path = $wp_plugin['path'];
539
+		elseif ( ! empty( $wp_plugin[ 'path' ] ) ) {
540
+			$plugin_path = $wp_plugin[ 'path' ];
541 541
 			$status = 'active';
542 542
 			$status_label = __( 'Active', 'gravityview' );
543 543
 			$button_label = __( 'Deactivate', 'gravityview' );
@@ -550,9 +550,9 @@  discard block
 block discarded – undo
550 550
 			$href = add_query_arg( array( 'license_key' => $license_key ), $href );
551 551
 		}
552 552
 
553
-		$download_info['link'] = add_query_arg( array( 'license_key' => $license_key ), $download_info['link'] );
553
+		$download_info[ 'link' ] = add_query_arg( array( 'license_key' => $license_key ), $download_info[ 'link' ] );
554 554
 
555
-		return compact( 'download_info','plugin_path', 'status', 'status_label', 'button_title', 'button_class', 'button_label', 'href', 'spinner', 'item_class', 'required_license', 'is_active' );
555
+		return compact( 'download_info', 'plugin_path', 'status', 'status_label', 'button_title', 'button_class', 'button_label', 'href', 'spinner', 'item_class', 'required_license', 'is_active' );
556 556
     }
557 557
 
558 558
 	/**
@@ -567,11 +567,11 @@  discard block
 block discarded – undo
567 567
 	    $base_price = \GV\Utils::get( $download, 'pricing/amount', 0 );
568 568
 		$base_price = \GFCommon::to_number( $base_price );
569 569
 
570
-		unset( $download['pricing']['amount'] );
570
+		unset( $download[ 'pricing' ][ 'amount' ] );
571 571
 
572 572
 		// Price options array, not single price
573
-		if ( ! $base_price && ! empty( $download['pricing'] ) ) {
574
-			$base_price = array_shift( $download['pricing'] );
573
+		if ( ! $base_price && ! empty( $download[ 'pricing' ] ) ) {
574
+			$base_price = array_shift( $download[ 'pricing' ] );
575 575
 		}
576 576
 
577 577
 		return floatval( $base_price );
@@ -585,13 +585,13 @@  discard block
 block discarded – undo
585 585
 	public function activate_download() {
586 586
 		$data = \GV\Utils::_POST( 'data', array() );
587 587
 
588
-		if ( empty( $data['path'] ) ) {
588
+		if ( empty( $data[ 'path' ] ) ) {
589 589
 			return;
590 590
 		}
591 591
 
592
-		$result = activate_plugin( $data['path'] );
592
+		$result = activate_plugin( $data[ 'path' ] );
593 593
 
594
-		if ( is_wp_error( $result ) || ! is_plugin_active( $data['path'] ) ) {
594
+		if ( is_wp_error( $result ) || ! is_plugin_active( $data[ 'path' ] ) ) {
595 595
 			wp_send_json_error( array(
596 596
                 'error' => sprintf( __( 'Plugin activation failed: %s', 'gravityview' ), $result->get_error_message() )
597 597
             ) );
@@ -608,13 +608,13 @@  discard block
 block discarded – undo
608 608
 	public function deactivate_download() {
609 609
 		$data = \GV\Utils::_POST( 'data', array() );
610 610
 
611
-		if ( empty( $data['path'] ) ) {
611
+		if ( empty( $data[ 'path' ] ) ) {
612 612
 			return;
613 613
 		}
614 614
 
615
-		deactivate_plugins( $data['path'] );
615
+		deactivate_plugins( $data[ 'path' ] );
616 616
 
617
-		if( is_plugin_active( $data['path'] ) ) {
617
+		if ( is_plugin_active( $data[ 'path' ] ) ) {
618 618
             wp_send_json_error( array(
619 619
                 'error' => sprintf( __( 'Plugin deactivation failed.', 'gravityview' ) )
620 620
             ) );
Please login to merge, or discard this patch.