From 5a4d9779acf84fb6291225f515a0ab5abf2fc221 Mon Sep 17 00:00:00 2001 From: ramadanomar Date: Fri, 21 Mar 2025 05:05:01 +0200 Subject: [PATCH 1/4] feat: saving "forced" enrollment action --- admin/class-openedx-commerce-admin.php | 15 +++- .../views/class-openedx-commerce-settings.php | 76 +++++++++++++++++++ openedx-commerce.php | 4 +- 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/admin/class-openedx-commerce-admin.php b/admin/class-openedx-commerce-admin.php index 80dc75b..59bc826 100644 --- a/admin/class-openedx-commerce-admin.php +++ b/admin/class-openedx-commerce-admin.php @@ -498,11 +498,24 @@ public function select_course_items( $items, $is_refunded = false ) { */ public function items_enrollment_request( $courses, $order_id, $billing_email, $request_type ) { + $force_enrollment = get_option('openedx-enrollment-force', false); + $allow_non_existing = get_option('openedx-enrollment-allowed', false); + + if ($force_enrollment && $allow_non_existing) { + $action = 'openedx_enrollment_allowed_force'; + } elseif ($force_enrollment) { + $action = 'openedx_enrollment_force'; + } elseif ($allow_non_existing) { + $action = 'openedx_enrollment_allowed'; + } else { + $action = 'enrollment_process'; + } + foreach ( $courses as $item_id => $item ) { $course_id = get_post_meta( $item['course_item']->get_product_id(), '_course_id', true ); $course_mode = get_post_meta( $item['course_item']->get_product_id(), '_mode', true ); - $action = 'enrollment_process'; + // $action = 'enrollment_process'; $enrollment_arr = array( 'openedx_enrollment_course_id' => $course_id, diff --git a/admin/views/class-openedx-commerce-settings.php b/admin/views/class-openedx-commerce-settings.php index b9d8713..3948983 100644 --- a/admin/views/class-openedx-commerce-settings.php +++ b/admin/views/class-openedx-commerce-settings.php @@ -125,6 +125,22 @@ public function openedx_settings_init() { 'openedx-settings-section' ); + add_settings_field( + 'openedx-enrollment-force', + 'Force Enrollment', + array( $this, 'openedx_enrollment_force_callback' ), + 'openedx-settings', + 'openedx-settings-section' + ); + + add_settings_field( + 'openedx-enrollment-allowed', + 'Allow Non-Existing Users', + array( $this, 'openedx_enrollment_allowed_callback' ), + 'openedx-settings', + 'openedx-settings-section' + ); + register_setting( 'openedx-settings-group', 'openedx-domain', @@ -149,6 +165,36 @@ public function openedx_settings_init() { 'sanitize_text_field' ); + register_setting( + 'openedx-settings-group', + 'openedx-enrollment-force', + array( + 'type' => 'boolean', + 'sanitize_callback' => 'rest_sanitize_boolean', + 'default' => false, + ) + ); + + register_setting( + 'openedx-settings-group', + 'openedx-enrollment-allowed', + array( + 'type' => 'boolean', + 'sanitize_callback' => 'rest_sanitize_boolean', + 'default' => false, + ) + ); + + register_setting( + 'openedx-settings-group', + 'openedx-enrollment-allowed', + array( + 'type' => 'boolean', + 'sanitize_callback' => 'rest_sanitize_boolean', + 'default' => false, + ) + ); + if ( ! isset( $_POST['openedx_commerce_new_token_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['openedx_commerce_new_token_nonce'] ) ), 'openedx_commerce_token' ) ) { @@ -324,5 +370,35 @@ public function openedx_settings_section_callback() { 'Configuring the necessary parameters here to establish the connection between this plugin and your Open edX platform. For more information, you can visit the how-to Create an Open edX Application for the Plugin Settings in the documentation.' ); } + + /** + * Output the enrollment force settings field. + * + * Retrieves the saved enrollment force value and outputs a checkbox input field and description text. + * + * @return void + */ + public function openedx_enrollment_force_callback() { + $force_enrollment = get_option('openedx-enrollment-force', false); + ?> + > + + + > + + Date: Mon, 4 Aug 2025 16:21:16 -0500 Subject: [PATCH 2/4] fix: linting and fixing QA reports fix: linting the settings file fix: linting --- admin/class-openedx-commerce-admin.php | 11 +++--- .../views/class-openedx-commerce-settings.php | 36 +++++++------------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/admin/class-openedx-commerce-admin.php b/admin/class-openedx-commerce-admin.php index 59bc826..5af280f 100644 --- a/admin/class-openedx-commerce-admin.php +++ b/admin/class-openedx-commerce-admin.php @@ -498,14 +498,14 @@ public function select_course_items( $items, $is_refunded = false ) { */ public function items_enrollment_request( $courses, $order_id, $billing_email, $request_type ) { - $force_enrollment = get_option('openedx-enrollment-force', false); - $allow_non_existing = get_option('openedx-enrollment-allowed', false); + $force_enrollment = get_option( 'openedx-enrollment-force', false ); + $allow_non_existing = get_option( 'openedx-enrollment-allowed', false ); - if ($force_enrollment && $allow_non_existing) { + if ( $force_enrollment && $allow_non_existing ) { $action = 'openedx_enrollment_allowed_force'; - } elseif ($force_enrollment) { + } elseif ( $force_enrollment ) { $action = 'openedx_enrollment_force'; - } elseif ($allow_non_existing) { + } elseif ( $allow_non_existing ) { $action = 'openedx_enrollment_allowed'; } else { $action = 'enrollment_process'; @@ -515,7 +515,6 @@ public function items_enrollment_request( $courses, $order_id, $billing_email, $ $course_id = get_post_meta( $item['course_item']->get_product_id(), '_course_id', true ); $course_mode = get_post_meta( $item['course_item']->get_product_id(), '_mode', true ); - // $action = 'enrollment_process'; $enrollment_arr = array( 'openedx_enrollment_course_id' => $course_id, diff --git a/admin/views/class-openedx-commerce-settings.php b/admin/views/class-openedx-commerce-settings.php index 3948983..64aeba6 100644 --- a/admin/views/class-openedx-commerce-settings.php +++ b/admin/views/class-openedx-commerce-settings.php @@ -127,15 +127,15 @@ public function openedx_settings_init() { add_settings_field( 'openedx-enrollment-force', - 'Force Enrollment', + __( 'Force Enrollment', 'openedx-commerce' ), array( $this, 'openedx_enrollment_force_callback' ), 'openedx-settings', 'openedx-settings-section' ); - + add_settings_field( 'openedx-enrollment-allowed', - 'Allow Non-Existing Users', + __( 'Allow Non-Existing Users', 'openedx-commerce' ), array( $this, 'openedx_enrollment_allowed_callback' ), 'openedx-settings', 'openedx-settings-section' @@ -169,9 +169,9 @@ public function openedx_settings_init() { 'openedx-settings-group', 'openedx-enrollment-force', array( - 'type' => 'boolean', + 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', - 'default' => false, + 'default' => false, ) ); @@ -179,19 +179,9 @@ public function openedx_settings_init() { 'openedx-settings-group', 'openedx-enrollment-allowed', array( - 'type' => 'boolean', - 'sanitize_callback' => 'rest_sanitize_boolean', - 'default' => false, - ) - ); - - register_setting( - 'openedx-settings-group', - 'openedx-enrollment-allowed', - array( - 'type' => 'boolean', + 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', - 'default' => false, + 'default' => false, ) ); @@ -379,10 +369,10 @@ public function openedx_settings_section_callback() { * @return void */ public function openedx_enrollment_force_callback() { - $force_enrollment = get_option('openedx-enrollment-force', false); + $force_enrollment = get_option( 'openedx-enrollment-force', false ); ?> - > - + > + - > - + > + Date: Mon, 4 Aug 2025 16:25:57 -0500 Subject: [PATCH 3/4] fix: bumping to v2.1.0 --- README.txt | 2 +- openedx-commerce.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index 8172823..2b9eabf 100644 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ Tags: openedx, open edx, ecommerce, lms, courses Requires at least: 6.3 Tested up to: 6.8 Requires PHP: 8.0 -Stable tag: 2.0.7 +Stable tag: 2.1.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html diff --git a/openedx-commerce.php b/openedx-commerce.php index 5fd0795..9ad9996 100644 --- a/openedx-commerce.php +++ b/openedx-commerce.php @@ -3,7 +3,7 @@ * Plugin Name: Open edX Commerce * Plugin URI: https://github.com/openedx/openedx-wordpress-ecommerce * Description: Easily connect your WooCommerce store to Open edX. - * Version: 2.0.8 + * Version: 2.1.0 * Author: Open edX Community * Author URI: https://github.com/openedx/openedx-wordpress-ecommerce * License: GPL-2.0+ @@ -32,7 +32,7 @@ * Start at version 1.0.0 and use SemVer - https://semver.org * Rename this for your plugin and update it as you release new versions. */ -define( 'OPENEDX_COMMERCE_VERSION', '2.0.8' ); +define( 'OPENEDX_COMMERCE_VERSION', '2.1.0' ); /** * The code that runs during plugin activation. From 6404a67d42fd1b59ef6d24750937875d13443187 Mon Sep 17 00:00:00 2001 From: Felipe Montoya Date: Tue, 5 Aug 2025 11:51:25 -0500 Subject: [PATCH 4/4] chore: adding changelog --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4900065..e8e29a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,26 @@ +## v2.1.0 - 2025-08-05 + +### [2.1.0](https://github.com/openedx/openedx-wordpress-ecommerce/compare/v2.0.7...v2.1.0) (2025-08-05) + +#### Features + +* feat: add publish to wordpress svn action (#103) +* feat: Save enrollment action preferences (#111) + +#### Bug Fixes + +* fix: add parent property to avoid dynamic property warning (#109) +* fix: updating i18n management (2025 best practices) (#114) + +### Documentation + +* docs: add automatic installation info and change github docs links to rtd docs (#108) + +### Maintenance + +* chore: actions auto updates. +* chore: Tag this repo as part of named releases (#110) + ## v2.0.7 - 2024-11-05 ### [2.0.7](https://github.com/openedx/openedx-wordpress-ecommerce/compare/v2.0.6...v2.0.7) (2024-11-05)