WC_Helper::render_helper_output()
Render the helper section content based on context.
Description Description
Source Source
File: includes/admin/helper/class-wc-helper.php
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 ( empty( $auth['access_token'] ) ) { $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(); $site_id = absint( $auth['site_id'] ); $subscriptions = self::get_subscriptions(); $updates = WC_Helper_Updater::get_update_data(); $subscriptions_product_ids = wp_list_pluck( $subscriptions, 'product_id' ); foreach ( $subscriptions as &$subscription ) { $subscription['active'] = in_array( $site_id, $subscription['connections'] ); $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['local'] = array( 'installed' => false, 'active' => false, 'version' => null, ); $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 ); $subscription['local']['installed'] = true; $subscription['local']['version'] = $local['Version']; if ( 'plugin' == $local['_type'] ) { if ( is_plugin_active( $local['_filename'] ) ) { $subscription['local']['active'] = true; } elseif ( is_multisite() && is_plugin_active_for_network( $local['_filename'] ) ) { $subscription['local']['active'] = true; } // 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'] ) { if ( in_array( $local['_stylesheet'], array( get_stylesheet(), get_template() ) ) ) { $subscription['local']['active'] = true; } // 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['has_update'] = false; if ( $subscription['local']['installed'] && ! empty( $updates[ $subscription['product_id'] ] ) ) { $subscription['has_update'] = version_compare( $updates[ $subscription['product_id'] ]['version'], $subscription['local']['version'], '>' ); } $subscription['download_primary'] = true; $subscription['download_url'] = 'https://woocommerce.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'] = $subscription['product_url']; $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' => 'https://woocommerce.com/my-account/my-subscriptions/', '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' => 'https://woocommerce.com/my-account/my-subscriptions/', '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' => 'https://woocommerce.com/my-account/my-subscriptions/', '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' => $data['_product_url'], '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://docs.woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-10', 'https://docs.woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-5' ), 'button_label' => __( 'Purchase', 'woocommerce' ), 'button_url' => $data['_product_url'], '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; }