VideoPress_CLI

VideoPress command line utilities.

Defined (1)

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

/modules/videopress/class.videopress-cli.php  
  1. class VideoPress_CLI extends WP_CLI_Command { 
  2. /** 
  3. * Import a VideoPress Video 
  4. * ## OPTIONS 
  5. * <guid>: Import the video with the specified guid 
  6. * ## EXAMPLES 
  7. * wp videopress import kUJmAcSf 
  8. */ 
  9. public function import( $args ) { 
  10. $guid = $args[0]; 
  11. $attachment_id = create_local_media_library_for_videopress_guid( $guid ); 
  12. if ( $attachment_id && ! is_wp_error( $attachment_id ) ) { 
  13. WP_CLI::success( sprintf( __( 'The video has been imported as Attachment ID %d', 'jetpack' ), $attachment_id ) ); 
  14. } else { 
  15. WP_CLI::error( __( 'An error has been encountered.', 'jetpack' ) ); 
  16.  
  17. /** 
  18. * Manually runs the job to cleanup videos from the media library that failed during the upload process. 
  19. * ## EXAMPLES 
  20. * wp videopress cleanup_videos 
  21. */ 
  22. public function cleanup_videos() { 
  23. $num_cleaned = videopress_cleanup_media_library(); 
  24.  
  25. WP_CLI::success( sprintf( _n( 'Cleaned up %d video.', 'Cleaned up a total of %d videos.', $num_cleaned, 'jetpack' ), $num_cleaned ) ); 
  26.  
  27. /** 
  28. * List out all of the crons that can be run. 
  29. * ## EXAMPLES 
  30. * wp videopress list_crons 
  31. */ 
  32. public function list_crons() { 
  33.  
  34. $scheduler = VideoPress_Scheduler::init(); 
  35. $crons = $scheduler->get_crons(); 
  36.  
  37. $schedules = wp_get_schedules(); 
  38.  
  39.  
  40. if ( count( $crons ) === 0 ) { 
  41. WP_CLI::success( __( 'Found no available cron jobs.', 'jetpack' ) ); 
  42.  
  43. } else { 
  44. WP_CLI::success( sprintf( _n( 'Found %d available cron job.', 'Found %d available cron jobs.', count( $crons ), 'jetpack' ), count( $crons ) ) ); 
  45.  
  46. foreach ( $crons as $cron_name => $cron ) { 
  47. $interval = isset( $schedules[ $cron['interval'] ]['display'] ) ? $schedules[ $cron['interval'] ]['display'] : $cron['interval']; 
  48. $runs_next = $scheduler->check_cron( $cron_name ); 
  49. $status = $runs_next ? sprintf( 'Scheduled - Runs Next at %s GMT', gmdate( 'Y-m-d H:i:s', $runs_next ) ) : 'Not Scheduled'; 
  50.  
  51. WP_CLI::log( 'Name: ' . $cron_name ); 
  52. WP_CLI::log( 'Method: ' . $cron['method'] ); 
  53. WP_CLI::log( 'Interval: ' . $interval ); 
  54. WP_CLI::log( 'Status: ' . $status ); 
  55.  
  56. /** 
  57. * Checks for the current status of a cron job. 
  58. * ## OPTIONS 
  59. * <cron_name>: The name of the cron job to check 
  60. * ## EXAMPLES 
  61. * wp videopress cron_status cleanup 
  62. */ 
  63. public function cron_status( $args ) { 
  64.  
  65. if ( ! isset( $args[0] ) ) { 
  66. return WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); 
  67.  
  68. $scheduler = VideoPress_Scheduler::init(); 
  69.  
  70. if ( ! $scheduler->is_cron_valid( $args[0] ) ) { 
  71. return WP_CLI::error( sprintf( __( 'There is no cron named %s.', 'jetpack' ), $args[0] ) ); 
  72.  
  73. $time = $scheduler->check_cron( $args[0] ); 
  74.  
  75. if ( ! $time ) { 
  76. WP_CLI::success( __( 'The cron is not scheduled to run.', 'jetpack' ) ); 
  77.  
  78. } else { 
  79. WP_CLI::success( sprintf( __( 'Cron will run at: %s GMT', 'jetpack' ), gmdate( 'Y-m-d H:i:s', $time ) ) ); 
  80.  
  81. /** 
  82. * Actives the given cron job 
  83. * ## OPTIONS 
  84. * <cron_name>: The name of the cron job to check 
  85. * ## EXAMPLES 
  86. * wp videopress activate_cron cleanup 
  87. */ 
  88. public function activate_cron( $args ) { 
  89.  
  90. if ( ! isset( $args[0] ) ) { 
  91. WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); 
  92.  
  93. $scheduler = VideoPress_Scheduler::init(); 
  94.  
  95. if ( ! $scheduler->is_cron_valid( $args[0] ) ) { 
  96. return WP_CLI::error( sprintf( __( 'There is no cron named %s.', 'jetpack' ), $args[0] ) ); 
  97.  
  98. $scheduler->activate_cron( $args[0] ); 
  99.  
  100. WP_CLI::success( sprintf( __( 'The cron named `%s` was scheduled.', 'jetpack' ), $args[0] ) ); 
  101.  
  102. /** 
  103. * Actives the given cron job 
  104. * ## OPTIONS 
  105. * <cron_name>: The name of the cron job to check 
  106. * ## EXAMPLES 
  107. * wp videopress deactivate_cron cleanup 
  108. */ 
  109. public function deactivate_cron( $args ) { 
  110.  
  111. if ( ! isset( $args[0] ) ) { 
  112. WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); 
  113.  
  114. $scheduler = VideoPress_Scheduler::init(); 
  115.  
  116. if ( ! $scheduler->is_cron_valid( $args[0] ) ) { 
  117. return WP_CLI::error( sprintf( __( 'There is no cron named %s.', 'jetpack' ), $args[0] ) ); 
  118.  
  119. $scheduler->deactivate_cron( $args[0] ); 
  120.  
  121. WP_CLI::success( sprintf( __( 'The cron named `%s` was removed from the schedule.', 'jetpack' ), $args[0] ) );