Upload::replace_temp_image( string $str, array|false $allowed_files = false )

Description #

Replace all dummy images found in editor type field.

Parameters #

  • $str
    string (Required) Content where to replace images.
  • $allowed_files
    array | false (Optional) Pass array of allowed file names . Default value: false

Source #

File: lib/form/class-upload.php

	public function replace_temp_image( $str, $allowed_files = false ) {
		$allowed_files = array_map( 'sanitize_file_name', $allowed_files );

		// Check for allowed files.
		$new_files = array();
		if ( false !== $allowed_files && $this->value() ) {
			foreach ( $this->value() as $k => $file ) {
				if ( in_array( $file['name'], $allowed_files, true ) ) {
					$new_files[] = $file;
				}
			}
			$this->value = $new_files;
		}

		if ( false === $this->uploaded ) {
			$this->save_uploads();
		}

		return preg_replace_callback( '/({{apimage (.*?)}})/', array( $this, 'file_name_search_replace' ), $str );
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment