Skip to content

utils/wp-api/utils

function apiEndpoint(
endpoint: string,
type: "categories" | "tags" | "posts" | "pages" | "media" | "settings",
path?: string): URL

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/utils.ts:165

Constructs a WordPress API endpoint URL based on the provided parameters.

string

The base URL of the WordPress website.

The type of resource to access. Can be ‘posts’, ‘pages’, ‘media’, ‘categories’, ‘tags’, or ‘settings’.

"categories" | "tags" | "posts" | "pages" | "media" | "settings"

string

An optional path to append to the endpoint.

URL

The constructed URL object pointing to the desired API endpoint.

If the endpoint argument is missing.


function cleanUpHtml(html: string): any

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/utils.ts:25

Cleans up the provided HTML string by removing certain attributes from images and modifying specific elements related to WordPress polls.

string

The HTML string to be cleaned up.

any

The cleaned-up HTML string.


function downloadAndUpdateImages(html: string, pathToFolder: string): Promise<any>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/utils.ts:140

Downloads and updates the image sources in the provided HTML string.

This function parses the given HTML string, finds all image elements, downloads the images to the specified folder, and updates the image sources to point to the downloaded images.

string

The HTML string containing image elements to be processed.

string

The path to the folder where images should be downloaded.

Promise<any>

A promise that resolves to the updated HTML string with new image sources.


function downloadImage(imageUrl: string | URL, destination: string | URL): Promise<boolean>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/utils.ts:51

Downloads an image from the specified URL and saves it to the given destination.

The URL of the image to download.

string | URL

The file path where the image should be saved.

string | URL

Promise<boolean>

  • A promise that resolves to true if the image was successfully downloaded, or false if the download failed or the file already exists.
  • Throws an error if there is an issue with the fetch request or file writing.

function downloadPostImage(src: string, pathToFolder: string): Promise<undefined | string>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/utils.ts:102

Downloads an image from the given source URL and saves it to the specified folder.

string

The URL of the image to download.

string

The path to the folder where the image should be saved.

Promise<undefined | string>

The file name of the downloaded image if successful, otherwise undefined.

  • If the src or pathToFolder parameters are not provided, the function will return immediately.
  • If the specified folder does not exist, it will be created recursively.
  • If the image already exists in the specified folder, the function will log a message and skip the download.
  • If the image download fails, the source URL will be added to the imagesNotDownloaded array.

function fetchAll(
url: URL,
page: number,
results: any[]): Promise<any[]>

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/utils.ts:194

Fetch all pages for a paginated WP endpoint.

URL

number = 1

any[] = []

Promise<any[]>


function stripHtml(string: string): string

Defined in: studiocms/packages/studiocms_devapps/src/utils/wp-api/utils.ts:14

Removes all HTML tags from a given string.

string

The input string containing HTML tags.

string

The input string with all HTML tags removed.