Aucune description

class-woo-custom-emails-per-product-admin-settings.php 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. class Woo_Custom_Emails_Per_Product_Admin_Settings {
  3. private $wce_settings_options;
  4. public function __construct() {
  5. add_action( 'admin_menu', array( &$this, 'wce_settings_add_plugin_page' ) );
  6. add_action( 'admin_init', array( &$this, 'wce_settings_page_init' ) );
  7. }
  8. public function wce_settings_add_plugin_page() {
  9. add_submenu_page(
  10. 'edit.php?post_type=woocustomemails', // parent slug
  11. __('WCE Settings','woo_custom_emails_domain'), // page title
  12. __('WCE Settings','woo_custom_emails_domain'), // menu title
  13. 'manage_options', // capability
  14. 'wce-settings', // menu slug
  15. array( $this, 'wce_settings_create_admin_page' ) // callback function
  16. );
  17. }
  18. public function wce_settings_create_admin_page() {
  19. $this->wce_settings_options = get_option( 'woocustomemails_settings_name' );
  20. // $this->plugin_settings_tabs['wce-settings'] = 'Display Settings';
  21. ?>
  22. <div class="wrap">
  23. <h2>Woo Custom Emails Settings</h2>
  24. <hr>
  25. <p class="howto"><?php _e('Settings for the Woo Custom Emails Per Product plugin.', 'woo_custom_emails_domain'); ?></p>
  26. <?php settings_errors(); ?>
  27. <?php
  28. if ( isset( $_GET ) ) {
  29. if ( empty( $_GET['tab'] ) ) {
  30. $active_tab = 'display_settings';
  31. } else {
  32. $active_tab = $_GET['tab'];
  33. }
  34. }
  35. ?>
  36. <h2 class="nav-tab-wrapper">
  37. <a href="?post_type=woocustomemails&page=<?php echo $_GET['page']; ?>&tab=display_settings" class="nav-tab <?php echo $active_tab == 'display_settings' ? 'nav-tab-active' : ''; ?>">Display Settings</a>
  38. <a href="?post_type=woocustomemails&page=<?php echo $_GET['page']; ?>&tab=admin_settings" class="nav-tab <?php echo $active_tab == 'admin_settings' ? 'nav-tab-active' : ''; ?>">Admin Settings</a>
  39. </h2>
  40. <form method="post" action="options.php">
  41. <?php
  42. if ( $active_tab == 'display_settings' ) {
  43. settings_fields( 'wce_settings_option_group' );
  44. do_settings_sections( 'wce-settings-admin' );
  45. submit_button();
  46. } elseif ( $active_tab == 'admin_settings' ) {
  47. echo __( '<p>More Admin Options &mdash; including the "Assigned Messages" feature &mdash; will be coming soon in a future release!</p>', 'woo_custom_emails_domain' );
  48. }
  49. ?>
  50. </form>
  51. </div>
  52. <?php }
  53. public function wce_settings_page_init() {
  54. register_setting(
  55. 'wce_settings_option_group', // option_group
  56. 'woocustomemails_settings_name', // option_name
  57. array( $this, 'wce_settings_sanitize' ) // sanitize_callback
  58. );
  59. add_settings_section(
  60. 'wce_settings_setting_section', // id
  61. 'Display Settings', // title
  62. array( $this, 'wce_settings_section_info' ), // callback
  63. 'wce-settings-admin' // page
  64. );
  65. add_settings_field(
  66. 'show_in_admin_email', // id
  67. 'Include in Admin Emails', // title
  68. array( $this, 'show_in_admin_email_callback' ), // callback
  69. 'wce-settings-admin', // page
  70. 'wce_settings_setting_section' // section
  71. );
  72. add_settings_field(
  73. 'display_classes', // id
  74. 'Display for Other Product Types', // title
  75. array( $this, 'display_classes_callback' ), // callback
  76. 'wce-settings-admin', // page
  77. 'wce_settings_setting_section' // section
  78. );
  79. }
  80. public function wce_settings_sanitize($input) {
  81. $sanitary_values = array();
  82. if ( isset( $input['show_in_admin_email'] ) ) {
  83. $sanitary_values['show_in_admin_email'] = $input['show_in_admin_email'];
  84. }
  85. if ( isset( $input['display_classes'] ) ) {
  86. $sanitary_values['display_classes'] = sanitize_text_field( $input['display_classes'] );
  87. }
  88. return $sanitary_values;
  89. }
  90. public function wce_settings_section_info() {
  91. echo __( 'Configure the display settings for Woo Custom Emails custom messages.', 'woo_custom_emails_domain' );
  92. }
  93. public function show_in_admin_email_callback() {
  94. printf(
  95. '<input type="checkbox" name="woocustomemails_settings_name[show_in_admin_email]" id="show_in_admin_email" value="show_in_admin_email" %s> <label for="show_in_admin_email">' . __( 'Show the Custom Messages content inside Admin order notification emails.', 'woo_custom_emails_domain' ) . '</label>',
  96. ( isset( $this->wce_settings_options['show_in_admin_email'] ) && $this->wce_settings_options['show_in_admin_email'] === 'show_in_admin_email' ) ? 'checked' : ''
  97. );
  98. }
  99. public function display_classes_callback() {
  100. printf(
  101. '<textarea class="large-text" rows="5" name="woocustomemails_settings_name[display_classes]" id="display_classes">%s</textarea>',
  102. isset( $this->wce_settings_options['display_classes'] ) ? esc_attr( $this->wce_settings_options['display_classes']) : ''
  103. );
  104. // Description.
  105. echo '<div class="description" style="margin-top: 20px;">' . __( 'By default, WooCommerce only shows the \'Custom Emails\' tab for the standard \'<b>product</b>\' post type.<br>Use this option to specify other product post types which will show the Custom Emails tab. This should be a comma-separated list.', 'woo_custom_emails_domain' ) . '</div>';
  106. // Code example.
  107. echo '<div class="description" style="margin-top: 20px; margin-left: 30px;"><b>Example:</b><pre>show_if_booking, show_if_grouped</pre></div>';
  108. // Instructions to find CSS Class.
  109. echo '<div class="description" style="margin-top: 20px;">' . __( '<b>How to Find the CSS Class for a Custom Product</b><br>To find the class for your product type, do the following:', 'woo_custom_emails_domain' );
  110. echo '<ol>';
  111. echo __( '<li>Go to <b>Products</b>, and Edit a custom product</li>', 'woo_custom_emails_domain' );
  112. echo __( '<li>Scroll down to the <b>Product Data</b> table</li>', 'woo_custom_emails_domain' );
  113. echo __( '<li><b>Inspect the code</b> for a tab menu item, like <b>Inventory</b> (or any menu item which appears only for your product type)</li>', 'woo_custom_emails_domain' );
  114. echo __( '<li>Find the custom CSS class for your product type which is assigned to that tab menu item. These classes usually start with <b>show_if_</b> -- ex: "show_if_booking"</li>', 'woo_custom_emails_domain' );
  115. echo __( '<li>Copy and paste that CSS class into the field above</li>', 'woo_custom_emails_domain' );
  116. echo __( '<li>Save your settings</li>', 'woo_custom_emails_domain' );
  117. echo '</ol>';
  118. echo '</div>';
  119. // Note text.
  120. echo '<div style="margin-top: 20px; padding: 20px; border: 1px solid rgba(0,0,0,0.15);"><b style="color: #ff0000;">' . __( 'Please Note:</b> This feature is experimental and is not guaranteed to work.<br>Some WooCommerce add-ons use their own method of sending emails, outside of the normal WooCommerce process this plugin uses.', 'woo_custom_emails_domain' ) . '</div>';
  121. }
  122. }
  123. if ( is_admin() ) {
  124. $wce_settings = new Woo_Custom_Emails_Per_Product_Admin_Settings();
  125. }
  126. /*
  127. * Retrieve values with:
  128. * $wce_settings_options = get_option( 'woocustomemails_settings_name' ); // Array of All Options
  129. * $show_in_admin_email = $wce_settings_options['show_in_admin_email']; // Include in Admin Emails
  130. * $display_classes = $wce_settings_options['display_classes']; // Display for Other Product Types
  131. */