css
8 years ago
js
6 years ago
class.jetpack-videopress.php
6 years ago
class.videopress-ajax.php
6 years ago
class.videopress-cli.php
7 years ago
class.videopress-edit-attachment.php
6 years ago
class.videopress-gutenberg.php
6 years ago
class.videopress-options.php
7 years ago
class.videopress-player.php
6 years ago
class.videopress-scheduler.php
7 years ago
class.videopress-video.php
6 years ago
class.videopress-xmlrpc.php
7 years ago
editor-media-view.php
6 years ago
shortcode.php
6 years ago
utility-functions.php
6 years ago
videopress-admin-rtl.css
7 years ago
videopress-admin-rtl.min.css
7 years ago
videopress-admin.css
9 years ago
videopress-admin.min.css
7 years ago
class.videopress-cli.php
168 lines
| 1 | <?php |
| 2 | |
| 3 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 4 | |
| 5 | /** |
| 6 | * VideoPress command line utilities. |
| 7 | */ |
| 8 | class VideoPress_CLI extends WP_CLI_Command { |
| 9 | /** |
| 10 | * Import a VideoPress Video |
| 11 | * |
| 12 | * ## OPTIONS |
| 13 | * |
| 14 | * <guid>: Import the video with the specified guid |
| 15 | * |
| 16 | * ## EXAMPLES |
| 17 | * |
| 18 | * wp videopress import kUJmAcSf |
| 19 | */ |
| 20 | public function import( $args ) { |
| 21 | $guid = $args[0]; |
| 22 | $attachment_id = create_local_media_library_for_videopress_guid( $guid ); |
| 23 | if ( $attachment_id && ! is_wp_error( $attachment_id ) ) { |
| 24 | WP_CLI::success( sprintf( __( 'The video has been imported as Attachment ID %d', 'jetpack' ), $attachment_id ) ); |
| 25 | } else { |
| 26 | WP_CLI::error( __( 'An error has been encountered.', 'jetpack' ) ); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Manually runs the job to cleanup videos from the media library that failed during the upload process. |
| 32 | * |
| 33 | * ## EXAMPLES |
| 34 | * |
| 35 | * wp videopress cleanup_videos |
| 36 | */ |
| 37 | public function cleanup_videos() { |
| 38 | $num_cleaned = videopress_cleanup_media_library(); |
| 39 | |
| 40 | WP_CLI::success( sprintf( _n( 'Cleaned up %d video.', 'Cleaned up a total of %d videos.', $num_cleaned, 'jetpack' ), $num_cleaned ) ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * List out all of the crons that can be run. |
| 45 | * |
| 46 | * ## EXAMPLES |
| 47 | * |
| 48 | * wp videopress list_crons |
| 49 | */ |
| 50 | public function list_crons() { |
| 51 | |
| 52 | $scheduler = VideoPress_Scheduler::init(); |
| 53 | $crons = $scheduler->get_crons(); |
| 54 | |
| 55 | $schedules = wp_get_schedules(); |
| 56 | |
| 57 | if ( count( $crons ) === 0 ) { |
| 58 | WP_CLI::success( __( 'Found no available cron jobs.', 'jetpack' ) ); |
| 59 | |
| 60 | } else { |
| 61 | WP_CLI::success( sprintf( _n( 'Found %d available cron job.', 'Found %d available cron jobs.', count( $crons ), 'jetpack' ), count( $crons ) ) ); |
| 62 | } |
| 63 | |
| 64 | foreach ( $crons as $cron_name => $cron ) { |
| 65 | $interval = isset( $schedules[ $cron['interval'] ]['display'] ) ? $schedules[ $cron['interval'] ]['display'] : $cron['interval']; |
| 66 | $runs_next = $scheduler->check_cron( $cron_name ); |
| 67 | $status = $runs_next ? sprintf( 'Scheduled - Runs Next at %s GMT', gmdate( 'Y-m-d H:i:s', $runs_next ) ) : 'Not Scheduled'; |
| 68 | |
| 69 | WP_CLI::log( 'Name: ' . $cron_name ); |
| 70 | WP_CLI::log( 'Method: ' . $cron['method'] ); |
| 71 | WP_CLI::log( 'Interval: ' . $interval ); |
| 72 | WP_CLI::log( 'Status: ' . $status ); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Checks for the current status of a cron job. |
| 78 | * |
| 79 | * ## OPTIONS |
| 80 | * |
| 81 | * <cron_name>: The name of the cron job to check |
| 82 | * |
| 83 | * ## EXAMPLES |
| 84 | * |
| 85 | * wp videopress cron_status cleanup |
| 86 | */ |
| 87 | public function cron_status( $args ) { |
| 88 | |
| 89 | if ( ! isset( $args[0] ) ) { |
| 90 | return WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); |
| 91 | } |
| 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 | |
| 99 | $time = $scheduler->check_cron( $args[0] ); |
| 100 | |
| 101 | if ( ! $time ) { |
| 102 | WP_CLI::success( __( 'The cron is not scheduled to run.', 'jetpack' ) ); |
| 103 | |
| 104 | } else { |
| 105 | WP_CLI::success( sprintf( __( 'Cron will run at: %s GMT', 'jetpack' ), gmdate( 'Y-m-d H:i:s', $time ) ) ); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Actives the given cron job |
| 111 | * |
| 112 | * ## OPTIONS |
| 113 | * |
| 114 | * <cron_name>: The name of the cron job to check |
| 115 | * |
| 116 | * ## EXAMPLES |
| 117 | * |
| 118 | * wp videopress activate_cron cleanup |
| 119 | */ |
| 120 | public function activate_cron( $args ) { |
| 121 | |
| 122 | if ( ! isset( $args[0] ) ) { |
| 123 | WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); |
| 124 | } |
| 125 | |
| 126 | $scheduler = VideoPress_Scheduler::init(); |
| 127 | |
| 128 | if ( ! $scheduler->is_cron_valid( $args[0] ) ) { |
| 129 | return WP_CLI::error( sprintf( __( 'There is no cron named %s.', 'jetpack' ), $args[0] ) ); |
| 130 | } |
| 131 | |
| 132 | $scheduler->activate_cron( $args[0] ); |
| 133 | |
| 134 | WP_CLI::success( sprintf( __( 'The cron named `%s` was scheduled.', 'jetpack' ), $args[0] ) ); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Actives the given cron job |
| 139 | * |
| 140 | * ## OPTIONS |
| 141 | * |
| 142 | * <cron_name>: The name of the cron job to check |
| 143 | * |
| 144 | * ## EXAMPLES |
| 145 | * |
| 146 | * wp videopress deactivate_cron cleanup |
| 147 | */ |
| 148 | public function deactivate_cron( $args ) { |
| 149 | |
| 150 | if ( ! isset( $args[0] ) ) { |
| 151 | WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); |
| 152 | } |
| 153 | |
| 154 | $scheduler = VideoPress_Scheduler::init(); |
| 155 | |
| 156 | if ( ! $scheduler->is_cron_valid( $args[0] ) ) { |
| 157 | return WP_CLI::error( sprintf( __( 'There is no cron named %s.', 'jetpack' ), $args[0] ) ); |
| 158 | } |
| 159 | |
| 160 | $scheduler->deactivate_cron( $args[0] ); |
| 161 | |
| 162 | WP_CLI::success( sprintf( __( 'The cron named `%s` was removed from the schedule.', 'jetpack' ), $args[0] ) ); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | WP_CLI::add_command( 'videopress', 'VideoPress_CLI' ); |
| 167 | } |
| 168 |