su_shortcode_dummy_text_fetch

The shortcodes-ultimate su shortcode dummy text fetch function.

Published Date - February 15, 2021

Description

su_shortcode_dummy_text_fetch( $what, $amount, $cache );

Parameters

  1. $what

  2. $amount

  3. $cache


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_shortcode_dummy_text_fetch' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/shortcodes/dummy-text.php';
}

// The input(s). 
$what = null;
$amount = null;
$cache = null;

// NOTICE! Understand what this does before running.
$result = su_shortcode_dummy_text_fetch( $what, $amount, $cache );
            

Defined

The function is defined in the following location(s).

shortcodes-ultimate/includes/shortcodes/dummy-text.php

function su_shortcode_dummy_text_fetch( $what, $amount, $cache ) {

	$key = sprintf( 'su/cache/dummy_text/%s/%s', $what, $amount );

	if ( $cache ) {
		$transient = get_transient( $key );
	}

	if ( $transient ) {
		return $transient;
	}

	$url = esc_url_raw(
		sprintf(
			'http://www.lipsum.com/feed/xml?what=%s&amount=%s&start=0',
			$what,
			$amount
		)
	);

	$xml  = simplexml_load_file( $url );
	$html = wpautop( str_replace( "\n", "\n\n", $xml->lipsum ) );

	set_transient( $key, $html, 30 * DAY_IN_SECONDS );

	return $html;

}