PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | jetpack_vendor/automattic/jetpack-post-list/src/class-post-list.php +69 -55 13.0.2 → 16.3 View file →
@@ -6,21 +6,42 @@
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.5.1';
19 + const PACKAGE_VERSION = '0.10.4';
20 + const FEATURE = 'enhanced_post_list';
16 21
17 22 /**
18 23 * The configuration method that is called from the jetpack-config package.
24 + *
25 + * @return Post_List Post_List instance.
19 26 */
20 27 public static function configure() {
28 + add_post_type_support( 'post', self::FEATURE );
29 + add_post_type_support( 'page', self::FEATURE );
30 + return self::setup();
31 + }
32 +
33 + /**
34 + * Convenience function to create an instance of the class and register the
35 + * filters and actions. It allows for the feature to be set up without adding
36 + * support for posts and pages.
37 + *
38 + * @return Post_List Post_List instance.
39 + */
40 + public static function setup() {
21 41 $post_list = self::get_instance();
22 42 $post_list->register();
43 + return $post_list;
23 44 }
24 45
25 46 /**
26 47 * Initialize the Post List UI.
@@ -70,8 +91,18 @@
70 91 'jetpack_posts_list_ui_style',
71 92 'rtl',
72 93 plugin_dir_url( __DIR__ ) . './src/rtl.css'
73 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 + );
74 105 }
75 106 }
76 107
77 108 /**
@@ -81,9 +112,9 @@
81 112 * @param string $post_type The post type associated with the current request.
82 113 */
83 114 public function maybe_customize_columns( $post_type ) {
84 115 // Add the thumbnail column if this is specifically "Posts" or "Pages".
85 - if ( in_array( $post_type, array( 'post', 'page' ), true ) ) {
116 + if ( post_type_supports( $post_type, self::FEATURE ) ) {
86 117 // Add the thumbnail column to the "Posts" admin table.
87 118 add_filter( 'manage_posts_columns', array( $this, 'add_thumbnail_column' ), 10, 2 );
88 119 add_action( 'manage_posts_custom_column', array( $this, 'populate_thumbnail_rows' ), 10, 2 );
89 120
@@ -93,47 +124,55 @@
93 124 }
94 125 }
95 126
96 127 /**
97 - * 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
98 143 * action if it is appropriate to do so.
99 144 *
100 145 * @param string $post_type The post type associated with the current request.
101 146 */
102 - public function maybe_add_share_action( $post_type ) {
103 - // Add Share action if post type supports 'publicize', uses the 'block editor', and the feature flag is true.
104 - if (
105 - post_type_supports( $post_type, 'publicize' ) &&
106 - use_block_editor_for_post_type( $post_type ) &&
107 - /**
108 - * Determine whether we should show the share action for this post type.
109 - * The default is false.
110 - *
111 - * @since 0.2.0
112 - *
113 - * @param boolean Whether we should show the share action for this post type.
114 - * @param string The current post type.
115 - */
116 - apply_filters( 'jetpack_post_list_display_share_action', false, $post_type )
117 - ) {
118 - // Add Share post action.
119 - add_filter( 'post_row_actions', array( $this, 'add_share_action' ), 20, 2 );
120 - 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;
121 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 );
122 153 }
123 154
124 155 /**
125 - * 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.
126 157 *
127 - * @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.
128 162 */
129 - public function add_filters_and_actions_for_screen( $current_screen ) {
130 - if ( 'edit' !== $current_screen->base ) {
131 - return;
163 + public function add_copy_link_action( $post_actions, $post ) {
164 + if ( $post->post_status === 'trash' ) {
165 + return $post_actions;
132 166 }
133 167
134 - $this->maybe_customize_columns( $current_screen->post_type );
135 - $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;
136 175 }
137 176
138 177 /**
139 178 * Checks if the current quick edit save is for a post list
@@ -146,38 +185,13 @@
146 185 // phpcs:disable WordPress.Security.NonceVerification.Missing
147 186 if ( ! empty( $_POST['screen'] ) && str_starts_with( sanitize_key( $_POST['screen'] ), 'edit-' ) && ! empty( $_POST['post_type'] ) ) {
148 187 $type = sanitize_key( $_POST['post_type'] );
149 188 $this->maybe_customize_columns( $type );
150 - $this->maybe_add_share_action( $type );
151 189 }
152 190 // phpcs:enable WordPress.Security.NonceVerification.Missing
153 191 }
154 192
155 193 /**
156 - * Adds the Share post action which links to the editor with the sidebar open.
157 - *
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.
162 - */
163 - public function add_share_action( $post_actions, $post ) {
164 - $edit_url = get_edit_post_link( $post->ID, 'raw' );
165 - if ( ! $edit_url ) {
166 - // Do nothing since we do not have an edit URL to work with.
167 - return $post_actions;
168 - }
169 -
170 - $url = add_query_arg( 'jetpackSidebarIsOpen', 'true', $edit_url );
171 - $text = _x( 'Share', 'Share the post on social networks', 'jetpack-post-list' );
172 - $title = _draft_or_post_title( $post );
173 - /* translators: post title */
174 - $label = sprintf( __( 'Share &#8220;%s&#8221; via Jetpack Social', 'jetpack-post-list' ), $title );
175 - $post_actions['share'] = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), esc_html( $text ) );
176 - return $post_actions;
177 - }
178 -
179 - /**
180 194 * Adds a new column header for displaying the thumbnail of a post.
181 195 *
182 196 * @param array $columns An array of column names.
183 197 * @param string $post_type The post type being displayed in the post list. Defaults to 'page'.
@@ -228,9 +242,9 @@
228 242 * @param WP_Screen $screen The current screen object.
229 243 * @return array The columns to hide by default.
230 244 */
231 245 public function adjust_default_columns( $cols, $screen ) {
232 - if ( ! ( 'edit' === $screen->base && in_array( $screen->post_type, array( 'post', 'page' ), true ) ) ) {
246 + if ( ! ( 'edit' === $screen->base && post_type_supports( $screen->post_type, self::FEATURE ) ) ) {
233 247 return $cols;
234 248 }
235 249
236 250 $cols[] = 'tags';