← All changes
|
jetpack_vendor/automattic/jetpack-post-list/src/class-post-list.php
+50
-53
13.3.3
→
16.3
View file →
| @@ -6,14 +6,18 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Post_List; |
| 9 | 9 | |
| 10 | +use Automattic\Jetpack\Assets; | |
| 11 | +use WP_Post; | |
| 12 | +use WP_Screen; | |
| 13 | + | |
| 10 | 14 | /** |
| 11 | 15 | * The Post_List Admin Area |
| 12 | 16 | */ |
| 13 | 17 | class Post_List { |
| 14 | 18 | |
| 15 | - const PACKAGE_VERSION = '0.6.1'; | |
| 19 | + const PACKAGE_VERSION = '0.10.4'; | |
| 16 | 20 | const FEATURE = 'enhanced_post_list'; |
| 17 | 21 | |
| 18 | 22 | /** |
| 19 | 23 | * The configuration method that is called from the jetpack-config package. |
| @@ -87,8 +91,18 @@ | ||
| 87 | 91 | 'jetpack_posts_list_ui_style', |
| 88 | 92 | 'rtl', |
| 89 | 93 | plugin_dir_url( __DIR__ ) . './src/rtl.css' |
| 90 | 94 | ); |
| 95 | + Assets::register_script( | |
| 96 | + 'jetpack_posts_list', | |
| 97 | + '../build/index.js', | |
| 98 | + __FILE__, | |
| 99 | + array( | |
| 100 | + 'in_footer' => true, | |
| 101 | + 'enqueue' => true, | |
| 102 | + 'textdomain' => 'jetpack-post-list', | |
| 103 | + ) | |
| 104 | + ); | |
| 91 | 105 | } |
| 92 | 106 | } |
| 93 | 107 | |
| 94 | 108 | /** |
| @@ -110,47 +124,55 @@ | ||
| 110 | 124 | } |
| 111 | 125 | } |
| 112 | 126 | |
| 113 | 127 | /** |
| 114 | - * Checks the current post type and adds the Share post | |
| 128 | + * If the current_screen has 'edit' as the base, add filters and actions to change the post list tables. | |
| 129 | + * | |
| 130 | + * @param object $current_screen The current screen. | |
| 131 | + */ | |
| 132 | + public function add_filters_and_actions_for_screen( $current_screen ) { | |
| 133 | + if ( 'edit' !== $current_screen->base ) { | |
| 134 | + return; | |
| 135 | + } | |
| 136 | + | |
| 137 | + $this->maybe_customize_columns( $current_screen->post_type ); | |
| 138 | + $this->maybe_add_copy_link_action( $current_screen->post_type ); | |
| 139 | + } | |
| 140 | + | |
| 141 | + /** | |
| 142 | + * Checks the current post type and adds the Copy link post | |
| 115 | 143 | * action if it is appropriate to do so. |
| 116 | 144 | * |
| 117 | 145 | * @param string $post_type The post type associated with the current request. |
| 118 | 146 | */ |
| 119 | - public function maybe_add_share_action( $post_type ) { | |
| 120 | - // Add Share action if post type supports 'publicize', uses the 'block editor', and the feature flag is true. | |
| 121 | - if ( | |
| 122 | - post_type_supports( $post_type, 'publicize' ) && | |
| 123 | - use_block_editor_for_post_type( $post_type ) && | |
| 124 | - /** | |
| 125 | - * Determine whether we should show the share action for this post type. | |
| 126 | - * The default is false. | |
| 127 | - * | |
| 128 | - * @since 0.2.0 | |
| 129 | - * | |
| 130 | - * @param boolean Whether we should show the share action for this post type. | |
| 131 | - * @param string The current post type. | |
| 132 | - */ | |
| 133 | - apply_filters( 'jetpack_post_list_display_share_action', false, $post_type ) | |
| 134 | - ) { | |
| 135 | - // Add Share post action. | |
| 136 | - add_filter( 'post_row_actions', array( $this, 'add_share_action' ), 20, 2 ); | |
| 137 | - add_filter( 'page_row_actions', array( $this, 'add_share_action' ), 20, 2 ); | |
| 147 | + public function maybe_add_copy_link_action( $post_type ) { | |
| 148 | + if ( ! is_post_type_viewable( $post_type ) ) { | |
| 149 | + return; | |
| 138 | 150 | } |
| 151 | + add_filter( 'post_row_actions', array( $this, 'add_copy_link_action' ), 20, 2 ); | |
| 152 | + add_filter( 'page_row_actions', array( $this, 'add_copy_link_action' ), 20, 2 ); | |
| 139 | 153 | } |
| 140 | 154 | |
| 141 | 155 | /** |
| 142 | - * If the current_screen has 'edit' as the base, add filters and actions to change the post list tables. | |
| 156 | + * Adds the Copy link post action which copies the post link to the clipboard. | |
| 143 | 157 | * |
| 144 | - * @param object $current_screen The current screen. | |
| 158 | + * @param array $post_actions The current array of post actions. | |
| 159 | + * @param WP_Post $post The current post in the post list table. | |
| 160 | + * | |
| 161 | + * @return array The modified post actions array. | |
| 145 | 162 | */ |
| 146 | - public function add_filters_and_actions_for_screen( $current_screen ) { | |
| 147 | - if ( 'edit' !== $current_screen->base ) { | |
| 148 | - return; | |
| 163 | + public function add_copy_link_action( $post_actions, $post ) { | |
| 164 | + if ( $post->post_status === 'trash' ) { | |
| 165 | + return $post_actions; | |
| 149 | 166 | } |
| 150 | 167 | |
| 151 | - $this->maybe_customize_columns( $current_screen->post_type ); | |
| 152 | - $this->maybe_add_share_action( $current_screen->post_type ); | |
| 168 | + $post_actions['copy-link'] = sprintf( | |
| 169 | + '<a href="%1$s" aria-label="%2$s" class="jetpack-post-list__copy-link-action">%3$s</a>', | |
| 170 | + esc_url( get_permalink( $post ) ), | |
| 171 | + esc_html__( 'Copy link to clipboard', 'jetpack-post-list' ), | |
| 172 | + esc_html__( 'Copy link', 'jetpack-post-list' ) | |
| 173 | + ); | |
| 174 | + return $post_actions; | |
| 153 | 175 | } |
| 154 | 176 | |
| 155 | 177 | /** |
| 156 | 178 | * Checks if the current quick edit save is for a post list |
| @@ -163,35 +185,10 @@ | ||
| 163 | 185 | // phpcs:disable WordPress.Security.NonceVerification.Missing |
| 164 | 186 | if ( ! empty( $_POST['screen'] ) && str_starts_with( sanitize_key( $_POST['screen'] ), 'edit-' ) && ! empty( $_POST['post_type'] ) ) { |
| 165 | 187 | $type = sanitize_key( $_POST['post_type'] ); |
| 166 | 188 | $this->maybe_customize_columns( $type ); |
| 167 | - $this->maybe_add_share_action( $type ); | |
| 168 | 189 | } |
| 169 | 190 | // phpcs:enable WordPress.Security.NonceVerification.Missing |
| 170 | - } | |
| 171 | - | |
| 172 | - /** | |
| 173 | - * Adds the Share post action which links to the editor with the sidebar open. | |
| 174 | - * | |
| 175 | - * @param array $post_actions The current array of post actions. | |
| 176 | - * @param WP_Post $post The current post in the post list table. | |
| 177 | - * | |
| 178 | - * @return array The modified post actions array. | |
| 179 | - */ | |
| 180 | - public function add_share_action( $post_actions, $post ) { | |
| 181 | - $edit_url = get_edit_post_link( $post->ID, 'raw' ); | |
| 182 | - if ( ! $edit_url ) { | |
| 183 | - // Do nothing since we do not have an edit URL to work with. | |
| 184 | - return $post_actions; | |
| 185 | - } | |
| 186 | - | |
| 187 | - $url = add_query_arg( 'jetpackSidebarIsOpen', 'true', $edit_url ); | |
| 188 | - $text = _x( 'Share', 'Share the post on social networks', 'jetpack-post-list' ); | |
| 189 | - $title = _draft_or_post_title( $post ); | |
| 190 | - /* translators: post title */ | |
| 191 | - $label = sprintf( __( 'Share “%s” via Jetpack Social', 'jetpack-post-list' ), $title ); | |
| 192 | - $post_actions['share'] = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), esc_html( $text ) ); | |
| 193 | - return $post_actions; | |
| 194 | 191 | } |
| 195 | 192 | |
| 196 | 193 | /** |
| 197 | 194 | * Adds a new column header for displaying the thumbnail of a post. |