Plugin Directory

Changeset 3000299


Ignore:
Timestamp:
11/22/2023 05:07:18 PM (17 months ago)
Author:
flyplugins
Message:

2.0 Release

Location:
memberpress-addon-for-wp-courseware
Files:
12 added
4 edited

Legend:

Unmodified
Added
Removed
  • memberpress-addon-for-wp-courseware/trunk/includes/class-wpcw-mp-members.php

    r2019574 r3000299  
    127127            );
    128128
     129            if ( isset( $_REQUEST['action'] ) && 'retroactiveassignment' === $_REQUEST['action'] ) {
     130                $level_ID = $levelDetails['id'];
     131                $this->retroactive_assignment( $level_ID );
     132
     133                return;
     134            }
     135
    129136            // Get a list of course IDs that exist.
    130137            $courses = wpcw_mp_addon_get_courses( false );
     
    149156            $elem = new FormElement( 'retroactive_assignment', __( 'Do you want to retroactively assign these courses to current customers?', 'wpcw-mp-addon' ), true );
    150157            $elem->setTypeAsRadioButtons( array(
    151                 'Yes' => __( 'Yes', 'wpcw-mp-addon' ),
    152                 'No'  => __( 'No', 'wpcw-mp-addon' ),
     158                'Yes' => __( 'Yes, enroll students into newly selected course(s)', 'wpcw-wc-addon' ),
     159                'No'  => __( 'No, just associate course(s) with the membership level.', 'wpcw-wc-addon' ),
    153160            ) );
     161
    154162            $form->addFormElement( $elem );
    155163
     
    165173                    global $wpdb, $wpcwdb;
    166174                    $wpdb->show_errors();
     175
     176                    $current_levelList = array();
     177
     178                    if ( $this->getCourseAccessListForLevel( $levelDetails['id'] ) ){
     179                        $current_levelList = array_keys( $this->getCourseAccessListForLevel( $levelDetails['id'] ) );
     180                    }
    167181
    168182                    // Remove all previous level mappings (as some will have been removed).
     
    193207                    if ( 'Yes' == $retroactive_assignment && count( $mapplingList ) >= 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName
    194208                        $level_ID = $levelDetails['id']; // phpcs:ignore WordPress.NamingConventions.ValidVariableName
     209
     210                        $new_levelList = array_keys( $mapplingList );
     211                        $remove_courses = array_diff( $current_levelList, $new_levelList );
     212                        $add_courses = array_diff( $new_levelList, $current_levelList );
     213
     214                        if ( $add_courses ){
     215                            set_transient( 'wpcw_add_courses_' . $level_ID, $add_courses, 60*60*12 );
     216                        }
     217                       
     218                        if ( $remove_courses ){
     219                            set_transient( 'wpcw_remove_courses_' . $level_ID, $remove_courses, 60*60*12 );
     220                        }
     221
    195222                        $this->retroactive_assignment( $level_ID ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName
     223
     224                        return;
    196225                        // $page->showMessage(__('All members were successfully retroactively enrolled into the selected courses.', 'wpcw-mp-addon'));
    197226                    }
     
    273302                        // Show which courses will be added to users created at this level.
    274303                        foreach ( $courses as $courseID => $courseName ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName
     304                            if ( ! isset($courseListInDB[ $courseID ]) ){
     305                                continue;
     306                            }
    275307                            $data['wpcw_members_levels'] .= sprintf( '<li class="wpcw_%s">%s</li>', ( isset( $courseListInDB[ $courseID ] ) ? 'enabled' : 'disabled' ), $courseName ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName
    276308                        }
  • memberpress-addon-for-wp-courseware/trunk/includes/class-wpcw-mp-membership.php

    r2360462 r3000299  
    111111
    112112            $mepr_db = new MeprDb();
    113             $page    = new PageBuilder( false );
     113
     114            $page = new PageBuilder( false );
     115
     116            $batch = 50;
     117            $step  = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1;
     118            $count = isset( $_GET['count'] ) ? absint( $_GET['count'] ) : 0;
     119            $steps = isset( $_GET['steps'] ) ? $_GET['steps'] : 'continue';
     120
     121            $coursesToAdd = get_transient( 'wpcw_add_courses_' . $level_id );
     122            $coursesToRemove = get_transient( 'wpcw_remove_courses_' . $level_id );
     123
     124            $summary_url = add_query_arg( array( 'page' => $this->extensionID ), admin_url( 'admin.php' ) );
     125            $course_url  = add_query_arg( array( 'page' => $this->extensionID, 'level_id' => $level_id ), admin_url( 'admin.php' ) );
     126
     127            if ( 'finished' === $steps ) {
     128                $page->showMessage(
     129                    esc_html__( 'Course access settings successfully updated.', 'wpcw-wc-addon' )
     130                    . '<br />' .
     131                    esc_html__( 'All existing customers were retroactively enrolled into the selected courses successfully.', 'wpcw-wc-addon' )
     132                    . '<br /><br />' .
     133                    /* translators: %s - Summary Url. */
     134                    sprintf( __( 'Want to return to the <a href="%s">Course Access Settings</a>?', 'wpcw-wc-addon' ), $summary_url )
     135                );
     136
     137                printf( '<br /><a href="%s" class="button-primary">%s</a>', $course_url, __( '&laquo; Return to Course', 'wpcw-wc-addon' ) );
     138
     139                if ( $coursesToRemove ){
     140                    delete_transient( 'wpcw_remove_courses_' . $level_id );
     141                }
     142
     143                if ( $coursesToAdd ){
     144                    delete_transient( 'wpcw_add_courses_' . $level_id );
     145                }
     146
     147                return;
     148            }
     149
     150            if ( isset( $_POST['retroactive_assignment'] ) ) {
     151                $step  = 1;
     152                $count = 0;
     153                $steps = 'continue';
     154            }
    114155
    115156            // Get user's assigned products and enroll them into courses accordingly.
    116             $transations = $wpdb->get_results(
     157            $customers = $wpdb->get_results(
    117158                $wpdb->prepare(
    118159                    "SELECT user_id, id
    119160                     FROM {$mepr_db->transactions}
    120161                     WHERE product_id = %d
    121                      AND (status = 'confirmed' OR status = 'complete')",
    122                     $level_id
    123                 )
    124             );
    125 
    126             if ( $transations ) {
    127                 foreach ( $transations as $transaction ) {
    128                     $user_id = $transaction->user_id;
    129                     $user    = new MeprUser( $user_id );
    130 
    131                     $product_subscriptions = $user->active_product_subscriptions( 'ids', true );
    132 
    133                     $this->handle_courseSync( $user_id, $product_subscriptions );
    134                 }
    135 
    136                 $page->showMessage( __( 'All members were retroactively enrolled into the selected courses successfully.', 'wpcw-mp-addon' ) );
     162                     AND (status = 'confirmed' OR status = 'complete')
     163                     LIMIT %d
     164                     OFFSET %d",
     165                    $level_id,
     166                    $batch,
     167                    $count
     168                ), ARRAY_A );
     169
     170            if ( ! $customers && ! isset( $_GET['action'] ) ) {
     171                $page->showMessage( esc_html__( 'No existing customers found for the specified product.', 'wpcw-wc-addon' ) );
    137172
    138173                return;
    139             } else {
    140                 $page->showMessage( __( 'No existing members found for the specified product.', 'wpcw-mp-addon' ) );
    141             }
     174            }
     175
     176            if ( $customers && 'continue' === $steps ) {
     177                if ( count( $customers ) < $batch ) {
     178                    $steps = 'finished';
     179                }
     180               
     181                foreach ( $customers as $customer ) {
     182                    wpcw_log($customer);
     183                    $customer_id = $customer['user_id'];
     184                    $user    = new MeprUser( $customer_id );
     185
     186                if ( $coursesToRemove ){
     187                        $products = array();
     188                        $courseIDList = array();
     189
     190                        $product_subscriptions = $user->active_product_subscriptions( 'ids', true );
     191
     192                        foreach ( $product_subscriptions as $subscription ) {
     193                                // Got courses for this product.
     194                                $courses = $this->getCourseAccessListForLevel( $subscription );
     195
     196                                if ( $courses ) {
     197                                    foreach ( $courses as $courseIDToKeep => $levelID ) {
     198                                        $courseIDList[] = $courseIDToKeep;
     199                                    }
     200                                }
     201                            }
     202
     203                        $removeCourses = array_diff( $coursesToRemove, $courseIDList );
     204
     205                        // De-enroll students from specified courses
     206                        $this->handle_course_de_enrollment( $customer_id, $removeCourses );
     207
     208                }
     209
     210                if ( $coursesToAdd ){
     211                        // Enroll students into specified courses
     212                        WPCW_courses_syncUserAccess( $customer_id, $coursesToAdd, 'add' );
     213                    }
     214                    // Increment Count.
     215                    $count += 1;
     216                }
     217
     218                $step += 1;
     219            }  else {
     220                $steps = 'finished';
     221            }
     222
     223            $page->showMessage( esc_html__( 'Please wait. Retroactively updating existing customers...', 'wpcw-wc-addon' ) );
     224
     225            $location_url = add_query_arg( array(
     226                'page'     => $this->extensionID,
     227                'level_id' => $level_id,
     228                'step'     => $step,
     229                'count'    => $count,
     230                'steps'    => $steps,
     231                'action'   => 'retroactiveassignment'
     232            ), admin_url( 'admin.php' ) );
     233
     234            ?>
     235            <script type="text/javascript">
     236                setTimeout( function () {
     237                    document.location.href = "<?php echo $location_url; ?>";
     238                }, 1000 );
     239            </script>
     240            <?php
    142241        }
    143242
     
    164263            // Over to the parent class to handle the sync of data.
    165264            $this->handle_courseSync( $user_id, $product_subscriptions );
     265        }
     266
     267        /**
     268         * Handle Course De-Enrollment.
     269         *
     270         * @since 1.5.0
     271         *
     272         * @param int   $student_id The student id.
     273         * @param array $course_ids The course ids to enroll.
     274         */
     275        public function handle_course_de_enrollment( $student_id, $course_ids = array() ) {
     276            global $wpdb, $wpcwdb;
     277
     278            if ( empty( $course_ids ) || ! is_array( $course_ids ) ) {
     279                return;
     280            }
     281
     282            $csv_course_ids = implode( ',', $course_ids );
     283
     284            $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpcwdb->user_courses} WHERE user_id = %d AND course_id IN ({$csv_course_ids})", $student_id ) ); // phpcs:ignore WordPress.DB
     285
     286            WPCW_queue_dripfeed::updateQueueItems_removeUser_fromCourseList( $student_id, $course_ids );
    166287        }
    167288
  • memberpress-addon-for-wp-courseware/trunk/readme.txt

    r2948951 r3000299  
    33Donate link: https://flyplugins.com/donate
    44Tags: learning management system, selling online courses
    5 Requires at least: 4.8
    6 Tested up to: 6.2.2
    7 Stable tag: 1.4.2
     5Requires at least: 4.9
     6Tested up to: 6.4.1
     7Stable tag: 2.0
     8Requires PHP: 5.2.4
    89License: GPLv3
    910License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1011
    11 This plugin adds integration between MemberPress and WP Courseware which allows you to associate courses to products for automatic enrollment.
     12This plugin adds integration between MemberPress and WP Courseware which allows you to associate course(s) to products for automatic enrollment.
    1213
    1314== Description ==
     
    1516
    1617= Would you like to sell an online course with MemberPress? =
    17 The MemberPress Addon for WP Courseware will add full integration with WP Courseware. Simply assign WP Courseware courses to a MemberPress product. When a student purchases the product, they will automatically be enrolled into the associated courses.
     18The MemberPress Addon for WP Courseware will add full integration with WP Courseware. Simply assign WP Courseware course(s) to a MemberPress product. When a student purchases the product, they will automatically be enrolled into the associated course(s).
    1819
    1920With this addon, you will be able to create a fully automated [Learning Management System](https://flyplugins.com/wp-courseware) and sell online courses.
     
    2324
    2425= Basic Configuration Steps =
    25 1. Create a course with WP Courseware and add modules, units, and quizzes
     261. Create a course with WP Courseware and add module(s), unit(s), and quiz(zes)
    26272. Create a course outline page using [shortcode]
    27283. Create a product and set a price
    28294. Associate one or more WP Courseware courses with the product
    29 5. New student pays for the product, and WP Courseware enrolls them to the appropriate courses based on the purchased product
     305. New student pays for the product, and WP Courseware enrolls them to the appropriate course(s) based on the purchased product
    3031
    3132= Check out Fly Plugins =
     
    7677== Changelog ==
    7778
     79= 2.0 =
     80* New: Added ability to retoactively enroll a large quantity of students.
     81* New: Added new filter wpcw_mp_addon_can_load to allow enrollment method to be changed to "add" instead of "sync"
     82
    7883= 1.4.2 =
    7984* Fix: Fixed issue where course list only displaying 20 courses
  • memberpress-addon-for-wp-courseware/trunk/wp-courseware-memberpress.php

    r2663782 r3000299  
    22/**
    33 * Plugin Name: WP Courseware - MemberPress Add On
    4  * Version: 1.4.2
     4 * Version: 2.0
    55 * Plugin URI: http://flyplugins.com
    66 * Description: The official extension for WP Courseware to add support for the MemberPress membership plugin for WordPress.
     
    1919
    2020// Constants.
    21 define( 'WPCW_MP_ADDON_VERSION', '1.4.2' );
     21define( 'WPCW_MP_ADDON_VERSION', '1.5.0' );
    2222
    2323/**
    2424 * WP Courseware Memberpress Addon.
    2525 *
    26  * @since 1.4.0
     26 * @since 1.5.0
    2727 */
    2828function _wpcw_mp_addon() {
Note: See TracChangeset for help on using the changeset viewer.