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4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / jetpack_vendor / automattic / jetpack-post-list / src / class-post-list.php
jetpack / jetpack_vendor / automattic / jetpack-post-list / src Last commit date
class-post-list.php 4 weeks ago class-post-thumbnail.php 3 years ago rtl.css 9 months ago style.css 9 months ago
class-post-list.php
258 lines
1 <?php
2 /**
3 * The Post List Admin Area.
4 *
5 * @package automattic/jetpack-post-list
6 */
7
8 namespace Automattic\Jetpack\Post_List;
9
10 use Automattic\Jetpack\Assets;
11 use WP_Post;
12 use WP_Screen;
13
14 /**
15 * The Post_List Admin Area
16 */
17 class Post_List {
18
19 const PACKAGE_VERSION = '0.9.29';
20 const FEATURE = 'enhanced_post_list';
21
22 /**
23 * The configuration method that is called from the jetpack-config package.
24 *
25 * @return Post_List Post_List instance.
26 */
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() {
41 $post_list = self::get_instance();
42 $post_list->register();
43 return $post_list;
44 }
45
46 /**
47 * Initialize the Post List UI.
48 *
49 * @return Post_List Post_List instance.
50 */
51 public static function get_instance() {
52 return new Post_List();
53 }
54
55 /**
56 * Sets up Post List action callbacks.
57 */
58 public function register() {
59 if ( ! did_action( 'jetpack_on_posts_list_init' ) ) {
60 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
61 add_action( 'current_screen', array( $this, 'add_filters_and_actions_for_screen' ) );
62 add_filter( 'default_hidden_columns', array( $this, 'adjust_default_columns' ), 10, 2 );
63
64 if ( wp_doing_ajax() && ! empty( $_POST['action'] ) && 'inline-save' === $_POST['action'] && check_ajax_referer( 'inlineeditnonce', '_inline_edit' ) ) {
65 $this->add_filters_and_actions_quick_edit();
66 }
67
68 /**
69 * Action called after initializing Post_List Admin resources.
70 *
71 * @since 0.1.0
72 */
73 do_action( 'jetpack_on_posts_list_init' );
74 }
75 }
76
77 /**
78 * Enqueue scripts.
79 *
80 * @param string $hook Page hook.
81 */
82 public function enqueue_scripts( $hook ) {
83 if ( 'edit.php' === $hook ) {
84 wp_enqueue_style(
85 'jetpack_posts_list_ui_style',
86 plugin_dir_url( __DIR__ ) . './src/style.css',
87 array(),
88 self::PACKAGE_VERSION
89 );
90 wp_style_add_data(
91 'jetpack_posts_list_ui_style',
92 'rtl',
93 plugin_dir_url( __DIR__ ) . './src/rtl.css'
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 );
105 }
106 }
107
108 /**
109 * Checks the current post type and customizes the post
110 * list columns if it is appropriate to do so.
111 *
112 * @param string $post_type The post type associated with the current request.
113 */
114 public function maybe_customize_columns( $post_type ) {
115 // Add the thumbnail column if this is specifically "Posts" or "Pages".
116 if ( post_type_supports( $post_type, self::FEATURE ) ) {
117 // Add the thumbnail column to the "Posts" admin table.
118 add_filter( 'manage_posts_columns', array( $this, 'add_thumbnail_column' ), 10, 2 );
119 add_action( 'manage_posts_custom_column', array( $this, 'populate_thumbnail_rows' ), 10, 2 );
120
121 // Add the thumbnail column to the "Pages" admin table.
122 add_filter( 'manage_pages_columns', array( $this, 'add_thumbnail_column' ) );
123 add_action( 'manage_pages_custom_column', array( $this, 'populate_thumbnail_rows' ), 10, 2 );
124 }
125 }
126
127 /**
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
143 * action if it is appropriate to do so.
144 *
145 * @param string $post_type The post type associated with the current request.
146 */
147 public function maybe_add_copy_link_action( $post_type ) {
148 if ( ! is_post_type_viewable( $post_type ) ) {
149 return;
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 );
153 }
154
155 /**
156 * Adds the Copy link post action which copies the post link to the clipboard.
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_copy_link_action( $post_actions, $post ) {
164 if ( $post->post_status === 'trash' ) {
165 return $post_actions;
166 }
167
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;
175 }
176
177 /**
178 * Checks if the current quick edit save is for a post list
179 * where we want to customize the columns. If so, then we call
180 * the methods to register the actions.
181 */
182 public function add_filters_and_actions_quick_edit() {
183 // We've already verified the nonce in the register method above, and we're not performing
184 // any action on these POST arguments.
185 // phpcs:disable WordPress.Security.NonceVerification.Missing
186 if ( ! empty( $_POST['screen'] ) && str_starts_with( sanitize_key( $_POST['screen'] ), 'edit-' ) && ! empty( $_POST['post_type'] ) ) {
187 $type = sanitize_key( $_POST['post_type'] );
188 $this->maybe_customize_columns( $type );
189 }
190 // phpcs:enable WordPress.Security.NonceVerification.Missing
191 }
192
193 /**
194 * Adds a new column header for displaying the thumbnail of a post.
195 *
196 * @param array $columns An array of column names.
197 * @param string $post_type The post type being displayed in the post list. Defaults to 'page'.
198 * @return array An array of column names.
199 */
200 public function add_thumbnail_column( $columns, $post_type = 'page' ) {
201 if ( ! post_type_supports( $post_type, 'thumbnail' ) ) {
202 return $columns;
203 }
204
205 $new_column = array( 'thumbnail' => '<span>' . __( 'Thumbnail', 'jetpack-post-list' ) . '</span>' );
206 $keys = array_keys( $columns );
207 $position = array_search( 'title', $keys, true );
208
209 // If 'title' not found, don't insert the thumbnail column.
210 if ( false !== $position ) {
211 $columns = array_merge( array_slice( $columns, 0, $position ), $new_column, array_slice( $columns, $position ) );
212 }
213
214 return $columns;
215 }
216
217 /**
218 * Displays the thumbnail content.
219 *
220 * @param string $column The name of the column to display.
221 * @param int $post_id The current post ID.
222 */
223 public function populate_thumbnail_rows( $column, $post_id ) {
224 if ( 'thumbnail' !== $column ) {
225 return;
226 }
227
228 $thumbnail = Post_Thumbnail::get_post_thumbnail( get_post( $post_id ) );
229 if ( $thumbnail ) {
230 echo '<img src="' . esc_url( $thumbnail['thumb'] ) . '" alt="' . esc_attr( $thumbnail['alt'] ) . '" height="50" width="50" />';
231 } else {
232 echo '<span class="dashicons dashicons-format-image" title="No thumbnail found."></span>';
233 }
234 }
235
236 /**
237 * Removes the tags and columns from the posts and pages
238 * screens if the screen options haven't been changed from
239 * the default.
240 *
241 * @param array $cols The columns to hide.
242 * @param WP_Screen $screen The current screen object.
243 * @return array The columns to hide by default.
244 */
245 public function adjust_default_columns( $cols, $screen ) {
246 if ( ! ( 'edit' === $screen->base && post_type_supports( $screen->post_type, self::FEATURE ) ) ) {
247 return $cols;
248 }
249
250 $cols[] = 'tags';
251 if ( 'post' === $screen->post_type ) {
252 $cols[] = 'categories';
253 }
254
255 return $cols;
256 }
257 }
258