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. add_action( 'plugins_loaded', array( $this, 'init_form_fields' ), 1 ); 
  48. $this->subtab_init(); 
  49.  
  50. $this->form_messages = array( 
  51. 'success_message' => __( 'Performance Settings successfully saved.', 'woocommerce-predictive-search' ),  
  52. 'error_message' => __( 'Error: Performance Settings can not save.', 'woocommerce-predictive-search' ),  
  53. 'reset_message' => __( 'Performance Settings successfully reseted.', 'woocommerce-predictive-search' ),  
  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 . '-' . $this->form_key . '_settings_init' , array( $this, 'after_save_settings' ) ); 
  61.  
  62. /**-----------------------------------------------------------------------------------*/ 
  63. /** subtab_init() */ 
  64. /** Sub Tab Init */ 
  65. /**-----------------------------------------------------------------------------------*/ 
  66. public function subtab_init() { 
  67.  
  68. add_filter( $this->plugin_name . '-' . $this->parent_tab . '_settings_subtabs_array', array( $this, 'add_subtab' ), $this->position ); 
  69.  
  70.  
  71. /**-----------------------------------------------------------------------------------*/ 
  72. /** set_default_settings() 
  73. /** Set default settings with function called from Admin Interface */ 
  74. /**-----------------------------------------------------------------------------------*/ 
  75. public function set_default_settings() { 
  76. global $wc_predictive_search_admin_interface; 
  77.  
  78. $wc_predictive_search_admin_interface->reset_settings( $this->form_fields, $this->option_name, false ); 
  79.  
  80. /**-----------------------------------------------------------------------------------*/ 
  81. /** after_save_settings() 
  82. /** Process when clean on deletion option is un selected */ 
  83. /**-----------------------------------------------------------------------------------*/ 
  84. public function after_save_settings() { 
  85.  
  86.  
  87. /**-----------------------------------------------------------------------------------*/ 
  88. /** get_settings() 
  89. /** Get settings with function called from Admin Interface */ 
  90. /**-----------------------------------------------------------------------------------*/ 
  91. public function get_settings() { 
  92. global $wc_predictive_search_admin_interface; 
  93.  
  94. $wc_predictive_search_admin_interface->get_settings( $this->form_fields, $this->option_name ); 
  95.  
  96. /** 
  97. * subtab_data() 
  98. * Get SubTab Data 
  99. * ============================================= 
  100. * array (  
  101. * 'name' => 'my_subtab_name' : (required) Enter your subtab name that you want to set for this subtab 
  102. * 'label' => 'My SubTab Name' : (required) Enter the subtab label 
  103. * 'callback_function' => 'my_callback_function' : (required) The callback function is called to show content of this subtab 
  104. * ) 
  105. */ 
  106. public function subtab_data() { 
  107.  
  108. $subtab_data = array(  
  109. 'name' => 'performance-settings',  
  110. 'label' => __( 'Performance', 'woocommerce-predictive-search' ),  
  111. 'callback_function' => 'wc_predictive_search_performance_settings_form',  
  112. ); 
  113.  
  114. if ( $this->subtab_data ) return $this->subtab_data; 
  115. return $this->subtab_data = $subtab_data; 
  116.  
  117.  
  118. /**-----------------------------------------------------------------------------------*/ 
  119. /** add_subtab() */ 
  120. /** Add Subtab to Admin Init 
  121. /**-----------------------------------------------------------------------------------*/ 
  122. public function add_subtab( $subtabs_array ) { 
  123.  
  124. if ( ! is_array( $subtabs_array ) ) $subtabs_array = array(); 
  125. $subtabs_array[] = $this->subtab_data(); 
  126.  
  127. return $subtabs_array; 
  128.  
  129. /**-----------------------------------------------------------------------------------*/ 
  130. /** settings_form() */ 
  131. /** Call the form from Admin Interface 
  132. /**-----------------------------------------------------------------------------------*/ 
  133. public function settings_form() { 
  134. global $wc_predictive_search_admin_interface; 
  135.  
  136. $output = ''; 
  137. $output .= $wc_predictive_search_admin_interface->admin_forms( $this->form_fields, $this->form_key, $this->option_name, $this->form_messages ); 
  138.  
  139. return $output; 
  140.  
  141. /**-----------------------------------------------------------------------------------*/ 
  142. /** init_form_fields() */ 
  143. /** Init all fields of this form */ 
  144. /**-----------------------------------------------------------------------------------*/ 
  145. public function init_form_fields() { 
  146.  
  147. $sync_button_text = __( 'Start Sync', 'woocommerce-predictive-search' ); 
  148. $synced_full_data = false; 
  149. if ( isset( $_GET['page'] ) && 'woo-predictive-search' == $_GET['page'] && isset( $_GET['tab'] ) && $this->parent_tab == $_GET['tab'] ) { 
  150. if ( ! isset( $_SESSION ) ) { 
  151. @session_start(); 
  152.  
  153. global $wpdb, $wc_ps_product_sku_data; 
  154. $total_products = $wpdb->get_var( $wpdb->prepare( 'SELECT count(id) FROM '.$wpdb->posts.' WHERE post_type=%s AND post_status=%s', 'product', 'publish' ) ); 
  155. $total_products = ! empty( $total_products ) ? $total_products : 0; 
  156.  
  157. $total_skus = $wc_ps_product_sku_data->get_total_items_need_sync(); 
  158. $total_skus = ! empty( $total_skus ) ? $total_skus : 0; 
  159.  
  160. $all_posts = wp_count_posts( 'post' ); 
  161. $total_posts = isset( $all_posts->publish ) ? $all_posts->publish : 0; 
  162.  
  163. $all_pages = wp_count_posts( 'page' ); 
  164. $total_pages = isset( $all_pages->publish ) ? $all_pages->publish : 0; 
  165.  
  166. global $wc_ps_posts_data; 
  167. $current_products = $wc_ps_posts_data->get_total_items_synched( 'product' ); 
  168. $current_skus = $wc_ps_product_sku_data->get_total_items_synched(); 
  169. $current_posts = $wc_ps_posts_data->get_total_items_synched( 'post' ); 
  170. $current_pages = $wc_ps_posts_data->get_total_items_synched( 'page' ); 
  171.  
  172. $current_categories = 0; 
  173. $total_categories = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(t.term_id) FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy = %s ", 'product_cat' ) ); 
  174.  
  175. $current_tags = 0; 
  176. $total_tags = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(t.term_id) FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy = %s ", 'product_tag' ) ); 
  177.  
  178. $current_items = $current_products + $current_skus + $current_posts + $current_pages; 
  179. $total_items = $total_products + $total_skus + $total_posts + $total_pages; 
  180.  
  181. $had_sync_posts_data = get_option( 'wc_predictive_search_had_sync_posts_data', 0 ); 
  182.  
  183. if ( 0 == $had_sync_posts_data ) { 
  184. $synced_full_data = true; 
  185. update_option( 'wc_predictive_search_synced_posts_data', 1 ); 
  186. } elseif ( $current_items > 0 && $current_items < $total_items ) { 
  187. update_option( 'wc_predictive_search_synced_posts_data', 0 ); 
  188. $sync_button_text = __( 'Continue Sync', 'woocommerce-predictive-search' ); 
  189. } elseif ( $current_items >= $total_items ) { 
  190. $synced_full_data = true; 
  191. update_option( 'wc_predictive_search_synced_posts_data', 1 ); 
  192. $sync_button_text = __( 'Re Sync', 'woocommerce-predictive-search' ); 
  193.  
  194. // Define settings 
  195. $this->form_fields = apply_filters( $this->option_name . '_settings_fields', array( 
  196.  
  197. array( 
  198. 'name' => __( 'Manual Database Sync', 'woocommerce-predictive-search' ),  
  199. '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', 'woocommerce-predictive-search' ),  
  200. 'id' => 'predictive_search_synch_data',  
  201. 'type' => 'heading',  
  202. 'is_box' => true,  
  203. ),  
  204. array( 
  205. 'name' => __( 'Sync Search Data', 'woocommerce-predictive-search' ),  
  206. 'id' => 'woocommerce_search_sync_data',  
  207. 'type' => 'ajax_multi_submit',  
  208. 'statistic_column' => 2,  
  209. 'multi_submit' => array( 
  210. array( 
  211. 'item_id' => 'sync_products',  
  212. 'item_name' => __( 'Products Synced', 'woocommerce-predictive-search' ),  
  213. 'current_items' => ( ! empty( $current_products ) ) ? (int) $current_products : 0,  
  214. 'total_items' => ( ! empty( $total_products ) ) ? (int) $total_products : 0,  
  215. 'progressing_text' => __( 'Syncing Products...', 'woocommerce-predictive-search' ),  
  216. 'completed_text' => __( 'Synced Products', 'woocommerce-predictive-search' ),  
  217. 'submit_data' => array( 
  218. 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ),  
  219. 'ajax_type' => 'POST',  
  220. 'data' => array( 
  221. 'action' => 'wc_predictive_search_sync_products',  
  222. ),  
  223. 'show_statistic' => true,  
  224. 'statistic_customizer' => array( 
  225. 'current_color' => '#96587d',  
  226. ),  
  227. ),  
  228. array( 
  229. 'item_id' => 'sync_product_skus',  
  230. 'item_name' => __( 'Product SKUs Synced', 'woocommerce-predictive-search' ) . '</span><div style="color: red"><strong>'.__( 'PREMIUM', 'woocommerce-predictive-search' ).'</strong></div><span>',  
  231. 'current_items' => ( ! empty( $current_skus ) ) ? (int) $current_skus : 0,  
  232. 'total_items' => ( ! empty( $total_skus ) ) ? (int) $total_skus : 0,  
  233. 'progressing_text' => __( 'Syncing Product SKUs...', 'woocommerce-predictive-search' ),  
  234. 'completed_text' => __( 'Synced Product SKUs', 'woocommerce-predictive-search' ),  
  235. 'submit_data' => array( 
  236. 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ),  
  237. 'ajax_type' => 'POST',  
  238. 'data' => array( 
  239. 'action' => 'wc_predictive_search_sync_product_skus',  
  240. ),  
  241. 'show_statistic' => true,  
  242. 'statistic_customizer' => array( 
  243. 'current_color' => '#96587d',  
  244. ),  
  245. ),  
  246. array( 
  247. 'item_id' => 'sync_categories',  
  248. 'item_name' => __( 'Product Categories Synced', 'woocommerce-predictive-search' ) . '</span><div style="color: red"><strong>'.__( 'PREMIUM', 'woocommerce-predictive-search' ).'</strong></div><span>',  
  249. 'current_items' => ( ! empty( $current_categories ) ) ? (int) $current_categories : 0,  
  250. 'total_items' => ( ! empty( $total_categories ) ) ? (int) $total_categories : 0,  
  251. 'progressing_text' => __( 'Syncing Product Categories...', 'woocommerce-predictive-search' ),  
  252. 'completed_text' => __( 'Synced Product Categories', 'woocommerce-predictive-search' ),  
  253. 'submit_data' => array( 
  254. 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ),  
  255. 'ajax_type' => 'POST',  
  256. 'data' => array( 
  257. 'action' => 'wc_predictive_search_sync_categories',  
  258. ),  
  259. 'show_statistic' => true,  
  260. 'statistic_customizer' => array( 
  261. 'current_color' => '#96587d',  
  262. ),  
  263. ),  
  264. array( 
  265. 'item_id' => 'sync_tags',  
  266. 'item_name' => __( 'Product Tags Synced', 'woocommerce-predictive-search' ) . '</span><div style="color: red"><strong>'.__( 'PREMIUM', 'woocommerce-predictive-search' ).'</strong></div><span>',  
  267. 'current_items' => ( ! empty( $current_tags ) ) ? (int) $current_tags : 0,  
  268. 'total_items' => ( ! empty( $total_tags ) ) ? (int) $total_tags : 0,  
  269. 'progressing_text' => __( 'Syncing Product Tags...', 'woocommerce-predictive-search' ),  
  270. 'completed_text' => __( 'Synced Product Tags', 'woocommerce-predictive-search' ),  
  271. 'submit_data' => array( 
  272. 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ),  
  273. 'ajax_type' => 'POST',  
  274. 'data' => array( 
  275. 'action' => 'wc_predictive_search_sync_tags',  
  276. ),  
  277. 'show_statistic' => true,  
  278. 'statistic_customizer' => array( 
  279. 'current_color' => '#96587d',  
  280. ),  
  281. ),  
  282. array( 
  283. 'item_id' => 'sync_posts',  
  284. 'item_name' => __( 'Posts Synced', 'woocommerce-predictive-search' ),  
  285. 'current_items' => ( ! empty( $current_posts ) ) ? (int) $current_posts : 0,  
  286. 'total_items' => ( ! empty( $total_posts ) ) ? (int) $total_posts : 0,  
  287. 'progressing_text' => __( 'Syncing Posts...', 'woocommerce-predictive-search' ),  
  288. 'completed_text' => __( 'Synced Posts', 'woocommerce-predictive-search' ),  
  289. 'submit_data' => array( 
  290. 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ),  
  291. 'ajax_type' => 'POST',  
  292. 'data' => array( 
  293. 'action' => 'wc_predictive_search_sync_posts',  
  294. ),  
  295. 'show_statistic' => true,  
  296. 'statistic_customizer' => array( 
  297. 'current_color' => '#7ad03a',  
  298. ),  
  299. array( 
  300. 'item_id' => 'sync_pages',  
  301. 'item_name' => __( 'Pages Synced', 'woocommerce-predictive-search' ),  
  302. 'current_items' => ( ! empty( $current_pages ) ) ? (int) $current_pages : 0,  
  303. 'total_items' => ( ! empty( $total_pages ) ) ? (int) $total_pages : 0,  
  304. 'progressing_text' => __( 'Syncing Pages...', 'woocommerce-predictive-search' ),  
  305. 'completed_text' => __( 'Synced Pages', 'woocommerce-predictive-search' ),  
  306. 'submit_data' => array( 
  307. 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ),  
  308. 'ajax_type' => 'POST',  
  309. 'data' => array( 
  310. 'action' => 'wc_predictive_search_sync_pages',  
  311. ),  
  312. 'show_statistic' => true,  
  313. 'statistic_customizer' => array( 
  314. 'current_color' => '#0073aa',  
  315. ),  
  316. ),  
  317. 'separate_option' => true,  
  318. 'button_name' => $sync_button_text,  
  319. 'resubmit' => $synced_full_data,  
  320. 'progressing_text' => __( 'Syncing Data...', 'woocommerce-predictive-search' ),  
  321. 'completed_text' => __( 'Synced Data', 'woocommerce-predictive-search' ),  
  322. 'successed_text' => __( 'Synced Data', 'woocommerce-predictive-search' ),  
  323. ),  
  324.  
  325. array( 
  326. 'name' => __( 'Search Performance Settings', 'woocommerce-predictive-search' ),  
  327. 'type' => 'heading',  
  328. 'desc' => '<img class="rwd_image_maps" src="'.WOOPS_IMAGES_URL.'/premium-performance-settings.png" usemap="#performanceMap" style="width: auto; max-width: 100%;" border="0" /> 
  329. <map name="performanceMap" id="performanceMap"> 
  330. <area shape="rect" coords="410, 145, 925, 210" href="'.$this->pro_plugin_page_url.'" target="_blank" /> 
  331. </map>',  
  332. 'id' => 'predictive_search_performance_settings',  
  333. 'is_box' => true,  
  334. ),  
  335. )); 
  336.  
  337. public function include_script() { 
  338. ?> 
  339. <style type="text/css"> 
  340. .a3-ps-synched-products { 
  341. color: #96587d; 
  342. .a3-ps-synched-posts { 
  343. color: #7ad03a; 
  344. .a3-ps-synched-pages { 
  345. color: #0073aa; 
  346. </style> 
  347. <script> 
  348. (function($) { 
  349.  
  350. $(document).ready(function() { 
  351.  
  352. $(document).on( 'a3rev-ui-ajax_multi_submit-end', '#woocommerce_search_sync_data', function( event, bt_ajax_submit, multi_ajax ) { 
  353. bt_ajax_submit.html('<?php echo __( 'Re Sync', 'woocommerce-predictive-search' ); ?>'); 
  354. $('body').find('.wc_ps_sync_data_warning').slideUp('slow'); 
  355. $.ajax({ 
  356. type: 'POST',  
  357. url: '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',  
  358. data: { action: 'wc_predictive_search_sync_end' },  
  359. success: function ( response ) { 
  360. }); 
  361. }); 
  362.  
  363. }); 
  364.  
  365. })(jQuery); 
  366. </script> 
  367. <?php 
  368. wp_enqueue_script( 'jquery-rwd-image-maps' );