WC_Helper::render_helper_output()public staticWC 1.0

Render the helper section content based on context.

Method of the class: WC_Helper{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_Helper::render_helper_output();

WC_Helper::render_helper_output() code WC 8.7.0

public static function render_helper_output() {
	$auth           = WC_Helper_Options::get( 'auth' );
	$auth_user_data = WC_Helper_Options::get( 'auth_user_data' );

	// Return success/error notices.
	$notices = self::_get_return_notices();

	// No active connection.
	if ( ! self::is_site_connected() ) {
		$connect_url = add_query_arg(
			array(
				'page'              => 'wc-addons',
				'section'           => 'helper',
				'wc-helper-connect' => 1,
				'wc-helper-nonce'   => wp_create_nonce( 'connect' ),
			),
			admin_url( 'admin.php' )
		);

		include self::get_view_filename( 'html-oauth-start.php' );
		return;
	}
	$disconnect_url = add_query_arg(
		array(
			'page'                 => 'wc-addons',
			'section'              => 'helper',
			'wc-helper-disconnect' => 1,
			'wc-helper-nonce'      => wp_create_nonce( 'disconnect' ),
		),
		admin_url( 'admin.php' )
	);

	$current_filter = self::get_current_filter();
	$refresh_url    = add_query_arg(
		array(
			'page'              => 'wc-addons',
			'section'           => 'helper',
			'filter'            => $current_filter,
			'wc-helper-refresh' => 1,
			'wc-helper-nonce'   => wp_create_nonce( 'refresh' ),
		),
		admin_url( 'admin.php' )
	);

	// Installed plugins and themes, with or without an active subscription.
	$woo_plugins = self::get_local_woo_plugins();
	$woo_themes  = self::get_local_woo_themes();

	$subscriptions_list_data   = self::get_subscription_list_data();
	$subscriptions             = array_filter(
		$subscriptions_list_data,
		function( $subscription ) {
			return ! empty( $subscription['product_key'] );
		}
	);
	$updates                   = WC_Helper_Updater::get_update_data();
	$subscriptions_product_ids = wp_list_pluck( $subscriptions, 'product_id' );

	foreach ( $subscriptions as &$subscription ) {
		$subscription['activate_url'] = add_query_arg(
			array(
				'page'                  => 'wc-addons',
				'section'               => 'helper',
				'filter'                => $current_filter,
				'wc-helper-activate'    => 1,
				'wc-helper-product-key' => $subscription['product_key'],
				'wc-helper-product-id'  => $subscription['product_id'],
				'wc-helper-nonce'       => wp_create_nonce( 'activate:' . $subscription['product_key'] ),
			),
			admin_url( 'admin.php' )
		);

		$subscription['deactivate_url'] = add_query_arg(
			array(
				'page'                  => 'wc-addons',
				'section'               => 'helper',
				'filter'                => $current_filter,
				'wc-helper-deactivate'  => 1,
				'wc-helper-product-key' => $subscription['product_key'],
				'wc-helper-product-id'  => $subscription['product_id'],
				'wc-helper-nonce'       => wp_create_nonce( 'deactivate:' . $subscription['product_key'] ),
			),
			admin_url( 'admin.php' )
		);

		$subscription['update_url'] = admin_url( 'update-core.php' );

		$local = wp_list_filter( array_merge( $woo_plugins, $woo_themes ), array( '_product_id' => $subscription['product_id'] ) );

		if ( ! empty( $local ) ) {
			$local = array_shift( $local );
			if ( 'plugin' === $local['_type'] ) {
				// A magic update_url.
				$subscription['update_url'] = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $local['_filename'], 'upgrade-plugin_' . $local['_filename'] );

			} elseif ( 'theme' === $local['_type'] ) {
				// Another magic update_url.
				$subscription['update_url'] = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' . $local['_stylesheet'] ), 'upgrade-theme_' . $local['_stylesheet'] );
			}
		}

		$subscription['download_primary'] = true;
		$subscription['download_url']     = 'https://woo.com/my-account/downloads/';
		if ( ! $subscription['local']['installed'] && ! empty( $updates[ $subscription['product_id'] ] ) ) {
			$subscription['download_url'] = $updates[ $subscription['product_id'] ]['package'];
		}

		$subscription['actions'] = array();

		if ( $subscription['has_update'] && ! $subscription['expired'] ) {
			$action = array(
				/* translators: %s: version number */
				'message'      => sprintf( __( 'Version %s is <strong>available</strong>.', 'woocommerce' ), esc_html( $updates[ $subscription['product_id'] ]['version'] ) ),
				'button_label' => __( 'Update', 'woocommerce' ),
				'button_url'   => $subscription['update_url'],
				'status'       => 'update-available',
				'icon'         => 'dashicons-update',
			);

			// Subscription is not active on this site.
			if ( ! $subscription['active'] ) {
				$action['message']     .= ' ' . __( 'To enable this update you need to <strong>activate</strong> this subscription.', 'woocommerce' );
				$action['button_label'] = null;
				$action['button_url']   = null;
			}

			$subscription['actions'][] = $action;
		}

		if ( $subscription['has_update'] && $subscription['expired'] ) {
			$action = array(
				/* translators: %s: version number */
				'message' => sprintf( __( 'Version %s is <strong>available</strong>.', 'woocommerce' ), esc_html( $updates[ $subscription['product_id'] ]['version'] ) ),
				'status'  => 'expired',
				'icon'    => 'dashicons-info',
			);

			$action['message']     .= ' ' . __( 'To enable this update you need to <strong>purchase</strong> a new subscription.', 'woocommerce' );
			$action['button_label'] = __( 'Purchase', 'woocommerce' );
			$action['button_url']   = self::add_utm_params_to_url_for_subscription_link(
				$subscription['product_url'],
				'purchase'
			);

			$subscription['actions'][] = $action;
		} elseif ( $subscription['expired'] && ! empty( $subscription['master_user_email'] ) ) {
			$action = array(
				'message' => sprintf( __( 'This subscription has expired. Contact the owner to <strong>renew</strong> the subscription to receive updates and support.', 'woocommerce' ) ),
				'status'  => 'expired',
				'icon'    => 'dashicons-info',
			);

			$subscription['actions'][] = $action;
		} elseif ( $subscription['expired'] ) {
			$action = array(
				'message'      => sprintf( __( 'This subscription has expired. Please <strong>renew</strong> to receive updates and support.', 'woocommerce' ) ),
				'button_label' => __( 'Renew', 'woocommerce' ),
				'button_url'   => self::add_utm_params_to_url_for_subscription_link(
					'https://woo.com/my-account/my-subscriptions/',
					'renew'
				),
				'status'       => 'expired',
				'icon'         => 'dashicons-info',
			);

			$subscription['actions'][] = $action;
		}

		if ( $subscription['expiring'] && ! $subscription['autorenew'] ) {
			$action = array(
				'message'      => __( 'Subscription is <strong>expiring</strong> soon.', 'woocommerce' ),
				'button_label' => __( 'Enable auto-renew', 'woocommerce' ),
				'button_url'   => self::add_utm_params_to_url_for_subscription_link(
					'https://woo.com/my-account/my-subscriptions/',
					'auto-renew'
				),
				'status'       => 'expired',
				'icon'         => 'dashicons-info',
			);

			$subscription['download_primary'] = false;
			$subscription['actions'][]        = $action;
		} elseif ( $subscription['expiring'] ) {
			$action = array(
				'message'      => sprintf( __( 'This subscription is expiring soon. Please <strong>renew</strong> to continue receiving updates and support.', 'woocommerce' ) ),
				'button_label' => __( 'Renew', 'woocommerce' ),
				'button_url'   => self::add_utm_params_to_url_for_subscription_link(
					'https://woo.com/my-account/my-subscriptions/',
					'renew'
				),
				'status'       => 'expired',
				'icon'         => 'dashicons-info',
			);

			$subscription['download_primary'] = false;
			$subscription['actions'][]        = $action;
		}

		// Mark the first action primary.
		foreach ( $subscription['actions'] as $key => $action ) {
			if ( ! empty( $action['button_label'] ) ) {
				$subscription['actions'][ $key ]['primary'] = true;
				break;
			}
		}
	}

	// Break the by-ref.
	unset( $subscription );

	// Installed products without a subscription.
	$no_subscriptions = array();
	foreach ( array_merge( $woo_plugins, $woo_themes ) as $filename => $data ) {
		if ( in_array( $data['_product_id'], $subscriptions_product_ids ) ) {
			continue;
		}

		$data['_product_url'] = '#';
		$data['_has_update']  = false;

		if ( ! empty( $updates[ $data['_product_id'] ] ) ) {
			$data['_has_update'] = version_compare( $updates[ $data['_product_id'] ]['version'], $data['Version'], '>' );

			if ( ! empty( $updates[ $data['_product_id'] ]['url'] ) ) {
				$data['_product_url'] = $updates[ $data['_product_id'] ]['url'];
			} elseif ( ! empty( $data['PluginURI'] ) ) {
				$data['_product_url'] = $data['PluginURI'];
			}
		}

		$data['_actions'] = array();

		if ( $data['_has_update'] ) {
			$action = array(
				/* translators: %s: version number */
				'message'      => sprintf( __( 'Version %s is <strong>available</strong>. To enable this update you need to <strong>purchase</strong> a new subscription.', 'woocommerce' ), esc_html( $updates[ $data['_product_id'] ]['version'] ) ),
				'button_label' => __( 'Purchase', 'woocommerce' ),
				'button_url'   => self::add_utm_params_to_url_for_subscription_link(
					$data['_product_url'],
					'purchase'
				),
				'status'       => 'expired',
				'icon'         => 'dashicons-info',
			);

			$data['_actions'][] = $action;
		} else {
			$action = array(
				/* translators: 1: subscriptions docs 2: subscriptions docs */
				'message'      => sprintf( __( 'To receive updates and support for this extension, you need to <strong>purchase</strong> a new subscription or consolidate your extensions to one connected account by <strong><a href="%1$s" title="Sharing Docs">sharing</a> or <a href="%2$s" title="Transferring Docs">transferring</a></strong> this extension to this connected account.', 'woocommerce' ), 'https://woo.com/document/managing-woocommerce-com-subscriptions/#section-10', 'https://woo.com/document/managing-woocommerce-com-subscriptions/#section-5' ),
				'button_label' => __( 'Purchase', 'woocommerce' ),
				'button_url'   => self::add_utm_params_to_url_for_subscription_link(
					$data['_product_url'],
					'purchase'
				),
				'status'       => 'expired',
				'icon'         => 'dashicons-info',
			);

			$data['_actions'][] = $action;
		}

		$no_subscriptions[ $filename ] = $data;
	}

	// Update the user id if it came from a migrated connection.
	if ( empty( $auth['user_id'] ) ) {
		$auth['user_id'] = get_current_user_id();
		WC_Helper_Options::update( 'auth', $auth );
	}

	// Sort alphabetically.
	uasort( $subscriptions, array( __CLASS__, '_sort_by_product_name' ) );
	uasort( $no_subscriptions, array( __CLASS__, '_sort_by_name' ) );

	// Filters.
	self::get_filters_counts( $subscriptions ); // Warm it up.
	self::_filter( $subscriptions, self::get_current_filter() );

	// We have an active connection.
	include self::get_view_filename( 'html-main.php' );
	return;
}