WC_Predictive_Search_Performance_Settings

The WooCommerce Predictive Search LITE WC Predictive Search Performance Settings class.

Defined (1)

The class is defined in the following location(s).

/admin/settings/performance-settings.php  
  1. class WC_Predictive_Search_Performance_Settings extends WC_Predictive_Search_Admin_UI 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. private $parent_tab = 'performance-settings'; 
  7.  
  8. /** 
  9. * @var array 
  10. */ 
  11. private $subtab_data; 
  12.  
  13. /** 
  14. * @var string 
  15. * You must change to correct option name that you are working 
  16. */ 
  17. public $option_name = ''; 
  18.  
  19. /** 
  20. * @var string 
  21. * You must change to correct form key that you are working 
  22. */ 
  23. public $form_key = 'wc_predictive_search_performance_settings'; 
  24.  
  25. /** 
  26. * @var string 
  27. * You can change the order show of this sub tab in list sub tabs 
  28. */ 
  29. private $position = 1; 
  30.  
  31. /** 
  32. * @var array 
  33. */ 
  34. public $form_fields = array(); 
  35.  
  36. /** 
  37. * @var array 
  38. */ 
  39. public $form_messages = array(); 
  40.  
  41. /**-----------------------------------------------------------------------------------*/ 
  42. /** __construct() */ 
  43. /** Settings Constructor */ 
  44. /**-----------------------------------------------------------------------------------*/ 
  45. public function __construct() { 
  46.  
  47. $this->init_form_fields(); 
  48. $this->subtab_init(); 
  49.  
  50. $this->form_messages = array( 
  51. 'success_message' => __( 'Performance Settings successfully saved.', 'woops' ),  
  52. 'error_message' => __( 'Error: Performance Settings can not save.', 'woops' ),  
  53. 'reset_message' => __( 'Performance Settings successfully reseted.', 'woops' ),  
  54. ); 
  55.  
  56. add_action( $this->plugin_name . '-' . $this->form_key . '_settings_end', array( $this, 'include_script' ) ); 
  57.  
  58. add_action( $this->plugin_name . '_set_default_settings' , array( $this, 'set_default_settings' ) ); 
  59.  
  60. add_action( $this->plugin_name . '_settings_' . 'predictive_search_synch_data' . '_start', array( $this, 'predictive_search_synch_data' ) ); 
  61.  
  62. add_action( $this->plugin_name . '-' . $this->form_key . '_settings_init' , array( $this, 'after_save_settings' ) ); 
  63.  
  64. /**-----------------------------------------------------------------------------------*/ 
  65. /** subtab_init() */ 
  66. /** Sub Tab Init */ 
  67. /**-----------------------------------------------------------------------------------*/ 
  68. public function subtab_init() { 
  69.  
  70. add_filter( $this->plugin_name . '-' . $this->parent_tab . '_settings_subtabs_array', array( $this, 'add_subtab' ), $this->position ); 
  71.  
  72.  
  73. /**-----------------------------------------------------------------------------------*/ 
  74. /** set_default_settings() 
  75. /** Set default settings with function called from Admin Interface */ 
  76. /**-----------------------------------------------------------------------------------*/ 
  77. public function set_default_settings() { 
  78. global $wc_predictive_search_admin_interface; 
  79.  
  80. $wc_predictive_search_admin_interface->reset_settings( $this->form_fields, $this->option_name, false ); 
  81.  
  82. /**-----------------------------------------------------------------------------------*/ 
  83. /** after_save_settings() 
  84. /** Process when clean on deletion option is un selected */ 
  85. /**-----------------------------------------------------------------------------------*/ 
  86. public function after_save_settings() { 
  87. if ( isset( $_POST['predicitve-search-synch-wp-data'] ) ) { 
  88. @set_time_limit(86400); 
  89. @ini_set("memory_limit", "1000M"); 
  90.  
  91. global $wc_ps_synch; 
  92. $wc_ps_synch->synch_full_database(); 
  93.  
  94. echo '<div class="updated"><p>' . __( '<strong>SUCCESS</strong>! Your Predictive Search Database has been successfully updated.', 'woops' ) . '</p></div>'; 
  95.  
  96. /**-----------------------------------------------------------------------------------*/ 
  97. /** get_settings() 
  98. /** Get settings with function called from Admin Interface */ 
  99. /**-----------------------------------------------------------------------------------*/ 
  100. public function get_settings() { 
  101. global $wc_predictive_search_admin_interface; 
  102.  
  103. $wc_predictive_search_admin_interface->get_settings( $this->form_fields, $this->option_name ); 
  104.  
  105. /** 
  106. * subtab_data() 
  107. * Get SubTab Data 
  108. * ============================================= 
  109. * array (  
  110. * 'name' => 'my_subtab_name' : (required) Enter your subtab name that you want to set for this subtab 
  111. * 'label' => 'My SubTab Name' : (required) Enter the subtab label 
  112. * 'callback_function' => 'my_callback_function' : (required) The callback function is called to show content of this subtab 
  113. * ) 
  114. */ 
  115. public function subtab_data() { 
  116.  
  117. $subtab_data = array(  
  118. 'name' => 'performance-settings',  
  119. 'label' => __( 'Performance', 'woops' ),  
  120. 'callback_function' => 'wc_predictive_search_performance_settings_form',  
  121. ); 
  122.  
  123. if ( $this->subtab_data ) return $this->subtab_data; 
  124. return $this->subtab_data = $subtab_data; 
  125.  
  126.  
  127. /**-----------------------------------------------------------------------------------*/ 
  128. /** add_subtab() */ 
  129. /** Add Subtab to Admin Init 
  130. /**-----------------------------------------------------------------------------------*/ 
  131. public function add_subtab( $subtabs_array ) { 
  132.  
  133. if ( ! is_array( $subtabs_array ) ) $subtabs_array = array(); 
  134. $subtabs_array[] = $this->subtab_data(); 
  135.  
  136. return $subtabs_array; 
  137.  
  138. /**-----------------------------------------------------------------------------------*/ 
  139. /** settings_form() */ 
  140. /** Call the form from Admin Interface 
  141. /**-----------------------------------------------------------------------------------*/ 
  142. public function settings_form() { 
  143. global $wc_predictive_search_admin_interface; 
  144.  
  145. $output = ''; 
  146. $output .= $wc_predictive_search_admin_interface->admin_forms( $this->form_fields, $this->form_key, $this->option_name, $this->form_messages ); 
  147.  
  148. return $output; 
  149.  
  150. /**-----------------------------------------------------------------------------------*/ 
  151. /** init_form_fields() */ 
  152. /** Init all fields of this form */ 
  153. /**-----------------------------------------------------------------------------------*/ 
  154. public function init_form_fields() { 
  155. if ( isset( $_GET['page'] ) && 'woo-predictive-search' == $_GET['page'] && isset( $_GET['tab'] ) && $this->parent_tab == $_GET['tab'] ) { 
  156. if ( ! isset( $_SESSION ) ) { 
  157. @session_start(); 
  158. // Define settings  
  159. $this->form_fields = apply_filters( $this->option_name . '_settings_fields', array( 
  160.  
  161. array( 
  162. 'name' => __( 'Manual Database Sync', 'woops' ),  
  163. 'desc' => __( 'Predictive Search database is auto updated whenever a product or post is published or updated. Please run a Manual database sync if you upload products by csv or feel that Predictive Search results are showing old data. Will sync the Predictive Search database with your current WooCommerce and WordPress databases', 'woops' ),  
  164. 'id' => 'predictive_search_synch_data',  
  165. 'type' => 'heading',  
  166. 'is_box' => true,  
  167. ),  
  168.  
  169. array( 
  170. 'name' => __( 'Search Performance Settings', 'woops' ),  
  171. 'type' => 'heading',  
  172. 'desc' => '<img class="rwd_image_maps" src="'.WOOPS_IMAGES_URL.'/premium-performance-settings.png" usemap="#performanceMap" style="width: auto; max-width: 100%;" border="0" /> 
  173. <map name="performanceMap" id="performanceMap"> 
  174. <area shape="rect" coords="410, 145, 925, 210" href="'.$this->pro_plugin_page_url.'" target="_blank" /> 
  175. </map>',  
  176. 'id' => 'predictive_search_performance_settings',  
  177. 'is_box' => true,  
  178. ),  
  179. )); 
  180.  
  181. public function predictive_search_synch_data() { 
  182. global $wc_ps_posts_data; 
  183. ?> 
  184. <tr valign="top" class=""> 
  185. <th class="titledesc" scope="row"><label><?php _e('Sync Search Data', 'woops');?></label></th> 
  186. <td class="forminp"> 
  187. <input type="submit" class="button button-primary" name="predicitve-search-synch-wp-data" value="<?php _e('Sync Now', 'woops');?>" /><br /> 
  188. <p> 
  189. <span class="a3-ps-synched-title"><?php _e('You have synced', 'woops');?>:</span> 
  190. <span class="a3-ps-synched-products"> 
  191. <?php 
  192. $total_products = $wc_ps_posts_data->get_total_items_synched('product'); 
  193. if ( $total_products > 0 ) { 
  194. echo sprintf( _n( '%s Product', '%s Products', $total_products, 'woops' ), number_format( $total_products ) ); 
  195. } else { 
  196. echo sprintf( __( '%s Product', 'woops' ), $total_products ); 
  197. ?> 
  198. </span>- 
  199. <span class="a3-ps-synched-posts"> 
  200. <?php 
  201. $total_posts = $wc_ps_posts_data->get_total_items_synched('post'); 
  202. if ( $total_posts > 0 ) { 
  203. echo sprintf( _n( '%s Post', '%s Posts', $total_posts, 'woops' ), number_format( $total_posts ) ); 
  204. } else { 
  205. echo sprintf( __( '%s Post', 'woops' ), $total_posts ); 
  206. ?> 
  207. </span>- 
  208. <span class="a3-ps-synched-pages"> 
  209. <?php 
  210. $total_pages = $wc_ps_posts_data->get_total_items_synched('page'); 
  211. if ( $total_pages > 0 ) { 
  212. echo sprintf( _n( '%s Page', '%s Pages', $total_pages, 'woops' ), number_format( $total_pages ) ); 
  213. } else { 
  214. echo sprintf( __( '%s Page', 'woops' ), $total_pages ); 
  215. ?> 
  216. </span> 
  217. </p> 
  218. </td> 
  219. </tr> 
  220. <?php 
  221.  
  222. public function include_script() { 
  223. ?> 
  224. <style type="text/css"> 
  225. .a3-ps-synched-products { 
  226. color: #96587d; 
  227. .a3-ps-synched-posts { 
  228. color: #7ad03a; 
  229. .a3-ps-synched-pages { 
  230. color: #0073aa; 
  231. </style> 
  232. <?php 
  233. wp_enqueue_script( 'jquery-rwd-image-maps' );