Tribe__Admin__Help_Page::print_plugin_box( string $plugin )

Prints the Plugin box for the given plugin


Parameters #

$plugin

(string) (Required) Plugin Name key


Top ↑

Return #

(void)


Top ↑

Source #

File: src/Tribe/Admin/Help_Page.php

	public function print_plugin_box( $plugin ) {
		$plugin = (object) $this->get_plugins( $plugin, false );
		$api_data = $this->get_plugin_api_data( $plugin );
		$addons = $this->get_addons( $plugin->name );
		$plugins = get_plugins();

		if ( $api_data ) {
			if ( ! function_exists( 'install_plugin_install_status' ) ) {
				include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
			}
			$status = install_plugin_install_status( $api_data );
			$plugin_active = is_plugin_active( $status['file'] );
			$plugin_exists = isset( $plugins[ $status['file'] ] );

			if ( 'install' !== $status['status'] && ! $plugin_active ) {
				$args = array(
					'action' => 'activate',
					'plugin' => $status['file'],
					'plugin_status' => 'all',
					'paged' => 1,
					's' => '',
				);
				$activate_url = wp_nonce_url( add_query_arg( $args, 'plugins.php' ), 'activate-plugin_' . $status['file'] );
				$link = '<a class="button" href="' . $activate_url . '" aria-label="' . esc_attr( sprintf( esc_attr__( 'Activate %s', 'tribe-common' ), $plugin->name ) ) . '">' . esc_html__( 'Activate Plugin', 'tribe-common' ) . '</a>';
			} elseif ( 'update_available' === $status['status'] ) {
				$args = array(
					'action' => 'upgrade-plugin',
					'plugin' => $status['file'],
				);
				$update_url = wp_nonce_url( add_query_arg( $args, 'update.php' ), 'upgrade-plugin_' . $status['file'] );

				$link = '<a class="button" href="' . $update_url . '">' . esc_html__( 'Upgrade Plugin', 'tribe-common' ) . '</a>';
			} elseif ( $plugin_exists ) {
				$link = '<a class="button disabled">' . esc_html__( 'You are up to date!', 'tribe-common' ) . '</a>';
			}
		}

		if ( ! isset( $link ) ) {
			if ( $api_data ) {
				$args = array(
					'tab'       => 'plugin-information',
					'plugin'    => $plugin->name,
					'TB_iframe' => true,
					'width'     => 772,
					'height'    => 600,
				);
				$iframe_url = add_query_arg( $args, admin_url( '/plugin-install.php' ) );
				$link = '<a class="button thickbox" href="' . $iframe_url . '" aria-label="' . esc_attr( sprintf( esc_attr__( 'Install %s', 'tribe-common' ), $plugin->name ) ) . '">' . esc_html__( 'Install Plugin', 'tribe-common' ) . '</a>';
			} else {
				$link = null;
			}
		}
		?>
		<div class="tribe-help-plugin-info">
			<h3><a href="<?php echo esc_url( $plugin->repo ); ?>" target="_blank"><?php echo esc_html( $plugin->title ); ?></a></h3>

			<?php
			if ( ! empty( $plugin->description ) && ! $plugin->is_active ) {
				echo wpautop( $plugin->description );
			}
			?>

			<?php if ( $api_data ) { ?>
				<dl>
					<dt><?php esc_html_e( 'Latest Version:', 'tribe-common' ); ?></dt>
					<dd><?php echo esc_html( $api_data->version ); ?></dd>

					<dt><?php esc_html_e( 'Requires:', 'tribe-common' ); ?></dt>
					<dd><?php echo esc_html__( 'WordPress ', 'tribe-common' ) . esc_html( $api_data->requires ); ?>+</dd>

					<dt><?php esc_html_e( 'Active Users:', 'tribe-common' ); ?></dt>
					<dd><?php echo esc_html( number_format( $api_data->active_installs ) ); ?>+</dd>

					<dt><?php esc_html_e( 'Rating:', 'tribe-common' ); ?></dt>
					<dd><a href="<?php echo esc_url( $plugin->stars_url ); ?>" target="_blank">
						<?php wp_star_rating( array(
							'rating' => $api_data->rating,
							'type'   => 'percent',
							'number' => $api_data->num_ratings,
						) );?>
					</a></dd>
				</dl>
			<?php } ?>

			<?php
			// Only show the link to the users can use it
			if ( current_user_can( 'update_plugins' ) && current_user_can( 'install_plugins' ) ) {
				echo $link ? '<p style="text-align: center;">' . $link . '</p>' : '';
			}
			?>

			<?php if ( ! empty( $addons ) ) { ?>
				<h3><?php esc_html_e( 'Premium Add-Ons', 'tribe-common' ); ?></h3>
				<ul class='tribe-list-addons'>
					<?php foreach ( $addons as $addon ) {
						$addon = (object) $addon;

						if ( isset( $addon->is_active ) && $addon->is_active ) {
							$active_title = __( 'Plugin Active', 'tribe-common' );
						} else {
							$active_title = __( 'Plugin Inactive', 'tribe-common' );
						}

						echo '<li title="' . esc_attr( $active_title ) . '" class="' . ( isset( $addon->is_active ) && $addon->is_active ? 'tribe-active-addon' : '' ) . '">';
						if ( isset( $addon->link ) ) {
							echo '<a href="' . esc_url( $addon->link ) . '" title="' . esc_attr__( 'Visit the Add-on Page', 'tribe-common' ) . '" target="_blank">';
						}
						echo esc_html( $addon->title );
						if ( isset( $addon->link ) ) {
							echo '</a>';
						}
						echo '</li>';
					} ?>
				</ul>
			<?php } ?>
		</div>
		<?php
	}

Top ↑

Changelog #

Changelog
Version Description
4.0 Introduced.