|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Lightweight Events add-on promotion in the LifterLMS core admin. |
| 4 | + * |
| 5 | + * Shows an "Events" tab in Course Options and Membership meta boxes |
| 6 | + * with a CTA to install the Events add-on when it is not active. |
| 7 | + * |
| 8 | + * Also adds an "Events" link in Course Builder lesson settings. |
| 9 | + * |
| 10 | + * @package LifterLMS/Admin/Classes |
| 11 | + * |
| 12 | + * @since 7.8.0 |
| 13 | + */ |
| 14 | + |
| 15 | +defined( 'ABSPATH' ) || exit; |
| 16 | + |
| 17 | +/** |
| 18 | + * LLMS_Admin_Events_Promo class. |
| 19 | + * |
| 20 | + * @since 7.8.0 |
| 21 | + */ |
| 22 | +class LLMS_Admin_Events_Promo { |
| 23 | + |
| 24 | + /** |
| 25 | + * Constructor. |
| 26 | + * |
| 27 | + * @since 7.8.0 |
| 28 | + */ |
| 29 | + public function __construct() { |
| 30 | + // Only show promo if the events plugin is not active. |
| 31 | + if ( class_exists( 'LLMS_Events_Plugin' ) ) { |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + add_filter( 'llms_metabox_fields_lifterlms_course_options', array( $this, 'add_course_promo_tab' ) ); |
| 36 | + add_filter( 'llms_metabox_fields_lifterlms_membership', array( $this, 'add_membership_promo_tab' ) ); |
| 37 | + add_filter( 'llms_metabox_fields_lifterlms_lesson', array( $this, 'add_lesson_promo_tab' ) ); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Add an Events promo tab to Course Options. |
| 42 | + * |
| 43 | + * @since 7.8.0 |
| 44 | + * |
| 45 | + * @param array $tabs Existing tabs. |
| 46 | + * @return array |
| 47 | + */ |
| 48 | + public function add_course_promo_tab( $tabs ) { |
| 49 | + $tabs[] = array( |
| 50 | + 'title' => __( 'Events', 'lifterlms' ), |
| 51 | + 'fields' => array( |
| 52 | + array( |
| 53 | + 'id' => '_llms_events_promo', |
| 54 | + 'type' => 'custom-html', |
| 55 | + 'label' => '', |
| 56 | + 'value' => $this->get_promo_html(), |
| 57 | + ), |
| 58 | + ), |
| 59 | + ); |
| 60 | + return $tabs; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Add an Events promo tab to Membership. |
| 65 | + * |
| 66 | + * @since 7.8.0 |
| 67 | + * |
| 68 | + * @param array $tabs Existing tabs. |
| 69 | + * @return array |
| 70 | + */ |
| 71 | + public function add_membership_promo_tab( $tabs ) { |
| 72 | + $tabs[] = array( |
| 73 | + 'title' => __( 'Events', 'lifterlms' ), |
| 74 | + 'fields' => array( |
| 75 | + array( |
| 76 | + 'id' => '_llms_events_promo', |
| 77 | + 'type' => 'custom-html', |
| 78 | + 'label' => '', |
| 79 | + 'value' => $this->get_promo_html(), |
| 80 | + ), |
| 81 | + ), |
| 82 | + ); |
| 83 | + return $tabs; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Add an Events promo tab to Lesson Settings. |
| 88 | + * |
| 89 | + * @since 7.8.0 |
| 90 | + * |
| 91 | + * @param array $tabs Existing tabs. |
| 92 | + * @return array |
| 93 | + */ |
| 94 | + public function add_lesson_promo_tab( $tabs ) { |
| 95 | + $tabs[] = array( |
| 96 | + 'title' => __( 'Events', 'lifterlms' ), |
| 97 | + 'fields' => array( |
| 98 | + array( |
| 99 | + 'id' => '_llms_events_promo', |
| 100 | + 'type' => 'custom-html', |
| 101 | + 'label' => '', |
| 102 | + 'value' => $this->get_promo_html(), |
| 103 | + ), |
| 104 | + ), |
| 105 | + ); |
| 106 | + return $tabs; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Get the promo HTML. |
| 111 | + * |
| 112 | + * @since 7.8.0 |
| 113 | + * |
| 114 | + * @return string |
| 115 | + */ |
| 116 | + private function get_promo_html() { |
| 117 | + $html = '<div class="llms-metabox" style="padding:20px;text-align:center;">'; |
| 118 | + $html .= '<div class="dashicons dashicons-calendar-alt" style="color:#2271b1;margin-bottom:12px;"></div>'; |
| 119 | + $html .= '<h3>' . esc_html__( 'Schedule Events for Your Students', 'lifterlms' ) . '</h3>'; |
| 120 | + $html .= '<p>' . esc_html__( 'Add live events, webinars, and in-person sessions to your courses and memberships. Students can subscribe to calendar feeds and never miss an event.', 'lifterlms' ) . '</p>'; |
| 121 | + $html .= '<a href="https://lifterlms.com/product/lifterlms-events/?utm_source=LifterLMS%20Plugin&utm_medium=Course%20Editor&utm_campaign=Events%20Promo" target="_blank" class="llms-button-primary">'; |
| 122 | + $html .= esc_html__( 'Get LifterLMS Events', 'lifterlms' ); |
| 123 | + $html .= '</a>'; |
| 124 | + $html .= '</div>'; |
| 125 | + |
| 126 | + return $html; |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +new LLMS_Admin_Events_Promo(); |
0 commit comments