CyberSEO Pro API Functions

CyberSEO Pro API functions

The CyberSEO Pro API provides a robust set of functions that can be incorporated into custom PHP code snippets. This powerful feature grants you full control over posts before they are inserted into the WordPress database, allowing for flexible content syndication tailored to your specific needs.

Custom PHP Code is a feature that lets you add personalized PHP code snippets into special code boxes on the feed settings page. This facilitates custom operations or modifications on the feed data as per your requirements. For a more comprehensive understanding of the Custom PHP Code feature, you can refer to the official CyberSEO documentation here.

Below is a list of API functions that you can use to manipulate and manage your feed data. Click on a function name to see its description and usage details:

These API functions provide a plethora of capabilities, including image manipulation, content translation, content spinning, shortcode processing, video handling, text processing, and more. By integrating these functions into your PHP code snippets, you can customize and control how posts are generated and inserted into your WordPress database.

cseo_post_exists

function cseo_post_exists($post): bool

Description

This function checks if a given post, represented in the WordPress post array format, exists in the WordPress database. It checks for the post by its link (retrieved from the feed and compared against the original post’s link stored in the WordPress database as a cyberseo_post_link custom field), title, or both, depending on the plugin’s settings for the processed feed from which the post is being generated. The function returns a boolean value indicating the existence of the post.

Parameters

$post
The post to check for in the WordPress database. This post should be represented as a WordPress post array.

Return Values

The function returns a boolean value. If the post exists in the WordPress database, the function returns true. If the post is not found in the database, the function returns false. This allows the caller to determine whether a given post, identified by its link and/or title, already exists in the WordPress database. It’s recommended that you use this function in your custom PHP snippet in the following way:

if (!cseo_post_exists($post)) {
    // Process the $post array here.
} else {
    // The post exists, so just skip and don't add it.
    return false;
}

cseo_file_get_contents

function cseo_file_get_contents($url, $as_array = false, $headers = false, $referrer = false, $ua = false): string|array|false

Description

This function is used to fetch content from a specified URL. It’s an enhanced version of the built-in PHP file_get_contents() and file() functions with more options such as HTTP headers, referrer, and user agent customization. It also has the ability to fetch content using a proxy and supports a variety of proxy settings. If cURL is not available or if the path is local, it falls back to using the standard file_get_contents() function.

Parameters

$url
The URL from which to fetch the content.
$as_array
(Optional) When set to true, the content is returned as an array where each line of the content is an element of the array. Default is false.
$headers
(Optional) Custom HTTP headers to be sent with the request. Default is false.
$referrer
(Optional) Referrer URL to be included in the request. Default is false.
$ua
(Optional) Custom user agent string to be used in the request. Default is false.

Return Values

The function returns the content fetched from the specified URL. If $as_array is set to true, the content is returned as an array where each line of the content is an element of the array. If the content could not be fetched, the function returns false.

cseo_save_image

function cseo_save_image($image_url, $preferred_name = '', $width = -1, $height = -1, $compression = -1, $output_image_type = null): string

Description

This function retrieves an image from a given URL, performs optional transformations (rescale and compression), and saves it locally in the WordPress uploads directory. If the local environment isn’t capable of processing images (e.g., non-writable upload path or missing GD library), the image is hotlinked.

Parameters

$image_url
The URL of the image to retrieve and save.
$preferred_name (optional)
The preferred name to use when saving the image. If not provided or cannot be used, the function will use the original image’s basename. This value is sanitized before use.
$width (optional)
The desired width of the saved image in pixels. A value of -1 implies no scaling for width. A percentage can also be specified (e.g., “50%”).
$height (optional)
The desired height of the saved image in pixels. A value of -1 implies no scaling for height. A percentage can also be specified (e.g., “50%”).
$compression (optional)
The desired compression level for JPEG images, with -1 meaning no compression change. Other formats ignore this parameter.
$output_image_type (optional)
The desired output image format. If not specified, the function will use the original image’s format. Acceptable values correspond to the IMAGETYPE_* constants in PHP (e.g., IMAGETYPE_JPEG, IMAGETYPE_PNG, etc.).

Return Values

Returns a string with the URL of the saved local image. If the image couldn’t be saved locally, it returns the original URL for hotlinking.

Notes

The function uses the GD library for image processing. If the GD library isn’t available, the function won’t process the image and will return the original URL.

cseo_store_image

function cseo_store_image($image_url, $preferred_name = '', $width = -1, $height = -1, $compression = -1, $output_image_type = null)

Description

This function queues an image for local storage in WordPress during the post generation. It doesn’t directly save the image to a server. Instead, it adds the image URL to a temporary list. The image links in the post body are later replaced with local ones by a separate script during post generation.

Parameters

$image_url
The URL of the image to be stored.
$preferred_name (optional)
The preferred name to use when saving the image. If not provided, it will default to an empty string.
$width (optional)
The desired width of the saved image in pixels. A value of -1 implies no scaling for width.
$height (optional)
The desired height of the saved image in pixels. A value of -1 implies no scaling for height.
$compression (optional)
The desired compression level for the saved image. -1 means no compression.
$output_image_type (optional)
The desired output image format. If not specified, it will default to null.

Notes

The function works by constructing an associative array containing the image details and adds it to the global $cseo_images_to_save array. Duplication is prevented by checking if the image details already exist in the array.

cseo_check_image_size

function cseo_check_image_size($image_url, $min_width, $min_height, $max_width, $max_height): bool

Description

This function checks if the dimensions of the image specified by the given URL fall within the minimum and maximum width and height parameters. If any of the dimensions don’t meet the provided constraints, the function returns false. If there are no constraints or the image meets all the constraints, the function returns true.

Parameters

$image_url
The URL of the image to check.
$min_width
The minimum width of the image. Pass 0 to skip this constraint.
$min_height
The minimum height of the image. Pass 0 to skip this constraint.
$max_width
The maximum width of the image. Pass 0 to skip this constraint.
$max_height
The maximum height of the image. Pass 0 to skip this constraint.

Return Values

Returns true if the image dimensions meet all the provided constraints or if no constraints are provided. Returns false if the image dimensions do not meet the constraints, if the image dimensions cannot be determined, or if the image URL does not reference a valid image.

cseo_add_image_to_library

function cseo_add_image_to_library($image_url, $title = '', $post_id = false): int|false

Description

This function adds an image to the WordPress media library from a given URL. If a post ID is provided, it attaches the image to the specified post; otherwise, it adds the image to a global array for later attachment.

Parameters

$image_url
The URL of the image to add to the media library.
$title (optional)
The title to assign to the image in the media library. If not provided, the image will be given a default title based on its filename.
$post_id (optional)
The ID of the post to which the image should be attached. If not provided or false, the image will be added to a global array for later attachment.

Return Values

Returns the attachment ID if the image is attached to a post successfully, otherwise returns false. Also, returns false if the provided $image_url is not a string.

cseo_attach_post_thumbnail

function cseo_attach_post_thumbnail($post_id, $image_url, $title): int|false

Description

This function attaches an image from the provided URL as a thumbnail to the post specified by the given ID. The title of the image is used when adding it to the library.

Parameters

$post_id
The ID of the post to which the image is to be attached as a thumbnail.
$image_url
The URL of the image to attach as a thumbnail.
$title
The title to use for the image when adding it to the library.

Return Values

Returns the ID of the attachment, if the image is successfully added to the library and attached as a thumbnail to the post. If the image cannot be added to the library or cannot be attached as a thumbnail, the function returns false.

cseo_save_video

function cseo_save_video($video, $preferred_name = ''): string

Description

This function retrieves a video file from a given URL and saves it locally in the WordPress uploads directory. It also allows renaming the saved video file.

Parameters

$video
The URL of the video to retrieve and save.
$preferred_name (optional)
The preferred name to use when saving the video. If not provided or cannot be used, the function will use the original video’s basename. This value is sanitized before use.

Return Values

Returns a string with the URL of the saved local video.

cseo_deepl_translate

function cseo_deepl_translate($apikey, $text, $target, $use_api_free = false, $return_empty = false): string|false

Description

This function utilizes the DeepL Translate service to translate a specified string into a desired language.

Parameters

$apikey
Your personal DeepL Translate API key.
$text
The string that you want to translate.
$target
The language you wish the text to be translated into, expressed in the format recognized by the DeepL Translate API. Example values include ‘English’, ‘German’, ‘Chinese’, and so forth.
$use_api_free
A boolean parameter that indicates whether the free or premium version of the DeepL API key should be used. The default is set to false, indicating use of the premium version.
$return_empty
A boolean parameter that determines the function’s behavior upon failure. If set to true, the function will return an empty string if translation fails. If set to false, the function will return a boolean false if the specified string was not successfully translated. The default is set to false.

Return Values

This function will return the translated text. However, if the translation process fails, the function’s return behavior will depend on the value of the $return_empty parameter as outlined above.

cseo_google_translate

function cseo_google_translate($apikey, $text, $source, $target, $return_empty = false): string|false

Description

This function uses the Google Translate API to translate a specified string from one language to another.

Parameters

$apikey
Your personal Google Translate API key.
$text
The string that you wish to translate.
$source
The source language of the text, formatted in accordance with the specifications of the Google Translate API.
$target
The target language into which the text will be translated. This should be represented in a format that aligns with the Google Translate API standards. Examples include ‘English’, ‘German’, ‘Chinese’, etc.
$return_empty
A boolean parameter that establishes the return value of the function in case of translation failure. If set to true, an empty string will be returned when the translation fails. If set to false, which is the default setting, the function will return a boolean false if the text could not be translated successfully.

Return Values

The function returns the translated text string. However, if the translation fails, the function’s return value will be dictated by the $return_empty parameter as described above.

cseo_yandex_translate

function cseo_yandex_translate($apikey, $text, $dir, $return_empty = false): string|false

Description

This function leverages the Yandex Translate API to translate a given string from one language to another.

Parameters

$apikey
Your personal Yandex Translate API key.
$text
The string that you wish to translate.
$dir
The direction of the translation. This parameter should be formatted as a pair of language codes separated by a hyphen. For example, ‘en-ru’ would translate from English to Russian.
$return_empty
A boolean parameter that dictates the return behavior of the function in case of a failed translation. If set to true, an empty string will be returned when translation fails. If set to false, which is the default setting, the function will return a boolean false if the translation is unsuccessful.

Return Values

The function returns the translated text string. If the translation fails, the function’s return value will depend on the $return_empty parameter, as outlined above.

cyberseo_openai_shortcode

function cyberseo_openai_shortcode($atts): string

Description

This function generates text content using the OpenAI GPT API based on provided shortcode attributes. If the OpenAI API key is not set, or if an error occurs during the request or the API’s hourly request limit has been reached, the function returns an empty string.

Parameters

$atts
An associative array of attributes to control the OpenAI API request and the output. See the shortcode documentation for more information about the available attributes.

Return Values

Returns a string representing the generated content. If the OpenAI API key is not set, an error occurs during the request or the API’s hourly request limit has been reached, it returns an empty string.

Available Attributes

'model'
Specifies the OpenAI model to be used for text generation. The default model is ‘gpt-3.5-turbo’.
'messages'
An array of messages used as a conversation with the ‘gpt-3.5-turbo’ and ‘gpt-4’ models. Each message is an array containing a ‘role’ and ‘content’.
'prompt'
Specifies the prompt for the AI model to continue.
'best_of'
The number of the best completions to generate and select from.
'temperature'
Controls the randomness of the model’s output. A higher value makes the output more random, while a lower value makes it more deterministic.
'top_p'
Sets the nucleus sampling parameter, which controls the diversity of the output.
'presence_penalty'
The penalty applied to the presence of new, previously unseen tokens in the output.
'frequency_penalty'
The penalty applied to the frequency of the output tokens.
'max_tokens'
Sets the maximum number of tokens in the generated text. The default value depends on the chosen model.

Returns

Returns the generated text as a string, or an empty string if an error occurs.

Example

$atts = array('model' => 'gpt-3.5-turbo', 'prompt' => 'Write a short story about a heroic cat.', 'max_tokens' => 250);
$post['post_content'] = cyberseo_openai_shortcode($atts);

cyberseo_pixabay_shortcode

function cyberseo_pixabay_shortcode($atts): string

Description

This function generates an HTML string for an image tag, retrieving an image from the Pixabay API based on the provided shortcode attributes. If the Pixabay API key is not set, or if an error occurs during the request, the function returns an empty string.

Parameters

$atts
An associative array of attributes to control the Pixabay API request and the output. See the shortcode documentation for more information about the available attributes.

Return Values

Returns a string containing an HTML image tag with the retrieved image. If the Pixabay API key is not set or an error occurs during the request, it returns an empty string.

Available Attributes

'q'
Query string for the image search. This value is sanitized to remove tags and emojis. You can also use commas to separate your list of keywords. In this case, a random keyword will be chosen.
'lang'
The language of the query string. Default is ‘en’.
'image_type'
The type of image to be searched for. Possible values are ‘all’, ‘photo’, ‘illustration’, ‘vector’. Default is ‘all’.
'orientation'
The orientation of the image to be searched for. Possible values are ‘all’, ‘horizontal’, ‘vertical’. Default is ‘all’.
'category'
The category of the image to be searched for. Leave empty for all categories.
'min_width'
The minimum width of the image to be searched for. Default is ‘0’.
'min_height'
The minimum height of the image to be searched for. Default is ‘0’.
'colors'
The colors of the image to be searched for. Leave empty for all colors.
'order'
The order of the search results. Possible values are ‘popular’, ‘latest’. Default is ‘popular’.
'page'
The page number of the search results. Default is ‘1’.
'per_page'
The number of results per page. Default is ‘200’.
'safesearch'
Whether to filter the search results for safe content. Default is ‘false’.
'editors_choice'
Whether to only include editor’s choice in the search results. Default is ‘false’.
'choose'
The index of the image to be chosen from the search results. Default is ‘0’, which chooses a random image.
'class'
The class attribute for the generated image tag. Default is ‘aligncenter’.
'name'
The name attribute for the generated image tag. Default is ”.

cyberseo_dalle_shortcode

function cyberseo_dalle_shortcode($atts): string

Description

This function generates an image using the OpenAI DALL-E API based on provided shortcode attributes. If the OpenAI API key is not set, an error occurs during the request or the API’s hourly request limit has been reached, the function returns an empty string.

Parameters

$atts
An associative array of attributes to control the OpenAI DALL-E API request and the output. See the shortcode documentation for more information about the available attributes.

Return Values

Returns a string representing the HTML img tag with the generated image. If the OpenAI API key is not set, an error occurs during the request or the API’s hourly request limit has been reached, it returns an empty string.

Available Attributes

'model'
Specifies the OpenAI model to be used for text generation. Default is ‘gpt-3.5-turbo’. Other available models include ‘text-davinci-003’, ‘text-curie-001’, ‘text-babbage-001’, and ‘text-ada-001’.
'messages'
An array of messages used as a conversation with the ‘gpt-3.5-turbo’ and ‘gpt-4’ models. Each message is an array containing a ‘role’ and ‘content’.
'prompt'
Specifies the prompt for the AI model to continue.
'best_of'
The number of the best completions to generate and select from.
'temperature'
Controls the randomness of the model’s output. A higher value makes the output more random, while a lower value makes it more deterministic.
'top_p'
Sets the nucleus sampling parameter, which controls the diversity of the output.
'presence_penalty'
The penalty applied to the presence of new, previously unseen tokens in the output.
'frequency_penalty'
The penalty applied to the frequency of the output tokens.
'max_tokens'
Sets the maximum number of tokens in the generated text. Default value depends on the chosen model.

cyberseo_stable_diffusion_shortcode

function cyberseo_stable_diffusion_shortcode($atts): string

Description

This function generates an image using the StabilityAI API based on provided shortcode attributes. If the StabilityAI API key is not set, an error occurs during the request or the API’s hourly request limit has been reached, the function returns an empty string.

Parameters

$atts
An associative array of attributes to control the StabilityAI API request and the output. See the shortcode documentation for more information about the available attributes.

Return Values

Returns a string representing the HTML img tag with the generated image. If the StabilityAI API key is not set, an error occurs during the request or the API’s hourly request limit has been reached, it returns an empty string.

Available Attributes

text
The input text for the image generation.
name
The name of the generated image.
stable_diffusion_engine
The engine to be used for the stable diffusion process. Default is ‘stable-diffusion-512-v2-1’.
cfg_scale
The scale of the image configuration. Default is 7.
clip_guidance_preset
The preset for clip guidance. Default is ‘NONE’.
height
The height of the generated image. Default is 512.
width
The width of the generated image. Default is 512.
samples
The number of samples. Default is 1.
steps
The number of steps. Default is 50.
weight
The weight of the text prompt. Default is 1.
class
The CSS class to assign to the image. Default is ‘aligncenter’.
function cyberseo_gallery_shortcode($atts): string|false

Description

This function creates a gallery shortcode based on the attributes passed to it. The gallery is fetched from a URL and parsed for images. The images are then processed and added to the gallery. If the operation fails, based on the attribute ‘on_fail’, the function can either return an empty string or false.

Parameters

$atts
An associative array of attributes used to create the gallery. The attributes include ‘url’ (the URL of the gallery), ‘cols’ (the number of columns in the gallery), ‘max_images’ (maximum number of images to include in the gallery), ‘size’ (the size of the images in the gallery), ‘link’ (the type of link for the images), ‘featured_image’ (sets the featured image in the gallery), and ‘on_fail’ (action to take if the operation fails).

Return Values

Returns a string representing the gallery shortcode or an empty string if no images are found or the operation fails. Returns false if the ‘on_fail’ attribute is set to ‘delete’ and the operation fails.

Available Attributes

url
The URL of the gallery.
cols
The number of columns in the gallery. Default is ‘4’.
max_images
Maximum number of images to include in the gallery. Default is PHP_INT_MAX if not set.
size
The size of the images in the gallery. Default is an empty string.
link
The type of link for the images. Default is an empty string.
featured_image
Sets the featured image in the gallery. Options are ‘first’, ‘last’, ‘random’. Default is an empty string.
on_fail
Action to take if the operation fails. Options are ‘delete’ (returns false), any other value (returns an empty string). Default is an empty string.

cseo_openai_rewrite

function cseo_openai_rewrite($content): string

Description

This function utilizes the OpenAI GPT API to spin or rewrite the provided HTML text string. The rewriting process maintains the original HTML layout, including all elements, but the textual content itself is rephrased to create a new unique variation. OpenAI’s GPT (Generative Pretrained Transformer) is an advanced language processing AI model that excels in understanding and generating human-like text.

Parameters

$content
The HTML text string that is to be spun or rewritten. The string should contain the original content with full HTML layout. This content is reprocessed by the OpenAI GPT API to create a unique text variation, while preserving the original HTML structure and elements.

Return Values

Returns a string that is the spun or rewritten version of the input text. The returned text maintains the original HTML structure and elements but has unique wording and phrasing for the textual content. This output is produced using the OpenAI GPT API’s advanced language processing capabilities.

cseo_spinnerchief

function cseo_spinnerchief($content): string

Description

This function takes an HTML text string as input and uses the third-party SpinnerChief service to create a new, unique variation of the text. SpinnerChief is a software tool that utilizes advanced artificial intelligence algorithms to rewrite or ‘spin’ text, ensuring uniqueness while maintaining readability.

Parameters

$content
The HTML text string to be spun. This string represents the original content that will be processed by the SpinnerChief service to create a new, unique variation.

Return Values

The function returns the spun version of the input text as a string. This result is a new, unique variation of the original content, as generated by the SpinnerChief service. The returned text maintains the original HTML structure and elements but has unique wording and phrasing for the textual content.

cseo_spinrewriter

function cseo_spinrewriter($content): string

Description

This function uses the third-party SpinRewriter service to spin or rewrite the provided HTML text string. During this process, the original HTML layout, including all elements, is preserved, and only the textual content is rephrased to create a unique version. SpinRewriter is a powerful tool used for text spinning that employs advanced language processing algorithms to ensure content uniqueness while maintaining readability.

Parameters

$content
The HTML text string that is to be spun or rewritten. The string should contain the original content along with the full HTML layout. This content is then processed by the SpinRewriter service to generate a unique text variation while keeping the original HTML structure and elements intact.

Return Values

Returns a string that is the spun or rewritten version of the input text. The returned text maintains the original HTML structure and elements but offers unique wording and phrasing for the textual content. This output is generated by leveraging the advanced language processing capabilities of the SpinRewriter service.

cseo_wordai

function cseo_wordai($content): string

Description

This function uses the third-party WordAI service to spin or rewrite the provided HTML text string. During this process, the original HTML layout, including all elements, is preserved, and only the textual content is rephrased to create a unique version. WordAI is an advanced tool for text spinning that utilizes complex language processing algorithms to ensure content uniqueness while maintaining readability.

Parameters

$content
The HTML text string that is to be spun or rewritten. The string should contain the original content along with the full HTML layout. This content is then processed by the WordAI service to generate a unique text variation while keeping the original HTML structure and elements intact.

Return Values

Returns a string that is the spun or rewritten version of the input text. The returned text maintains the original HTML structure and elements but offers unique wording and phrasing for the textual content. This output is generated by leveraging the advanced language processing capabilities of the WordAI service.

cseo_chimprewriter

function cseo_chimprewriter($content): string

Description

This function utilizes the third-party ChimpRewriter service to spin or rewrite the provided HTML text string. During this process, the original HTML layout, including all elements, is preserved, while the textual content alone is reworded to generate a unique version. ChimpRewriter is a prominent text spinning tool that harnesses sophisticated language processing algorithms to maintain content originality while preserving readability.

Parameters

$content
The HTML text string that is intended to be spun or rewritten. This string should incorporate the original content together with the complete HTML layout. The ChimpRewriter service then processes this content to yield a unique textual variant, ensuring the original HTML structure and elements remain unaffected.

Return Values

Returns a string that is the spun or rewritten version of the input text. The returned text sustains the original HTML structure and elements, but offers uniquely worded and phrased textual content. The output is produced by exploiting the advanced language processing capabilities of the ChimpRewriter service.

cseo_espinner

function cseo_espinner($content): string

Description

This function leverages the third-party ESPinner service to spin or rewrite the provided HTML text string. Throughout this process, the original HTML layout, inclusive of all elements, is preserved, and only the textual content is reworded to create a unique version. ESPinner is a renowned text spinning tool that utilizes advanced language processing algorithms to ensure content uniqueness while preserving readability.

Parameters

$content
The HTML text string that is aimed to be spun or rewritten. This string should encompass the original content along with the full HTML layout. The ESPinner service then processes this content to produce a unique textual variant, keeping the original HTML structure and elements unaltered.

Return Values

Returns a string that represents the spun or rewritten version of the input text. The returned text retains the original HTML structure and elements, but delivers uniquely worded and phrased textual content. The output is crafted by employing the advanced language processing capabilities of the ESPinner service.

cseo_tbs

function cseo_tbs($content): string

Description

This function employs the third-party TBS (The Best Spinner) service to spin or rewrite the supplied HTML text string. During this operation, the original HTML layout, including all the elements, is maintained, and only the textual content is reworded to generate a unique variant. The Best Spinner is a distinguished text spinning tool that uses cutting-edge language processing algorithms to ensure content originality while upholding readability.

Parameters

$content
The HTML text string that needs to be spun or rewritten. This string should include the original content along with the full HTML layout. The TBS service then treats this content to create a unique textual alternative, ensuring that the original HTML structure and elements stay intact.

Return Values

Returns a string that is the spun or rewritten version of the input text. The returned text upholds the original HTML structure and elements but features uniquely phrased and worded textual content. The output is generated by harnessing the sophisticated language processing potential of The Best Spinner service.

cseo_xspinner

function cseo_xspinner($content): string

Description

This function utilizes the third-party XSpinner service to spin or rewrite the supplied HTML text string. The procedure ensures the original HTML layout, along with all its elements, remains intact while the textual content is reworded to produce a distinct variant. XSpinner is a renowned spinning tool that leverages state-of-the-art language processing algorithms to create fresh content while maintaining readability.

Parameters

$content
The HTML text string that needs spinning or rewriting. This string should encapsulate the original content with the complete HTML layout. The XSpinner service then processes this content to create a unique textual version, while ensuring the original HTML structure and elements are preserved.

Return Values

Returns a string that is the spun or rewritten version of the input text. The returned text retains the original HTML structure and elements but features uniquely phrased and worded textual content. This output is produced using the advanced language processing capabilities of the XSpinner service.

cseo_synonymize

function cseo_synonymize($content): string

Description

This function applies synonymization to the provided text string using a built-in synonym/rewrite table. Synonymization involves the substitution of words in the text with their synonyms to create a distinct but semantically similar version of the original content. The process leverages the built-in table that encapsulates synonyms and rewrite rules.

Parameters

$content
The text string to be synonymized or rewritten. This string contains the original content which the function processes to produce a semantically similar version using the built-in synonym/rewrite table.

Return Values

Returns a string which is the synonymized or rewritten version of the input text. The returned text features distinct wording but similar meaning to the original content, achieved by leveraging the synonyms and rewrite rules defined in the built-in table.

cseo_get_random_image

function cseo_get_random_image($keyword, $min_width = 0, $min_height = 0): string

Description

This function retrieves a random image with a Creative Common License from a Google Images search that matches the given keyword. The function allows you to specify a minimum width and height for the desired image. If no image is found, an empty string is returned.

Parameters

$keywords
The keywords to search for images in Google Images. Use commas to separate your list of keywords. In this case, a random keyword will be chosen.
$min_width (optional)
The minimum width of the image. Default value is 0.
$min_height (optional)
The minimum height of the image. Default value is 0.

Return Values

Returns the URL of a random image that meets the search criteria and size requirements, or an empty string if no such image is found.

cseo_get_youtube_video

function cseo_get_youtube_video($keyword): string

Description

This function retrieves a YouTube video that matches the provided keyword. It performs a YouTube search with the keyword, then selects the first video that is playable in an embeddable player. The function returns an HTML string that embeds the video, or an empty string if no suitable video is found.

Parameters

$keyword
The keyword to search for videos on YouTube.

Return Values

Returns a string of HTML code that embeds the found YouTube video in a webpage, or an empty string if no suitable video is found.

cseo_is_binary

function cseo_is_binary($url): bool

Description

This function checks whether a given URL points to a binary file. It uses the HTTP headers of the URL to check for the content type and content length. If the content type is ‘text’ or the content length is 0, it’s considered not a binary file.

Parameters

$url
The URL of the file to be checked for binary file type.

Return Values

Returns a boolean value: true if the URL points to a binary file, false otherwise.

cseo_must_be_binary

function cseo_must_be_binary($filename)

Description

This function adds a filename to the list of URLs that must be checked for binary file type. It’s intended for use with the CyberSEO Pro Syndicator to prevent posts from being added if the specified URL doesn’t link to a binary file.

Parameters

$filename
The URL of the file to be checked for binary file type.

cseo_unzip

function cseo_unzip($content): mixed

Description

This function attempts to unzip a provided content, assuming it represents a zipped file. If unzipping fails for any reason, the function returns the original content.

Parameters

$content
The binary content assumed to be a zipped file.

Return Values

Returns the unzipped content if successful. If the operation fails, it returns the original content. The return type could be a string (the original content) or mixed (the unzipped content).

cseo_remove_emojis

function cseo_remove_emojis($string): string

Description

This function is designed to remove emojis from a provided string. It is a helpful tool for ensuring that text is free of these characters, which can sometimes cause issues with certain text processing or display operations.

Parameters

$string
The string from which emojis should be removed. This could be a short message, a long text, or any other string that might contain emojis.

Return Values

The function returns the input string, but with all emojis removed. The result is a clean, emoji-free string that can be used in contexts where emojis may not be desirable or supported.

cseo_remove_utf8_bom

function cseo_remove_utf8_bom($text): string

Description

This function is designed to remove the UTF-8 byte order mark (BOM) from a provided string. The UTF-8 BOM is a sequence of bytes at the start of a text stream (0xEF, 0xBB, 0xBF) that can cause issues with certain text processing or display operations.

Parameters

$text
The text string from which the UTF-8 BOM should be removed.

Return Values

The function returns the input text, but with the UTF-8 BOM removed. The result is a clean string that is free of the UTF-8 BOM, allowing it to be safely used in contexts where the BOM may cause problems.

cseo_strip_specific_tags

function cseo_strip_specific_tags($html, $tagsToRemove): string

Description

This function is designed to remove specific HTML tags from a given string. This is useful when you want to cleanse a block of HTML code of certain elements while leaving the rest intact.

Parameters

$html
The HTML string from which specific tags should be removed.
$tagsToRemove
An array or a comma-separated list of HTML tags to be removed from the HTML string. The tags should be specified without the angle brackets. For instance, to remove paragraph and break tags, you would pass [‘p’, ‘br’] or ‘p,br’.

Return Values

The function returns the input HTML string, but with the specified tags removed. The result is a cleaned-up HTML string that can be used in contexts where certain tags are not wanted or supported.

cseo_shorten_string_by_words

cseo_shorten_string_by_words($string, $max_length): string

Description

This function is designed to truncate a provided plain text string to a specified maximum length. The truncated string is appended with “…”.

Parameters

$text
The plain string that you wish to truncate.
$max_length
The maximum desired length for the truncated string.

Return Values

The function returns the input plain text string, truncated to the specified length and appended with “…”.

cseo_shorten_html

function cseo_shorten_html($text, $max_length = 0, $ending = '...', $exact = false): string

Description

This function is designed to truncate a provided HTML string to a specified maximum length, ensuring that it does not break any HTML tags in the process. The function takes into account the length of the plain text content, not the HTML markup. The truncated string is appended with a specified ending sequence (by default, an ellipsis).

Parameters

$text
The HTML string that you wish to truncate.
$max_length
The maximum desired length for the truncated string. This length refers to the text content only and does not count HTML tags. If set to 0, which is the default setting, no truncation occurs and the function returns the input string as is.
$ending
A string to be appended to the end of the truncated text, indicating that the content has been shortened. By default, this is set to an ellipsis (‘…’).
$exact
A boolean parameter that dictates how the string is truncated. If set to true, the string is cut off exactly at the specified maximum length, possibly in the middle of a word. If set to false, which is the default setting, the string is cut off at the nearest space character, ensuring that no words are split in the middle.

Return Values

The function returns the input HTML string, truncated to the specified length and appended with the specified ending. The result is a shortened HTML string that maintains proper HTML tag structure, regardless of where the truncation occurred.

cseo_strip_tags

function cseo_strip_tags($string): string

Description

This function is designed to strip HTML tags from a given string, with the exception of the style tags. It first strips all HTML tags, leaving the style tags intact, and then removes the content within the style tags, ensuring that the styles do not affect the remaining text.

Parameters

$string
The string from which HTML tags should be stripped. This string could contain a mixture of plain text and HTML markup.

Return Values

The function returns the input string, but with all HTML tags removed, excluding the style tags. The content within the style tags is also removed to prevent it from affecting the resulting text. The result is a clean string with the visual presentation defined in style tags preserved.

cseo_text_to_html

function cseo_text_to_html($text): string

Description

This function is designed to convert a plain text string into HTML by wrapping each line of text within paragraph tags. The function treats each line as a separate paragraph, and any empty lines are omitted in the output to avoid creating unnecessary empty paragraph tags.

Parameters

$text
The plain text string to be converted into HTML. The string can contain multiple lines, separated by newline characters (“\n”).

Return Values

The function returns the input text, but with each line wrapped within paragraph tags, thereby converting the plain text into HTML. The result is an HTML string that represents the original text but with the added semantics and styling capabilities of HTML paragraph elements.

cseo_apply_spintax

function cseo_apply_spintax($text): string

Description

This function applies Spintax to a given text. Spintax, or spin syntax, is a feature often used in SEO where variations of text are indicated in curly braces “{” and “}”, separated by vertical bars “|”. The function randomly selects one of these options for every set of variations in the text, creating unique output each time it is run.

Parameters

$text
The text to apply Spintax to.

Return Values

Returns a string where Spintax has been applied. Each variation marked by Spintax in the original text is replaced with one randomly selected option.