PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/backupbuddy/controllers/pages/server_info/cron.php

https://gitlab.com/mattswann/launch-housing
PHP | 157 lines | 114 code | 32 blank | 11 comment | 16 complexity | cd71c361af8bfff32120aa1621bcc64a MD5 | raw file
  1. All scheduled WordPress tasks (CRON jobs) are listed below. Use caution when manually running or deleting scheduled CRON
  2. jobs as plugins, themes, or WordPress itself may expect these to remain in place. WordPress will recreate any mandatory
  3. internal CRON jobs automatically if they are removed.<br><br>
  4. <?php
  5. $cron = get_option('cron');
  6. // Handle CRON deletions.
  7. if ( pb_backupbuddy::_POST( 'bulk_action' ) == 'delete_cron' ) {
  8. if ( defined( 'PB_DEMO_MODE' ) ) {
  9. pb_backupbuddy::alert( 'Access denied in demo mode.', true );
  10. } else {
  11. $delete_items = pb_backupbuddy::_POST( 'items' );
  12. $deleted_crons = array(); // For listing in alert.
  13. foreach( $delete_items as $delete_item ) {
  14. $cron_parts = explode( '|', $delete_item );
  15. $timestamp = $cron_parts[0];
  16. $cron_hook = $cron_parts[1];
  17. $cron_key = $cron_parts[2];
  18. if ( isset( $cron[ $timestamp ][ $cron_hook ][ $cron_key ] ) ) { // Run cron.
  19. $cron_array = $cron[ $timestamp ][ $cron_hook ][ $cron_key ]; // Get cron array based on passed values.
  20. $result = backupbuddy_core::unschedule_event( $timestamp, $cron_hook, $cron_array['args'] ); // Delete the scheduled cron.
  21. if ( $result === FALSE ) {
  22. pb_backupbuddy::alert( 'Error #5657667675. Unable to delete CRON job. Please see your BackupBuddy error log for details.' );
  23. }
  24. $deleted_crons[] = $cron_hook . ' / ' . $cron_key; // Add deleted cron to list of deletions for display.
  25. } else { // Cron not found, error.
  26. pb_backupbuddy::alert( 'Invalid CRON job. Not found.', true );
  27. }
  28. }
  29. pb_backupbuddy::alert( __('Deleted scheduled CRON event(s):', 'it-l10n-backupbuddy' ) . '<br>' . implode( '<br>', $deleted_crons ) );
  30. $cron = get_option('cron'); // Reset to most up to date status for cron listing below. Takes into account deletions.
  31. }
  32. }
  33. // Handle RUNNING cron jobs manually.
  34. if ( !empty( $_GET['run_cron'] ) ) {
  35. if ( defined( 'PB_DEMO_MODE' ) ) {
  36. pb_backupbuddy::alert( 'Access denied in demo mode.', true );
  37. } else {
  38. $cron_parts = explode( '|', pb_backupbuddy::_GET( 'run_cron' ) );
  39. $timestamp = $cron_parts[0];
  40. $cron_hook = $cron_parts[1];
  41. $cron_key = $cron_parts[2];
  42. if ( isset( $cron[ $timestamp ][ $cron_hook ][ $cron_key ] ) ) { // Run cron.
  43. $cron_array = $cron[ $timestamp ][ $cron_hook ][ $cron_key ]; // Get cron array based on passed values.
  44. /*
  45. if ( count( $cron_array['args'] ) == 1 ) {
  46. $args = $cron_array['args'][0];
  47. } else {
  48. $args = $cron_array['args'];
  49. }
  50. */
  51. do_action_ref_array( $cron_hook, $cron_array['args'] ); // Run the cron job!
  52. pb_backupbuddy::alert( 'Ran CRON event `' . $cron_hook . ' / ' . $cron_key . '`. Its schedule was not modified.' );
  53. } else { // Cron not found, error.
  54. pb_backupbuddy::alert( 'Invalid CRON job. Not found.', true );
  55. }
  56. }
  57. }
  58. include( '_cron.php' );
  59. // Display CRON table.
  60. pb_backupbuddy::$ui->list_table(
  61. $crons, // Array of cron items set in code section above.
  62. array(
  63. 'action' => pb_backupbuddy::page_url() . '#pb_backupbuddy_getting_started_tab_tools',
  64. 'columns' => array(
  65. __( 'Scheduled Events', 'it-l10n-backupbuddy' ),
  66. __( 'Next Run', 'it-l10n-backupbuddy' ),
  67. __( 'Period', 'it-l10n-backupbuddy' ),
  68. __( 'Interval', 'it-l10n-backupbuddy' ),
  69. __( 'Arguments', 'it-l10n-backupbuddy' ),
  70. ),
  71. 'css' => 'width: 100%;',
  72. 'hover_actions' => array(
  73. 'run_cron' => 'Run cron job now',
  74. ),
  75. 'bulk_actions' => array( 'delete_cron' => 'Delete' ),
  76. 'hover_action_column_key' => '0',
  77. )
  78. );
  79. echo '<br><br>';
  80. // Display time intervals table.
  81. $pretty_intervals = array();
  82. $schedule_intervals = wp_get_schedules();
  83. foreach( $schedule_intervals as $interval_tag => $schedule_interval ) {
  84. $pretty_intervals[ $schedule_interval['interval'] ] = array(
  85. $schedule_interval['display'],
  86. $interval_tag,
  87. $schedule_interval['interval'],
  88. );
  89. }
  90. ksort( $pretty_intervals );
  91. pb_backupbuddy::$ui->list_table(
  92. $pretty_intervals, // Array of cron items set in code section above.
  93. array(
  94. 'columns' => array(
  95. __( 'Schedule Periods', 'it-l10n-backupbuddy' ),
  96. __( 'Tag', 'it-l10n-backupbuddy' ),
  97. __( 'Interval', 'it-l10n-backupbuddy' ),
  98. ),
  99. 'css' => 'width: 100%;',
  100. )
  101. );
  102. echo '<br><br>';
  103. echo '<center>' . __('Current Time', 'it-l10n-backupbuddy' ) . ': ' . pb_backupbuddy::$format->date( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) . ' (' . time() . ')</center>';
  104. if ( empty( $_GET['show_cron_array'] ) ) {
  105. ?>
  106. <p>
  107. <center>
  108. <a href="<?php echo pb_backupbuddy::page_url(); ?>&tab=3&show_cron_array=true#pb_backupbuddy_getting_started_tab_tools" style="text-decoration: none;">
  109. <?php _e('Display CRON Debugging Array', 'it-l10n-backupbuddy' ); ?>
  110. </a>
  111. </center>
  112. </p>
  113. <?php
  114. } else {
  115. echo '<br><textarea readonly="readonly" style="width: 793px;" rows="13" cols="75" wrap="off">';
  116. print_r( $cron );
  117. echo '</textarea><br><br>';
  118. }
  119. unset( $cron );
  120. ?>
  121. <br>
  122. <div class="description">
  123. <b>Note</b>: Due to the way schedules are triggered in WordPress your site must be accessed (frontend or admin area) for scheduled backups to occur.
  124. WordPress scheduled events ("crons") may be viewed or run manually in the table above</a>. A <a href="https://www.google.com/search?q=free+website+uptime&oq=free+website+uptime" target="_blank">free website uptime</a> service or <a href="https://ithemes.com/sync-pro/uptime-monitoring/" target="_blank">iThemes Sync Pro's Uptime Monitoring</a> can be used to automatically access your site regularly to help trigger scheduled actions ("crons") in cases of low site activity, with the added perk of keeping track of your site uptime.
  125. </div>