| 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', array($this, 'registering_new_block_category'), 10, 2); |
| 27 |
|
| 28 |
add_action('wp_ajax_render_block_tutor', array($this, 'render_block_tutor')); |
| 29 |
} |
| 30 |
|
| 31 |
function register_blocks() { |
| 32 |
wp_register_script( |
| 33 |
'tutor-student-registration-block', tutor()->url . 'assets/js/gutenberg_blocks.js', array( 'wp-blocks', 'wp-element' ) |
| 34 |
); |
| 35 |
|
| 36 |
register_block_type( 'tutor-gutenberg/student-registration', array( |
| 37 |
'editor_script' => 'tutor-student-registration-block', |
| 38 |
'render_callback' => array($this, 'render_block_student_registration'), |
| 39 |
) ); |
| 40 |
register_block_type( 'tutor-gutenberg/student-dashboard', array( |
| 41 |
'editor_script' => 'tutor-student-registration-block', |
| 42 |
'render_callback' => array($this, 'render_block_tutor_dashboard'), |
| 43 |
) ); |
| 44 |
register_block_type( 'tutor-gutenberg/instructor-registration', array( |
| 45 |
'editor_script' => 'tutor-student-registration-block', |
| 46 |
'render_callback' => array($this, 'render_block_tutor_instructor_registration_form'), |
| 47 |
) ); |
| 48 |
} |
| 49 |
|
| 50 |
public function registering_new_block_category($categories, $post ){ |
| 51 |
return array_merge( |
| 52 |
array( |
| 53 |
array( |
| 54 |
'slug' => 'tutor', |
| 55 |
'title' => __( 'Tutor LMS', 'tutor' ), |
| 56 |
), |
| 57 |
), |
| 58 |
$categories |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
public function render_block_student_registration($args){ |
| 63 |
return do_shortcode("[tutor_student_registration_form]"); |
| 64 |
} |
| 65 |
public function render_block_tutor_dashboard($args){ |
| 66 |
return do_shortcode("[tutor_dashboard]"); |
| 67 |
} |
| 68 |
public function render_block_tutor_instructor_registration_form($args){ |
| 69 |
return do_shortcode("[tutor_instructor_registration_form]"); |
| 70 |
} |
| 71 |
|
| 72 |
//For editor |
| 73 |
public function render_block_tutor(){ |
| 74 |
$shortcode = sanitize_text_field($_POST['shortcode']); |
| 75 |
wp_send_json_success(do_shortcode("[{$shortcode}]")); |
| 76 |
} |
| 77 |
|
| 78 |
} |