LLMS_Blocks_Post_Types

Setup editor templates for LifterLMS custom Post Types


Source Source

File: libraries/lifterlms-blocks/includes/class-llms-blocks-post-types.php

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
class LLMS_Blocks_Post_Types {
 
    /**
     * Constructor
     *
     * @since 1.0.0
     * @since 1.7.0 Add membership categories and tags to WordPress REST API.
     *               Add membership post type editor template.
     *
     * @return void
     */
    public function __construct() {
 
        // Enable REST API for custom post types.
        add_filter( 'lifterlms_register_post_type_course', array( $this, 'enable_rest' ), 5 );
        add_filter( 'lifterlms_register_post_type_lesson', array( $this, 'enable_rest' ), 5 );
        add_filter( 'lifterlms_register_post_type_membership', array( $this, 'enable_rest' ), 5 );
 
        // Enable REST API for custom post taxonomies.
        add_filter( 'lifterlms_register_taxonomy_args_course_cat', array( $this, 'enable_rest' ), 5 );
        add_filter( 'lifterlms_register_taxonomy_args_course_tag', array( $this, 'enable_rest' ), 5 );
        add_filter( 'lifterlms_register_taxonomy_args_course_track', array( $this, 'enable_rest' ), 5 );
        add_filter( 'lifterlms_register_taxonomy_args_course_difficulty', array( $this, 'enable_rest' ), 5 );
        add_filter( 'lifterlms_register_taxonomy_args_membership_cat', array( $this, 'enable_rest' ), 5 );
        add_filter( 'lifterlms_register_taxonomy_args_membership_tag', array( $this, 'enable_rest' ), 5 );
 
        // Setup block editor templates.
        add_filter( 'lifterlms_register_post_type_course', array( $this, 'add_course_template' ), 5 );
        add_filter( 'lifterlms_register_post_type_membership', array( $this, 'add_membership_template' ), 5 );
        add_filter( 'lifterlms_register_post_type_lesson', array( $this, 'add_lesson_template' ), 5 );
 
    }
 
    /**
     * Enable the rest API for custom post types & taxonomies
     *
     * @since 1.0.0
     * @since 1.5.2 Only `show_in_rest` for authenticated users with the `lifterls_instructor` capability.
     *
     * @param array $data post type / taxonomy data.
     * @return array
     */
    public function enable_rest( $data ) {
 
        if ( current_user_can( 'lifterlms_instructor' ) ) {
            $data['show_in_rest'] = true;
        }
 
        return $data;
 
    }
 
    /**
     * Add an editor template for courses
     *
     * @param   array $post_type post type data.
     * @return  array
     * @since   1.0.0
     * @version 1.0.0
     */
    public function add_course_template( $post_type ) {
 
        $post_type['template'] = array(
            array(
                'core/paragraph',
                array(
                    'placeholder' => __( 'Add a short description of your course visible to all visitors...', 'lifterlms' ),
                ),
            ),
            array( 'llms/course-information' ),
            array( 'llms/instructors' ),
            array( 'llms/pricing-table' ),
            array( 'llms/course-progress' ),
            array( 'llms/course-continue-button' ),
            array( 'llms/course-syllabus' ),
        );
 
        return $post_type;
 
    }
 
    /**
     * Add an editor template for memberships.
     *
     * @since 1.7.0
     * @since 1.11.0 Add instructors block.
     *
     * @param array $post_type Post type registration data.
     * @return array
     */
    public function add_membership_template( $post_type ) {
 
        $post_type['template'] = array(
            array(
                'core/paragraph',
                array(
                    'placeholder' => __( 'Add a short description of your membership visible to all visitors...', 'lifterlms' ),
                ),
            ),
            array( 'llms/instructors' ),
            array( 'llms/pricing-table' ),
        );
 
        return $post_type;
 
    }
 
    /**
     * Add an editor template for lessons
     *
     * @param   array $post_type post type data.
     * @return  array
     * @since   1.0.0
     * @version 1.0.0
     */
    public function add_lesson_template( $post_type ) {
 
        $post_type['template'] = array(
            array(
                'core/paragraph',
                array(
                    'placeholder' => __( 'Add your lesson content...', 'lifterlms' ),
                ),
            ),
            array( 'llms/lesson-progression' ),
            array( 'llms/lesson-navigation' ),
        );
 
        return $post_type;
 
    }
 
}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
1.7.0 Add membership categories and tags to WordPress REST API. Add membership post type editor template.
1.5.2 Only show_in_rest for authenticated users with the lifterls_instructor capability.
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.