PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/woocommerce/includes/admin/settings/class-wc-settings-emails.php

https://gitlab.com/campus-academy/krowkaramel
PHP | 371 lines | 282 code | 42 blank | 47 comment | 12 complexity | 673800030a96072d73516087969625e3 MD5 | raw file
  1. <?php
  2. /**
  3. * WooCommerce Email Settings
  4. *
  5. * @package WooCommerce\Admin
  6. * @version 2.1.0
  7. */
  8. defined( 'ABSPATH' ) || exit;
  9. if ( class_exists( 'WC_Settings_Emails', false ) ) {
  10. return new WC_Settings_Emails();
  11. }
  12. /**
  13. * WC_Settings_Emails.
  14. */
  15. class WC_Settings_Emails extends WC_Settings_Page {
  16. /**
  17. * Constructor.
  18. */
  19. public function __construct() {
  20. $this->id = 'email';
  21. $this->label = __( 'Emails', 'woocommerce' );
  22. add_action( 'woocommerce_admin_field_email_notification', array( $this, 'email_notification_setting' ) );
  23. parent::__construct();
  24. }
  25. /**
  26. * Get own sections.
  27. *
  28. * @return array
  29. */
  30. protected function get_own_sections() {
  31. return array(
  32. '' => __( 'Email options', 'woocommerce' ),
  33. );
  34. }
  35. /**
  36. * Get settings array.
  37. *
  38. * @return array
  39. */
  40. protected function get_settings_for_default_section() {
  41. $desc_help_text = sprintf(
  42. /* translators: %1$s: Link to WP Mail Logging plugin, %2$s: Link to Email FAQ support page. */
  43. __( 'To ensure your store&rsquo;s notifications arrive in your and your customers&rsquo; inboxes, we recommend connecting your email address to your domain and setting up a dedicated SMTP server. If something doesn&rsquo;t seem to be sending correctly, install the <a href="%1$s">WP Mail Logging Plugin</a> or check the <a href="%2$s">Email FAQ page</a>.', 'woocommerce' ),
  44. 'https://wordpress.org/plugins/wp-mail-logging/',
  45. 'https://docs.woocommerce.com/document/email-faq'
  46. );
  47. $settings =
  48. array(
  49. array(
  50. 'title' => __( 'Email notifications', 'woocommerce' ),
  51. /* translators: %s: help description with link to WP Mail logging and support page. */
  52. 'desc' => sprintf( __( 'Email notifications sent from WooCommerce are listed below. Click on an email to configure it.<br>%s', 'woocommerce' ), $desc_help_text ),
  53. 'type' => 'title',
  54. 'id' => 'email_notification_settings',
  55. ),
  56. array( 'type' => 'email_notification' ),
  57. array(
  58. 'type' => 'sectionend',
  59. 'id' => 'email_notification_settings',
  60. ),
  61. array(
  62. 'type' => 'sectionend',
  63. 'id' => 'email_recipient_options',
  64. ),
  65. array(
  66. 'title' => __( 'Email sender options', 'woocommerce' ),
  67. 'type' => 'title',
  68. 'desc' => '',
  69. 'id' => 'email_options',
  70. ),
  71. array(
  72. 'title' => __( '"From" name', 'woocommerce' ),
  73. 'desc' => __( 'How the sender name appears in outgoing WooCommerce emails.', 'woocommerce' ),
  74. 'id' => 'woocommerce_email_from_name',
  75. 'type' => 'text',
  76. 'css' => 'min-width:400px;',
  77. 'default' => esc_attr( get_bloginfo( 'name', 'display' ) ),
  78. 'autoload' => false,
  79. 'desc_tip' => true,
  80. ),
  81. array(
  82. 'title' => __( '"From" address', 'woocommerce' ),
  83. 'desc' => __( 'How the sender email appears in outgoing WooCommerce emails.', 'woocommerce' ),
  84. 'id' => 'woocommerce_email_from_address',
  85. 'type' => 'email',
  86. 'custom_attributes' => array(
  87. 'multiple' => 'multiple',
  88. ),
  89. 'css' => 'min-width:400px;',
  90. 'default' => get_option( 'admin_email' ),
  91. 'autoload' => false,
  92. 'desc_tip' => true,
  93. ),
  94. array(
  95. 'type' => 'sectionend',
  96. 'id' => 'email_options',
  97. ),
  98. array(
  99. 'title' => __( 'Email template', 'woocommerce' ),
  100. 'type' => 'title',
  101. /* translators: %s: Nonced email preview link */
  102. 'desc' => sprintf( __( 'This section lets you customize the WooCommerce emails. <a href="%s" target="_blank">Click here to preview your email template</a>.', 'woocommerce' ), wp_nonce_url( admin_url( '?preview_woocommerce_mail=true' ), 'preview-mail' ) ),
  103. 'id' => 'email_template_options',
  104. ),
  105. array(
  106. 'title' => __( 'Header image', 'woocommerce' ),
  107. 'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'woocommerce' ),
  108. 'id' => 'woocommerce_email_header_image',
  109. 'type' => 'text',
  110. 'css' => 'min-width:400px;',
  111. 'placeholder' => __( 'N/A', 'woocommerce' ),
  112. 'default' => '',
  113. 'autoload' => false,
  114. 'desc_tip' => true,
  115. ),
  116. array(
  117. 'title' => __( 'Footer text', 'woocommerce' ),
  118. /* translators: %s: Available placeholders for use */
  119. 'desc' => __( 'The text to appear in the footer of all WooCommerce emails.', 'woocommerce' ) . ' ' . sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '{site_title} {site_url}' ),
  120. 'id' => 'woocommerce_email_footer_text',
  121. 'css' => 'width:400px; height: 75px;',
  122. 'placeholder' => __( 'N/A', 'woocommerce' ),
  123. 'type' => 'textarea',
  124. 'default' => '{site_title} &mdash; Built with {WooCommerce}',
  125. 'autoload' => false,
  126. 'desc_tip' => true,
  127. ),
  128. array(
  129. 'title' => __( 'Base color', 'woocommerce' ),
  130. /* translators: %s: default color */
  131. 'desc' => sprintf( __( 'The base color for WooCommerce email templates. Default %s.', 'woocommerce' ), '<code>#96588a</code>' ),
  132. 'id' => 'woocommerce_email_base_color',
  133. 'type' => 'color',
  134. 'css' => 'width:6em;',
  135. 'default' => '#96588a',
  136. 'autoload' => false,
  137. 'desc_tip' => true,
  138. ),
  139. array(
  140. 'title' => __( 'Background color', 'woocommerce' ),
  141. /* translators: %s: default color */
  142. 'desc' => sprintf( __( 'The background color for WooCommerce email templates. Default %s.', 'woocommerce' ), '<code>#f7f7f7</code>' ),
  143. 'id' => 'woocommerce_email_background_color',
  144. 'type' => 'color',
  145. 'css' => 'width:6em;',
  146. 'default' => '#f7f7f7',
  147. 'autoload' => false,
  148. 'desc_tip' => true,
  149. ),
  150. array(
  151. 'title' => __( 'Body background color', 'woocommerce' ),
  152. /* translators: %s: default color */
  153. 'desc' => sprintf( __( 'The main body background color. Default %s.', 'woocommerce' ), '<code>#ffffff</code>' ),
  154. 'id' => 'woocommerce_email_body_background_color',
  155. 'type' => 'color',
  156. 'css' => 'width:6em;',
  157. 'default' => '#ffffff',
  158. 'autoload' => false,
  159. 'desc_tip' => true,
  160. ),
  161. array(
  162. 'title' => __( 'Body text color', 'woocommerce' ),
  163. /* translators: %s: default color */
  164. 'desc' => sprintf( __( 'The main body text color. Default %s.', 'woocommerce' ), '<code>#3c3c3c</code>' ),
  165. 'id' => 'woocommerce_email_text_color',
  166. 'type' => 'color',
  167. 'css' => 'width:6em;',
  168. 'default' => '#3c3c3c',
  169. 'autoload' => false,
  170. 'desc_tip' => true,
  171. ),
  172. array(
  173. 'type' => 'sectionend',
  174. 'id' => 'email_template_options',
  175. ),
  176. array(
  177. 'title' => __( 'Store management insights', 'woocommerce' ),
  178. 'type' => 'title',
  179. 'id' => 'email_merchant_notes',
  180. ),
  181. array(
  182. 'title' => __( 'Enable email insights', 'woocommerce' ),
  183. 'desc' => __( 'Receive email notifications with additional guidance to complete the basic store setup and helpful insights', 'woocommerce' ),
  184. 'id' => 'woocommerce_merchant_email_notifications',
  185. 'type' => 'checkbox',
  186. 'checkboxgroup' => 'start',
  187. 'default' => 'no',
  188. 'autoload' => false,
  189. ),
  190. array(
  191. 'type' => 'sectionend',
  192. 'id' => 'email_merchant_notes',
  193. ),
  194. );
  195. return apply_filters( 'woocommerce_email_settings', $settings );
  196. }
  197. /**
  198. * Output the settings.
  199. */
  200. public function output() {
  201. global $current_section;
  202. // Define emails that can be customised here.
  203. $mailer = WC()->mailer();
  204. $email_templates = $mailer->get_emails();
  205. if ( $current_section ) {
  206. foreach ( $email_templates as $email_key => $email ) {
  207. if ( strtolower( $email_key ) === $current_section ) {
  208. $this->run_email_admin_options( $email );
  209. break;
  210. }
  211. }
  212. }
  213. parent::output();
  214. }
  215. /**
  216. * Run the 'admin_options' method on a given email.
  217. * This method exists to easy unit testing.
  218. *
  219. * @param object $email The email object to run the method on.
  220. */
  221. protected function run_email_admin_options( $email ) {
  222. $email->admin_options();
  223. }
  224. /**
  225. * Save settings.
  226. */
  227. public function save() {
  228. global $current_section;
  229. if ( ! $current_section ) {
  230. $this->save_settings_for_current_section();
  231. $this->do_update_options_action();
  232. } else {
  233. $wc_emails = WC_Emails::instance();
  234. if ( in_array( $current_section, array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) ), true ) ) {
  235. foreach ( $wc_emails->get_emails() as $email_id => $email ) {
  236. if ( sanitize_title( $email_id ) === $current_section ) {
  237. $this->do_update_options_action( $email->id );
  238. }
  239. }
  240. } else {
  241. $this->save_settings_for_current_section();
  242. $this->do_update_options_action();
  243. }
  244. }
  245. }
  246. /**
  247. * Output email notification settings.
  248. */
  249. public function email_notification_setting() {
  250. // Define emails that can be customised here.
  251. $mailer = WC()->mailer();
  252. $email_templates = $mailer->get_emails();
  253. ?>
  254. <tr valign="top">
  255. <td class="wc_emails_wrapper" colspan="2">
  256. <table class="wc_emails widefat" cellspacing="0">
  257. <thead>
  258. <tr>
  259. <?php
  260. $columns = apply_filters(
  261. 'woocommerce_email_setting_columns',
  262. array(
  263. 'status' => '',
  264. 'name' => __( 'Email', 'woocommerce' ),
  265. 'email_type' => __( 'Content type', 'woocommerce' ),
  266. 'recipient' => __( 'Recipient(s)', 'woocommerce' ),
  267. 'actions' => '',
  268. )
  269. );
  270. foreach ( $columns as $key => $column ) {
  271. echo '<th class="wc-email-settings-table-' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
  272. }
  273. ?>
  274. </tr>
  275. </thead>
  276. <tbody>
  277. <?php
  278. foreach ( $email_templates as $email_key => $email ) {
  279. echo '<tr>';
  280. foreach ( $columns as $key => $column ) {
  281. switch ( $key ) {
  282. case 'name':
  283. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
  284. <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=email&section=' . strtolower( $email_key ) ) ) . '">' . esc_html( $email->get_title() ) . '</a>
  285. ' . wc_help_tip( $email->get_description() ) . '
  286. </td>';
  287. break;
  288. case 'recipient':
  289. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
  290. ' . esc_html( $email->is_customer_email() ? __( 'Customer', 'woocommerce' ) : $email->get_recipient() ) . '
  291. </td>';
  292. break;
  293. case 'status':
  294. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">';
  295. if ( $email->is_manual() ) {
  296. echo '<span class="status-manual tips" data-tip="' . esc_attr__( 'Manually sent', 'woocommerce' ) . '">' . esc_html__( 'Manual', 'woocommerce' ) . '</span>';
  297. } elseif ( $email->is_enabled() ) {
  298. echo '<span class="status-enabled tips" data-tip="' . esc_attr__( 'Enabled', 'woocommerce' ) . '">' . esc_html__( 'Yes', 'woocommerce' ) . '</span>';
  299. } else {
  300. echo '<span class="status-disabled tips" data-tip="' . esc_attr__( 'Disabled', 'woocommerce' ) . '">-</span>';
  301. }
  302. echo '</td>';
  303. break;
  304. case 'email_type':
  305. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
  306. ' . esc_html( $email->get_content_type() ) . '
  307. </td>';
  308. break;
  309. case 'actions':
  310. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
  311. <a class="button alignright" href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=email&section=' . strtolower( $email_key ) ) ) . '">' . esc_html__( 'Manage', 'woocommerce' ) . '</a>
  312. </td>';
  313. break;
  314. default:
  315. do_action( 'woocommerce_email_setting_column_' . $key, $email );
  316. break;
  317. }
  318. }
  319. echo '</tr>';
  320. }
  321. ?>
  322. </tbody>
  323. </table>
  324. </td>
  325. </tr>
  326. <?php
  327. }
  328. }
  329. return new WC_Settings_Emails();