diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..697910d --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,63 @@ +name: Lint +on: + push: + branches: + - '**' + paths: + - '**.php' + pull_request: + types: [opened, edited, reopened, ready_for_review] + paths: + - '**.php' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + cancel-in-progress: true + +jobs: + phpcs: + name: Run PHP Code Sniffer + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v3 + + # User PHP 7.4 here for compatibility with the WordPress codesniffer rules. + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + coverage: none + tools: composer, cs2pr + + - uses: technote-space/get-diff-action@v6 + with: + SUFFIX_FILTER: .php + + - name: Get Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + if: "!! env.GIT_DIFF" + + - name: Cache Composer vendor directory + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + if: "!! env.GIT_DIFF" + + - name: Validate composer.json and composer.lock + run: composer validate + if: "!! env.GIT_DIFF" + + - name: Install dependencies + run: composer install --no-progress --optimize-autoloader --prefer-dist + if: "!! env.GIT_DIFF" + + - name: Detecting PHP Code Standards Violations + run: vendor/bin/phpcs --standard=phpcs.xml -s ${{ env.GIT_DIFF }} + if: "!! env.GIT_DIFF" diff --git a/bootstrap.php b/bootstrap.php index b3cdc6f..917bfa2 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -12,7 +12,7 @@ function () { register( - [ + array( 'name' => 'marketplace', 'label' => __( 'Marketplace', 'newfold-module-marketplace' ), 'callback' => function ( Container $container ) { @@ -20,7 +20,7 @@ function () { }, 'isActive' => true, 'isHidden' => true, - ] + ) ); } diff --git a/composer.json b/composer.json index 5894471..ee0f7e9 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,23 @@ "bootstrap.php" ] }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, "require": { "newfold-labs/wp-module-data": "^2.0.0" + }, + "require-dev": { + "newfold-labs/wp-php-standards": "^1.2" + }, + "scripts": { + "fix": [ + "vendor/bin/phpcbf --standard=phpcs.xml ." + ], + "lint": [ + "vendor/bin/phpcs --standard=phpcs.xml -s ." + ] } } diff --git a/composer.lock b/composer.lock index 30f9e2a..997b936 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f26a38560ee32779231b1b6c1e6a8ccf", + "content-hash": "f8a64deb185d19e383cea8c491cb214b", "packages": [ { "name": "newfold-labs/wp-module-data", @@ -51,7 +51,404 @@ "time": "2022-04-19T21:25:10+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, + { + "name": "newfold-labs/wp-php-standards", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/newfold-labs/wp-php-standards.git", + "reference": "e97e34d7d2df0cefdcb6f3c06714aae417b26044" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/newfold-labs/wp-php-standards/zipball/e97e34d7d2df0cefdcb6f3c06714aae417b26044", + "reference": "e97e34d7d2df0cefdcb6f3c06714aae417b26044", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "@stable", + "phpcompatibility/phpcompatibility-wp": "@stable", + "squizlabs/php_codesniffer": "@stable", + "wp-coding-standards/wpcs": "@stable" + }, + "type": "phpcodesniffer-standard", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Micah Wood", + "email": "micah@wpscholar.com" + } + ], + "description": "PHP Code Sniffer Standards for Newfold WordPress projects.", + "support": { + "source": "https://github.com/newfold-labs/wp-php-standards/tree/1.2.2", + "issues": "https://github.com/newfold-labs/wp-php-standards/issues" + }, + "time": "2023-01-06T11:45:52+00:00" + }, + { + "name": "phpcompatibility/php-compatibility", + "version": "9.3.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibility" + }, + "time": "2019-12-27T09:44:58+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.3.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "paragonie/random_compat": "dev-master", + "paragonie/sodium_compat": "dev-master" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" + }, + "time": "2022-10-25T01:46:02+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.1.4", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" + }, + "time": "2022-10-24T09:00:36+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.7.1", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619", + "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2022-06-18T07:21:10+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "7da1894633f168fe244afc6de00d141f27517b62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62", + "reference": "7da1894633f168fe244afc6de00d141f27517b62", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.3.1" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "time": "2020-05-13T23:57:56+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], @@ -59,5 +456,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.3.0" } diff --git a/includes/Marketplace.php b/includes/Marketplace.php index f8f95ed..eff56b2 100644 --- a/includes/Marketplace.php +++ b/includes/Marketplace.php @@ -4,6 +4,9 @@ use NewfoldLabs\WP\ModuleLoader\Container; +/** + * Class for handling the initialization of the marketplace module. + */ class Marketplace { /** @@ -16,7 +19,7 @@ class Marketplace { /** * Constructor. * - * @param Container $container + * @param Container $container The plugin container. */ public function __construct( Container $container ) { diff --git a/includes/MarketplaceApi.php b/includes/MarketplaceApi.php index 90a5fe7..fd40e8e 100644 --- a/includes/MarketplaceApi.php +++ b/includes/MarketplaceApi.php @@ -2,9 +2,6 @@ namespace NewFoldLabs\WP\Module\Marketplace; -// use WP_Forge\Helpers\Arr; - -use NewfoldLabs\WP\Module\Data\HiiveConnection; use function NewfoldLabs\WP\ModuleLoader\container; /** @@ -27,8 +24,8 @@ public static function registerRoutes() { 'newfold-marketplace/v1', '/marketplace', array( - 'methods' => \WP_REST_Server::READABLE, - 'callback' => __CLASS__ . '::marketplace_callback', + 'methods' => \WP_REST_Server::READABLE, + 'callback' => __CLASS__ . '::marketplace_callback', 'permission_callback' => function () { return current_user_can( 'manage_options' ); }, @@ -40,8 +37,8 @@ public static function registerRoutes() { /** * Set the transient where marketplace is stored. * - * @param string $data json of marketplace. - * @param float|int $expiration Transient expiration. + * @param string $data json of marketplace. + * @param float|int $expiration Transient expiration. */ public static function setTransient( $data, $expiration = DAY_IN_SECONDS ) { set_transient( self::TRANSIENT, $data, $expiration ); @@ -49,6 +46,10 @@ public static function setTransient( $data, $expiration = DAY_IN_SECONDS ) { /** * Get expiration from response + * + * @param array $marketplace Response from marketplace endpoint. + * + * @return float|int|mixed */ public static function get_expiration( $marketplace ) { // get response['meta']['ttl'] if it exists, otherwise set to default 24hrs @@ -61,34 +62,41 @@ public static function get_expiration( $marketplace ) { /** * Get marketplace data + * + * @param \WP_REST_Request $request Request object. + * + * @return \WP_Error|\WP_HTTP_Response|\WP_REST_Response + * + * @throws \NewfoldLabs\Container\NotFoundException When item is not found in the container. + * @throws \WP_Forge\Container\NotFoundException When item is not found in the container. */ public static function marketplace_callback( \WP_REST_Request $request ) { - + $marketplace = get_transient( self::TRANSIENT ); if ( false === $marketplace ) { $args = array( 'per_page' => 60, - // if marketplace brand is set on container, - // use it as brand override, - // otherwise use plugin id (default) - 'brand' => container()->has('marketplace_brand') ? - container()->get('marketplace_brand') : + // if marketplace brand is set on container, + // use it as brand override, + // otherwise use plugin id (default) + 'brand' => container()->has( 'marketplace_brand' ) ? + container()->get( 'marketplace_brand' ) : container()->plugin()->id, ); - $products = self::product_data( $args ); + $products = self::product_data( $args ); $categories = self::category_data( $args ); if ( $products && $categories ) { - $marketplace = json_encode( + $marketplace = wp_json_encode( array( 'categories' => $categories, - 'products' => $products - ) + 'products' => $products, + ) ); - $expiration = self::get_expiration( $products ); + $expiration = self::get_expiration( $products ); self::setTransient( $marketplace, $expiration ); } } @@ -97,28 +105,26 @@ public static function marketplace_callback( \WP_REST_Request $request ) { /** * Get product data from products endpoint - * - * @param Array $args + * + * @param array $args Query arguments for endpoint request. */ - public static function product_data( $args ){ + public static function product_data( $args ) { // construct endpoint with args $marketplace_endpoint = add_query_arg( $args, NFD_HIIVE_URL . '/marketplace/v1/products' ); - + $response = wp_remote_get( $marketplace_endpoint, array( 'headers' => array( - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - // 'Authorization' => 'Bearer ' . HiiveConnection::get_auth_token(), // not needed since it's now a publicly accessible endpoint + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', ), ) ); - - // return rest_ensure_response( $response ); + if ( ! is_wp_error( $response ) ) { $body = wp_remote_retrieve_body( $response ); $data = json_decode( $body, true ); @@ -136,28 +142,26 @@ public static function product_data( $args ){ /** * Get category data from categories endpoint - * - * @param Array $args + * + * @param array $args Query arguments for endpoint request. */ - public static function category_data( $args ){ + public static function category_data( $args ) { // construct endpoint with args $category_endpoint = add_query_arg( $args, NFD_HIIVE_URL . '/marketplace/v1/products/categories' ); - + $response = wp_remote_get( $category_endpoint, array( 'headers' => array( - 'Content-Type' => 'application/json', - 'Accept' => 'application/json', - // 'Authorization' => 'Bearer ' . HiiveConnection::get_auth_token(), // not needed since it's now a publicly accessible endpoint + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', ), ) ); - - // return rest_ensure_response( $response ); + if ( ! is_wp_error( $response ) ) { $body = wp_remote_retrieve_body( $response ); $data = json_decode( $body, true ); diff --git a/includes/PluginsMarketplace.php b/includes/PluginsMarketplace.php index 94ebc8e..0f60e17 100644 --- a/includes/PluginsMarketplace.php +++ b/includes/PluginsMarketplace.php @@ -10,96 +10,105 @@ */ class PluginsMarketplace { - /** + /** * Initialize. */ - public static function init() { - // Filters wheather the premuim plugins tab is enabled or disabled. Default is enabled. - $enabled = apply_filters( 'nfd_enable_plugins_marketplace', true ); - - if ($enabled) { - add_action( 'admin_menu', array( __CLASS__, 'add_premuim_plugins_menu_link' ) ); - add_filter( 'install_plugins_tabs', array( __CLASS__, 'add_premuim_plugins_tab' ) ); - add_action( 'admin_head-plugin-install.php', array( __CLASS__, 'premuim_plugins_tab_enqueue_assets' ) ); - } - } - - /** + public static function init() { + // Filters wheather the premuim plugins tab is enabled or disabled. Default is enabled. + $enabled = apply_filters( 'nfd_enable_plugins_marketplace', true ); + + if ( $enabled ) { + add_action( 'admin_menu', array( __CLASS__, 'add_premuim_plugins_menu_link' ) ); + add_filter( 'install_plugins_tabs', array( __CLASS__, 'add_premuim_plugins_tab' ) ); + add_action( 'admin_head-plugin-install.php', array( __CLASS__, 'premuim_plugins_tab_enqueue_assets' ) ); + } + } + + /** * Add "Premium" sub-link to admin menu. */ - public static function add_premuim_plugins_menu_link() { - add_submenu_page( - 'plugins.php', - 'Premium Plugins', - 'Premium', - 'manage_options', - 'plugin-install.php?tab=premium-marketplace', - ); - - // Add crown icon to menu and filter links - add_action( - 'admin_footer', - function () { ?> - - + + + plugin()->id . '-wordpress-plugin' ); + public static function add_premuim_plugins_tab( array $tabs ) { + $tabs['premium-marketplace'] = __( 'Premium', 'newfold-marketplace-module' ); - return $tabs; - } + return $tabs; + } - /** + /** * Enqueue assets and set locals. */ - public static function premuim_plugins_tab_enqueue_assets() { - if ( false === ( isset($_GET['tab']) && $_GET['tab'] == 'premium-marketplace' ) ) { - return; - } - - $assetsDir = container()->plugin()->url . 'vendor/newfold-labs/wp-module-marketplace/includes/assets/'; - - wp_enqueue_style( 'nfd_plugins_marketplace_css', $assetsDir . 'css/NFDPluginsMarketplace.css' ); - wp_enqueue_script( 'nfd_plugins_marketplace_js', $assetsDir . 'js/NFDPluginsMarketplace.js' ); - - wp_localize_script('nfd_plugins_marketplace_js', 'nfdPremiumPluginsMarketplace', - array( - 'restApiNonce' => wp_create_nonce('wp_rest'), - 'marketplaceDescription' => __( "Unlock the full potential of your WordPress website with premium plugins from", container()->plugin()->id . '-wordpress-plugin' ) . " " . ucwords(container()->plugin()->id), - ) - ); - } + public static function premuim_plugins_tab_enqueue_assets() { + if ( false === ( isset( $_GET['tab'] ) && 'premium-marketplace' === $_GET['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return; + } + + $assetsDir = container()->plugin()->url . 'vendor/newfold-labs/wp-module-marketplace/includes/assets/'; + + wp_enqueue_style( 'nfd_plugins_marketplace_css', $assetsDir . 'css/NFDPluginsMarketplace.css', array(), container()->plugin()->version ); + wp_enqueue_script( 'nfd_plugins_marketplace_js', $assetsDir . 'js/NFDPluginsMarketplace.js', array(), container()->plugin()->version, true ); + + wp_localize_script( + 'nfd_plugins_marketplace_js', + 'nfdPremiumPluginsMarketplace', + array( + 'restApiNonce' => wp_create_nonce( 'wp_rest' ), + 'marketplaceDescription' => __( 'Unlock the full potential of your WordPress website with premium plugins from', 'newfold-marketplace-module' ) . ' ' . ucwords( container()->plugin()->id ), + ) + ); + } } diff --git a/includes/Themes.php b/includes/Themes.php index b706dbb..fcdfc42 100644 --- a/includes/Themes.php +++ b/includes/Themes.php @@ -111,7 +111,7 @@ public static function add_upload_theme_button() { * Adds Upload Theme page to WordPress */ public static function upload_theme_page() { - if ( ! isset( $_GET['page'] ) || 'upload-theme' !== $_GET['page'] ) { + if ( ! isset( $_GET['page'] ) || 'upload-theme' !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } @@ -146,7 +146,7 @@ public static function add_premuim_themes_tab() { const themesFilterContainer = document.querySelector('.wp-filter .filter-links'); const marketplacePremiumThemesLink = document.createElement('li'); - marketplacePremiumThemesLink.innerHTML = 'plugin()->id . '-wordpress-plugin' ); ?>'; + marketplacePremiumThemesLink.innerHTML = ''; themesFilterContainer.appendChild(marketplacePremiumThemesLink); }); @@ -157,13 +157,12 @@ public static function add_premuim_themes_tab() { /** * Filters query arguments to only retrieve block themes (full-site-editing) from the WordPress.org Themes API. * - * @since 2.8.0 - * - * @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. + * @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. * @param string $action Requested action. Likely values are 'theme_information', * 'feature_list', or 'query_themes'. * * @return object updated $args for this request. + * @since 2.8.0 */ public static function query_block_themes_args( $args, $action ) { @@ -186,14 +185,13 @@ public static function query_block_themes_args( $args, $action ) { /** * Sorts the returned WordPress.org Themes API response to show self::$priority_themes on top. * - * @since 2.8.0 - * * @param array|stdClass|WP_Error $res WordPress.org Themes API response. * @param string $action Requested action. Likely values are 'theme_information', * 'feature_list', or 'query_themes'. * @param stdClass $args Arguments used to query for installer pages from the WordPress.org Themes API. * * @return stdClass $res sorted themes with self::$priority_themes on top. + * @since 2.8.0 */ public static function sort_query_themes_results( $res, $action, $args ) { @@ -223,12 +221,12 @@ public static function recommended_theme_ribbon() { ?>