| 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(); |
| 217 |
|