su_shortcode_feed

The shortcodes-ultimate su shortcode feed function.

Published Date - February 15, 2021

Description

su_shortcode_feed( $atts, $content );

Parameters

  1. $atts

  2. $content


Usage

The following example is for adding a hook callback.

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

// The input(s). 
$atts = null;
$content = null;

// NOTICE! Understand what this does before running.
$result = su_shortcode_feed( $atts, $content );
            

Defined

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

shortcodes-ultimate/includes/shortcodes/feed.php

function su_shortcode_feed( $atts = null, $content = null ) {

	$atts   = su_parse_shortcode_atts( 'feed', $atts );
	$feed   = null;
	$items  = array();
	$output = '';

	$atts['url'] = wp_specialchars_decode( $atts['url'] );

	if ( ! filter_var( $atts['url'], FILTER_VALIDATE_URL ) ) {
		return su_error_message( 'Feed', __( 'invalid feed URL', 'shortcodes-ultimate' ) );
	}

	$feed = fetch_feed( $atts['url'] );

	if ( is_wp_error( $feed ) ) {
		return su_error_message( 'Feed', $feed->get_error_message() );
	}

	$items = $feed->get_items( 0, (int) $atts['limit'] );

	if ( ! count( $items ) ) {
		return su_error_message( 'Feed', __( 'no items in the feed', 'shortcodes-ultimate' ) );
	}

	foreach ( $items as $item ) {

		$output .= sprintf(
			'<li><a href="%s" target="_%s" title="%s">%s</a></li>',
			esc_attr( $item->get_permalink() ),
			sanitize_key( $atts['target'] ),
			esc_attr( $item->get_description() ),
			wp_kses_post( $item->get_title() )
		);

	}

	return sprintf(
		'<ul class="su-feed%s">%s</ul>',
		esc_attr( su_get_css_class( $atts ) ),
		$output
	);

}