'author-rss-feed-widget', 'description' => __( 'Shows author-specific RSS feeds on author pages or posts', 'author-rss-feed' ) ); parent::__construct( 'author-rss-feed', __( 'Author RSS Feed', 'author-rss-feed' ), $widget_details ); } /** * Widget Form * * The form shown in the admin when building the widget. * * @param array $instance The widget details * @author Daniel Pataki * @since 1.0.0 * */ public function form( $instance ) { $title = ( !empty( $instance['title'] ) ) ? $instance['title'] : ''; $count = ( !empty( $instance['count'] ) ) ? $instance['count'] : 5; $default_feed = ( !isset( $instance['default_feed'] ) ) ? 'https://wordpress.org/news/feed/' : $instance['default_feed']; $feed_field = ( !empty( $instance['feed_field'] ) ) ? $instance['feed_field'] : 'author_feed'; $show_on = ( !isset( $instance['show_on'] ) ) ? array( 'author_archives', 'single_posts' ) : $instance['show_on']; $show_on_options = array( 'single_posts' => __( 'Single Posts', 'author-rss-feed' ), 'author_archives' => __( 'Author Archives', 'author-rss-feed' ), ); ?>


$name ) : $checked = ( in_array( $value, $show_on ) ) ? 'checked="checked"' : ''; ?> type='checkbox' id="get_field_id( 'show_on' ); ?>-" name="get_field_name( 'show_on' ); ?>[]" value=''>

determine_feed_url( $instance ); $feed = $this->get_feed( $feed_url, $instance['count'] ); if( is_wp_error( $feed ) ) { return; } echo $args['before_widget']; if( !empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; } echo ''; echo $args['after_widget']; } /** * Determine Feed URL * * Figures out the feed URL based on the widget settings * * @param array $instance The widget details * @author Daniel Pataki * @since 1.0.0 * */ function determine_feed_url( $instance ) { // Singular Page Authors if( is_singular() && in_array( 'single_posts', $instance['show_on'] ) ) { global $post; $author_rss = get_user_meta( $post->post_author, $instance['feed_field'], true ); } // Author Archive Authors elseif( is_author() ) { $profile = get_user_by( 'id', get_query_var( 'author' ) ); if( empty( $profile ) ) { global $wp_query; $profile = get_user_by( 'slug', $wp_query->query['author_name'] ); } $author_rss = get_user_meta( $profile->ID, $instance['feed_field'], true ); } $author_rss = ( empty( $author_rss ) ) ? $instance['default_feed'] : $author_rss; return $author_rss; } /** * Get And Format Field * * @param string $feed_url The feed URL to retrieve data from * @author Daniel Pataki * @since 1.0.0 * */ function get_feed( $feed_url, $feed_count ) { $feed_data = array(); $feed = fetch_feed( $feed_url ); if( is_wp_error( $feed ) ) { return $feed; } $i=0; foreach ( $feed->get_items( 0, $feed_count ) as $item ) { $link = $item->get_link(); while ( stristr( $link, 'http' ) != $link ) { $link = substr( $link, 1 ); } $feed_data[$i]['link'] = esc_url( strip_tags( $link ) ); $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); if ( empty( $title ) ) { $title = __( 'Untitled', 'author-rss-feed' ); } $feed_data[$i]['title'] = $title; $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); $feed_data[$i]['description'] = $desc; $feed_data[$i]['date'] = $item->get_date( 'U' ); $i++; } return $feed_data; } } ?>