mirror of
https://github.com/10h30/Display-Posts-Shortcode-Remote.git
synced 2026-07-12 03:05:59 +09:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 12684b8b65 | |||
| bd7a7b91ba | |||
| 614ae1d45a | |||
| b52d6a871b | |||
| 7742683dad |
@@ -11,7 +11,7 @@
|
||||
* Plugin Name: Display Posts Shortcode - Remote
|
||||
* Plugin URI: https://connections-pro.com/
|
||||
* Description: An extension for the Display Posts Shortcode plugin which adds a shortcode for displaying posts from a remote WordPress site.
|
||||
* Version: 1.1
|
||||
* Version: 1.1.1
|
||||
* Author: Steven A. Zahm
|
||||
* Author URI: https://connections-pro.com
|
||||
* License: GPL-2.0+
|
||||
@@ -24,7 +24,7 @@ if ( ! class_exists( 'Display_Posts_Remote' ) ) {
|
||||
|
||||
final class Display_Posts_Remote {
|
||||
|
||||
const VERSION = '1.1';
|
||||
const VERSION = '1.1.1';
|
||||
|
||||
/**
|
||||
* @var Display_Posts_Remote Stores the instance of this class.
|
||||
@@ -253,7 +253,7 @@ if ( ! class_exists( 'Display_Posts_Remote' ) ) {
|
||||
$url = trailingslashit( $atts['url'] ) . 'wp-json/wp/v2/posts';
|
||||
$url = add_query_arg( '_embed' , '', $url );
|
||||
|
||||
if ( ! empty( $atts['category_id'] ) ) {
|
||||
if ( ! empty( $atts['category_id'] ) && ( is_array( $atts['category_id'] ) || false !== filter_var( $atts['category_id'], FILTER_VALIDATE_BOOLEAN ) ) ) {
|
||||
|
||||
if ( is_array( $atts['category_id'] ) ) {
|
||||
|
||||
@@ -319,7 +319,7 @@ if ( ! class_exists( 'Display_Posts_Remote' ) ) {
|
||||
public function getDefaults() {
|
||||
|
||||
return array(
|
||||
'category_id' => 0,
|
||||
'category_id' => '',
|
||||
'content_class' => 'content',
|
||||
'date_format' => '(n/j/Y)',
|
||||
'include_content' => FALSE,
|
||||
@@ -327,7 +327,7 @@ if ( ! class_exists( 'Display_Posts_Remote' ) ) {
|
||||
'include_date_modified' => FALSE,
|
||||
'include_link' => TRUE,
|
||||
'include_title' => TRUE,
|
||||
'image_size' => 'thumbnail',
|
||||
'image_size' => '',
|
||||
'no_posts_message' => __( 'No posts to display.', 'display-posts-shortcode-remote' ),
|
||||
'order' => 'desc',
|
||||
'orderby' => 'date',
|
||||
@@ -353,6 +353,19 @@ if ( ! class_exists( 'Display_Posts_Remote' ) ) {
|
||||
$defaults = Display_Posts_Remote()->getDefaults();
|
||||
$atts = shortcode_atts( $defaults, $untrusted, 'display-posts-remote' );
|
||||
|
||||
$restSupportOrderby = array(
|
||||
'author',
|
||||
'date',
|
||||
'id',
|
||||
'include',
|
||||
'modified',
|
||||
'parent',
|
||||
'relevance',
|
||||
'slug',
|
||||
'include_slugs',
|
||||
'title',
|
||||
);
|
||||
|
||||
$atts['category_id'] = wp_parse_id_list( $atts['category_id'] );
|
||||
$atts['content_class'] = array_map( 'sanitize_html_class', ( explode( ' ', $atts['content_class'] ) ) );
|
||||
$atts['date_format'] = sanitize_text_field( $atts['date_format'] );
|
||||
@@ -364,7 +377,7 @@ if ( ! class_exists( 'Display_Posts_Remote' ) ) {
|
||||
$atts['image_size'] = sanitize_key( $atts['image_size'] );
|
||||
$atts['no_posts_message'] = sanitize_text_field( $atts['no_posts_message'] );
|
||||
$atts['order'] = in_array( strtolower( $atts['order'] ), array( 'asc', 'desc' ) ) ? strtolower( sanitize_key( $atts['order'] ) ) : 'desc';
|
||||
$atts['orderby'] = in_array( strtolower( $atts['orderby'] ), array( 'date', 'id', 'relevance', 'slug', 'title' ) ) ? strtolower( sanitize_key( $atts['orderby'] ) ) : 'date';
|
||||
$atts['orderby'] = in_array( strtolower( $atts['orderby'] ), $restSupportOrderby ) ? strtolower( sanitize_key( $atts['orderby'] ) ) : 'date';
|
||||
$atts['posts_per_page'] = filter_var(
|
||||
$atts['posts_per_page'],
|
||||
FILTER_VALIDATE_INT,
|
||||
@@ -451,9 +464,12 @@ if ( ! class_exists( 'Display_Posts_Remote' ) ) {
|
||||
|
||||
$title = '';
|
||||
}
|
||||
//print_r($post);
|
||||
|
||||
$imageAttributes = $self->getImageAttributes( $atts );
|
||||
|
||||
if ( ! empty ($atts['image_size'])) {
|
||||
|
||||
if ( $atts['image_size'] && $post->has_post_thumbnail() && $atts['include_link'] ) {
|
||||
|
||||
$image = '<a class="image" href="' . esc_url( $post->get_permalink() ) . '">' . $post->get_the_post_thumbnail( $atts['image_size'], $imageAttributes ) . '</a> ';
|
||||
@@ -471,6 +487,8 @@ if ( ! class_exists( 'Display_Posts_Remote' ) ) {
|
||||
$image = '<span class="image">' . $post->get_the_post_thumbnail( 'full', $imageAttributes ) . '</span> ';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( $atts['include_date'] ) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user