| @@ -1,217 +1,216 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Class LP_Settings_Emails | |
| 4 | - * | |
| 5 | - * @author ThimPress | |
| 6 | - * @package LearnPress/Classes | |
| 7 | - * @version 4.0.0 | |
| 8 | - */ | |
| 9 | - | |
| 10 | -defined( 'ABSPATH' ) || exit; | |
| 11 | - | |
| 12 | -require_once 'email-groups/class-lp-settings-emails-group.php'; | |
| 13 | - | |
| 14 | -class LP_Settings_Emails extends LP_Abstract_Settings_Page { | |
| 15 | - /** | |
| 16 | - * @var null | |
| 17 | - */ | |
| 18 | - protected static $_instance = null; | |
| 19 | - | |
| 20 | - /** | |
| 21 | - * Constructor | |
| 22 | - */ | |
| 23 | - public function __construct() { | |
| 24 | - $this->id = 'emails'; | |
| 25 | - $this->text = esc_html__( 'Emails', 'learnpress' ); | |
| 26 | - | |
| 27 | - parent::__construct(); | |
| 28 | - | |
| 29 | - add_filter( 'learn-press/admin/submenu-section-title', array( $this, 'custom_section_title' ), 10, 2 ); | |
| 30 | - } | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * Add tooltip to section title | |
| 34 | - * | |
| 35 | - * @param string $title | |
| 36 | - * @param string $slug | |
| 37 | - * | |
| 38 | - * @return string | |
| 39 | - */ | |
| 40 | - public function custom_section_title( $title, $slug ) { | |
| 41 | - $sections = $this->get_sections(); | |
| 42 | - | |
| 43 | - if ( ! empty( $sections[ $slug ] ) && $sections[ $slug ] instanceof LP_Email ) { | |
| 44 | - if ( $sections[ $slug ]->description ) { | |
| 45 | - $title = $title . sprintf( '<span class="learn-press-tooltip" data-tooltip="%s"></span>', esc_attr( $sections[ $slug ]->description ) ); | |
| 46 | - } | |
| 47 | - } | |
| 48 | - | |
| 49 | - return $title; | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * Sections | |
| 54 | - * | |
| 55 | - * @return mixed | |
| 56 | - */ | |
| 57 | - public function get_sections() { | |
| 58 | - static $sections; | |
| 59 | - if ( is_null( $sections ) ) { | |
| 60 | - $emails = LP_Emails::instance()->emails; | |
| 61 | - | |
| 62 | - $sections = array( | |
| 63 | - 'general' => esc_html__( 'General', 'learnpress' ), | |
| 64 | - ); | |
| 65 | - | |
| 66 | - if ( $emails ) { | |
| 67 | - $groups = array( | |
| 68 | - include 'email-groups/class-lp-settings-new-order-emails.php', | |
| 69 | - include 'email-groups/class-lp-settings-processing-order-emails.php', | |
| 70 | - include 'email-groups/class-lp-settings-completed-order-emails.php', | |
| 71 | - include 'email-groups/class-lp-settings-cancelled-order-emails.php', | |
| 72 | - include 'email-groups/class-lp-settings-enrolled-course-emails.php', | |
| 73 | - include 'email-groups/class-lp-settings-finished-course-emails.php', | |
| 74 | - include 'email-groups/class-lp-settings-become-teacher-emails.php', | |
| 75 | - include 'email-groups/class-lp-settings-reset-password-emails.php', | |
| 76 | - ); | |
| 77 | - | |
| 78 | - $groups = apply_filters( 'learn-press/email-section-classes', $groups ); | |
| 79 | - | |
| 80 | - foreach ( $groups as $group ) { | |
| 81 | - $sections[ $group->group_id ] = $group; | |
| 82 | - } | |
| 83 | - | |
| 84 | - foreach ( $emails as $email ) { | |
| 85 | - if ( ! is_object( $email ) ) { | |
| 86 | - continue; | |
| 87 | - } | |
| 88 | - | |
| 89 | - foreach ( $groups as $group ) { | |
| 90 | - if ( is_object( $group ) && ! empty( $group->items[ $email->id ] ) ) { | |
| 91 | - continue 2; | |
| 92 | - } | |
| 93 | - } | |
| 94 | - | |
| 95 | - if ( isset( $sections[ $email->id ] ) ) { | |
| 96 | - $sections[ $email->id ] = $email; | |
| 97 | - } | |
| 98 | - } | |
| 99 | - } | |
| 100 | - } | |
| 101 | - | |
| 102 | - return apply_filters( 'learn-press/settings/section/' . $this->id, $sections ); | |
| 103 | - } | |
| 104 | - | |
| 105 | - /** | |
| 106 | - * Settings fields of general section. | |
| 107 | - * | |
| 108 | - * @return mixed | |
| 109 | - */ | |
| 110 | - public function get_settings_general() { | |
| 111 | - return apply_filters( | |
| 112 | - 'learn-press/emails-settings/general', | |
| 113 | - array( | |
| 114 | - array( | |
| 115 | - 'title' => esc_html__( 'Email sender options', 'learnpress' ), | |
| 116 | - 'type' => 'title', | |
| 117 | - 'desc' => esc_html__( 'For all outgoing LearnPress notification emails.', 'learnpress' ), | |
| 118 | - ), | |
| 119 | - array( | |
| 120 | - 'title' => esc_html__( '"From" name', 'learnpress' ), | |
| 121 | - 'id' => 'emails_general[from_name]', | |
| 122 | - 'default' => get_option( 'blogname' ), | |
| 123 | - 'type' => 'text', | |
| 124 | - 'css' => 'width:400px', | |
| 125 | - ), | |
| 126 | - array( | |
| 127 | - 'type' => 'sectionend', | |
| 128 | - ), | |
| 129 | - array( | |
| 130 | - 'title' => esc_html__( 'Email template', 'learnpress' ), | |
| 131 | - 'type' => 'title', | |
| 132 | - 'desc' => esc_html__( 'This section lets you customize the LearnPress emails', 'learnpress' ), | |
| 133 | - ), | |
| 134 | - /*array( | |
| 135 | - 'title' => esc_html__( 'Content type', 'learnpress' ), | |
| 136 | - 'id' => 'emails_general[default_email_content]', | |
| 137 | - 'default' => 'html', | |
| 138 | - 'type' => 'select', | |
| 139 | - 'options' => array( | |
| 140 | - 'plain' => esc_html__( 'Plain Text', 'learnpress' ), | |
| 141 | - 'html' => esc_html__( 'HTML', 'learnpress' ), | |
| 142 | - ), | |
| 143 | - ),*/ | |
| 144 | - array( | |
| 145 | - 'title' => esc_html__( 'Header image', 'learnpress' ), | |
| 146 | - 'id' => 'emails_general[header_image]', | |
| 147 | - 'default' => '', | |
| 148 | - 'type' => 'image', | |
| 149 | - ), | |
| 150 | - array( | |
| 151 | - 'title' => esc_html__( 'Footer text', 'learnpress' ), | |
| 152 | - 'id' => 'emails_general[footer_text]', | |
| 153 | - 'default' => esc_html__( 'LearnPress', 'learnpress' ), | |
| 154 | - 'type' => 'textarea', | |
| 155 | - ), | |
| 156 | - array( | |
| 157 | - 'title' => esc_html__( 'Emails', 'learnpress' ), | |
| 158 | - 'id' => 'emails_general[list_emails]', | |
| 159 | - 'default' => '', | |
| 160 | - 'type' => 'list-emails', | |
| 161 | - ), | |
| 162 | - array( | |
| 163 | - 'type' => 'sectionend', | |
| 164 | - ), | |
| 165 | - ) | |
| 166 | - ); | |
| 167 | - } | |
| 168 | - | |
| 169 | - /** | |
| 170 | - * Display admin page for payments settings tab. | |
| 171 | - * | |
| 172 | - * @param string $section | |
| 173 | - * @param string $tab | |
| 174 | - * @version 4.0.0 | |
| 175 | - */ | |
| 176 | - public function admin_page_settings( $section = null, $tab = null ) { | |
| 177 | - $sections = array(); | |
| 178 | - $items = LP_Admin_Menu::instance()->get_menu_items(); | |
| 179 | - | |
| 180 | - if ( ! empty( $items['settings'] ) ) { | |
| 181 | - $tab = $items['settings']->get_active_tab(); | |
| 182 | - $section = $items['settings']->get_active_section(); | |
| 183 | - $sections = $items['settings']->get_sections(); | |
| 184 | - } | |
| 185 | - $section_data = ! empty( $sections[ $section ] ) ? $sections[ $section ] : false; | |
| 186 | - | |
| 187 | - if ( $section_data instanceof LP_Email ) { | |
| 188 | - $section_data->admin_option_settings(); | |
| 189 | - } else { | |
| 190 | - if ( is_callable( array( $this, 'admin_options_' . $section ) ) ) { | |
| 191 | - call_user_func_array( array( $this, 'admin_options_' . $section ), array( $section, $tab ) ); | |
| 192 | - } else { | |
| 193 | - do_action( 'learn-press/admin/setting-payments/admin-options-' . $section, $tab ); | |
| 194 | - } | |
| 195 | - } | |
| 196 | - } | |
| 197 | - | |
| 198 | - /** | |
| 199 | - * Output admin option of general page. | |
| 200 | - * | |
| 201 | - * @param string $section | |
| 202 | - * @param string $tab | |
| 203 | - */ | |
| 204 | - public function admin_options_general( $section, $tab ) { | |
| 205 | - parent::admin_page_settings( $section, $tab ); | |
| 206 | - } | |
| 207 | - | |
| 208 | - public static function instance() { | |
| 209 | - if ( ! self::$_instance ) { | |
| 210 | - self::$_instance = new self(); | |
| 211 | - } | |
| 212 | - | |
| 213 | - return self::$_instance; | |
| 214 | - } | |
| 215 | -} | |
| 216 | - | |
| 217 | -return LP_Settings_Emails::instance(); | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Class LP_Settings_Emails | |
| 4 | + * | |
| 5 | + * @author ThimPress | |
| 6 | + * @package LearnPress/Classes | |
| 7 | + * @version 4.0.0 | |
| 8 | + */ | |
| 9 | + | |
| 10 | +use LearnPress\TemplateHooks\Admin\AdminSettingsPage; | |
| 11 | + | |
| 12 | +defined( 'ABSPATH' ) || exit; | |
| 13 | + | |
| 14 | +require_once 'email-groups/class-lp-settings-emails-group.php'; | |
| 15 | + | |
| 16 | +class LP_Settings_Emails extends LP_Abstract_Settings_Page { | |
| 17 | + /** | |
| 18 | + * @var null | |
| 19 | + */ | |
| 20 | + protected static $_instance = null; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * Constructor | |
| 24 | + */ | |
| 25 | + public function __construct() { | |
| 26 | + $this->id = 'emails'; | |
| 27 | + $this->text = esc_html__( 'Emails', 'learnpress' ); | |
| 28 | + | |
| 29 | + parent::__construct(); | |
| 30 | + | |
| 31 | + add_filter( 'learn-press/admin/submenu-section-title', array( $this, 'custom_section_title' ), 10, 2 ); | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Add tooltip to section title | |
| 36 | + * | |
| 37 | + * @param string $title | |
| 38 | + * @param string $slug | |
| 39 | + * | |
| 40 | + * @return string | |
| 41 | + */ | |
| 42 | + public function custom_section_title( $title, $slug ) { | |
| 43 | + $sections = $this->get_sections(); | |
| 44 | + | |
| 45 | + if ( ! empty( $sections[ $slug ] ) && $sections[ $slug ] instanceof LP_Email ) { | |
| 46 | + if ( $sections[ $slug ]->description ) { | |
| 47 | + $title = $title . sprintf( '<span class="learn-press-tooltip" data-tooltip="%s"></span>', esc_attr( $sections[ $slug ]->description ) ); | |
| 48 | + } | |
| 49 | + } | |
| 50 | + | |
| 51 | + return $title; | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Sections | |
| 56 | + * | |
| 57 | + * @return mixed | |
| 58 | + */ | |
| 59 | + public function get_sections() { | |
| 60 | + static $sections; | |
| 61 | + if ( is_null( $sections ) ) { | |
| 62 | + $emails = LP_Emails::instance()->emails; | |
| 63 | + | |
| 64 | + $sections = array( | |
| 65 | + 'general' => esc_html__( 'General', 'learnpress' ), | |
| 66 | + ); | |
| 67 | + | |
| 68 | + if ( $emails ) { | |
| 69 | + $groups = array( | |
| 70 | + include 'email-groups/class-lp-settings-new-order-emails.php', | |
| 71 | + include 'email-groups/class-lp-settings-processing-order-emails.php', | |
| 72 | + include 'email-groups/class-lp-settings-completed-order-emails.php', | |
| 73 | + include 'email-groups/class-lp-settings-cancelled-order-emails.php', | |
| 74 | + include 'email-groups/class-lp-settings-refunded-order-emails.php', | |
| 75 | + include 'email-groups/class-lp-settings-refund-request-order-emails.php', | |
| 76 | + include 'email-groups/class-lp-settings-enrolled-course-emails.php', | |
| 77 | + include 'email-groups/class-lp-settings-finished-course-emails.php', | |
| 78 | + include 'email-groups/class-lp-settings-become-teacher-emails.php', | |
| 79 | + include 'email-groups/class-lp-settings-reset-password-emails.php', | |
| 80 | + ); | |
| 81 | + | |
| 82 | + $groups = apply_filters( 'learn-press/email-section-classes', $groups ); | |
| 83 | + | |
| 84 | + foreach ( $groups as $group ) { | |
| 85 | + $sections[ $group->group_id ] = $group; | |
| 86 | + } | |
| 87 | + | |
| 88 | + foreach ( $emails as $email ) { | |
| 89 | + if ( ! is_object( $email ) ) { | |
| 90 | + continue; | |
| 91 | + } | |
| 92 | + | |
| 93 | + foreach ( $groups as $group ) { | |
| 94 | + if ( is_object( $group ) && ! empty( $group->items[ $email->id ] ) ) { | |
| 95 | + continue 2; | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 99 | + if ( isset( $sections[ $email->id ] ) ) { | |
| 100 | + $sections[ $email->id ] = $email; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + } | |
| 104 | + } | |
| 105 | + | |
| 106 | + return apply_filters( 'learn-press/settings/section/' . $this->id, $sections ); | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * Settings fields of general section. | |
| 111 | + * | |
| 112 | + * @return mixed | |
| 113 | + */ | |
| 114 | + public function get_settings_general() { | |
| 115 | + return apply_filters( | |
| 116 | + 'learn-press/emails-settings/general', | |
| 117 | + array( | |
| 118 | + array( | |
| 119 | + 'title' => esc_html__( 'Email sender options', 'learnpress' ), | |
| 120 | + 'type' => 'title', | |
| 121 | + 'desc' => esc_html__( 'For all outgoing LearnPress notification emails.', 'learnpress' ), | |
| 122 | + ), | |
| 123 | + array( | |
| 124 | + 'title' => esc_html__( '"From" name', 'learnpress' ), | |
| 125 | + 'id' => 'emails_general[from_name]', | |
| 126 | + 'default' => get_option( 'blogname' ), | |
| 127 | + 'type' => 'text', | |
| 128 | + 'css' => 'width:400px', | |
| 129 | + ), | |
| 130 | + array( | |
| 131 | + 'type' => 'sectionend', | |
| 132 | + ), | |
| 133 | + array( | |
| 134 | + 'title' => esc_html__( 'Email template', 'learnpress' ), | |
| 135 | + 'type' => 'title', | |
| 136 | + 'desc' => esc_html__( 'This section lets you customize the LearnPress emails', 'learnpress' ), | |
| 137 | + ), | |
| 138 | + /*array( | |
| 139 | + 'title' => esc_html__( 'Content type', 'learnpress' ), | |
| 140 | + 'id' => 'emails_general[default_email_content]', | |
| 141 | + 'default' => 'html', | |
| 142 | + 'type' => 'select', | |
| 143 | + 'options' => array( | |
| 144 | + 'plain' => esc_html__( 'Plain Text', 'learnpress' ), | |
| 145 | + 'html' => esc_html__( 'HTML', 'learnpress' ), | |
| 146 | + ), | |
| 147 | + ),*/ | |
| 148 | + array( | |
| 149 | + 'title' => esc_html__( 'Header image', 'learnpress' ), | |
| 150 | + 'id' => 'emails_general[header_image]', | |
| 151 | + 'default' => '', | |
| 152 | + 'type' => 'image', | |
| 153 | + ), | |
| 154 | + array( | |
| 155 | + 'title' => esc_html__( 'Footer text', 'learnpress' ), | |
| 156 | + 'id' => 'emails_general[footer_text]', | |
| 157 | + 'default' => esc_html__( 'LearnPress', 'learnpress' ), | |
| 158 | + 'type' => 'textarea', | |
| 159 | + ), | |
| 160 | + array( | |
| 161 | + 'title' => esc_html__( 'Emails', 'learnpress' ), | |
| 162 | + 'id' => 'emails_general[list_emails]', | |
| 163 | + 'default' => '', | |
| 164 | + 'type' => 'list-emails', | |
| 165 | + ), | |
| 166 | + array( | |
| 167 | + 'type' => 'sectionend', | |
| 168 | + ), | |
| 169 | + ) | |
| 170 | + ); | |
| 171 | + } | |
| 172 | + | |
| 173 | + /** | |
| 174 | + * Display admin page for payments settings tab. | |
| 175 | + * | |
| 176 | + * @param string $section | |
| 177 | + * @param string $tab | |
| 178 | + * @version 4.0.0 | |
| 179 | + */ | |
| 180 | + public function admin_page_settings( $section = null, $tab = null ) { | |
| 181 | + $tab = AdminSettingsPage::instance()->get_active_tab(); | |
| 182 | + $section = AdminSettingsPage::instance()->get_active_section(); | |
| 183 | + $sections = AdminSettingsPage::instance()->get_sections(); | |
| 184 | + $section_data = ! empty( $sections[ $section ] ) ? $sections[ $section ] : false; | |
| 185 | + | |
| 186 | + if ( $section_data instanceof LP_Email ) { | |
| 187 | + $section_data->admin_option_settings(); | |
| 188 | + } else { | |
| 189 | + if ( is_callable( array( $this, 'admin_options_' . $section ) ) ) { | |
| 190 | + call_user_func_array( array( $this, 'admin_options_' . $section ), array( $section, $tab ) ); | |
| 191 | + } else { | |
| 192 | + do_action( 'learn-press/admin/setting-payments/admin-options-' . $section, $tab ); | |
| 193 | + } | |
| 194 | + } | |
| 195 | + } | |
| 196 | + | |
| 197 | + /** | |
| 198 | + * Output admin option of general page. | |
| 199 | + * | |
| 200 | + * @param string $section | |
| 201 | + * @param string $tab | |
| 202 | + */ | |
| 203 | + public function admin_options_general( $section, $tab ) { | |
| 204 | + parent::admin_page_settings( $section, $tab ); | |
| 205 | + } | |
| 206 | + | |
| 207 | + public static function instance() { | |
| 208 | + if ( ! self::$_instance ) { | |
| 209 | + self::$_instance = new self(); | |
| 210 | + } | |
| 211 | + | |
| 212 | + return self::$_instance; | |
| 213 | + } | |
| 214 | +} | |
| 215 | + | |
| 216 | +return LP_Settings_Emails::instance(); | |