_wp_customize_publish_changeset

Publish a snapshot's changes.

Description

_wp_customize_publish_changeset( (string) $new_status, (string) $old_status, (WP_Post) $changeset_post ); 

Parameters (3)

0. $new_status (string)
New post status.
1. $old_status (string)
Old post status.
2. $changeset_post (WP_Post)
Changeset post object.

Usage

  1. if ( !function_exists( '_wp_customize_publish_changeset' ) ) { 
  2. require_once ABSPATH . WPINC . '/theme.php'; 
  3.  
  4. // New post status. 
  5. $new_status = ''; 
  6.  
  7. // Old post status. 
  8. $old_status = ''; 
  9.  
  10. // Changeset post object. 
  11. $changeset_post = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _wp_customize_publish_changeset($new_status, $old_status, $changeset_post); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/theme.php  
  1. function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) { 
  2. global $wp_customize, $wpdb; 
  3.  
  4. $is_publishing_changeset = ( 
  5. 'customize_changeset' === $changeset_post->post_type 
  6. && 
  7. 'publish' === $new_status 
  8. && 
  9. 'publish' !== $old_status 
  10. ); 
  11. if ( ! $is_publishing_changeset ) { 
  12. return; 
  13.  
  14. if ( empty( $wp_customize ) ) { 
  15. require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 
  16. $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $changeset_post->post_name ) ); 
  17.  
  18. if ( ! did_action( 'customize_register' ) ) { 
  19. /** 
  20. * When running from CLI or Cron, the customize_register action will need 
  21. * to be triggered in order for core, themes, and plugins to register their 
  22. * settings. Normally core will add_action( 'customize_register' ) at 
  23. * priority 10 to register the core settings, and if any themes/plugins 
  24. * also add_action( 'customize_register' ) at the same priority, they 
  25. * will have a $wp_customize with those settings registered since they 
  26. * call add_action() afterward, normally. However, when manually doing 
  27. * the customize_register action after the setup_theme, then the order 
  28. * will be reversed for two actions added at priority 10, resulting in 
  29. * the core settings no longer being available as expected to themes/plugins. 
  30. * So the following manually calls the method that registers the core 
  31. * settings up front before doing the action. 
  32. */ 
  33. remove_action( 'customize_register', array( $wp_customize, 'register_controls' ) ); 
  34. $wp_customize->register_controls(); 
  35.  
  36. /** This filter is documented in /wp-includes/class-wp-customize-manager.php */ 
  37. do_action( 'customize_register', $wp_customize ); 
  38. $wp_customize->_publish_changeset_values( $changeset_post->ID ) ; 
  39.  
  40. /** 
  41. * Trash the changeset post if revisions are not enabled. Unpublished 
  42. * changesets by default get garbage collected due to the auto-draft status. 
  43. * When a changeset post is published, however, it would no longer get cleaned 
  44. * out. Ths is a problem when the changeset posts are never displayed anywhere,  
  45. * since they would just be endlessly piling up. So here we use the revisions 
  46. * feature to indicate whether or not a published changeset should get trashed 
  47. * and thus garbage collected. 
  48. */ 
  49. if ( ! wp_revisions_enabled( $changeset_post ) ) { 
  50. $post = $changeset_post; 
  51. $post_id = $changeset_post->ID; 
  52.  
  53. /** 
  54. * The following re-formulates the logic from wp_trash_post() as done in 
  55. * wp_publish_post(). The reason for bypassing wp_trash_post() is that it 
  56. * will mutate the the post_content and the post_name when they should be 
  57. * untouched. 
  58. */ 
  59. if ( ! EMPTY_TRASH_DAYS ) { 
  60. wp_delete_post( $post_id, true ); 
  61. } else { 
  62. /** This action is documented in wp-includes/post.php */ 
  63. do_action( 'wp_trash_post', $post_id ); 
  64.  
  65. add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status ); 
  66. add_post_meta( $post_id, '_wp_trash_meta_time', time() ); 
  67.  
  68. $old_status = $post->post_status; 
  69. $new_status = 'trash'; 
  70. $wpdb->update( $wpdb->posts, array( 'post_status' => $new_status ), array( 'ID' => $post->ID ) ); 
  71. clean_post_cache( $post->ID ); 
  72.  
  73. $post->post_status = $new_status; 
  74. wp_transition_post_status( $new_status, $old_status, $post ); 
  75.  
  76. /** This action is documented in wp-includes/post.php */ 
  77. do_action( 'edit_post', $post->ID, $post ); 
  78.  
  79. /** This action is documented in wp-includes/post.php */ 
  80. do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); 
  81.  
  82. /** This action is documented in wp-includes/post.php */ 
  83. do_action( 'save_post', $post->ID, $post, true ); 
  84.  
  85. /** This action is documented in wp-includes/post.php */ 
  86. do_action( 'wp_insert_post', $post->ID, $post, true ); 
  87.  
  88. /** This action is documented in wp-includes/post.php */ 
  89. do_action( 'trashed_post', $post_id );