Plugin Directory

Changeset 2389243


Ignore:
Timestamp:
09/27/2020 07:19:48 PM (5 years ago)
Author:
Bijingus
Message:

Fixed issue with REST API disabling Gutenberg editor. Changed REST options to include the option to remove all lesson content and excerpts from the REST API.

Location:
wp-courses/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wp-courses/trunk/README.md

    r2388997 r2389243  
    55Requires at least: 4.6
    66Tested up to: 5.5.1
    7 Stable tag: 2.0.28
     7Stable tag: 2.0.29
    88License: GPLv2 or later license
    99
  • wp-courses/trunk/wp-courses.php

    r2388997 r2389243  
    33 * Plugin Name: WP Courses LMS
    44 * Description: WP Courses is a free learning management system (LMS) plugin for WordPress.  It includes a rich feature set that allows you to create unlimited courses, restrict content and much more.
    5  * Version: 2.0.28
     5 * Version: 2.0.29
    66 * Author: Myles English
    77 * Plugin URI: https://wpcoursesplugin.com
     
    295295// Register Custom Post Type Course
    296296function wpc_register_course_cp(){
     297
    297298    $labels = array(
    298299        'name'               => _x( 'Courses', 'post type general name'),
     
    326327        'supports'              => array('title', 'editor', 'excerpt', 'page-attributes', 'thumbnail', 'custom-fields'),
    327328        'has_archive'           => true,
    328         'show_in_rest'          => false,
    329     );
    330 
    331    $wpc_enable_rest_course = get_option( 'wpc_enable_rest_course' );
    332 
    333     if( $wpc_enable_rest_course == 'true' ){
    334         $args['show_in_rest'] = true;
    335     }
     329        'show_in_rest'          => true,
     330    );
    336331
    337332    register_post_type('course', $args);
     
    393388    'public'              => true,
    394389    'show_ui'             => true,
    395     'show_in_rest'        => false,
     390    'show_in_rest'        => true,
    396391    'labels'        => $labels,
    397392    'description'   => __('Enter a lesson description here', 'wp-courses'),
     
    399394  );
    400395
    401     $wpc_enable_rest_lesson = get_option('wpc_enable_rest_lesson');
    402 
    403     if( $wpc_enable_rest_lesson == 'true' ){
    404         $args['show_in_rest'] = true;
    405     }
    406 
    407396  register_post_type( 'lesson', $args );
    408397  flush_rewrite_rules( false );
    409398}
    410399add_action( 'init', 'wpc_register_lesson_cp' );
     400
     401function wpc_remove_lesson_rest_api_data( $data, $post, $context ) {
     402
     403    $can_edit = current_user_can( 'edit_posts' );
     404
     405    if ( $can_edit != true ) {
     406
     407        $wpc_enable_rest_lesson = get_option( 'wpc_enable_rest_lesson' );
     408
     409        if( $wpc_enable_rest_lesson != 'true' ){
     410            unset ($data->data ['content']);
     411            unset ($data->data ['excerpt']);
     412        }
     413    }
     414
     415    return $data;
     416
     417}
     418
     419add_filter( 'rest_prepare_lesson', 'wpc_remove_lesson_rest_api_data', 12, 3 );
     420
    411421//Custom Messages for Custom Post Type Lesson
    412422function wpc_lesson_messages_cp( $messages ) {
     
    464474        'public'              => true,
    465475        'show_ui'             => true,
    466         'show_in_rest'        => false,
     476        'show_in_rest'        => true,
    467477        'labels'              => $labels,
    468478        'description'         => __('Enter a module description here', 'wp-courses'),
    469479        'supports'            => array( 'title' ),
    470480    );
    471 
    472     $wpc_enable_rest_lesson = get_option('wpc_enable_rest_lesson');
    473 
    474     if( $wpc_enable_rest_lesson == 'true' ){
    475         $args['show_in_rest'] = true;
    476     }
    477481
    478482    register_post_type( 'wpc-module', $args );
     
    533537    'public'              => true,
    534538    'show_ui'             => true,
    535     'show_in_rest'        => false,
     539    'show_in_rest'        => true,
    536540    'labels'              => $labels,
    537541    'description'         => __('Enter a Teacher Description Here', 'wp-courses'),
    538542    'supports'            => array('title', 'editor', 'excerpt', 'page-attributes', 'thumbnail'),
    539543    );
    540 
    541     $wpc_enable_rest_teacher = get_option('wpc_enable_rest_teacher');
    542 
    543     if( $wpc_enable_rest_teacher == 'true' ){
    544         $args['show_in_rest'] = true;
    545     }
    546544
    547545    register_post_type('teacher', $args);
  • wp-courses/trunk/wp-courses.pot

    r2388997 r2389243  
    44"Project-Id-Version: WP Courses LMS\n"
    55"Report-Msgid-Bugs-To: \n"
    6 "POT-Creation-Date: 2020-09-26 21:56+0000\n"
     6"POT-Creation-Date: 2020-09-27 19:18+0000\n"
    77"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    88"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    158158msgstr ""
    159159
    160 #: admin-nav-menu.php:11 wp-courses.php:310
     160#: admin-nav-menu.php:11 wp-courses.php:311
    161161msgid "Courses"
    162162msgstr ""
     
    183183msgstr ""
    184184
    185 #: wp-courses.php:322
     185#: wp-courses.php:323
    186186msgid "Enter a Course Description Here"
    187187msgstr ""
    188188
    189 #: wp-courses.php:397
     189#: wp-courses.php:392
    190190msgid "Enter a lesson description here"
    191191msgstr ""
    192192
    193 #: wp-courses.php:468
     193#: wp-courses.php:478
    194194msgid "Enter a module description here"
    195195msgstr ""
    196196
    197 #: wp-courses.php:537
     197#: wp-courses.php:541
    198198msgid "Enter a Teacher Description Here"
    199199msgstr ""
     
    248248msgstr ""
    249249
    250 #: wp-courses.php:378
     250#: wp-courses.php:373
    251251msgid "Lessons"
    252252msgstr ""
     
    280280msgstr ""
    281281
    282 #: wp-courses.php:448
     282#: wp-courses.php:458
    283283msgid "Modules"
    284284msgstr ""
     
    414414msgstr ""
    415415
    416 #: admin-nav-menu.php:29 wp-courses.php:519
     416#: admin-nav-menu.php:29 wp-courses.php:523
    417417msgid "Teachers"
    418418msgstr ""
  • wp-courses/trunk/wpc-options.php

    r2388997 r2389243  
    33function wpc_register_settings() {
    44
    5     add_option( 'wpc_enable_rest_course', 'false');
    65    add_option( 'wpc_enable_rest_lesson', 'false');
    7     add_option( 'wpc_enable_rest_teacher', 'false');
    86
    97    add_option( 'wpc_show_breadcrumb_trail', 'true');
     
    2927    add_option( 'wpc_primary_button_active_text_color', '#fff');
    3028
    31     // register_setting( 'wpc_options', 'wpc_profile_page', 'wpc_callback' );
    32     // register_setting( 'wpc_options', 'wpc_course_page', 'wpc_callback' );
    33 
    34     register_setting( 'wpc_options', 'wpc_enable_rest_course', 'wpc_callback' );
    3529    register_setting( 'wpc_options', 'wpc_enable_rest_lesson', 'wpc_callback' );
    36     register_setting( 'wpc_options', 'wpc_enable_rest_teacher', 'wpc_callback' );
    3730
    3831    register_setting( 'wpc_options', 'wpc_show_breadcrumb_trail', 'wpc_callback' );
     
    7265            settings_fields( 'wpc_options' );
    7366
    74             $wpc_enable_rest_course = get_option('wpc_enable_rest_course');
    7567            $wpc_enable_rest_lesson = get_option('wpc_enable_rest_lesson');
    76             $wpc_enable_rest_teacher = get_option('wpc_enable_rest_teacher');
    7768
    7869            $wpc_show_breadcrumb_trail = get_option('wpc_show_breadcrumb_trail');
     
    10091            $id = get_the_ID();
    10192
    102             if( $wpc_enable_rest_course == 'true' ){
    103                 $rest_course_checked = 'checked';
    104             } else {
    105                 $rest_course_checked = '';
    106             }
    107 
    10893            if( $wpc_enable_rest_lesson == 'true' ){
    10994                $rest_lesson_checked = 'checked';
     
    11297            }
    11398
    114             if( $wpc_enable_rest_teacher == 'true' ){
    115                 $rest_teacher_checked = 'checked';
    116             } else {
    117                 $rest_teacher_checked = '';
    118             }
    119 
    12099            if($wpc_show_breadcrumb_trail == 'true'){
    121100                $breadcrumb_checked = 'checked';
     
    151130
    152131                <div class="wpc-option">
    153                     <input type="checkbox" id="wpc-enable-lesson-rest" name="wpc_enable_rest_lesson" value="true" <?php echo $rest_lesson_checked; ?>/><label for="wpc-enable-lesson-rest">Enable REST API for Lessons and Modules.  <b>Warning!</b>  If checked, restricted lesson content is accessable <b>TO ANYONE</b> via the REST API.</label>
    154                 </div>
    155 
    156                 <div class="wpc-option">
    157                     <input type="checkbox" id="wpc-enable-course-rest" name="wpc_enable_rest_course" value="true" <?php echo $rest_course_checked; ?>/><label for="wpc-enable-course-rest">Enable REST API for Courses</label>
    158                 </div>
    159 
    160                 <div class="wpc-option">
    161                     <input type="checkbox" id="wpc-enable-teacher-rest" name="wpc_enable_rest_teacher" value="true" <?php echo $rest_teacher_checked; ?>/><label for="wpc-enable-teacher-rest">Enable REST API for Teachers</label>
     132                    <input type="checkbox" id="wpc-enable-lesson-rest" name="wpc_enable_rest_lesson" value="true" <?php echo $rest_lesson_checked; ?>/><label for="wpc-enable-lesson-rest">Show lesson content in the REST API.  <b>Warning!</b>  If checked, restricted lesson content is accessable <b>TO ANYONE</b> via the REST API.</label>
    162133                </div>
    163134
Note: See TracChangeset for help on using the changeset viewer.