/includes/actions/recheck.php

  1. <?php 
  2.  
  3. if(!defined('GPI_DIRECTORY')) { 
  4. die(); 
  5.  
  6. function gpi_action_recheck_page($page_id, $page_report) { 
  7.  
  8. global $wpdb; 
  9. $gpi_page_stats = $wpdb->base_prefix . 'gpi_page_stats'; 
  10.  
  11. if(is_array($page_report) && !empty($page_report)) { 
  12.  
  13. // Build our where clauses for selecting URLs 
  14. $page_report_count = count($page_report); 
  15. $x = 1; 
  16. $where_clause = ''; 
  17. foreach($page_report as $page) 
  18. if($x < $page_report_count) { 
  19. $where_clause .= 'ID = ' . $page . ' OR '; 
  20. } else { 
  21. $where_clause .= 'ID = ' . $page; 
  22. $x++; 
  23.  
  24. // Set Force Recheck to 1 on selected URLs 
  25. $wpdb->query(" 
  26. UPDATE $gpi_page_stats SET force_recheck = 1 
  27. WHERE $where_clause 
  28. "); 
  29.  
  30. // Schedule the api to check pages immediately 
  31. $GPI_ListTable = new GPI_List_Table(); 
  32. $gpi_options = $GPI_ListTable->getOptions(); 
  33.  
  34. require_once GPI_DIRECTORY . '/core/core.php'; 
  35. $googlePagespeedInsights = new googlePagespeedInsights($gpi_options); 
  36.  
  37. $googlePagespeedInsights->google_pagespeed_insights_Update_Options('last_run_finished', false, 'gpagespeedi_options'); 
  38. wp_schedule_event( time(), 'gpi_lastrun_checker', 'googlepagespeedinsightschecker' ); 
  39.  
  40. $return_message = $page_report_count; 
  41.  
  42. } elseif(!empty($page_id)) { 
  43.  
  44. // Set Force Recheck to 1 on selected URL 
  45. $wpdb->query(" 
  46. UPDATE $gpi_page_stats SET force_recheck = 1 
  47. WHERE ID = $page_id 
  48. "); 
  49.  
  50. // Schedule the api to check pages immediately 
  51. $GPI_ListTable = new GPI_List_Table(); 
  52. $gpi_options = $GPI_ListTable->getOptions(); 
  53.  
  54. require_once GPI_DIRECTORY . '/core/core.php'; 
  55. $googlePagespeedInsights = new googlePagespeedInsights($gpi_options); 
  56.  
  57. $googlePagespeedInsights->google_pagespeed_insights_Update_Options('last_run_finished', false, 'gpagespeedi_options'); 
  58. wp_schedule_event( time(), 'gpi_lastrun_checker', 'googlepagespeedinsightschecker' ); 
  59.  
  60. $return_message = '1'; 
  61.  
  62. return $return_message; 
.