learnpress
/
inc
/
ExternalPlugin
/
Elementor
/
Widgets
/
Instructor
/
SingleInstructorBaseElementor.php
SingleInstructorBaseElementor.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.1, at inc/ExternalPlugin/Elementor/Widgets/Instructor/SingleInstructorBaseElementor.php
| 1 | <?php |
| 2 | /** |
| 3 | * Class SingleInstructorBaseElementor |
| 4 | * |
| 5 | * Has general methods for sections single instructor widgets use |
| 6 | * |
| 7 | * @sicne 4.2.3 |
| 8 | * @version 1.0.0 |
| 9 | */ |
| 10 | |
| 11 | namespace LearnPress\ExternalPlugin\Elementor\Widgets\Instructor; |
| 12 | |
| 13 | use Elementor\Plugin; |
| 14 | use Exception; |
| 15 | use LearnPress\ExternalPlugin\Elementor\LPElementor; |
| 16 | use LearnPress\ExternalPlugin\Elementor\LPElementorWidgetBase; |
| 17 | use LearnPress\Helpers\Config; |
| 18 | use LearnPress\Models\UserModel; |
| 19 | use LearnPress\TemplateHooks\Instructor\SingleInstructorTemplate; |
| 20 | use LP_User; |
| 21 | |
| 22 | class SingleInstructorBaseElementor extends LPElementorWidgetBase { |
| 23 | /** |
| 24 | * Set category for widget |
| 25 | * |
| 26 | * @return string[] |
| 27 | */ |
| 28 | public function get_categories() { |
| 29 | return array( LPElementor::CATE_INSTRUCTOR ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Detect instructor id if is single instructor page |
| 34 | * |
| 35 | * @param array $settings |
| 36 | * @param UserModel|false $instructor |
| 37 | * @param string $label_default |
| 38 | * |
| 39 | * @since 4.2.3 |
| 40 | * @version 1.0.1 |
| 41 | * @return void |
| 42 | * @throws Exception |
| 43 | */ |
| 44 | protected function detect_instructor_id( array $settings, &$instructor = null, string $label_default = '' ) { |
| 45 | /** |
| 46 | * Get instructor id |
| 47 | * |
| 48 | * If is page is single instructor, will be get instructor id from query var |
| 49 | * Else will be get instructor id from widget |
| 50 | */ |
| 51 | $instructor = SingleInstructorTemplate::instance()->detect_instructor_by_page(); |
| 52 | if ( ! $instructor instanceof UserModel ) { |
| 53 | $instructor_id = (int) $settings['instructor_id'] ?? 0; |
| 54 | $instructor = UserModel::find( $instructor_id, true ); |
| 55 | } |
| 56 | |
| 57 | if ( ! $instructor ) { |
| 58 | if ( Plugin::$instance->editor->is_edit_mode() ) { |
| 59 | throw new Exception( $label_default ); |
| 60 | } else { |
| 61 | throw new Exception( __( 'Instructor not found!', 'learnpress' ) ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if ( ! $instructor->is_instructor() ) { |
| 66 | throw new Exception( __( 'User is not Instructor!', 'learnpress' ) ); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 |