diff options
author | Yury German <blueknight@gentoo.org> | 2022-01-23 18:37:36 -0500 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2022-01-23 18:37:36 -0500 |
commit | f18b23a3a9378fb0a98856d436aa9ebf94e47429 (patch) | |
tree | e418433e22854ebd2d77eaa869d5d0470a973317 /plugins/jetpack/modules/videopress/class.jetpack-videopress.php | |
parent | Add classic-editor 1.5 (diff) | |
download | blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.gz blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.bz2 blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.zip |
Updating Classic Editor, Google Authenticatior, Jetpack, Public Post Preview, Table of Contents, Wordpress Importer
Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/jetpack/modules/videopress/class.jetpack-videopress.php')
-rw-r--r-- | plugins/jetpack/modules/videopress/class.jetpack-videopress.php | 130 |
1 files changed, 108 insertions, 22 deletions
diff --git a/plugins/jetpack/modules/videopress/class.jetpack-videopress.php b/plugins/jetpack/modules/videopress/class.jetpack-videopress.php index 5b73dde6..0d02cbe0 100644 --- a/plugins/jetpack/modules/videopress/class.jetpack-videopress.php +++ b/plugins/jetpack/modules/videopress/class.jetpack-videopress.php @@ -1,6 +1,7 @@ <?php use Automattic\Jetpack\Assets; +use Automattic\Jetpack\Connection\Client; /** * VideoPress in Jetpack @@ -42,7 +43,8 @@ class Jetpack_VideoPress { public function on_init() { add_action( 'wp_enqueue_media', array( $this, 'enqueue_admin_scripts' ) ); add_filter( 'plupload_default_settings', array( $this, 'videopress_pluploder_config' ) ); - add_filter( 'wp_get_attachment_url', array( $this, 'update_attachment_url_for_videopress' ), 10, 2 ); + add_filter( 'wp_get_attachment_url', array( $this, 'maybe_get_attached_url_for_videopress' ), 10, 2 ); + add_filter( 'get_attached_file', array( $this, 'maybe_get_attached_url_for_videopress' ), 10, 2 ); if ( Jetpack_Plan::supports( 'videopress' ) ) { add_filter( 'upload_mimes', array( $this, 'add_video_upload_mimes' ), 999 ); @@ -51,12 +53,43 @@ class Jetpack_VideoPress { add_action( 'admin_print_footer_scripts', array( $this, 'print_in_footer_open_media_add_new' ) ); add_action( 'admin_head', array( $this, 'enqueue_admin_styles' ) ); + add_filter( 'pre_delete_attachment', array( $this, 'delete_video_wpcom' ), 10, 2 ); add_filter( 'wp_mime_type_icon', array( $this, 'wp_mime_type_icon' ), 10, 3 ); - add_filter( 'wp_video_extensions', array( $this, 'add_videopress_extenstion' ) ); VideoPress_Scheduler::init(); VideoPress_XMLRPC::init(); + + if ( $this->is_videopress_enabled() ) { + add_action( 'admin_notices', array( $this, 'media_new_page_admin_notice' ) ); + } + } + + /** + * The media-new.php page isn't supported for uploading to VideoPress. + * + * There is either a technical reason for this (bulk uploader isn't overridable), + * or it is an intentional way to give site owners an option for uploading videos that bypass VideoPress. + */ + public function media_new_page_admin_notice() { + global $pagenow; + + if ( 'media-new.php' === $pagenow ) { + echo '<div class="notice notice-warning is-dismissible">' . + '<p>' . + wp_kses( + sprintf( + /* translators: %s is the url to the Media Library */ + __( 'VideoPress uploads are not supported here. To upload to VideoPress, add your videos from the <a href="%s">Media Library</a> or the block editor using the Video block.', 'jetpack' ), + esc_url( admin_url( 'upload.php' ) ) + ), + array( + 'a' => array( 'href' => array() ), + ) + ) . + '</p>' . + '</div>'; + } } /** @@ -99,24 +132,68 @@ class Jetpack_VideoPress { } /** - * Returns true if the provided user is the Jetpack connection owner. + * Register and enqueue VideoPress admin styles. + */ + public function enqueue_admin_styles() { + wp_register_style( 'videopress-admin', plugins_url( 'videopress-admin.css', __FILE__ ), array(), $this->version ); + wp_enqueue_style( 'videopress-admin' ); + } + + /** + * Attempts to delete a VideoPress video from wp.com. + * Will block the deletion from continuing if certain errors return from the wp.com API. * - * @deprecated since 7.7 + * @param Boolean $delete if the deletion should occur or not (unused). + * @param WP_Post $post the post object. * - * @param Integer|Boolean $user_id the user identifier. False for current user. - * @return bool Whether the current user is the connection owner. + * @return null|WP_Error|Boolean null if deletion should continue. */ - public function is_connection_owner( $user_id = false ) { - _deprecated_function( __METHOD__, 'jetpack-7.7', 'Automattic\\Jetpack\\Connection\\Manager::is_connection_owner' ); - return Jetpack::connection()->is_connection_owner( $user_id ); + public function delete_video_wpcom( $delete, $post ) { + if ( ! is_videopress_attachment( $post->ID ) ) { + return null; + } + + $guid = get_post_meta( $post->ID, 'videopress_guid', true ); + if ( empty( $guid ) ) { + $this->delete_video_poster_attachment( $post->ID ); + return null; + } + + // Phone home and have wp.com delete the VideoPress entry and files. + $wpcom_response = Client::wpcom_json_api_request_as_blog( + sprintf( '/videos/%s/delete', $guid ), + '1.1', + array( 'method' => 'POST' ) + ); + + if ( is_wp_error( $wpcom_response ) ) { + return $wpcom_response; + } + + // Upon success or a 404 (video already deleted on wp.com), return null to allow the deletion to continue. + if ( 200 === $wpcom_response['response']['code'] || 404 === $wpcom_response['response']['code'] ) { + $this->delete_video_poster_attachment( $post->ID ); + return null; + } + + // Otherwise we stop the deletion from proceeding. + return false; } /** - * Register and enqueue VideoPress admin styles. + * Deletes a video poster attachment if it exists. + * + * @param int $attachment_id the WP attachment id. */ - public function enqueue_admin_styles() { - wp_register_style( 'videopress-admin', plugins_url( 'videopress-admin.css', __FILE__ ), array(), $this->version ); - wp_enqueue_style( 'videopress-admin' ); + private function delete_video_poster_attachment( $attachment_id ) { + $thumbnail_id = get_post_meta( $attachment_id, '_thumbnail_id', true ); + if ( ! empty( $thumbnail_id ) ) { + // Let's ensure this is a VP poster image before we delete it. + if ( '1' === get_post_meta( $thumbnail_id, 'videopress_poster_image', true ) ) { + // This call triggers the `delete_video_wpcom` filter again but it bails early at the is_videopress_attachment() check. + wp_delete_attachment( $thumbnail_id ); + } + } } /** @@ -174,21 +251,21 @@ class Jetpack_VideoPress { } /** - * An override for the attachment url, which returns back the WPCOM VideoPress processed url. - * - * This is an action proxy to the videopress_get_attachment_url() utility function. + * Returns the VideoPress URL for the give post id, otherwise returns the provided default. * - * @param string $url - * @param int $post_id + * This is an attachment-based filter handler. * - * @return string + * @param string $default The default return value if post id is not a VideoPress video. + * @param int $post_id The post id for the current attachment. */ - public function update_attachment_url_for_videopress( $url, $post_id ) { - if ( $videopress_url = videopress_get_attachment_url( $post_id ) ) { + public function maybe_get_attached_url_for_videopress( $default, $post_id ) { + $videopress_url = videopress_get_attachment_url( $post_id ); + + if ( null !== $videopress_url ) { return $videopress_url; } - return $url; + return $default; } /** @@ -236,6 +313,15 @@ class Jetpack_VideoPress { return false; } + return $this->is_videopress_enabled(); + } + + /** + * Detects if VideoPress is enabled. + * + * @return bool + */ + protected function is_videopress_enabled() { $options = VideoPress_Options::get_options(); return $options['shadow_blog_id'] > 0; |