woocommerce-rest-api.php
69 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: WooCommerce REST API |
| 4 | * Plugin URI: https://github.com/woocommerce/woocommerce-rest-api |
| 5 | * Description: The WooCommerce core REST API, installed as a feature plugin for development and testing purposes. Requires WooCommerce 3.7+ and PHP 5.3+. |
| 6 | * Author: Automattic |
| 7 | * Author URI: https://woocommerce.com |
| 8 | * Version: 1.0.7 |
| 9 | * Requires PHP: 5.6 |
| 10 | * License: GPLv3 |
| 11 | * |
| 12 | * @package Automattic/WooCommerce/RestApi |
| 13 | * @internal This file is only used when running the REST API as a feature plugin. |
| 14 | */ |
| 15 | |
| 16 | defined( 'ABSPATH' ) || exit; |
| 17 | |
| 18 | if ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Autoload packages. |
| 24 | * |
| 25 | * The package autoloader includes version information which prevents classes in this feature plugin |
| 26 | * conflicting with WooCommerce core. |
| 27 | * |
| 28 | * We want to fail gracefully if `composer install` has not been executed yet, so we are checking for the autoloader. |
| 29 | * If the autoloader is not present, let's log the failure and display a nice admin notice. |
| 30 | */ |
| 31 | $autoloader = __DIR__ . '/vendor/autoload_packages.php'; |
| 32 | if ( is_readable( $autoloader ) ) { |
| 33 | require $autoloader; |
| 34 | } else { |
| 35 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 36 | error_log( // phpcs:ignore |
| 37 | sprintf( |
| 38 | /* translators: 1: composer command. 2: plugin directory */ |
| 39 | esc_html__( 'Your installation of the WooCommerce REST API feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce' ), |
| 40 | '`composer install`', |
| 41 | '`' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '`' |
| 42 | ) |
| 43 | ); |
| 44 | } |
| 45 | /** |
| 46 | * Outputs an admin notice if composer install has not been ran. |
| 47 | */ |
| 48 | add_action( |
| 49 | 'admin_notices', |
| 50 | function() { |
| 51 | ?> |
| 52 | <div class="notice notice-error"> |
| 53 | <p> |
| 54 | <?php |
| 55 | printf( |
| 56 | /* translators: 1: composer command. 2: plugin directory */ |
| 57 | esc_html__( 'Your installation of the WooCommerce REST API feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce' ), |
| 58 | '<code>composer install</code>', |
| 59 | '<code>' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '</code>' |
| 60 | ); |
| 61 | ?> |
| 62 | </p> |
| 63 | </div> |
| 64 | <?php |
| 65 | } |
| 66 | ); |
| 67 | return; |
| 68 | } |
| 69 |