Title: WP_Customize_Manager::prepare_starter_content_attachments
Published: December 7, 2016
Last modified: August 20, 2026

---

# WP_Customize_Manager::prepare_starter_content_attachments( array $attachments ): array

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#changelog)

Prepares starter content attachments.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#description)󠁿

Ensure that the attachments are valid and that they have slugs and file name/path.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#parameters)󠁿

 `$attachments`arrayrequired

Attachments.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#return)󠁿

 array Prepared attachments.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#source)󠁿

    ```php
    protected function prepare_starter_content_attachments( $attachments ) {
    	$prepared_attachments = array();
    	if ( empty( $attachments ) ) {
    		return $prepared_attachments;
    	}

    	// Such is The WordPress Way.
    	require_once ABSPATH . 'wp-admin/includes/file.php';
    	require_once ABSPATH . 'wp-admin/includes/media.php';
    	require_once ABSPATH . 'wp-admin/includes/image.php';

    	foreach ( $attachments as $symbol => $attachment ) {

    		// A file is required and URLs to files are not currently allowed.
    		if ( empty( $attachment['file'] ) || preg_match( '#^https?://$#', $attachment['file'] ) ) {
    			continue;
    		}

    		$file_path = null;
    		if ( file_exists( $attachment['file'] ) ) {
    			$file_path = $attachment['file']; // Could be absolute path to file in plugin.
    		} elseif ( is_child_theme() && file_exists( get_stylesheet_directory() . '/' . $attachment['file'] ) ) {
    			$file_path = get_stylesheet_directory() . '/' . $attachment['file'];
    		} elseif ( file_exists( get_template_directory() . '/' . $attachment['file'] ) ) {
    			$file_path = get_template_directory() . '/' . $attachment['file'];
    		} else {
    			continue;
    		}
    		$file_name = wp_basename( $attachment['file'] );

    		// Skip file types that are not recognized.
    		$checked_filetype = wp_check_filetype( $file_name );
    		if ( empty( $checked_filetype['type'] ) ) {
    			continue;
    		}

    		// Ensure post_name is set since not automatically derived from post_title for new auto-draft posts.
    		if ( empty( $attachment['post_name'] ) ) {
    			if ( ! empty( $attachment['post_title'] ) ) {
    				$attachment['post_name'] = sanitize_title( $attachment['post_title'] );
    			} else {
    				$attachment['post_name'] = sanitize_title( preg_replace( '/\.\w+$/', '', $file_name ) );
    			}
    		}

    		$attachment['file_name']         = $file_name;
    		$attachment['file_path']         = $file_path;
    		$prepared_attachments[ $symbol ] = $attachment;
    	}
    	return $prepared_attachments;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-manager.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-customize-manager.php#L1659)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-customize-manager.php#L1659-L1709)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#related)󠁿

| Uses | Description | 
| [get_stylesheet_directory()](https://developer.wordpress.org/reference/functions/get_stylesheet_directory/)`wp-includes/theme.php` |

Retrieves stylesheet directory path for the active theme.

  | 
| [get_template_directory()](https://developer.wordpress.org/reference/functions/get_template_directory/)`wp-includes/theme.php` |

Retrieves template directory path for the active theme.

  | 
| [is_child_theme()](https://developer.wordpress.org/reference/functions/is_child_theme/)`wp-includes/theme.php` |

Whether a child theme is in use.

  | 
| [sanitize_title()](https://developer.wordpress.org/reference/functions/sanitize_title/)`wp-includes/formatting.php` |

Sanitizes a string into a slug, which can be used in URLs or HTML attributes.

  | 
| [wp_check_filetype()](https://developer.wordpress.org/reference/functions/wp_check_filetype/)`wp-includes/functions.php` |

Retrieves the file type from the file name.

  | 
| [wp_basename()](https://developer.wordpress.org/reference/functions/wp_basename/)`wp-includes/formatting.php` |

i18n-friendly version of basename().

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#)

| Used by | Description | 
| [WP_Customize_Manager::import_theme_starter_content()](https://developer.wordpress.org/reference/classes/wp_customize_manager/import_theme_starter_content/)`wp-includes/class-wp-customize-manager.php` |

Imports theme starter content into the customized state.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_starter_content_attachments/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_manager%2Fprepare_starter_content_attachments%2F)
before being able to contribute a note or feedback.