| 1 |
<?php |
| 2 |
/** |
| 3 |
* Become A Teacher Shortcode. |
| 4 |
* |
| 5 |
* @author ThimPress |
| 6 |
* @category Shortcodes |
| 7 |
* @package Learnpress/Shortcodes |
| 8 |
* @version 4.0.0 |
| 9 |
* @extends LP_Abstract_Shortcode |
| 10 |
*/ |
| 11 |
|
| 12 |
defined( 'ABSPATH' ) || exit(); |
| 13 |
|
| 14 |
if ( ! class_exists( 'LP_Shortcode_Become_A_Teacher' ) ) { |
| 15 |
class LP_Shortcode_Become_A_Teacher extends LP_Abstract_Shortcode { |
| 16 |
|
| 17 |
/** |
| 18 |
* @var array |
| 19 |
*/ |
| 20 |
protected static $messages = array(); |
| 21 |
|
| 22 |
/** |
| 23 |
* LP_Checkout_Shortcode constructor. |
| 24 |
* |
| 25 |
* @param mixed $atts |
| 26 |
*/ |
| 27 |
public function __construct( $atts = '' ) { |
| 28 |
parent::__construct( $atts ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Add new message into queue. |
| 33 |
* |
| 34 |
* @param $message |
| 35 |
* @param string $code |
| 36 |
*/ |
| 37 |
public static function add_message( $message, $code = '' ) { |
| 38 |
self::$messages[ $code ] = $message; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Get added message by code from queue. |
| 43 |
* |
| 44 |
* @param string $code |
| 45 |
* |
| 46 |
* @return bool|mixed |
| 47 |
*/ |
| 48 |
public static function get_message( $code = '' ) { |
| 49 |
return isset( self::$messages[ $code ] ) ? self::$messages[ $code ] : false; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Get all messages added into queue. |
| 54 |
* |
| 55 |
* @return array |
| 56 |
*/ |
| 57 |
public static function get_messages() { |
| 58 |
return self::$messages; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Output form. |
| 63 |
* |
| 64 |
* @return string |
| 65 |
*/ |
| 66 |
public function output() { |
| 67 |
wp_enqueue_style( 'learnpress' ); |
| 68 |
ob_start(); |
| 69 |
|
| 70 |
$message = ''; |
| 71 |
$atts = $this->get_atts(); |
| 72 |
$user = learn_press_get_current_user( false ); |
| 73 |
|
| 74 |
if ( ! $user || $user instanceof LP_User_Guest ) { |
| 75 |
$message = sprintf( esc_html__( 'Please %s to send your request!', 'learnpress' ), sprintf( '<strong><a href="%s">%s</a></strong>', learn_press_get_login_url(), _x( 'login', 'become-teacher-form', 'learnpress' ) ) ); |
| 76 |
} else { |
| 77 |
if ( learn_press_become_teacher_sent() ) { |
| 78 |
$message = esc_html__( 'You have already sent the request. Please wait for the approval.', 'learnpress' ); |
| 79 |
} elseif ( learn_press_user_maybe_is_a_teacher() ) { |
| 80 |
$message = esc_html__( 'You are a teacher!', 'learnpress' ); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
if ( apply_filters( 'learn_press_become_a_teacher_display_form', true, $message ) ) { |
| 85 |
$atts = shortcode_atts( |
| 86 |
array( |
| 87 |
'title' => esc_html__( 'Become a Teacher', 'learnpress' ), |
| 88 |
'description' => esc_html__( 'Fill in your information and send it to us to become a teacher.', 'learnpress' ), |
| 89 |
'submit_button_text' => esc_html__( 'Submit', 'learnpress' ), |
| 90 |
'submit_button_process_text' => esc_html__( 'Processing', 'learnpress' ), |
| 91 |
), |
| 92 |
$atts |
| 93 |
); |
| 94 |
|
| 95 |
wp_enqueue_style( 'learnpress' ); |
| 96 |
wp_enqueue_script( 'lp-become-a-teacher' ); |
| 97 |
|
| 98 |
if ( empty( $message ) || ( class_exists( '\Elementor\Plugin' ) && \Elementor\Plugin::$instance->editor->is_edit_mode() ) ) { |
| 99 |
learn_press_get_template( 'global/become-teacher-form.php', $atts ); |
| 100 |
} else { |
| 101 |
learn_press_display_message( $message ); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
return ob_get_clean(); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|