← All changes
|
jetpack_vendor/automattic/jetpack-videopress/src/class-admin-ui.php
+95
-10
16.2
→
16.3
View file →
| @@ -29,8 +29,17 @@ | ||
| 29 | 29 | |
| 30 | 30 | const ADMIN_PAGE_SLUG = 'jetpack-videopress'; |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | + * The name hosts use for the VideoPress sidebar item in the visibility filter. | |
| 34 | + * | |
| 35 | + * Deliberately not ADMIN_PAGE_SLUG: this is a name hosts write into their own code, so | |
| 36 | + * it has to survive a slug change. Both registrations below share it, since they are | |
| 37 | + * mutually exclusive and a host hiding VideoPress should not have to know which is live. | |
| 38 | + */ | |
| 39 | + const VISIBILITY_KEY = 'jetpack-videopress'; | |
| 40 | + | |
| 41 | + /** | |
| 33 | 42 | * The My Jetpack interstitial where VideoPress can be activated, relative to wp-admin. |
| 34 | 43 | * |
| 35 | 44 | * Used as the target of the "Jetpack > VideoPress" menu item when VideoPress |
| 36 | 45 | * is not active. |
| @@ -64,8 +73,15 @@ | ||
| 64 | 73 | */ |
| 65 | 74 | const CHAPTERS_EDITOR_ROUTE_PATHS = array( '/video/$id/editor' ); |
| 66 | 75 | |
| 67 | 76 | /** |
| 77 | + * The screen ID alias_screen_id_for_wp_build() replaced, until it is restored. | |
| 78 | + * | |
| 79 | + * @var string|null | |
| 80 | + */ | |
| 81 | + private static $wp_build_original_screen_id = null; | |
| 82 | + | |
| 83 | + /** | |
| 68 | 84 | * Initializes the Admin UI of VideoPress |
| 69 | 85 | * |
| 70 | 86 | * This method is called only once by the Initializer class |
| 71 | 87 | * |
| @@ -119,9 +135,9 @@ | ||
| 119 | 135 | if ( ! self::is_modernized() || ! self::is_videopress_admin_request() ) { |
| 120 | 136 | return; |
| 121 | 137 | } |
| 122 | 138 | |
| 123 | - self::load_wp_build(); | |
| 139 | + self::load_wp_build_with_screen_alias(); | |
| 124 | 140 | |
| 125 | 141 | // wp-build registers standalone modules (e.g. the init module) on |
| 126 | 142 | // wp_default_scripts, which has already fired by admin_menu. Register them |
| 127 | 143 | // directly so the init module makes it into the import map. |
| @@ -127,10 +143,8 @@ | ||
| 127 | 143 | // directly so the init module makes it into the import map. |
| 128 | 144 | if ( function_exists( 'jetpack_videopress_register_script_modules' ) ) { |
| 129 | 145 | jetpack_videopress_register_script_modules(); // @phan-suppress-current-line PhanUndeclaredFunction -- Checked with function_exists(); defined in the generated build/modules.php, which Phan excludes. |
| 130 | 146 | } |
| 131 | - | |
| 132 | - add_action( 'current_screen', array( __CLASS__, 'alias_screen_id_for_wp_build' ) ); | |
| 133 | 147 | } |
| 134 | 148 | |
| 135 | 149 | /** |
| 136 | 150 | * Select the dashboard render callback: the modernized wp-build render function |
| @@ -182,9 +196,14 @@ | ||
| 182 | 196 | 'Jetpack VideoPress', |
| 183 | 197 | 'VideoPress', |
| 184 | 198 | 'manage_options', |
| 185 | 199 | self::ADMIN_PAGE_SLUG, |
| 186 | - $callback | |
| 200 | + $callback, | |
| 201 | + null, | |
| 202 | + array( | |
| 203 | + 'product' => 'videopress', | |
| 204 | + 'key' => self::VISIBILITY_KEY, | |
| 205 | + ) | |
| 187 | 206 | ); |
| 188 | 207 | add_action( 'load-' . $page_suffix, array( __CLASS__, 'admin_init' ) ); |
| 189 | 208 | } |
| 190 | 209 | |
| @@ -239,9 +258,15 @@ | ||
| 239 | 258 | 'Jetpack VideoPress', |
| 240 | 259 | 'VideoPress', |
| 241 | 260 | 'manage_options', |
| 242 | 261 | self::MY_JETPACK_ADD_VIDEOPRESS_URI, |
| 243 | - null | |
| 262 | + null, | |
| 263 | + null, | |
| 264 | + // Hidden while VideoPress is off, unless a host forces the shared key visible. | |
| 265 | + array( | |
| 266 | + 'product' => 'videopress', | |
| 267 | + 'key' => self::VISIBILITY_KEY, | |
| 268 | + ) | |
| 244 | 269 | ); |
| 245 | 270 | } |
| 246 | 271 | |
| 247 | 272 | /** |
| @@ -722,8 +747,32 @@ | ||
| 722 | 747 | ); |
| 723 | 748 | } |
| 724 | 749 | |
| 725 | 750 | /** |
| 751 | + * Load wp-build with the screen ID aliased across its generated enqueue check. | |
| 752 | + * | |
| 753 | + * @see WP_Build_Screen_Id::load_with_alias() | |
| 754 | + * @return void | |
| 755 | + */ | |
| 756 | + private static function load_wp_build_with_screen_alias() { | |
| 757 | + // Fallback: an older wp-build-polyfills under the jetpack-autoloader may predate load_with_alias(). | |
| 758 | + if ( method_exists( \Automattic\Jetpack\WP_Build_Polyfills\WP_Build_Screen_Id::class, 'load_with_alias' ) ) { | |
| 759 | + \Automattic\Jetpack\WP_Build_Polyfills\WP_Build_Screen_Id::load_with_alias( | |
| 760 | + array( __CLASS__, 'alias_screen_id_for_wp_build' ), | |
| 761 | + array( __CLASS__, 'restore_screen_id_after_wp_build' ), | |
| 762 | + function () { | |
| 763 | + self::load_wp_build(); | |
| 764 | + } | |
| 765 | + ); | |
| 766 | + return; | |
| 767 | + } | |
| 768 | + | |
| 769 | + add_action( 'admin_enqueue_scripts', array( __CLASS__, 'alias_screen_id_for_wp_build' ) ); | |
| 770 | + self::load_wp_build(); | |
| 771 | + add_action( 'admin_enqueue_scripts', array( __CLASS__, 'restore_screen_id_after_wp_build' ) ); | |
| 772 | + } | |
| 773 | + | |
| 774 | + /** | |
| 726 | 775 | * Remove the chapters editor routes from the generated route registry when |
| 727 | 776 | * the chapters editor filter is off. |
| 728 | 777 | * |
| 729 | 778 | * The wp-build routes loader (`build/routes.php`) stores each page's route |
| @@ -739,9 +788,9 @@ | ||
| 739 | 788 | * |
| 740 | 789 | * @return void |
| 741 | 790 | */ |
| 742 | 791 | public static function maybe_strip_chapters_editor_routes() { |
| 743 | - if ( self::is_chapters_editor_enabled() ) { | |
| 792 | + if ( self::is_chapters_editor_enabled() || self::is_trim_cut_enabled() ) { | |
| 744 | 793 | return; |
| 745 | 794 | } |
| 746 | 795 | |
| 747 | 796 | $global_name = 'jetpack_videopress_jetpack_videopress_dashboard_routes_data'; |
| @@ -789,20 +838,40 @@ | ||
| 789 | 838 | * |
| 790 | 839 | * Hooked only when modernization is on AND we're on the VideoPress admin page, |
| 791 | 840 | * so this never affects any other request. |
| 792 | 841 | * |
| 793 | - * @param \WP_Screen|null $screen The current screen object (passed by WP). | |
| 842 | + * @since 0.51.1 Takes no argument; hooked on `admin_enqueue_scripts`. | |
| 843 | + * | |
| 794 | 844 | * @return void |
| 795 | 845 | */ |
| 796 | - public static function alias_screen_id_for_wp_build( $screen ) { | |
| 797 | - if ( ! is_object( $screen ) ) { | |
| 846 | + public static function alias_screen_id_for_wp_build() { | |
| 847 | + $screen = get_current_screen(); | |
| 848 | + if ( ! $screen ) { | |
| 798 | 849 | return; |
| 799 | 850 | } |
| 800 | 851 | |
| 801 | - $screen->id = 'jetpack-videopress-dashboard'; | |
| 852 | + self::$wp_build_original_screen_id = $screen->id; | |
| 853 | + $screen->id = 'jetpack-videopress-dashboard'; | |
| 802 | 854 | } |
| 803 | 855 | |
| 804 | 856 | /** |
| 857 | + * Undo alias_screen_id_for_wp_build(), so code after the generated check sees the real screen ID. | |
| 858 | + * | |
| 859 | + * @since 0.51.1 | |
| 860 | + * | |
| 861 | + * @return void | |
| 862 | + */ | |
| 863 | + public static function restore_screen_id_after_wp_build() { | |
| 864 | + $screen = get_current_screen(); | |
| 865 | + if ( ! $screen || null === self::$wp_build_original_screen_id ) { | |
| 866 | + return; | |
| 867 | + } | |
| 868 | + | |
| 869 | + $screen->id = self::$wp_build_original_screen_id; | |
| 870 | + self::$wp_build_original_screen_id = null; | |
| 871 | + } | |
| 872 | + | |
| 873 | + /** | |
| 805 | 874 | * Returns true when the wp-build modernization filter is enabled. |
| 806 | 875 | * |
| 807 | 876 | * @return bool |
| 808 | 877 | */ |
| @@ -807,8 +876,24 @@ | ||
| 807 | 876 | * @return bool |
| 808 | 877 | */ |
| 809 | 878 | public static function is_modernized() { |
| 810 | 879 | return (bool) apply_filters( self::MODERNIZATION_FILTER, true ); |
| 880 | + } | |
| 881 | + | |
| 882 | + /** | |
| 883 | + * Whether the trim and cut editor and its REST endpoints are available. | |
| 884 | + * | |
| 885 | + * @since 0.53.0 | |
| 886 | + * @return bool | |
| 887 | + */ | |
| 888 | + public static function is_trim_cut_enabled() { | |
| 889 | + /** | |
| 890 | + * Enable trim and cut after the video editing service is available for this site. | |
| 891 | + * | |
| 892 | + * @since 0.53.0 | |
| 893 | + * @param bool $enabled Whether trim and cut is enabled. Default false. | |
| 894 | + */ | |
| 895 | + return (bool) apply_filters( 'jetpack_videopress_trim_cut', false ); | |
| 811 | 896 | } |
| 812 | 897 | |
| 813 | 898 | /** |
| 814 | 899 | * Returns true when the chapters editor feature filter is enabled. |