Changeset 10815 for sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/importer.php
- Timestamp:
- 03/11/2021 11:48:52 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/importer.php
r10779 r10815 19 19 20 20 /** 21 * Memoized user ID of default import post author. 22 * 23 * @var int 24 */ 25 protected static $import_user_id; 26 27 /** 21 28 * The slug base. 22 29 * … … 118 125 add_action( "handbook_{$post_type_base}_import_all_markdown", [ $this, 'import_all_markdown' ] ); 119 126 add_filter( 'display_post_states', [ $this, 'display_post_states' ], 10, 2 ); 127 add_filter( 'wporg_markdown_post_data_pre_insert', [ $this, 'assign_post_author' ] ); 120 128 121 129 $editor = new Editor( $this ); … … 190 198 191 199 /** 200 * Adds user as the default post author for imported posts that don't have 201 * a post author already assigned. 202 * 203 * By default, assigns all imported posts to the 'wordpressdotorg' user if 204 * it exists. Use {@see 'handbooks_import_default_author_slug'} to filter 205 * the default imported post author. Otherwise, no post author is assigned. 206 * 207 * @param array $post_data Post data. 208 * @return array 209 */ 210 public static function assign_post_author( $post_data ) { 211 // Bail early if the post already has a post author specified. 212 if ( isset( $post_data['post_author'] ) ) { 213 return $post_data; 214 } 215 216 // Get the default import author if not already memoized. 217 if ( ! self::$import_user_id ) { 218 /** 219 * Filters the slug of the user to be assigned as the post 220 * author for all imported posts. 221 * 222 * @param string $slug Slug of user to assign as imported post author. 223 * Use empty string or false to prevent a post author 224 * from being assigned. Default 'wordpressdotorg'. 225 * @return string 226 */ 227 $default_user_slug = apply_filters( 'handbooks_import_default_author_slug', 'wordpressdotorg' ); 228 229 if ( $default_user_slug ) { 230 $user = get_user_by( 'slug', $default_user_slug ); 231 if ( $user ) { 232 self::$import_user_id = $user->ID; 233 } 234 } 235 } 236 237 // Add the default import author if it was found. 238 if ( self::$import_user_id ) { 239 $post_data['post_author'] = self::$import_user_id; 240 } 241 242 return $post_data; 243 } 244 245 /** 192 246 * Indicates if the specified handbook is imported. 193 247 *
Note: See TracChangeset
for help on using the changeset viewer.