From c53be8a846d871c04a5e647cecbcac8c37e999d1 Mon Sep 17 00:00:00 2001 From: devuri Date: Sat, 5 Dec 2020 03:06:38 -0500 Subject: [PATCH] feat: new shortcode can now allow turn on 'links' and 'caption' --- src/InstagramFeed.php | 31 +++++ src/View/Display.php | 265 ++++++++++++++++++++++++++++++++++++++++++ src/shortcode.php | 23 ++-- 3 files changed, 304 insertions(+), 15 deletions(-) create mode 100644 src/InstagramFeed.php create mode 100644 src/View/Display.php diff --git a/src/InstagramFeed.php b/src/InstagramFeed.php new file mode 100644 index 0000000..84f3976 --- /dev/null +++ b/src/InstagramFeed.php @@ -0,0 +1,31 @@ +igfeed( $args ); + } + + /** + * Get the Admin list of Feed items + */ + public static function admin_view() { + return self::get()->admin_view(); + } +} diff --git a/src/View/Display.php b/src/View/Display.php new file mode 100644 index 0000000..156e06c --- /dev/null +++ b/src/View/Display.php @@ -0,0 +1,265 @@ +'; // @codingStandardsIgnoreLine + if ( is_array( get_option( 'simsf_user_media' ) ) ) { + /** + * Get IG list + * limit the return values + */ + $i = 0; + foreach ( get_option( 'simsf_user_media' ) as $mkey => $media ) { + if ( isset( $media->caption ) ) { + $caption = $media->caption; + } else { + $caption = ''; + } + if ( 'VIDEO' === $media->media_type ) continue; + echo '
' . esc_attr( $caption ) . '
'; + if ( ++$i === $limit ) break; + } + } + echo ''; + } + + /** + * The feed igfeed() + * + * Shortcode to display the instagram feed [igfeed]. + * + * @param array $args . + */ + public function igfeed( $args = array() ) { + + $defaults = array( + 'limit' => 6, + 'linked' => 'no', + 'caption' => 'off', + ); + $args = wp_parse_args( $args, $defaults ); + + // make sure limit is integer. + $args['limit'] = absint( $args['limit'] ); + + // caption and linked. + if ( 'yes' === $args['linked'] && 'on' === $args['caption'] ) { + return $this->view_linked_caption( $args['limit'] ); + } + + // without caption no link. + if ( 'on' === $args['caption'] ) { + return $this->view_with_caption( $args['limit'] ); + } + + // linked without caption. + if ( 'yes' === $args['linked'] ) { + return $this->view_linked( $args['limit'] ); + } + + return $this->view( $args['limit'] ); + + } + + /** + * Display View + * + * Get the Images + * + * @param integer $limit . + * + * @return void + */ + public function view_linked_caption( $limit = 6 ) { + ?> +
+
+ $media ) { + + if ( isset( $media->caption ) ) { + $caption = $media->caption; + } else { + $caption = ''; + } + + if ( 'VIDEO' === $media->media_type ) continue; + ?> + + +
+
+ +
+
+ $media ) { + + if ( isset( $media->caption ) ) { + $caption = $media->caption; + } else { + $caption = ''; + } + + if ( 'VIDEO' === $media->media_type ) continue; + ?> +
+ <?php echo esc_attr( $caption ); ?> +
+

+ +

+
+
+ +
+
+ +
+
+ $media ) { + + if ( isset( $media->caption ) ) { + $caption = $media->caption; + } else { + $caption = ''; + } + + if ( 'VIDEO' === $media->media_type ) continue; + ?> +
+ + <?php echo esc_attr( $caption ); ?> + +
+ +
+
+ +
+
+ $media ) { + + if ( isset( $media->caption ) ) { + $caption = $media->caption; + } else { + $caption = ''; + } + + if ( 'VIDEO' === $media->media_type ) continue; + ?> +
+ <?php echo esc_attr( $caption ); ?> +
+ +
+
+ 6, - 'linked' => 'no', + 'limit' => 6, + 'linked' => 'no', + 'caption' => 'off', ), $atts ); - // params . - $limit = absint( $a['limit'] ); - $linked = strtolower( $a['linked'] ); - /** * Load the grid styles */ - wp_enqueue_style( 'sim-social-feed-grid' ); + wp_enqueue_style( 'igfeed-grid' ); ob_start(); - if ( 'yes' === $linked ) { - InstagramSocialFeed::igfeedlinked( $limit ); - } else { - InstagramSocialFeed::igfeed( $limit ); - } + InstagramFeed::view( $a ); $output_sfd = ob_get_contents(); @@ -42,4 +35,4 @@ function simsf_igmedia_feed( $atts ) { return $output_sfd; } - add_shortcode( 'ig_socialfeed', 'simsf_igmedia_feed' ); + add_shortcode( 'igfeed', 'simsf_igmedia_feed' );