Changeset 13210 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
- Timestamp:
- 02/13/2024 01:20:43 AM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r13196 r13210 79 79 add_action( 'rest_api_init', array( __NAMESPACE__ . '\API\Base', 'init' ) ); 80 80 81 // Allow post_modified not to be modified when we don't specifically bump it .81 // Allow post_modified not to be modified when we don't specifically bump it, and slugs for pending plugins. 82 82 add_filter( 'wp_insert_post_data', array( $this, 'filter_wp_insert_post_data' ), 10, 2 ); 83 83 … … 119 119 /** 120 120 * Filters `wp_insert_post()` to respect the presented data. 121 * 121 122 * This function overrides `wp_insert_post()`s constant updating of 122 * the post_modified fields .123 * the post_modified fields, and allows for pending posts to have a slug. 123 124 * 124 125 * @param array $data The data to be inserted into the database. … … 128 129 */ 129 130 public function filter_wp_insert_post_data( $data, $postarr ) { 130 if ( 'plugin' === $postarr['post_type'] ) { 131 $data['post_modified'] = $postarr['post_modified']; 132 $data['post_modified_gmt'] = $postarr['post_modified_gmt']; 133 } 131 if ( 'plugin' !== $postarr['post_type'] ) { 132 return $data; 133 } 134 135 // Allow setting post_modified fields. 136 $data['post_modified'] = $postarr['post_modified']; 137 $data['post_modified_gmt'] = $postarr['post_modified_gmt']; 138 139 /* 140 * wp_insert_post() does not allow `pending` posts to have a slug, unless the user can publish it. 141 * 142 * Inherit the previous slug, never allowing it to go to empty for this case. 143 * 144 * There's an edgecase here, where we might be inserting a post as pending for the first time, 145 * in that case we just do our best to respect the data provided.. 146 */ 147 if ( 148 'pending' === $data['post_status'] && 149 empty( $data['post_name'] ) 150 ) { 151 if ( ! empty( $postarr['ID'] ) ) { 152 // Updating an existing post. 153 $data['post_name'] = get_post_field( 'post_name', $postarr['ID'] ); 154 } else { 155 // New insert, we'll just hope that it was specified. 156 $data['post_name'] = $postarr['post_name'] ?? ''; 157 } 158 } 159 134 160 return $data; 135 161 }
Note: See TracChangeset
for help on using the changeset viewer.