Addons.php
4 years ago
Admin.php
4 years ago
Ajax.php
4 years ago
Announcements.php
4 years ago
Assets.php
4 years ago
Backend_Page_Trait.php
4 years ago
Course.php
4 years ago
Course_Filter.php
4 years ago
Course_List.php
4 years ago
Course_Settings_Tabs.php
4 years ago
Course_Widget.php
4 years ago
Custom_Validation.php
4 years ago
Dashboard.php
4 years ago
FormHandler.php
4 years ago
Frontend.php
4 years ago
Gutenberg.php
4 years ago
Input.php
4 years ago
Instructor.php
4 years ago
Instructors_List.php
4 years ago
Lesson.php
4 years ago
Options_V2.php
4 years ago
Post_types.php
4 years ago
Private_Course_Access.php
4 years ago
Q_and_A.php
4 years ago
Question_Answers_List.php
4 years ago
Quiz.php
4 years ago
Quiz_Attempts_List.php
4 years ago
RestAPI.php
4 years ago
Reviews.php
4 years ago
Rewrite_Rules.php
4 years ago
Shortcode.php
4 years ago
Student.php
4 years ago
Students_List.php
4 years ago
Taxonomies.php
4 years ago
Template.php
4 years ago
Theme_Compatibility.php
5 years ago
Tools.php
4 years ago
Tools_V2.php
4 years ago
Tutor.php
4 years ago
TutorEDD.php
4 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
4 years ago
Tutor_Setup.php
4 years ago
Upgrader.php
4 years ago
User.php
4 years ago
Utils.php
4 years ago
Video_Stream.php
4 years ago
Withdraw.php
4 years ago
Withdraw_Requests_List.php
4 years ago
WooCommerce.php
4 years ago
Gutenberg.php
105 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Gutenberg class |
| 4 | * |
| 5 | * @author: themeum |
| 6 | * @author_uri: https://themeum.com |
| 7 | * @package Tutor |
| 8 | * @since v.1.0.0 |
| 9 | */ |
| 10 | |
| 11 | |
| 12 | namespace TUTOR; |
| 13 | |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) |
| 16 | exit; |
| 17 | |
| 18 | class Gutenberg { |
| 19 | |
| 20 | public function __construct() { |
| 21 | if ( ! function_exists('register_block_type')){ |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | add_action( 'init', array($this, 'register_blocks') ); |
| 26 | add_filter('block_categories_all', array($this, 'registering_new_block_category'), 10, 2); |
| 27 | add_action('wp_ajax_render_block_tutor', array($this, 'render_block_tutor')); |
| 28 | } |
| 29 | |
| 30 | function register_blocks() { |
| 31 | global $pagenow; |
| 32 | if ( 'widgets.php' !== $pagenow ) { |
| 33 | wp_register_script( |
| 34 | 'tutor-student-registration-block', tutor()->url . 'assets/js/lib/gutenberg_blocks.js', array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ) |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | register_block_type( 'tutor-gutenberg/student-registration', array( |
| 39 | 'editor_script' => 'tutor-student-registration-block', |
| 40 | 'render_callback' => array($this, 'render_block_student_registration'), |
| 41 | ) ); |
| 42 | /* |
| 43 | register_block_type( 'tutor-gutenberg/student-dashboard', array( |
| 44 | 'editor_script' => 'tutor-student-registration-block', |
| 45 | 'render_callback' => array($this, 'render_block_tutor_dashboard'), |
| 46 | ) );*/ |
| 47 | register_block_type( 'tutor-gutenberg/instructor-registration', array( |
| 48 | 'editor_script' => 'tutor-student-registration-block', |
| 49 | 'render_callback' => array($this, 'render_block_tutor_instructor_registration_form'), |
| 50 | ) ); |
| 51 | |
| 52 | // Check if WP version is equal to or greater than 5.9. |
| 53 | global $wp_version; |
| 54 | if ( version_compare( $wp_version, '5.9', '>=' ) && function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { |
| 55 | wp_localize_script( 'tutor-student-registration-block', '_tutor_gutenberg_block_data', array( |
| 56 | 'is_wp_version_5_9' => 'true', |
| 57 | ) ); |
| 58 | } else { |
| 59 | wp_localize_script( 'tutor-student-registration-block', '_tutor_gutenberg_block_data', array( |
| 60 | 'is_wp_version_5_9' => 'false', |
| 61 | ) ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | public function registering_new_block_category($categories, $post ){ |
| 66 | return array_merge( |
| 67 | array( |
| 68 | array( |
| 69 | 'slug' => 'tutor', |
| 70 | 'title' => __( 'Tutor LMS', 'tutor' ), |
| 71 | ), |
| 72 | ), |
| 73 | $categories |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | public function render_block_student_registration($args){ |
| 78 | return do_shortcode("[tutor_student_registration_form]"); |
| 79 | } |
| 80 | public function render_block_tutor_dashboard($args){ |
| 81 | return do_shortcode("[tutor_dashboard]"); |
| 82 | } |
| 83 | public function render_block_tutor_instructor_registration_form($args){ |
| 84 | return do_shortcode("[tutor_instructor_registration_form]"); |
| 85 | } |
| 86 | |
| 87 | //For editor |
| 88 | public function render_block_tutor(){ |
| 89 | tutor_utils()->checking_nonce(); |
| 90 | |
| 91 | $shortcode = sanitize_text_field($_POST['shortcode']); |
| 92 | |
| 93 | $allowed_shortcode = array( |
| 94 | 'tutor_instructor_registration_form', |
| 95 | 'tutor_student_registration_form' |
| 96 | ); |
| 97 | |
| 98 | if(!in_array($shortcode, $allowed_shortcode)) { |
| 99 | wp_send_json_error( ); |
| 100 | } |
| 101 | |
| 102 | wp_send_json_success(do_shortcode("[{$shortcode}]")); |
| 103 | } |
| 104 | |
| 105 | } |