From 50f9cb14b6d64d048ec31a63e264ec8a58712e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Ramirez=20Giraldo?= <52968528+julianramirez2@users.noreply.github.com> Date: Wed, 30 Aug 2023 17:25:01 -0500 Subject: [PATCH] feat: wpcs workflow and code quality improved (#31) * feat: analizing all files with Wordpress CS * refactor: wordpress coding standard corrections * fix: unit testing new admin file name based on WPCS * refactor: exclusions removed and WPCS corrections * fix: set end of line char as \n * fix: deleted autogenerated unnecessary files * refactor: ignore singular string rule * fix: deleted phpunit cache file * refactor: improved wpcs workflow name * fix: added end of line * fix: end of line added to phpcs xml * fix: deleted vendor directory because merge conflicts * fix: updated composer with required dependencies --- .github/workflows/continuous-integration.yml | 6 +- .github/workflows/linting.yml | 29 - .github/workflows/wordpress-cs-check.yml | 33 + admin/Openedx_Woocommerce_Plugin_Admin.php | 315 ----- ...class-openedx-woocommerce-plugin-admin.php | 338 +++++ admin/index.php | 3 +- ...enedx-woocommerce-plugin-admin-display.php | 2 +- ...oocommerce_Plugin_Enrollment_Info_Form.php | 226 ---- .../Openedx_Woocommerce_Plugin_Settings.php | 311 ----- ...oocommerce-plugin-enrollment-info-form.php | 261 ++++ ...ss-openedx-woocommerce-plugin-settings.php | 328 +++++ composer.json | 29 +- composer.lock | 1155 +++++++++++------ .../Openedx_Woocommerce_Plugin_Loader.php | 167 --- ...-openedx-woocommerce-plugin-activator.php} | 7 +- ...penedx-woocommerce-plugin-deactivator.php} | 7 +- ...class-openedx-woocommerce-plugin-i18n.php} | 11 +- ...lass-openedx-woocommerce-plugin-loader.php | 178 +++ ...p => class-openedx-woocommerce-plugin.php} | 262 ++-- includes/index.php | 5 +- .../Openedx_Woocommerce_Plugin_Api_Calls.php | 74 -- .../Openedx_Woocommerce_Plugin_Enrollment.php | 383 ------ .../model/Openedx_Woocommerce_Plugin_Logs.php | 102 -- .../Openedx_Woocommerce_Plugin_Post_Type.php | 127 -- ...s-openedx-woocommerce-plugin-api-calls.php | 90 ++ ...-openedx-woocommerce-plugin-enrollment.php | 418 ++++++ .../class-openedx-woocommerce-plugin-log.php | 104 ++ ...s-openedx-woocommerce-plugin-post-type.php | 153 +++ index.php | 5 +- openedx-woocommerce-plugin.php | 67 +- phpcs-report.xml | 4 + phpcs.xml | 58 +- ...ass-openedx-woocommerce-plugin-public.php} | 15 +- public/index.php | 5 +- ...nedx-woocommerce-plugin-public-display.php | 2 +- test/EnrollmentTest.php | 50 - test/class-enrollment-test.php | 62 + test/phpunit.xml | 4 +- uninstall.php | 1 - utils/Openedx_Utils.php | 16 - utils/openedx-utils.php | 23 + 41 files changed, 2973 insertions(+), 2463 deletions(-) delete mode 100644 .github/workflows/linting.yml create mode 100644 .github/workflows/wordpress-cs-check.yml delete mode 100644 admin/Openedx_Woocommerce_Plugin_Admin.php create mode 100644 admin/class-openedx-woocommerce-plugin-admin.php delete mode 100644 admin/views/Openedx_Woocommerce_Plugin_Enrollment_Info_Form.php delete mode 100644 admin/views/Openedx_Woocommerce_Plugin_Settings.php create mode 100644 admin/views/class-openedx-woocommerce-plugin-enrollment-info-form.php create mode 100644 admin/views/class-openedx-woocommerce-plugin-settings.php delete mode 100644 includes/Openedx_Woocommerce_Plugin_Loader.php rename includes/{Openedx_Woocommerce_Plugin_Activator.php => class-openedx-woocommerce-plugin-activator.php} (99%) rename includes/{Openedx_Woocommerce_Plugin_Deactivator.php => class-openedx-woocommerce-plugin-deactivator.php} (99%) rename includes/{Openedx_Woocommerce_Plugin_i18n.php => class-openedx-woocommerce-plugin-i18n.php} (95%) create mode 100644 includes/class-openedx-woocommerce-plugin-loader.php rename includes/{Openedx_Woocommerce_Plugin.php => class-openedx-woocommerce-plugin.php} (50%) delete mode 100644 includes/model/Openedx_Woocommerce_Plugin_Api_Calls.php delete mode 100644 includes/model/Openedx_Woocommerce_Plugin_Enrollment.php delete mode 100644 includes/model/Openedx_Woocommerce_Plugin_Logs.php delete mode 100644 includes/model/Openedx_Woocommerce_Plugin_Post_Type.php create mode 100644 includes/model/class-openedx-woocommerce-plugin-api-calls.php create mode 100644 includes/model/class-openedx-woocommerce-plugin-enrollment.php create mode 100644 includes/model/class-openedx-woocommerce-plugin-log.php create mode 100644 includes/model/class-openedx-woocommerce-plugin-post-type.php create mode 100644 phpcs-report.xml rename public/{Openedx_Woocommerce_Plugin_Public.php => class-openedx-woocommerce-plugin-public.php} (93%) delete mode 100644 test/EnrollmentTest.php create mode 100644 test/class-enrollment-test.php delete mode 100644 utils/Openedx_Utils.php create mode 100644 utils/openedx-utils.php diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9a9434e..6de3270 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -30,14 +30,14 @@ jobs: with: find: "Version: *[0-9.]*" replace: "Version: ${{ steps.tag_version.outputs.new_version }}" - include: "openedx-woocommerce-plugin.php" + include: "class-openedx-woocommerce-plugin.php" - name: Update php file version - define statement uses: jacobtomlinson/gha-find-replace@v3 with: find: "(define\\( 'OPENEDX_WOOCOMMERCE_PLUGIN_VERSION', ')([^']*)(.*);" replace: "define( 'OPENEDX_WOOCOMMERCE_PLUGIN_VERSION', '${{ steps.tag_version.outputs.new_version }}' );" - include: "openedx-woocommerce-plugin.php" + include: "class-openedx-woocommerce-plugin.php" - name: Update README version uses: jacobtomlinson/gha-find-replace@v3 @@ -60,7 +60,7 @@ jobs: with: branch: ${{ github.ref }} commit_message: "docs(bumpversion): ${{ steps.tag_version.outputs.previous_tag }} → ${{ steps.tag_version.outputs.new_tag }}" - file_pattern: README.txt CHANGELOG.md openedx-woocommerce-plugin.php + file_pattern: README.txt CHANGELOG.md class-openedx-woocommerce-plugin.php release: needs: bumpversion diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml deleted file mode 100644 index cea673a..0000000 --- a/.github/workflows/linting.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: "Linting" - -on: - pull_request: - paths: - - "**.php" - - "phpcs.xml" - - ".github/workflows/phpcs.yml" - -jobs: - phpcs: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # important! - - # we may use whatever way to install phpcs, just specify the path on the next step - # however, curl seems to be the fastest - - name: Install PHP_CodeSniffer - run: | - curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar - php phpcs.phar --version - - - uses: tinovyatkin/action-php-codesniffer@v1 - with: - files: "**.php" # you may customize glob as needed - phpcs_path: php phpcs.phar - standard: phpcs.xml diff --git a/.github/workflows/wordpress-cs-check.yml b/.github/workflows/wordpress-cs-check.yml new file mode 100644 index 0000000..6ee6f24 --- /dev/null +++ b/.github/workflows/wordpress-cs-check.yml @@ -0,0 +1,33 @@ +name: WordPress Coding Standards check +on: + pull_request + +jobs: + phpcs: + name: PHPCS check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: "shivammathur/setup-php@v2" + with: + php-version: 'latest' + ini-values: memory_limit=1G' + coverage: none + tools: cs2pr + + - name: Install Composer dependencies + uses: "ramsey/composer-install@v2" + with: + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") + + - name: Run PHPCS checks + id: phpcs + run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml --standard=phpcs.xml + + - name: Show PHPCS results in PR + if: ${{ always() && steps.phpcs.outcome == 'failure' }} + run: cs2pr ./phpcs-report.xml diff --git a/admin/Openedx_Woocommerce_Plugin_Admin.php b/admin/Openedx_Woocommerce_Plugin_Admin.php deleted file mode 100644 index 4d9060b..0000000 --- a/admin/Openedx_Woocommerce_Plugin_Admin.php +++ /dev/null @@ -1,315 +0,0 @@ - - */ -class Openedx_Woocommerce_Plugin_Admin -{ - - /** - * The ID of this plugin. - * - * @since 1.0.0 - * @access private - * @var string $plugin_name The ID of this plugin. - */ - private $plugin_name; - - /** - * The version of this plugin. - * - * @since 1.0.0 - * @access private - * @var string $version The current version of this plugin. - */ - private $version; - - /** - * The enrollment instance. - * - * @since 1.0.0 - * @access private - * @var object $openedx_enrollment The current instance of enrollment request. - */ - public $openedx_enrollment; - - /** - * Initialize the class and set its properties. - * - * @since 1.0.0 - * - * @param string $plugin_name The name of this plugin. - * @param string $version The version of this plugin. - * @param string $test Flag variable to know if it is a test. - */ - public function __construct($plugin_name, $version, $test = null) - { - - $this->plugin_name = $plugin_name; - $this->version = $version; - if (!$test) { - $this->createEnrollmentClass(); - } - } - - /** - * Create an instance of the Openedx_Woocommerce_Plugin_Enrollment class. - * - * @since 1.0.0 - * - * @return void - */ - public function createEnrollmentClass() - { - $this->openedx_enrollment = new Openedx_Woocommerce_Plugin_Enrollment($this); - } - - /** - * Register the stylesheets for the admin area. - * - * @since 1.0.0 - */ - public function enqueue_styles() - { - - /** - * This function is provided for demonstration purposes only. - * - * An instance of this class should be passed to the run() function - * defined in Openedx_Woocommerce_Plugin_Loader as all of the hooks are defined - * in that particular class. - * - * The Openedx_Woocommerce_Plugin_Loader will then create the relationship - * between the defined hooks and the functions defined in this - * class. - */ - - //wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/openedx-woocommerce-plugin-admin.css', array(), $this->version, 'all' ); - - } - - /** - * Register the JavaScript for the admin area. - * - * @since 1.0.0 - * - * @return void - */ - public function enqueue_scripts() - { - - /** - * This function is provided for demonstration purposes only. - * - * An instance of this class should be passed to the run() function - * defined in Openedx_Woocommerce_Plugin_Loader as - * all of the hooks are defined in that particular class. - * - * The Openedx_Woocommerce_Plugin_Loader will then create the relationship - * between the defined hooks and the functions defined in this - * class. - */ - } - - /** - * Register Enrollment Request custom post type - * - * @since 1.0.0 - */ - public function register_enrollment_custom_post_type() - { - $this->openedx_enrollment->register_enrollment_custom_post_type(); - } - - /** - * Render Enrollment Request info form - * - * @since 1.0.0 - */ - public function render_enrollment_info_form($post) - { - $this->openedx_enrollment_info_form = new Openedx_Woocommerce_Plugin_Enrollment_Info_Form($post); - } - - /** - * Wrapper function to register a new post type - * - * @param string $post_type Post type name. - * @param string $plural Post type item plural name. - * @param string $single Post type item single name. - * @param string $description Description of post type. - * @return object Post type class object - */ - public function register_post_type($post_type = '', $plural = '', $single = '', $description = '', $options = array()) - { - - if (!$post_type || !$plural || !$single) { - return; - } - - $post_type = $this->createPostType($post_type, $plural, $single, $description, $options); - - return $post_type; - } - - /** - * Create a new instance of the Openedx_Woocommerce_Plugin_Post_Type class and register a new post type. - * - * @param string $post_type Post type name. - * @param string $plural Post type item plural name. - * @param string $single Post type item single name. - * @param string $description Description of the post type. - * @param array $options Additional options for the post type. - * @return object Post type class object. - */ - public function createPostType( - $post_type = '', - $plural = '', - $single = '', - $description = '', - $options = array() - ){ - return new Openedx_Woocommerce_Plugin_Post_Type($post_type, $plural, $single, $description, $options); - } - - /** - * Register course ID and mode fields for product - * - * @since 1.1.1 - */ - function add_custom_product_fields() - { - global $post; - - echo '
'; - } - - - /** - * Create a custom column in order items table inside an order - * - * @param array $columns Array of order items table columns - * - * @return void - */ - function add_custom_column_order_items($columns) - { - $column_name = 'Related Enrollment Request'; - echo 'Your Open edX platform's web address.
- - - - - -Identifier for OAuth application in your Open edX - platform.
- - - - - -- Confidential key for OAuth application in your Open edX platform. -
- - - -Select the Generate Token button to obtain a JWT Token.
- - render_enrollment_info_form( $enrollment_request ); + $this->replace_admin_meta_boxes(); + $this->register_log_manager(); + } + + /** + * Register log manager + * + * @return void + */ + public function register_log_manager() { + $this->log_manager = new Openedx_Woocommerce_Plugin_Log(); + } + + /** + * Print openedx enrollment edit metabox + * + * @param WP_Post $post Current post object. + */ + public function render_enrollment_info_form( $post ) { + + if ( $this->post_type !== $post->post_type ) { + return; + } + + $post_id = $post->ID; + + $course_id = get_post_meta( $post_id, 'course_id', true ); + $email = get_post_meta( $post_id, 'email', true ); + $mode = get_post_meta( $post_id, 'mode', true ); + $is_active = get_post_meta( $post_id, 'is_active', true ); + $order_id = get_post_meta( $post_id, 'order_id', true ); + if ( $order_id ) { + $order_url = admin_url( 'post.php?post=' . intval( $order_id ) ) . '&action=edit'; + } + $mode_options = utils\get_enrollment_options(); + + $new_enrollment = false; + if ( ! $course_id && ! $email ) { + $new_enrollment = true; + } + + ?> +Your Open edX platform's web address.
+ + + + + +Identifier for OAuth application in your Open edX + platform.
+ + + + + ++ Confidential key for OAuth application in your Open edX platform. +
+ + + +Select the Generate Token button to obtain a JWT Token.
+ + =7.0.0", - "psr/http-message": "^1.0 || ^2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interfaces for PSR-7 HTTP message factories", - "keywords": [ - "factory", - "http", - "message", - "psr", - "psr-17", - "psr-7", - "request", - "response" - ], - "support": { - "source": "https://github.com/php-fig/http-factory/tree/1.0.2" - }, - "time": "2023-04-10T20:10:41+00:00" - }, - { - "name": "psr/http-message", - "version": "2.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "support": { - "source": "https://github.com/php-fig/http-message/tree/2.0" - }, - "time": "2023-04-04T09:54:51+00:00" - }, - { - "name": "ralouphie/getallheaders", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" - }, - "type": "library", - "autoload": { - "files": [ - "src/getallheaders.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" - } - ], - "description": "A polyfill for getallheaders.", - "support": { - "issues": "https://github.com/ralouphie/getallheaders/issues", - "source": "https://github.com/ralouphie/getallheaders/tree/develop" - }, - "time": "2019-03-08T08:55:37+00:00" - }, - { - "name": "symfony/deprecation-contracts", - "version": "v3.0.2", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", - "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", - "shasum": "" - }, - "require": { - "php": ">=8.0.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.0-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.2" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-01-02T09:55:41+00:00" - } - ], - "packages-dev": [ - { - "name": "doctrine/instantiator", - "version": "1.5.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0" - }, - "require-dev": { - "doctrine/coding-standard": "^9 || ^11", - "ext-pdo": "*", - "ext-phar": "*", - "phpbench/phpbench": "^0.16 || ^1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.30 || ^5.4" + "forward-command": false + } }, - "type": "library", "autoload": { "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + "GuzzleHttp\\Psr7\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -643,36 +335,71 @@ ], "authors": [ { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "https://ocramius.github.io/" + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" } ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "description": "PSR-7 message implementation that also provides common utility methods", "keywords": [ - "constructor", - "instantiate" + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" ], "support": { - "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.5.0" + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.6.1" }, "funding": [ { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" + "url": "https://github.com/GrahamCampbell", + "type": "github" }, { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" + "url": "https://github.com/Nyholm", + "type": "github" }, { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", "type": "tidelift" } ], - "time": "2022-12-30T00:15:36+00:00" + "time": "2023-08-27T10:13:57+00:00" }, { "name": "myclabs/deep-copy", @@ -1316,11 +1043,215 @@ "type": "github" }, { - "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", - "type": "tidelift" + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2023-08-19T07:10:56+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/0955afe48220520692d2d09f7ab7e0f93ffd6a31", + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/1.0.2" + }, + "time": "2023-04-10T20:12:12+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "e616d01114759c4c489f93b099585439f795fe35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", + "reference": "e616d01114759c4c489f93b099585439f795fe35", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/1.0.2" + }, + "time": "2023-04-10T20:10:41+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" } ], - "time": "2023-08-19T07:10:56+00:00" + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" }, { "name": "sebastian/cli-parser", @@ -2286,6 +2217,73 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "shasum": "" + }, + "require": { + "php": ">=8.0.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.2" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:55:41+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.1", @@ -2337,6 +2335,336 @@ "time": "2021-07-28T10:34:58+00:00" } ], + "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.2", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\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/Dealerdirect/phpcodesniffer-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/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2022-02-04T12:51:07+00:00" + }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "98bcdbacbda14b1db85f710b1853125726795bbc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/98bcdbacbda14b1db85f710b1853125726795bbc", + "reference": "98bcdbacbda14b1db85f710b1853125726795bbc", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.1" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "time": "2023-08-26T04:46:45+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "69465cab9d12454e5e7767b9041af0cd8cd13be7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/69465cab9d12454e5e7767b9041af0cd8cd13be7", + "reference": "69465cab9d12454e5e7767b9041af0cd8cd13be7", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.7.1 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.0.5 || ^2.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "time": "2023-07-16T21:39:41+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.7.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "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", + "static analysis" + ], + "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": "2023-02-22T23:07:41+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "bb792cb331472b82c5d7f28fb9b8ec2d20f68826" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/bb792cb331472b82c5d7f28fb9b8ec2d20f68826", + "reference": "bb792cb331472b82c5d7f28fb9b8ec2d20f68826", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.2" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" + }, + "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", + "static analysis", + "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": "2023-08-21T14:28:38+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], @@ -2349,5 +2677,8 @@ "ext-json": "*", "ext-sqlite3": "*" }, + "platform-overrides": { + "php": "8.0.7" + }, "plugin-api-version": "2.3.0" } diff --git a/includes/Openedx_Woocommerce_Plugin_Loader.php b/includes/Openedx_Woocommerce_Plugin_Loader.php deleted file mode 100644 index d08104e..0000000 --- a/includes/Openedx_Woocommerce_Plugin_Loader.php +++ /dev/null @@ -1,167 +0,0 @@ - - */ -class Openedx_Woocommerce_Plugin_Loader { - - /** - * The array of actions registered with WordPress. - * - * @since 1.0.0 - * @access protected - * @var array $actions The actions registered with WordPress to fire when the plugin loads. - */ - protected $actions; - - /** - * The array of filters registered with WordPress. - * - * @since 1.0.0 - * @access protected - * @var array $filters The filters registered with WordPress to fire when the plugin loads. - */ - protected $filters; - - protected $styles; - - /** - * Initialize the collections used to maintain the actions and filters. - * - * @since 1.0.0 - */ - public function __construct() { - - $this->actions = array(); - $this->filters = array(); - $this->styles = array(); - - } - - /** - * Add a new action to the collection to be registered with WordPress. - * - * @since 1.0.0 - * @param string $hook The name of the WordPress action that is being registered. - * @param object $component A reference to the instance of the object on which the action is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority Optional. The priority at which the function should be fired. Default is 10. - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. - */ - public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { - $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); - } - - /** - * Add a new filter to the collection to be registered with WordPress. - * - * @since 1.0.0 - * @param string $hook The name of the WordPress filter that is being registered. - * @param object $component A reference to the instance of the object on which the filter is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority Optional. The priority at which the function should be fired. Default is 10. - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 - */ - public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { - $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); - } - - /** - * Add a new style to the collection to be registered with WordPress. - * - * @since 1.1.1 - * @param string $handle Name of the stylesheet. Should be unique. - * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. - * @param array $deps An array of registered stylesheet handles this stylesheet depends on. - * @param string $ver String specifying the stylesheet version number, if it has one. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the stylesheet. - * @param string $media The media for which this stylesheet has been defined. - * @return array The collection of actions and filters registered with WordPress. - */ - public function wp_enqueue_style( $handle, $src, $deps, $ver, $media ) { - $this->styles = $this->add_style($handle, $src, $deps, $ver, $media); - } - - /** - * A utility function that is used to register the actions and hooks into a single - * collection. - * - * @since 1.0.0 - * @access private - * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). - * @param string $hook The name of the WordPress filter that is being registered. - * @param object $component A reference to the instance of the object on which the filter is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority The priority at which the function should be fired. - * @param int $accepted_args The number of arguments that should be passed to the $callback. - * @return array The collection of actions and filters registered with WordPress. - */ - private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { - - $hooks[] = array( - 'hook' => $hook, - 'component' => $component, - 'callback' => $callback, - 'priority' => $priority, - 'accepted_args' => $accepted_args - ); - - return $hooks; - - } - - private function add_style( $handle, $src, $deps, $ver, $media ) { - - $hooks[] = array( - 'handle' => $handle, - 'src' => $src, - 'deps' => $deps, - 'ver' => $ver, - 'media' => $media - ); - - return $hooks; - - } - - /** - * Register the filters and actions with WordPress. - * - * @since 1.0.0 - */ - public function run() { - - foreach ( $this->filters as $hook ) { - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); - } - - foreach ( $this->actions as $hook ) { - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); - } - - foreach ( $this->styles as $hook ) { - wp_enqueue_style( $hook['handle'], $hook['src'], $hook['deps'], $hook['ver'], $hook['media'] ); - } - - } - -} diff --git a/includes/Openedx_Woocommerce_Plugin_Activator.php b/includes/class-openedx-woocommerce-plugin-activator.php similarity index 99% rename from includes/Openedx_Woocommerce_Plugin_Activator.php rename to includes/class-openedx-woocommerce-plugin-activator.php index 9f725fb..b4f3b3e 100644 --- a/includes/Openedx_Woocommerce_Plugin_Activator.php +++ b/includes/class-openedx-woocommerce-plugin-activator.php @@ -1,7 +1,4 @@ */ -class Openedx_Woocommerce_Plugin_i18n { +class Openedx_Woocommerce_Plugin_I18n { /** @@ -41,9 +40,5 @@ public function load_plugin_textdomain() { false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' ); - } - - - } diff --git a/includes/class-openedx-woocommerce-plugin-loader.php b/includes/class-openedx-woocommerce-plugin-loader.php new file mode 100644 index 0000000..91597e3 --- /dev/null +++ b/includes/class-openedx-woocommerce-plugin-loader.php @@ -0,0 +1,178 @@ + + */ +class Openedx_Woocommerce_Plugin_Loader { + + /** + * The array of actions registered with WordPress. + * + * @since 1.0.0 + * @access protected + * @var array $actions The actions registered with WordPress to fire when the plugin loads. + */ + protected $actions; + + /** + * The array of filters registered with WordPress. + * + * @since 1.0.0 + * @access protected + * @var array $filters The filters registered with WordPress to fire when the plugin loads. + */ + protected $filters; + + /** + * The array of styles registered with WordPress. + * + * @since 1.1.1 + * @access protected + * @var array $styles The styles registered with WordPress to fire when the plugin loads. + */ + protected $styles; + + /** + * Initialize the collections used to maintain the actions and filters. + * + * @since 1.0.0 + */ + public function __construct() { + + $this->actions = array(); + $this->filters = array(); + $this->styles = array(); + } + + /** + * Add a new action to the collection to be registered with WordPress. + * + * @since 1.0.0 + * @param string $hook The name of the WordPress action that is being registered. + * @param object $component A reference to the instance of the object on which the action is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority Optional. The priority at which the function should be fired. Default is 10. + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. + */ + public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { + $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); + } + + /** + * Add a new filter to the collection to be registered with WordPress. + * + * @since 1.0.0 + * @param string $hook The name of the WordPress filter that is being registered. + * @param object $component A reference to the instance of the object on which the filter is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority Optional. The priority at which the function should be fired. Default is 10. + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. + */ + public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { + $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); + } + + /** + * Add a new style to the collection to be registered with WordPress. + * + * @since 1.1.1 + * @param string $handle Name of the stylesheet. Should be unique. + * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. + * @param array $deps An array of registered stylesheet handles this stylesheet depends on. + * @param string $ver String specifying the stylesheet version number, if it has one. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the stylesheet. + * @param string $media The media for which this stylesheet has been defined. + */ + public function wp_enqueue_style( $handle, $src, $deps, $ver, $media ) { + $this->styles = $this->add_style( $handle, $src, $deps, $ver, $media ); + } + + /** + * A utility function that is used to register the actions and hooks into a single + * collection. + * + * @since 1.0.0 + * @access private + * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). + * @param string $hook The name of the WordPress filter that is being registered. + * @param object $component A reference to the instance of the object on which the filter is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority The priority at which the function should be fired. + * @param int $accepted_args The number of arguments that should be passed to the $callback. + * @return array The collection of actions and filters registered with WordPress. + */ + private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { + + $hooks[] = array( + 'hook' => $hook, + 'component' => $component, + 'callback' => $callback, + 'priority' => $priority, + 'accepted_args' => $accepted_args, + ); + + return $hooks; + } + + /** + * A utility function that is used to register the styles into a single + * + * @since 1.1.1 + * @access private + * @param string $handle Name of the stylesheet. Should be unique. + * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. + * @param array $deps An array of registered stylesheet handles this stylesheet depends on. + * @param string $ver String specifying the stylesheet version number, if it has one. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the stylesheet. + * @param string $media The media for which this stylesheet has been defined. + */ + private function add_style( $handle, $src, $deps, $ver, $media ) { + + $hooks[] = array( + 'handle' => $handle, + 'src' => $src, + 'deps' => $deps, + 'ver' => $ver, + 'media' => $media, + ); + + return $hooks; + } + + /** + * Register the filters and actions with WordPress. + * + * @since 1.0.0 + */ + public function run() { + + foreach ( $this->filters as $hook ) { + add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); + } + + foreach ( $this->actions as $hook ) { + add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); + } + + foreach ( $this->styles as $hook ) { + wp_enqueue_style( $hook['handle'], $hook['src'], $hook['deps'], $hook['ver'], $hook['media'] ); + } + } +} diff --git a/includes/Openedx_Woocommerce_Plugin.php b/includes/class-openedx-woocommerce-plugin.php similarity index 50% rename from includes/Openedx_Woocommerce_Plugin.php rename to includes/class-openedx-woocommerce-plugin.php index 9409db4..6c1a6b0 100644 --- a/includes/Openedx_Woocommerce_Plugin.php +++ b/includes/class-openedx-woocommerce-plugin.php @@ -1,25 +1,4 @@ */ -class Openedx_Woocommerce_Plugin -{ + +namespace App; + +use App\admin\Openedx_Woocommerce_Plugin_Admin; +use App\public\Openedx_Woocommerce_Plugin_Public; +use App\admin\views\Openedx_Woocommerce_Plugin_Settings; + +/** + * This class contains the function to register a new custom post type. + */ +class Openedx_Woocommerce_Plugin { + /** * The loader that's responsible for maintaining and registering all hooks that power @@ -74,11 +63,10 @@ class Openedx_Woocommerce_Plugin * * @since 1.0.0 */ - public function __construct() - { - if (defined('OPENEDX_WOOCOMMERCE_PLUGIN_VERSION')) { - $this->version = OPENEDX_WOOCOMMERCE_PLUGIN_VERSION; - } else { + public function __construct() { + if ( defined( 'OPENEDX_WOOCOMMERCE_PLUGIN_VERSION' ) ) { + $this->version = OPENEDX_WOOCOMMERCE_PLUGIN_VERSION; + } else { $this->version = '1.0.0'; } $this->plugin_name = 'openedx-woocommerce-plugin'; @@ -88,7 +76,7 @@ public function __construct() $this->define_admin_hooks(); $this->define_public_hooks(); $this->define_plugin_settings_hooks(); - } + } /** * Load the required dependencies for this plugin. @@ -106,81 +94,83 @@ public function __construct() * @since 1.0.0 * @access private */ - private function load_dependencies() - { + private function load_dependencies() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'includes/Openedx_Woocommerce_Plugin_Loader.php'; + include_once plugin_dir_path( __DIR__ ) + . 'includes/class-openedx-woocommerce-plugin-loader.php'; /** * The class responsible for defining internationalization functionality * of the plugin. */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'includes/Openedx_Woocommerce_Plugin_i18n.php'; + include_once plugin_dir_path( __DIR__ ) + . 'includes/class-openedx-woocommerce-plugin-i18n.php'; /** * The class responsible for defining all actions that occur in the admin area. */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'admin/Openedx_Woocommerce_Plugin_Admin.php'; + include_once plugin_dir_path( __DIR__ ) + . 'admin/class-openedx-woocommerce-plugin-admin.php'; /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'public/Openedx_Woocommerce_Plugin_Public.php'; + include_once plugin_dir_path( __DIR__ ) + . 'public/class-openedx-woocommerce-plugin-public.php'; $this->loader = new Openedx_Woocommerce_Plugin_Loader(); /** * The class responsible for defining the enrollment object */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'includes/model/Openedx_Woocommerce_Plugin_Enrollment.php'; + include_once plugin_dir_path( __DIR__ ) + . 'includes/model/class-openedx-woocommerce-plugin-enrollment.php'; /** * The class responsible for defining the custom-post-type object */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'includes/model/Openedx_Woocommerce_Plugin_Post_Type.php'; + include_once plugin_dir_path( __DIR__ ) + . 'includes/model/class-openedx-woocommerce-plugin-post-type.php'; - include_once plugin_dir_path(dirname(__FILE__)) - . 'includes/model/Openedx_Woocommerce_Plugin_Logs.php'; + include_once plugin_dir_path( __DIR__ ) + . 'includes/model/class-openedx-woocommerce-plugin-log.php'; /** * The class responsible for rendering the enrollment info form */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'admin/views/Openedx_Woocommerce_Plugin_Enrollment_Info_Form.php'; + include_once plugin_dir_path( __DIR__ ) + . 'admin/views/class-openedx-woocommerce-plugin-enrollment-info-form.php'; - /** - * The file that contains variables and functions used repeatedly in the plugin. - */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'utils/Openedx_Utils.php'; + /** + * The file that contains variables and functions used repeatedly in the plugin. + */ + include_once plugin_dir_path( __DIR__ ) + . 'utils/openedx-utils.php'; /** - * + * The file that contains variables and functions used repeatedly in the plugin. */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'admin/views/Openedx_Woocommerce_Plugin_Settings.php'; - - /** - * Includes the Openedx_Woocommerce_Plugin_Api_Calls model class file. - * - * This includes the file defining the Openedx_Woocommerce_Plugin_Api_Calls class - * which handles making API requests to the Open edX platform. - * - * The path is relative to the main plugin file directory. - */ - include_once plugin_dir_path(dirname(__FILE__)) - . 'includes/model/Openedx_Woocommerce_Plugin_Api_Calls.php'; + include_once plugin_dir_path( __DIR__ ) + . 'admin/views/class-openedx-woocommerce-plugin-settings.php'; + + /** + * Includes the Openedx_Woocommerce_Plugin_Api_Calls model class file. + * + * This includes the file defining the Openedx_Woocommerce_Plugin_Api_Calls class + * which handles making API requests to the Open edX platform. + * + * The path is relative to the main plugin file directory. + */ + include_once plugin_dir_path( __DIR__ ) + . 'includes/model/class-openedx-woocommerce-plugin-api-calls.php'; + + include_once plugin_dir_path( __DIR__ ) + . 'test/class-enrollment-test.php'; } /** @@ -192,16 +182,16 @@ private function load_dependencies() * @since 1.0.0 * @access private */ - private function set_locale() - { + private function set_locale() { $plugin_i18n = new Openedx_Woocommerce_Plugin_i18n(); - $this->loader->add_action('plugins_loaded' - , $plugin_i18n - , 'load_plugin_textdomain' - ); - } + $this->loader->add_action( + 'plugins_loaded', + $plugin_i18n, + 'load_plugin_textdomain' + ); + } /** * Register all of the hooks related to the admin area functionality @@ -210,45 +200,47 @@ private function set_locale() * @since 1.0.0 * @access private */ - private function define_admin_hooks() - { + private function define_admin_hooks() { $plugin_admin = new Openedx_Woocommerce_Plugin_Admin( - $this->get_plugin_name(), + $this->get_plugin_name(), $this->get_version() ); - // Register enrollment request custom-post-type - $this->loader->add_action('init', - $plugin_admin, - 'register_enrollment_custom_post_type' - ); - - // Render enrollment request info form - $this->loader->add_action('edit_form_after_title', $plugin_admin, 'render_enrollment_info_form'); - $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); - $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); - $this->loader->add_filter('gettext', $this, 'openedx_plugin_custom_post_message', 10, 3); + // Register enrollment request custom-post-type. + $this->loader->add_action( + 'init', + $plugin_admin, + 'register_enrollment_custom_post_type' + ); + + // Render enrollment request info form. + $this->loader->add_action( 'edit_form_after_title', $plugin_admin, 'render_enrollment_info_form' ); + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); + $this->loader->add_filter( 'gettext', $this, 'openedx_plugin_custom_post_message', 10, 3 ); $this->loader->wp_enqueue_style( - $this->plugin_name, - plugin_dir_url(__FILE__) . '../admin/css/openedx-woocommerce-plugin-admin.css', - array(), - $this->version, + $this->plugin_name, + plugin_dir_url( __FILE__ ) . '../admin/css/openedx-woocommerce-plugin-admin.css', + array(), + $this->version, 'all' ); - // Redirection from enrollment to order and enrollment to order - $this->loader->add_filter('woocommerce_admin_order_item_headers', $plugin_admin, 'add_custom_column_order_items'); - $this->loader->add_action('woocommerce_admin_order_item_values', $plugin_admin, 'add_admin_order_item_values', 10, 3); - $this->loader->add_action('save_post_shop_order', $plugin_admin, 'save_order_meta_data'); + // Redirection from enrollment to order and enrollment to order. + $this->loader->add_filter( 'woocommerce_admin_order_item_headers', $plugin_admin, 'add_custom_column_order_items' ); + $this->loader->add_action( 'woocommerce_admin_order_item_values', $plugin_admin, 'add_admin_order_item_values', 10, 3 ); + $this->loader->add_action( 'save_post_shop_order', $plugin_admin, 'save_order_meta_data' ); $this->loader->add_action( - 'woocommerce_product_options_general_product_data', - $plugin_admin, + 'woocommerce_product_options_general_product_data', + $plugin_admin, 'add_custom_product_fields' ); - $this->loader->add_action('woocommerce_process_product_meta', - $plugin_admin, - 'save_custom_product_fields'); + $this->loader->add_action( + 'woocommerce_process_product_meta', + $plugin_admin, + 'save_custom_product_fields' + ); } /** @@ -258,46 +250,44 @@ private function define_admin_hooks() * @since 1.0.0 * @access private */ - private function define_public_hooks() - { + private function define_public_hooks() { - $plugin_public = new Openedx_Woocommerce_Plugin_Public( - $this->get_plugin_name(), - $this->get_version()); + $plugin_public = new Openedx_Woocommerce_Plugin_Public( + $this->get_plugin_name(), + $this->get_version() + ); - $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); - $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); } /** * Define the plugin settings hooks. * - * Initializes the Openedx_Woocommerce_Plugin_Settings class + * Initializes the Openedx_Woocommerce_Plugin_Settings class * and registers its admin menu and settings hooks using the loader. - * + * * @return void - */ - private function define_plugin_settings_hooks() - { + */ + private function define_plugin_settings_hooks() { $plugin_settings = new Openedx_Woocommerce_Plugin_Settings(); - $this->loader->add_action('admin_menu', $plugin_settings, 'openedx_settings_submenu'); - $this->loader->add_action('admin_init', $plugin_settings, 'openedx_settings_init'); + $this->loader->add_action( 'admin_menu', $plugin_settings, 'openedx_settings_submenu' ); + $this->loader->add_action( 'admin_init', $plugin_settings, 'openedx_settings_init' ); } - /** - * Modify the message displayed when a custom-post-type is updated - * - * @param string $translated_text translation text - * @param string $text text to be translated - * @param string $domain text domain - * @return string $translated_text post updated message - */ - function openedx_plugin_custom_post_message($translated_text, $text, $domain) - { - - if ($domain === 'default' && $text === 'Post updated.') { + /** + * Modify the message displayed when a custom-post-type is updated + * + * @param string $translated_text translation text. + * @param string $text text to be translated. + * @param string $domain text domain. + * @return string $translated_text post updated message. + */ + public function openedx_plugin_custom_post_message( $translated_text, $text, $domain ) { + + if ( 'default' === $domain && 'Post updated.' === $text ) { $translated_text = 'Enrollment action executed'; } return $translated_text; @@ -308,10 +298,9 @@ function openedx_plugin_custom_post_message($translated_text, $text, $domain) * * @since 1.0.0 */ - public function run() - { + public function run() { $this->loader->run(); - } + } /** * The name of the plugin used to uniquely identify it within the context of @@ -320,10 +309,9 @@ public function run() * @since 1.0.0 * @return string The name of the plugin. */ - public function get_plugin_name() - { + public function get_plugin_name() { return $this->plugin_name; - } + } /** * The reference to the class that orchestrates the hooks with the plugin. @@ -331,8 +319,7 @@ public function get_plugin_name() * @since 1.0.0 * @return Openedx_Woocommerce_Plugin_Loader Orchestrates the hooks of the plugin. */ - public function get_loader() - { + public function get_loader() { return $this->loader; } @@ -342,8 +329,7 @@ public function get_loader() * @since 1.0.0 * @return string The version number of the plugin. */ - public function get_version() - { - return $this->version; - } + public function get_version() { + return $this->version; + } } diff --git a/includes/index.php b/includes/index.php index e71af0e..3c379e1 100644 --- a/includes/index.php +++ b/includes/index.php @@ -1 +1,4 @@ -client = new Client(); - } - - /** - * Generates an access token using the Open edX API credentials. - * - * Makes a POST request to the Open edX API /oauth2/access_token endpoint - * to generate a new JWT access token. - * - * @param string $client_id The Open edX API client ID. - * @param string $client_secret The Open edX API client secret. - * @param string $domain The Open edX domain. - * @return string|array The access token string, or an error array. - */ - public function generate_token($client_id, $client_secret, $domain){ - - try { - $response = $this->client->request('POST', $domain.'/oauth2/access_token', [ - 'form_params' => [ - 'client_id' => $client_id, - 'client_secret' => $client_secret, - 'grant_type' => 'client_credentials', - 'token_type' => 'jwt' - ] - ]); - - $status_code = $response->getStatusCode(); - $response_data = json_decode($response->getBody(), true); - return array("success", $response_data); - - } catch (RequestException $e) { - if ($e->hasResponse()) { - $status_code = $e->getResponse()->getStatusCode(); - $error_data = $e->getResponse()->getBody()->getContents(); - return array("error_has_response", $status_code, $error_data); - } else { - return array("error_no_response", $e); - } - } catch (GuzzleException $e) { - return array("error_no_response", $e); - } - } - -} diff --git a/includes/model/Openedx_Woocommerce_Plugin_Enrollment.php b/includes/model/Openedx_Woocommerce_Plugin_Enrollment.php deleted file mode 100644 index ad28de2..0000000 --- a/includes/model/Openedx_Woocommerce_Plugin_Enrollment.php +++ /dev/null @@ -1,383 +0,0 @@ -parent = $parent; - - // Register all the model related hooks and log manager. - $this->register_hook_callbacks(); - $this->register_log_manager(); - } - - /** - * Register the log manager object to the variable. - * - * @return void - */ - public function register_log_manager() - { - $this->log_manager = new Openedx_Woocommerce_Plugin_Log(); - } - - protected function register_hook_callbacks() - { - /** - * If you think all model related add_actions & filters should be in - * the model class only, then this this the place where you can place - * them. - * - * You can remove this method if you are not going to use it. - */ - - // Add types of status to the enrollment request custom-post-type - add_action('init', array($this, 'register_status'), 10, 3); - - // Add the enrollment logic to the save post hook - add_action('save_post', array($this, 'save_action'), 10, 3); - } - - public function register_enrollment_custom_post_type() - { - // Add the custom post type. - $enrollment_cpt_options = array( - 'public' => false, - 'hierarchical' => false, - 'show_ui' => true, - 'show_in_menu' => true, - 'show_in_nav_menus' => true, - 'supports' => array(''), - 'menu_icon' => 'dashicons-admin-post', - 'labels' => array( - 'name' => 'Open edX Enrollment Requests', - 'singular_name' => 'Open edX Enrollment Request', - 'menu_name' => 'Open edX Sync', - 'all_items' => 'Enrollments Manager', - 'add_new_item' => 'Add New Enrollment Request', - 'edit_item' => 'Edit Enrollment Request', - ), - ); - - // Register post-type using wrapper custom-post-type function - $this->parent->register_post_type('openedx_enrollment', ' ', ' ', '', $enrollment_cpt_options); - } - - /** - * Unregister the save hook to prevent an infinite cycle of hook recursion - * - * @return void - */ - public function unregisterSaveHook() - { - remove_action('save_post', array($this, 'save_action'), 10, 3); - } - - /** - * Register the save hook to prevent an infinite cycle of hook recursion - * - * @return void - */ - public function registerSaveHook() - { - add_action('save_post', array($this, 'save_action'), 10, 3); - } - - /** - * Creates specific status for the post type - * - * @return void - */ - public function register_status() - { - register_post_status( - 'enrollment-success', - array( - 'label' => __('Success', 'wp-edunext-marketing-site'), - 'public' => false, - 'internal' => true, - 'private' => true, - 'exclude_from_search' => false, - 'show_in_admin_all_list' => true, - 'show_in_admin_status_list' => true, - 'label_count' => _n_noop('Success (%s)', 'Success (%s)', 'wp-edunext-marketing-site'), - ) - ); - register_post_status( - 'enrollment-pending', - array( - 'label' => __('Pending', 'wp-edunext-marketing-site'), - 'public' => false, - 'internal' => true, - 'private' => true, - 'exclude_from_search' => false, - 'show_in_admin_all_list' => true, - 'show_in_admin_status_list' => true, - 'label_count' => _n_noop('Pending (%s)', 'Pending (%s)', 'wp-edunext-marketing-site'), - ) - ); - register_post_status( - 'enrollment-error', - array( - 'label' => __('Error', 'wp-edunext-marketing-site'), - 'public' => false, - 'internal' => true, - 'private' => true, - 'exclude_from_search' => false, - 'show_in_admin_all_list' => true, - 'show_in_admin_status_list' => true, - 'label_count' => _n_noop('Error (%s)', 'Error (%s)', 'wp-edunext-marketing-site'), - ) - ); - } - - /** - * Wrapper for the WP function that prevents an infinite cycle of hook recursion - * - * @param array $post The post info in an array. - */ - public function wp_update_post($post) - { - $this->unregisterSaveHook(); - - wp_update_post($post); - - $this->registerSaveHook(); - } - - /** - * Save post metadata when a post is saved. - * - * @param int $post_id The post ID. - * @param post $post The post object. - * @param bool $update Whether this is an existing post being updated or not. - */ - public function save_action($post_id, $post, $update) - { - - if ($this->post_type !== $post->post_type) { - return; - } - - $enrollment_arr = array( - 'enrollment_course_id' => sanitize_text_field($_POST['enrollment_course_id'] ?? ''), - 'enrollment_email' => sanitize_text_field($_POST['enrollment_email'] ?? ''), - 'enrollment_mode' => sanitize_text_field($_POST['enrollment_mode'] ?? ''), - 'enrollment_request_type' => sanitize_text_field( - $_POST['enrollment_request_type'] ?? '' - ), - 'enrollment_order_id' => sanitize_text_field($_POST['enrollment_order_id'] ?? ''), - ); - - $enrollment_action = sanitize_text_field($_POST['enrollment_action'] ?? ''); - - $this->save_enrollment($post, $enrollment_arr, $enrollment_action); - } - - /** - * Creates a new post in the database and runs it through the save. - * - * @param array $enrollment_arr An array containing the enrollment info. - * @param string $enrollment_action The API action to perform once the wp process is done. - * - * @return object $post The post object. - */ - public function insert_new($enrollment_arr, $enrollment_action = '') - { - $this->unregister_save_hook(); - - $new_enrollment = array( - 'post_content' => 'Created automatically by woocommerce to fullfill an order.', - 'post_type' => 'openedx_enrollment', - ); - $post_id = wp_insert_post($new_enrollment); - $post = get_post($post_id); - - $this->save_enrollment($post, $enrollment_arr, $enrollment_action); - return $post; - } - - /** - * Save openedx request based on the incomming args. - * - * @param post $post The post object. - * @param array $enrollment_arr An array containing the enrollment info. - * @param string $enrollment_action The API action to perform once the wp process is done. - */ - public function save_enrollment($post, $enrollment_arr, $enrollment_action) - { - - $post_id = $post->ID; - - // Prepare enrollment data function call - $data = $this->prepare_enrollment_data($post_id, $enrollment_arr); - - // Split returned arrays into 2 variables for old and current data. - $old_data = $data['old_data_array']; - $enrollment_data = $data['enrollment_arr']; - - // Check if the enrollment main data is empty. - if ($this->is_enrollment_data_empty($enrollment_data)) { - return; - } - - // Update post meta data for the Enrollment. - $this->update_enrollment_meta_data($post_id, $enrollment_data); - - /* - * Check if old post_meta tags are different from the new ones to - * change Enrollment Request name in Enrollment Manager requests list. - */ - - if ( - $old_data['enrollment_course_id'] !== $enrollment_data['enrollment_course_id'] - || $old_data['enrollment_email'] !== $enrollment_data['enrollment_email'] - || $old_data['enrollment_mode'] !== $enrollment_data['enrollment_mode'] - ) { - $this->updatePost($post_id); - } - - $nonValidStatuses = array('enrollment-success','enrollment-pending','enrollment-error'); - - // Only update the post status if it has no custom status yet. - if (!in_array($post->post_status, $nonValidStatuses, true)) { - $this->updatePost($post_id, 'enrollment-pending'); - } - - $this->log_manager->createChangeLog($post_id, $old_data, $enrollment_data, $enrollment_action); - } - - - /** - * Check if important enrollment data is empty to stop operation - * - * @param array $enrollment_data An array containing the enrollment info. - */ - public function is_enrollment_data_empty($enrollment_data){ - if ( - !$enrollment_data['enrollment_course_id'] - || !$enrollment_data['enrollment_email'] - || !$enrollment_data['enrollment_mode'] - ){ - return true; - } - } - - /** - * Prepare the array of information to use in the Enrollment process. - * - * @param string $post_id The Enrollment Request ID. - * @param array $enrollment_arr An array containing the enrollment info. - */ - public function prepare_enrollment_data($post_id, $enrollment_arr) - { - - // Sanitize enrollment arr - sanitize_text_field($enrollment_arr['enrollment_course_id']); - sanitize_text_field($enrollment_arr['enrollment_email']); - sanitize_text_field($enrollment_arr['enrollment_mode']); - sanitize_text_field($enrollment_arr['enrollment_request_type']); - sanitize_text_field($enrollment_arr['enrollment_order_id']); - - // Array of old post metadata - $old_data_array = array( - 'enrollment_course_id' => get_post_meta($post_id, 'course_id', true), - 'enrollment_email' => get_post_meta($post_id, 'email', true), - 'enrollment_mode' => get_post_meta($post_id, 'mode', true), - 'enrollment_request_type' => get_post_meta($post_id, 'enrollment_request_type', true), - 'enrollment_order_id' => get_post_meta($post_id, 'order_id', true) - ); - - // Return both arrays - return array( - 'enrollment_arr' => $enrollment_arr, - 'old_data_array' => $old_data_array - ); - } - - /** - * Update the Enrollment Request metadata with the current information. - * @param string $post_id The Enrollment Request ID. - * @param array $enrollment_arr An array containing the enrollment info. - */ - public function update_enrollment_meta_data($post_id, $enrollment_data) - { - // Update the $post metadata. - update_post_meta($post_id, 'course_id', $enrollment_data['enrollment_course_id']); - update_post_meta($post_id, 'email', $enrollment_data['enrollment_email']); - update_post_meta($post_id, 'mode', $enrollment_data['enrollment_mode']); - update_post_meta($post_id, 'order_id', $enrollment_data['enrollment_order_id']); - update_post_meta($post_id, 'enrollment_request_type', $enrollment_data['enrollment_request_type']); - - if ($enrollment_data['enrollment_request_type'] === 'enroll') { - update_post_meta($post_id, 'is_active', true); - } - if ($enrollment_data['enrollment_request_type'] === 'unenroll') { - update_post_meta($post_id, 'is_active', false); - } - } - - /** - * Update post status - * - * @param string $status The status of the request. - * @param int $post_id The post ID. - */ - public function updatePost($post_id, $status = null) - { - - $enrollment_course_id = get_post_meta($post_id, 'course_id', true); - $enrollment_email = get_post_meta($post_id, 'email', true); - $enrollment_mode = get_post_meta($post_id, 'mode', true); - - $post_update = array( - 'ID' => $post_id, - 'post_title' - => $enrollment_course_id . - ' | ' . $enrollment_email . - ' | Mode: ' . $enrollment_mode, - ); - - if ($status) { - $post_update['post_status'] = $status; - } - - $this->wp_update_post($post_update); - } -} diff --git a/includes/model/Openedx_Woocommerce_Plugin_Logs.php b/includes/model/Openedx_Woocommerce_Plugin_Logs.php deleted file mode 100644 index e374ef6..0000000 --- a/includes/model/Openedx_Woocommerce_Plugin_Logs.php +++ /dev/null @@ -1,102 +0,0 @@ -prefix . 'enrollment_logs_req_table'; - $new_post = get_post($post_id); - - $date = current_time('mysql', true); - $user_id = get_current_user_id(); - $username = get_user_by('id', $user_id)->user_login; - - $log_data = array( - 'post_id' => $post_id, - 'mod_date' => $date, - 'user' => $username, - 'action_name' => $enrollment_action, - 'object_before' => json_encode($old_data_array), - 'object_after' => json_encode($enrollment_arr) - ); - - if (empty($old_data_array['enrollment_course_id'])) { - $log_data['object_status'] = 'Object Created'; - $old_data_array = '--'; - }else{ - $log_data['object_status'] = 'Object Modified'; - } - - $wpdb->insert($logs_table, $log_data); - - } catch (Exception $e) { - error_log('An error occurred creating change log: ' . $e->getMessage()); - } - } - - /** - * Get logs from the database for a given post. - * - * @param int $post_id The post ID. - * @return string $formatted_logs Logs formatted as HTML. - */ - public function getLogs($post_id) - { - global $wpdb; - $logs_table = $wpdb->prefix . 'enrollment_logs_req_table'; - - try { - $logs = $wpdb->get_results( - $wpdb->prepare( - "SELECT * FROM $logs_table WHERE post_id = %d ORDER BY mod_date DESC", - $post_id - ), - ARRAY_A - ); - - $formatted_logs = ''; - foreach ($logs as $log) { - $formatted_logs .= "