PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.5
Jetpack – WP Security, Backup, Speed, & Growth v12.5
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 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / custom-post-types / comics.php

comics.php in Jetpack – WP Security, Backup, Speed, & Growth 12.5, at modules/custom-post-types/comics.php

735 lines 22.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Create and manage comics with this Custom Post Type.
4 *
5 * @package automattic/jetpack
6 */
7
8 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
9
10 use Automattic\Jetpack\Assets;
11
12 /**
13 * Create a jetpack-comic CPT.
14 */
15 class Jetpack_Comic {
16 const POST_TYPE = 'jetpack-comic';
17
18 /**
19 * Initialize the class.
20 *
21 * @return self
22 */
23 public static function init() {
24 static $instance = false;
25
26 if ( ! $instance ) {
27 $instance = new Jetpack_Comic();
28 }
29
30 return $instance;
31 }
32
33 /**
34 * Conditionally hook into WordPress.
35 *
36 * Themes must declare that they support this module by adding
37 * add_theme_support( 'jetpack-comic' ); during after_setup_theme.
38 *
39 * If no theme support is found there is no need to hook into
40 * WordPress. We'll just return early instead.
41 */
42 public function __construct() {
43 // Make sure the post types are loaded for imports
44 add_action( 'import_start', array( $this, 'register_post_types' ) );
45
46 // Add to REST API post type allowed list.
47 add_filter( 'rest_api_allowed_post_types', array( $this, 'allow_rest_api_type' ) );
48
49 // If called via REST API, we need to register later in lifecycle
50 add_action( 'restapi_theme_init', array( $this, 'maybe_register_post_types' ) );
51
52 // Return early if theme does not support Jetpack Comic.
53 if ( ! ( $this->site_supports_comics() ) ) {
54 return;
55 }
56
57 $this->register_post_types();
58
59 add_action( 'pre_get_posts', array( $this, 'add_posts_to_loop' ) );
60
61 // In order for the Feedbag job to find Comic posts, we need to circumvent any pretty
62 // URLs in the RSS feed given to Feedbag in favor of /?p=123&post_type=jetpack-comic
63 add_filter( 'the_permalink_rss', array( $this, 'custom_permalink_for_feedbag' ) );
64
65 // There are some cases (like when Feedbag is fetching posts) that the comics
66 // post type needs to be registered no matter what, but none of the UI needs to be
67 // available.
68
69 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
70
71 if ( function_exists( 'queue_publish_post' ) ) {
72 add_action( 'publish_jetpack-comic', 'queue_publish_post', 10, 2 );
73 }
74
75 add_action( 'pre_get_posts', array( $this, 'include_in_feeds' ) );
76
77 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
78
79 add_filter( 'manage_' . self::POST_TYPE . '_posts_columns', array( $this, 'manage_posts_columns' ) );
80 add_action( 'manage_' . self::POST_TYPE . '_posts_custom_column', array( $this, 'manage_posts_custom_column' ), 10, 2 );
81 add_image_size( 'jetpack-comic-thumb', 150, 0, false );
82
83 // Enable front-end uploading for users special enough.
84 if ( current_user_can( 'upload_files' ) && current_user_can( 'edit_posts' ) ) {
85 add_action( 'wp_ajax_jetpack_comic_upload', array( $this, 'upload' ) );
86 add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
87 }
88
89 /**
90 * Add a "Convert to Comic" and "Convert to Post" option to the bulk
91 * edit dropdowns.
92 */
93 add_action( 'admin_footer-edit.php', array( $this, 'admin_footer' ) );
94 add_action( 'load-edit.php', array( $this, 'bulk_edit' ) );
95 add_action( 'admin_notices', array( $this, 'bulk_edit_notices' ) );
96 }
97
98 /**
99 * Enqueue JavaScript in the footer.
100 *
101 * @return void
102 */
103 public function admin_footer() {
104 $post_type = get_post_type();
105
106 ?>
107 <script type="text/javascript">
108 jQuery( document ).ready( function( $ ) {
109 <?php if ( ! $post_type || 'post' === $post_type ) { ?>
110 $( '<option>' )
111 .val( 'post2comic' )
112 .text( <?php echo wp_json_encode( __( 'Convert to Comic', 'jetpack' ) ); ?> )
113 .appendTo( "select[name='action'], select[name='action2']" );
114 <?php } ?>
115 <?php if ( ! $post_type || self::POST_TYPE === $post_type ) { ?>
116 $( '<option>' )
117 .val( 'comic2post' )
118 .text( <?php echo wp_json_encode( __( 'Convert to Post', 'jetpack' ) ); ?> )
119 .appendTo( "select[name='action'], select[name='action2']" );
120 <?php } ?>
121
122 $( '#message.jetpack-comic-post-type-conversion' ).remove().insertAfter( $( '.wrap h2:first' ) ).show();
123 });
124 </script>
125 <?php
126 }
127
128 /**
129 * Handle the "Convert to [Post|Comic]" bulk action.
130 *
131 * @return void
132 */
133 public function bulk_edit() {
134 if ( empty( $_REQUEST['post'] ) ) {
135 return;
136 }
137
138 $wp_list_table = _get_list_table( 'WP_Posts_List_Table' );
139 $action = $wp_list_table->current_action();
140
141 check_admin_referer( 'bulk-posts' );
142
143 if ( 'post2comic' === $action || 'comic2post' === $action ) {
144 if ( ! current_user_can( 'publish_posts' ) ) {
145 wp_die( esc_html__( 'You are not allowed to make this change.', 'jetpack' ) );
146 }
147
148 $post_ids = array_map( 'intval', $_REQUEST['post'] );
149
150 $modified_count = 0;
151
152 foreach ( $post_ids as $post_id ) {
153 $destination_post_type = ( $action === 'post2comic' ) ? self::POST_TYPE : 'post';
154 $origin_post_type = ( $destination_post_type === 'post' ) ? self::POST_TYPE : 'post';
155
156 if ( current_user_can( 'edit_post', $post_id ) ) {
157 $post = get_post( $post_id );
158
159 // Only convert posts that are post => comic or comic => post.
160 // (e.g., Ignore comic => comic, page => post, etc. )
161 if ( $post->post_type !== $destination_post_type && $post->post_type === $origin_post_type ) {
162 $post_type_object = get_post_type_object( $destination_post_type );
163
164 if ( current_user_can( $post_type_object->cap->publish_posts ) ) {
165 set_post_type( $post_id, $destination_post_type );
166 ++$modified_count;
167 }
168 }
169 }
170 }
171
172 $sendback = remove_query_arg( array( 'exported', 'untrashed', 'deleted', 'ids' ), wp_get_referer() );
173
174 if ( ! $sendback ) {
175 $sendback = add_query_arg( array( 'post_type', get_post_type() ), admin_url( 'edit.php' ) );
176 }
177
178 $pagenum = $wp_list_table->get_pagenum();
179 $bulk_edit_comics_nonce = wp_create_nonce( 'bulk-edit-comics-nonce' );
180 $sendback = add_query_arg(
181 array(
182 'paged' => $pagenum,
183 'post_type_changed' => $modified_count,
184 'bulk_edit_comics_nonce' => $bulk_edit_comics_nonce,
185 ),
186 $sendback
187 );
188
189 wp_safe_redirect( $sendback );
190 exit();
191 }
192 }
193
194 /**
195 * Show the post conversion success notice.
196 *
197 * @return void
198 */
199 public function bulk_edit_notices() {
200 global $pagenow;
201
202 if (
203 empty( $_GET['bulk_edit_comics_nonce'] )
204 || ! wp_verify_nonce( sanitize_key( $_GET['bulk_edit_comics_nonce'] ), 'bulk-edit-comics-nonce' )
205 ) {
206 return;
207 }
208
209 $number_posts_changed = isset( $_GET['post_type_changed'] )
210 ? (int) $_GET['post_type_changed']
211 : 0;
212
213 if ( 'edit.php' === $pagenow && $number_posts_changed ) {
214 ?>
215 <div id="message" class="updated below-h2 jetpack-comic-post-type-conversion" style="display: none;"><p>
216 <?php
217 echo esc_html(
218 sprintf(
219 /* Translators: placeholder is a number. */
220 _n( '%s post converted.', '%s posts converted', (int) $number_posts_changed, 'jetpack' ),
221 number_format_i18n( $number_posts_changed )
222 )
223 );
224 ?>
225 </p></div>
226 <?php
227 }
228 }
229
230 /**
231 * Enqueue scripts and styles.
232 *
233 * @return void
234 */
235 public function register_scripts() {
236 wp_enqueue_style( 'jetpack-comics-style', plugins_url( 'comics/comics.css', __FILE__ ), array(), JETPACK__VERSION );
237 wp_style_add_data( 'jetpack-comics-style', 'rtl', 'replace' );
238
239 $is_amp = class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request();
240 if ( ! $is_amp ) {
241 wp_enqueue_script(
242 'jetpack-comics',
243 Assets::get_file_url_for_environment(
244 '_inc/build/custom-post-types/comics/comics.min.js',
245 'modules/custom-post-types/comics/comics.js'
246 ),
247 array( 'jquery' ),
248 JETPACK__VERSION,
249 false
250 );
251
252 $options = array(
253 'nonce' => wp_create_nonce( 'jetpack_comic_upload_nonce' ),
254 'writeURL' => admin_url( 'admin-ajax.php?action=jetpack_comic_upload' ),
255 'labels' => array(
256 'dragging' => __( 'Drop images to upload', 'jetpack' ),
257 'uploading' => __( 'Uploading...', 'jetpack' ),
258 'processing' => __( 'Processing...', 'jetpack' ),
259 'unsupported' => __( "Sorry, your browser isn't supported. Upgrade at browsehappy.com.", 'jetpack' ),
260 'invalidUpload' => __( 'Only images can be uploaded here.', 'jetpack' ),
261 'error' => __( "Your upload didn't complete; try again later or cross your fingers and try again right now.", 'jetpack' ),
262 ),
263 );
264
265 wp_localize_script( 'jetpack-comics', 'Jetpack_Comics_Options', $options );
266 }
267 }
268
269 /**
270 * Enqueue stylesheet in the admin.
271 */
272 public function admin_enqueue_scripts() {
273 wp_enqueue_style( 'jetpack-comics-admin', plugins_url( 'comics/admin.css', __FILE__ ), array(), JETPACK__VERSION );
274 }
275
276 /**
277 * Register the post types if the theme supports them.
278 */
279 public function maybe_register_post_types() {
280 // Return early if theme does not support Jetpack Comic.
281 if ( ! ( $this->site_supports_comics() ) ) {
282 return;
283 }
284
285 $this->register_post_types();
286 }
287
288 /**
289 * Register our CPT.
290 */
291 public function register_post_types() {
292 if ( post_type_exists( self::POST_TYPE ) ) {
293 return;
294 }
295
296 register_post_type(
297 self::POST_TYPE,
298 array(
299 'description' => __( 'Comics', 'jetpack' ),
300 'labels' => array(
301 'name' => esc_html__( 'Comics', 'jetpack' ),
302 'singular_name' => esc_html__( 'Comic', 'jetpack' ),
303 'menu_name' => esc_html__( 'Comics', 'jetpack' ),
304 'all_items' => esc_html__( 'All Comics', 'jetpack' ),
305 'add_new' => esc_html__( 'Add New', 'jetpack' ),
306 'add_new_item' => esc_html__( 'Add New Comic', 'jetpack' ),
307 'edit_item' => esc_html__( 'Edit Comic', 'jetpack' ),
308 'new_item' => esc_html__( 'New Comic', 'jetpack' ),
309 'view_item' => esc_html__( 'View Comic', 'jetpack' ),
310 'search_items' => esc_html__( 'Search Comics', 'jetpack' ),
311 'not_found' => esc_html__( 'No Comics found', 'jetpack' ),
312 'not_found_in_trash' => esc_html__( 'No Comics found in Trash', 'jetpack' ),
313 'filter_items_list' => esc_html__( 'Filter comics list', 'jetpack' ),
314 'items_list_navigation' => esc_html__( 'Comics list navigation', 'jetpack' ),
315 'items_list' => esc_html__( 'Comics list', 'jetpack' ),
316 ),
317 'supports' => array(
318 'title',
319 'editor',
320 'thumbnail',
321 'comments',
322 'revisions',
323 'publicize', // Jetpack
324 'subscriptions', // wpcom
325 'shortlinks', // Jetpack
326 ),
327 'rewrite' => array(
328 'slug' => 'comic',
329 'with_front' => false,
330 ),
331 'taxonomies' => array(
332 'category',
333 'post_tag',
334 ),
335 // Only make the type public for sites that support Comics.
336 'public' => true,
337 'menu_position' => 5, // below Posts
338 'map_meta_cap' => true,
339 'has_archive' => true,
340 'query_var' => 'comic',
341 'show_in_rest' => true,
342 )
343 );
344 }
345
346 /**
347 * Add a Preview colunm to the Comic CPT admin view.
348 *
349 * @param array $columns An array of column names.
350 * @return array Updated `$columns`.
351 */
352 public function manage_posts_columns( $columns ) {
353 $new_columns = array(
354 'preview-jetpack-comic' => __( 'Preview', 'jetpack' ),
355 );
356 return array_merge( array_slice( $columns, 0, 2 ), $new_columns, array_slice( $columns, 2 ) );
357 }
358
359 /**
360 * Display the post's featured image in column.
361 *
362 * @param string $column_name The name of the column to display.
363 * @param int $post_ID The current post ID.
364 */
365 public function manage_posts_custom_column( $column_name, $post_ID ) {
366 if ( 'preview-jetpack-comic' === $column_name && has_post_thumbnail( $post_ID ) ) {
367 echo get_the_post_thumbnail( $post_ID, 'jetpack-comic-thumb' );
368 }
369 }
370
371 /**
372 * The function url_to_postid() doesn't handle pretty permalinks
373 * for CPTs very well. When we're generating an RSS feed to be consumed
374 * for Feedbag (the Reader's feed storage mechanism), eschew
375 * a pretty URL for one that will get the post into the Reader.
376 *
377 * @see https://core.trac.wordpress.org/ticket/19744
378 * @param string $permalink The existing (possibly pretty) permalink.
379 *
380 * @return string The permalink to use.
381 */
382 public function custom_permalink_for_feedbag( $permalink ) {
383 global $post;
384
385 if ( ! empty( $GLOBALS['is_feedbag_rss_script'] ) && self::POST_TYPE === $post->post_type ) {
386 $permalink = home_url(
387 add_query_arg(
388 array(
389 'p' => $post->ID,
390 'post_type' => self::POST_TYPE,
391 ),
392 '?'
393 )
394 );
395 }
396
397 return $permalink;
398 }
399
400 /**
401 * Update messages for the Comic admin.
402 *
403 * @param array $messages Existing post update messages.
404 *
405 * @return array $messages Amended post update messages.
406 */
407 public function updated_messages( $messages ) {
408 global $post;
409
410 $messages['jetpack-comic'] = array(
411 0 => '', // Unused. Messages start at index 1.
412 1 => sprintf(
413 /* Translators: link to comic item's page. */
414 __( 'Comic updated. <a href="%s">View comic</a>', 'jetpack' ),
415 esc_url( get_permalink( $post->ID ) )
416 ),
417 2 => esc_html__( 'Custom field updated.', 'jetpack' ),
418 3 => esc_html__( 'Custom field deleted.', 'jetpack' ),
419 4 => esc_html__( 'Comic updated.', 'jetpack' ),
420 /* translators: %s: date and time of the revision */
421 5 => isset( $_GET['revision'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Copying core message handling.
422 ? sprintf(
423 /* Translators: link to comic item's page. */
424 esc_html__( 'Comic restored to revision from %s', 'jetpack' ),
425 wp_post_revision_title( (int) $_GET['revision'], false ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Copying core message handling.
426 )
427 : false,
428 6 => sprintf(
429 /* Translators: link to comic item's page. */
430 __( 'Comic published. <a href="%s">View comic</a>', 'jetpack' ),
431 esc_url( get_permalink( $post->ID ) )
432 ),
433 7 => esc_html__( 'Comic saved.', 'jetpack' ),
434 8 => sprintf(
435 /* Translators: link to portfolio item's page. */
436 __( 'Comic submitted. <a target="_blank" href="%s">Preview comic</a>', 'jetpack' ),
437 esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) )
438 ),
439 9 => sprintf(
440 /* Translators: link to comic item's page. */
441 __( 'Comic scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview comic</a>', 'jetpack' ),
442 // translators: Publish box date format, see https://php.net/date
443 date_i18n( __( 'M j, Y @ G:i', 'jetpack' ), strtotime( $post->post_date ) ),
444 esc_url( get_permalink( $post->ID ) )
445 ),
446 10 => sprintf(
447 /* Translators: link to comic item's page. */
448 __( 'Comic draft updated. <a target="_blank" href="%s">Preview comic</a>', 'jetpack' ),
449 esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) )
450 ),
451 );
452
453 return $messages;
454 }
455
456 /**
457 * Should this Custom Post Type be made available?
458 *
459 * @return bool
460 */
461 public function site_supports_comics() {
462 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
463 $php_self = isset( $_SERVER['PHP_SELF'] )
464 ? sanitize_text_field( wp_unslash( $_SERVER['PHP_SELF'] ) )
465 : '';
466 $blog_ids = isset( $_SERVER['argv'] )
467 ? array_map( 'intval', (array) wp_unslash( $_SERVER['argv'] ) )
468 : array();
469
470 if (
471 ! empty( $php_self )
472 && 'blog-rss.php' === substr( $php_self, -12 )
473 && count( $blog_ids ) > 1
474 ) {
475 // blog-rss.php isn't run in the context of the target blog when the init action fires,
476 // so check manually whether the target blog supports comics.
477 switch_to_blog( $blog_ids[1] );
478 // The add_theme_support( 'jetpack-comic' ) won't fire on switch_to_blog, so check for Panel manually.
479 $supports_comics = ( ( function_exists( 'site_vertical' ) && 'comics' === site_vertical() )
480 || current_theme_supports( self::POST_TYPE )
481 || get_stylesheet() === 'pub/panel' );
482 restore_current_blog();
483
484 /** This action is documented in modules/custom-post-types/nova.php */
485 return (bool) apply_filters( 'jetpack_enable_cpt', $supports_comics, self::POST_TYPE );
486 }
487 }
488
489 $supports_comics = false;
490
491 /**
492 * If we're on WordPress.com, and it has the menu site vertical.
493 *
494 * @todo: Extract this out into a wpcom only file.
495 */
496 if ( function_exists( 'site_vertical' ) && 'comics' === site_vertical() ) {
497 $supports_comics = true;
498 }
499
500 /**
501 * Else, if the current theme requests it.
502 */
503 if ( current_theme_supports( self::POST_TYPE ) ) {
504 $supports_comics = true;
505 }
506
507 /**
508 * Filter it in case something else knows better.
509 */
510 /** This action is documented in modules/custom-post-types/nova.php */
511 return (bool) apply_filters( 'jetpack_enable_cpt', $supports_comics, self::POST_TYPE );
512 }
513
514 /**
515 * Anywhere that a feed is displaying posts, show comics too.
516 *
517 * @param WP_Query $query The current query.
518 *
519 * @return void
520 */
521 public function include_in_feeds( $query ) {
522 if ( ! $query->is_feed() ) {
523 return;
524 }
525
526 // Don't modify the query if the post type isn't public.
527 if ( ! get_post_type_object( 'jetpack-comic' )->public ) {
528 return;
529 }
530
531 $query_post_types = $query->get( 'post_type' );
532
533 if ( empty( $query_post_types ) ) {
534 $query_post_types = 'post';
535 }
536
537 if ( ! is_array( $query_post_types ) ) {
538 $query_post_types = array( $query_post_types );
539 }
540
541 if ( in_array( 'post', $query_post_types, true ) ) {
542 $query_post_types[] = self::POST_TYPE;
543 $query->set( 'post_type', $query_post_types );
544 }
545 }
546
547 /**
548 * API endpoint for front-end image uploading.
549 */
550 public function upload() {
551 global $content_width;
552
553 header( 'Content-Type: application/json' );
554
555 if (
556 empty( $_REQUEST['nonce'] )
557 || ! wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), 'jetpack_comic_upload_nonce' )
558 ) {
559 die( wp_json_encode( array( 'error' => __( 'Invalid or expired nonce.', 'jetpack' ) ) ) );
560 }
561
562 $_POST['action'] = 'wp_handle_upload';
563
564 $image_id_arr = array();
565 $image_error_arr = array();
566
567 $i = 0;
568
569 while ( isset( $_FILES[ 'image_' . $i ] ) ) {
570 // Create attachment for the image.
571 $image_id = media_handle_upload( "image_$i", 0 );
572
573 if ( is_wp_error( $image_id ) ) {
574 $error = array( $image_id, $image_id->get_error_message() );
575 array_push( $image_error_arr, $error );
576 } else {
577 array_push( $image_id_arr, $image_id );
578 }
579
580 ++$i;
581 }
582
583 if ( $image_id_arr === array() ) {
584 // All image uploads failed.
585 $rv = array( 'error' => '' );
586
587 foreach ( $image_error_arr as $error ) {
588 $rv['error'] .= $error[1] . "\n";
589 }
590 } else {
591 if ( count( $image_id_arr ) === 1 ) {
592 $image_id = $image_id_arr[0];
593
594 // Get the image
595 $image_src = get_the_guid( $image_id );
596 $image_dims = wp_get_attachment_image_src( $image_id, 'full' );
597
598 // Take off 10px of width to account for padding and border. @todo make this smarter.
599 if ( $content_width ) {
600 $image_width = $content_width - 10;
601 } else {
602 $image_width = $image_dims[1] - 10;
603 }
604
605 $image_name = isset( $_FILES['image_0']['name'] )
606 ? sanitize_file_name( wp_unslash( $_FILES['image_0']['name'] ) )
607 : '';
608 $post_content = sprintf(
609 '<a href="%1$s"><img src="%1$s?w=%2$d" alt="%3$s" class="size-full wp-image alignnone" id="%4$s" data-filename="%3$s"/></a>',
610 esc_url( $image_src ),
611 esc_attr( $image_width ),
612 esc_attr( $image_name ),
613 esc_attr( $image_id )
614 );
615 } else {
616 $post_content = '[gallery ids="' . esc_attr( implode( ',', $image_id_arr ) ) . '"]';
617 }
618
619 // Create a new post with the image(s)
620 $post_id = wp_insert_post(
621 array(
622 'post_content' => $post_content,
623 'post_type' => 'jetpack-comic',
624 'post_status' => 'draft',
625 ),
626 true
627 );
628
629 if ( is_wp_error( $post_id, 'WP_Error' ) ) {
630 // Failed to create the post.
631 $rv = array( 'error' => $post_id->get_error_message() );
632
633 // Delete the uploaded images.
634 foreach ( $image_id_arr as $image_id ) {
635 wp_delete_post( $image_id, true );
636 }
637 } else {
638 foreach ( $image_id_arr as $image_id ) {
639 wp_update_post(
640 array(
641 'ID' => $image_id,
642 'post_parent' => $post_id,
643 )
644 );
645 }
646
647 if ( current_theme_supports( 'post-thumbnails' ) && count( $image_id_arr ) === 1 ) {
648 set_post_thumbnail( $post_id, $image_id_arr[0] );
649 }
650
651 $rv = array(
652 'url' => add_query_arg(
653 array(
654 'post' => $post_id,
655 'action' => 'edit',
656 ),
657 admin_url( 'post.php' )
658 ),
659 );
660 }
661 }
662
663 die( wp_json_encode( $rv ) );
664 }
665
666 /**
667 * Add comic posts to the tag and category pages.
668 *
669 * @param WP_Query $query Post query.
670 *
671 * @return WP_Query
672 */
673 public function add_posts_to_loop( $query ) {
674 if ( ! is_admin() && $query->is_main_query() && ( $query->is_category() || $query->is_tag() ) ) {
675 $post_types = $query->get( 'post_type' );
676
677 if ( ! $post_types || 'post' === $post_types ) {
678 $post_types = array( 'post', self::POST_TYPE );
679 } elseif ( is_array( $post_types ) ) {
680 $post_types[] = self::POST_TYPE;
681 }
682
683 $query->set( 'post_type', $post_types );
684 }
685
686 return $query;
687 }
688
689 /**
690 * Add to REST API post type allowed list.
691 *
692 * @param array $post_types Array of post types to add to the allowed list.
693 *
694 * @return array
695 */
696 public function allow_rest_api_type( $post_types ) {
697 $post_types[] = self::POST_TYPE;
698 return $post_types;
699 }
700
701 }
702
703 add_action( 'init', array( 'Jetpack_Comic', 'init' ) );
704
705 /**
706 * Custom welcome email for WordPress.com sites in the Comic vertical.
707 *
708 * @param string $welcome_email Body of the email.
709 * @param int $blog_id Site ID.
710 * @param int $user_id User ID.
711 * @param string $password User password, or "N/A" if the user account is not new.
712 * @param string $title Site title.
713 * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang id.
714 *
715 * @return string
716 */
717 function comics_welcome_email( $welcome_email, $blog_id, $user_id, $password, $title, $meta ) {
718 if ( ( isset( $meta['vertical'] ) && 'comics' === $meta['vertical'] ) || has_blog_sticker( 'vertical-comics', $blog_id ) ) {
719 return __(
720 "Welcome! Ready to publish your first strip?
721
722 Your webcomic's new site is ready to go. Get started by <a href=\"BLOG_URLwp-admin/customize.php#title\">setting your comic's title and tagline</a> so your readers know what it's all about.
723
724 Looking for more help with setting up your site? Check out the WordPress.com <a href=\"https://learn.wordpress.com/\" target=\"_blank\">beginner's tutorial</a> and the <a href=\"https://en.support.wordpress.com/comics/\" target=\"_blank\">guide to comics on WordPress.com</a>. Dive right in by <a href=\"BLOG_URLwp-admin/customize.php#title\">publishing your first strip!</a>
725
726 Lots of laughs,
727 The WordPress.com Team",
728 'jetpack'
729 );
730 }
731
732 return $welcome_email;
733 }
734 add_filter( 'update_welcome_email_pre_replacement', 'comics_welcome_email', 10, 6 );
735