plugin_status = $plugin_status; } /** * Returns the WooCommerce plugin status. * * @since 1.21.0 * * @return array{installed: bool, active: bool, canManage: bool, link: string} Plugin status. */ public function get_plugin_status(): array { $is_installed = \array_key_exists( self::PLUGIN, $this->plugin_status->get_plugins() ); $is_active = $this->is_plugin_active(); $can_manage = false; $link = ''; if ( $is_active ) { $can_manage = current_user_can( 'manage_woocommerce' ); // phpcs:ignore WordPress.WP.Capabilities.Unknown if ( $can_manage ) { $link = admin_url( 'admin.php?page=wc-admin' ); } } elseif ( $is_installed ) { if ( current_user_can( 'activate_plugin', self::PLUGIN ) ) { $link = admin_url( 'plugins.php' ); } } elseif ( current_user_can( 'install_plugins' ) ) { $link = admin_url( add_query_arg( [ 's' => rawurlencode( __( 'WooCommerce', 'web-stories' ) ), 'tab' => 'search', ], 'plugin-install.php' ) ); } else { $link = __( 'https://wordpress.org/plugins/woocommerce/', 'web-stories' ); } return [ 'installed' => $is_active || $is_installed, 'active' => $is_active, 'canManage' => $can_manage, 'link' => $link, ]; } /** * Determines whether WooCommerce is active. * * @since 1.21.0 * * @return bool Whether WooCommerce is active. */ protected function is_plugin_active(): bool { return class_exists( 'WooCommerce', false ); } }