/wp-content/plugins/dokan-lite/includes/emails/class-dokan-email-product-published.php

https://bitbucket.org/digitalklones/wordpress · PHP · 185 lines · 111 code · 23 blank · 51 comment · 5 complexity · 569d883f07d9bc0bc118e8b222f78b7b MD5 · raw file

  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit;
  4. }
  5. if ( ! class_exists( 'Dokan_Email_Product_Published' ) ) :
  6. /**
  7. * New Product Published Email to vendor.
  8. *
  9. * An email sent to the vendor when a pending Product is published by admin.
  10. *
  11. * @class Dokan_Email_Product_Published
  12. * @version 2.6.8
  13. * @author weDevs
  14. * @extends WC_Email
  15. */
  16. class Dokan_Email_Product_Published extends WC_Email {
  17. /**
  18. * Constructor.
  19. */
  20. public function __construct() {
  21. $this->id = 'pending_product_published';
  22. $this->title = __( 'Dokan Pending Product Published', 'dokan-lite' );
  23. $this->description = __( 'These emails are sent to vendor of the product when a pending product is published.', 'dokan-lite' );
  24. $this->template_html = 'emails/product-published.php';
  25. $this->template_plain = 'emails/plain/product-published.php';
  26. $this->template_base = DOKAN_DIR.'/templates/';
  27. // Triggers for this email
  28. add_action( 'dokan_pending_product_published_notification', array( $this, 'trigger' ), 30, 2 );
  29. // Call parent constructor
  30. parent::__construct();
  31. // Other settings
  32. $this->recipient = 'vendor@ofthe.product';
  33. }
  34. /**
  35. * Get email subject.
  36. *
  37. * @since 3.1.0
  38. * @return string
  39. */
  40. public function get_default_subject() {
  41. return __( '[{site_name}] Your product - {product_title} - is now published', 'dokan-lite' );
  42. }
  43. /**
  44. * Get email heading.
  45. *
  46. * @since 3.1.0
  47. * @return string
  48. */
  49. public function get_default_heading() {
  50. return __( '{product_title} - is published', 'dokan-lite' );
  51. }
  52. /**
  53. * Trigger the sending of this email.
  54. *
  55. * @param int $product_id The product ID.
  56. * @param array $postdata.
  57. */
  58. public function trigger( $post, $seller ) {
  59. if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
  60. return;
  61. }
  62. $product = wc_get_product( $post->ID );
  63. if ( is_a( $product, 'WC_Product' ) ) {
  64. $this->object = $product;
  65. $this->find['product-title'] = '{product_title}';
  66. $this->find['price'] = '{price}';
  67. $this->find['seller-name'] = '{seller_name}';
  68. $this->find['product_url'] = '{product_url}';
  69. $this->find['product_edit_link'] = '{product_edit_link}';
  70. $this->find['site_name'] = '{site_name}';
  71. $this->find['site_url'] = '{site_url}';
  72. $this->replace['product-title'] = $product->get_title();
  73. $this->replace['price'] = $product->get_price();
  74. $this->replace['seller-name'] = $seller->display_name;
  75. $this->replace['product_url'] = get_permalink( $post->ID );
  76. $this->replace['product_edit_link'] = dokan_edit_product_url( $post->ID );
  77. $this->replace['site_name'] = $this->get_from_name();
  78. $this->replace['site_url'] = site_url();
  79. }
  80. $this->setup_locale();
  81. $this->send( $seller->user_email, $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  82. $this->restore_locale();
  83. }
  84. /**
  85. * Get content html.
  86. *
  87. * @access public
  88. * @return string
  89. */
  90. public function get_content_html() {
  91. ob_start();
  92. wc_get_template( $this->template_html, array(
  93. 'product' => $this->object,
  94. 'email_heading' => $this->get_heading(),
  95. 'sent_to_admin' => true,
  96. 'plain_text' => false,
  97. 'email' => $this,
  98. 'data' => $this->replace
  99. ), 'dokan/', $this->template_base );
  100. return ob_get_clean();
  101. }
  102. /**
  103. * Get content plain.
  104. *
  105. * @access public
  106. * @return string
  107. */
  108. public function get_content_plain() {
  109. ob_start();
  110. wc_get_template( $this->template_html, array(
  111. 'product' => $this->object,
  112. 'email_heading' => $this->get_heading(),
  113. 'sent_to_admin' => true,
  114. 'plain_text' => true,
  115. 'email' => $this,
  116. 'data' => $this->replace
  117. ), 'dokan/', $this->template_base );
  118. return ob_get_clean();
  119. }
  120. /**
  121. * Initialise settings form fields.
  122. */
  123. public function init_form_fields() {
  124. $this->form_fields = array(
  125. 'enabled' => array(
  126. 'title' => __( 'Enable/Disable', 'dokan-lite' ),
  127. 'type' => 'checkbox',
  128. 'label' => __( 'Enable this email notification', 'dokan-lite' ),
  129. 'default' => 'yes',
  130. ),
  131. 'subject' => array(
  132. 'title' => __( 'Subject', 'dokan-lite' ),
  133. 'type' => 'text',
  134. 'desc_tip' => true,
  135. /* translators: %s: list of placeholders */
  136. 'description' => sprintf( __( 'Available placeholders: %s', 'dokan-lite' ), '<code>{site_name}, {product_title}, {seller_name}</code>' ),
  137. 'placeholder' => $this->get_default_subject(),
  138. 'default' => '',
  139. ),
  140. 'heading' => array(
  141. 'title' => __( 'Email heading', 'dokan-lite' ),
  142. 'type' => 'text',
  143. 'desc_tip' => true,
  144. /* translators: %s: list of placeholders */
  145. 'description' => sprintf( __( 'Available placeholders: %s', 'dokan-lite' ), '<code>{site_name}, {product_title}, {seller_name}</code>' ),
  146. 'placeholder' => $this->get_default_heading(),
  147. 'default' => '',
  148. ),
  149. 'email_type' => array(
  150. 'title' => __( 'Email type', 'dokan-lite' ),
  151. 'type' => 'select',
  152. 'description' => __( 'Choose which format of email to send.', 'dokan-lite' ),
  153. 'default' => 'html',
  154. 'class' => 'email_type wc-enhanced-select',
  155. 'options' => $this->get_email_type_options(),
  156. 'desc_tip' => true,
  157. ),
  158. );
  159. }
  160. }
  161. endif;
  162. return new Dokan_Email_Product_Published();