Agentic
4 months ago
BlockTemplates
4 weeks ago
EmailImprovements
1 year ago
EmailPreview
4 weeks ago
Emails
1 year ago
ImportExport
1 year ago
Logging
1 year ago
Marketing
2 years ago
Notes
4 weeks ago
Onboarding
5 months ago
Orders
4 weeks ago
ProductForm
2 years ago
ProductReviews
4 weeks ago
RemoteFreeExtensions
4 weeks ago
Schedulers
4 weeks ago
Settings
2 weeks ago
Suggestions
4 weeks ago
WCPayPromotion
10 months ago
ActivityPanels.php
3 years ago
Analytics.php
4 weeks ago
CategoryLookup.php
4 years ago
Coupons.php
1 year ago
CouponsMovedTrait.php
5 months ago
CustomerEffortScoreTracks.php
7 months ago
Events.php
2 months ago
FeaturePlugin.php
4 months ago
Homescreen.php
1 month ago
Loader.php
4 weeks ago
Marketing.php
1 year ago
Marketplace.php
5 months ago
MobileAppBanner.php
4 years ago
OrderMilestoneEasterEgg.php
4 weeks ago
RemoteInboxNotifications.php
3 years ago
Settings.php
2 weeks ago
ShippingLabelBanner.php
1 year ago
ShippingLabelBannerDisplayRules.php
1 year ago
SiteHealth.php
3 years ago
Survey.php
4 years ago
SystemStatusReport.php
1 year ago
Translations.php
1 year ago
WCAdminAssets.php
2 weeks ago
WCAdminSharedSettings.php
1 year ago
WCAdminUser.php
9 months ago
WcPayWelcomePage.php
1 year ago
Marketplace.php
143 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Marketplace. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Internal\Admin; |
| 7 | |
| 8 | use WC_Helper_Options; |
| 9 | use WC_Helper_Updater; |
| 10 | |
| 11 | /** |
| 12 | * Contains backend logic for the Marketplace feature. |
| 13 | */ |
| 14 | class Marketplace { |
| 15 | const MARKETPLACE_TAB_SLUG = 'woo'; |
| 16 | |
| 17 | /** |
| 18 | * Class initialization, to be executed when the class is resolved by the container. |
| 19 | * |
| 20 | * @internal |
| 21 | */ |
| 22 | final public function init() { |
| 23 | add_action( 'init', array( $this, 'on_init' ) ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Hook into WordPress on init. |
| 28 | */ |
| 29 | public function on_init() { |
| 30 | add_action( 'admin_menu', array( $this, 'register_pages' ), 70 ); |
| 31 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 32 | |
| 33 | // Add a Woo Marketplace link to the plugin install action links. |
| 34 | add_filter( 'install_plugins_tabs', array( $this, 'add_woo_plugin_install_action_link' ) ); |
| 35 | add_action( 'install_plugins_pre_woo', array( $this, 'maybe_open_woo_tab' ) ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Registers report pages. |
| 40 | */ |
| 41 | public function register_pages() { |
| 42 | if ( ! function_exists( 'wc_admin_register_page' ) ) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | $marketplace_pages = $this->get_marketplace_pages(); |
| 47 | |
| 48 | foreach ( $marketplace_pages as $marketplace_page ) { |
| 49 | if ( ! is_null( $marketplace_page ) ) { |
| 50 | wc_admin_register_page( $marketplace_page ); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get report pages. |
| 57 | */ |
| 58 | public function get_marketplace_pages() { |
| 59 | $marketplace_pages = array( |
| 60 | array( |
| 61 | 'id' => 'woocommerce-marketplace', |
| 62 | 'parent' => 'woocommerce', |
| 63 | 'title' => __( 'Extensions', 'woocommerce' ) . $this->badge(), |
| 64 | 'page_title' => __( 'Extensions', 'woocommerce' ), |
| 65 | 'path' => '/extensions', |
| 66 | ), |
| 67 | ); |
| 68 | |
| 69 | /** |
| 70 | * The marketplace items used in the menu. |
| 71 | * |
| 72 | * @since 8.0 |
| 73 | */ |
| 74 | return apply_filters( 'woocommerce_marketplace_menu_items', $marketplace_pages ); |
| 75 | } |
| 76 | |
| 77 | private function badge(): string { |
| 78 | $option = WC_Helper_Options::get( 'my_subscriptions_tab_loaded' ); |
| 79 | |
| 80 | if ( ! $option ) { |
| 81 | return WC_Helper_Updater::get_updates_count_html(); |
| 82 | } |
| 83 | |
| 84 | return ''; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Enqueue update script. |
| 89 | * |
| 90 | * @param string $hook_suffix The current admin page. |
| 91 | */ |
| 92 | public function enqueue_scripts( $hook_suffix ) { |
| 93 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
| 94 | if ( 'woocommerce_page_wc-admin' !== $hook_suffix ) { |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | if ( ! isset( $_GET['path'] ) || '/extensions' !== $_GET['path'] ) { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | // Enqueue WordPress updates script to enable plugin and theme installs and updates. |
| 103 | wp_enqueue_script( 'updates' ); |
| 104 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Add a Woo Marketplace link to the plugin install action links. |
| 109 | * |
| 110 | * @param array $tabs Plugins list tabs. |
| 111 | * @return array |
| 112 | */ |
| 113 | public function add_woo_plugin_install_action_link( $tabs ) { |
| 114 | $tabs[ self::MARKETPLACE_TAB_SLUG ] = 'WooCommerce Marketplace'; |
| 115 | return $tabs; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Open the Woo tab when the user clicks on the Woo link in the plugin installer. |
| 120 | */ |
| 121 | public function maybe_open_woo_tab() { |
| 122 | // phpcs:disable WordPress.Security.NonceVerification.Recommended |
| 123 | if ( ! isset( $_GET['tab'] ) || self::MARKETPLACE_TAB_SLUG !== $_GET['tab'] ) { |
| 124 | return; |
| 125 | } |
| 126 | // phpcs:enable WordPress.Security.NonceVerification.Recommended |
| 127 | |
| 128 | $woo_url = add_query_arg( |
| 129 | array( |
| 130 | 'page' => 'wc-admin', |
| 131 | 'path' => '/extensions', |
| 132 | 'tab' => 'extensions', |
| 133 | 'ref' => 'plugins', |
| 134 | ), |
| 135 | admin_url( 'admin.php' ) |
| 136 | ); |
| 137 | |
| 138 | wc_admin_record_tracks_event( 'marketplace_plugin_install_woo_clicked' ); |
| 139 | wp_safe_redirect( $woo_url ); |
| 140 | exit; |
| 141 | } |
| 142 | } |
| 143 |