[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> feed.php (source)

   1  <?php
   2  /**
   3   * WordPress Feed API
   4   *
   5   * Many of the functions used in here belong in The Loop, or The Loop for the
   6   * Feeds.
   7   *
   8   * @package WordPress
   9   * @subpackage Feed
  10   * @since 2.1.0
  11   */
  12  
  13  /**
  14   * RSS container for the bloginfo function.
  15   *
  16   * You can retrieve anything that you can using the get_bloginfo() function.
  17   * Everything will be stripped of tags and characters converted, when the values
  18   * are retrieved for use in the feeds.
  19   *
  20   * @since 1.5.1
  21   * @see get_bloginfo() For the list of possible values to display.
  22   *
  23   * @param string $show See get_bloginfo() for possible values.
  24   * @return string
  25   */
  26  function get_bloginfo_rss( $show = '' ) {
  27      $info = strip_tags( get_bloginfo( $show ) );
  28      /**
  29       * Filters the bloginfo for use in RSS feeds.
  30       *
  31       * @since 2.2.0
  32       *
  33       * @see convert_chars()
  34       * @see get_bloginfo()
  35       *
  36       * @param string $info Converted string value of the blog information.
  37       * @param string $show The type of blog information to retrieve.
  38       */
  39      return apply_filters( 'get_bloginfo_rss', convert_chars( $info ), $show );
  40  }
  41  
  42  /**
  43   * Display RSS container for the bloginfo function.
  44   *
  45   * You can retrieve anything that you can using the get_bloginfo() function.
  46   * Everything will be stripped of tags and characters converted, when the values
  47   * are retrieved for use in the feeds.
  48   *
  49   * @since 0.71
  50   * @see get_bloginfo() For the list of possible values to display.
  51   *
  52   * @param string $show See get_bloginfo() for possible values.
  53   */
  54  function bloginfo_rss( $show = '' ) {
  55      /**
  56       * Filters the bloginfo for display in RSS feeds.
  57       *
  58       * @since 2.1.0
  59       *
  60       * @see get_bloginfo()
  61       *
  62       * @param string $rss_container RSS container for the blog information.
  63       * @param string $show          The type of blog information to retrieve.
  64       */
  65      echo apply_filters( 'bloginfo_rss', get_bloginfo_rss( $show ), $show );
  66  }
  67  
  68  /**
  69   * Retrieve the default feed.
  70   *
  71   * The default feed is 'rss2', unless a plugin changes it through the
  72   * {@see 'default_feed'} filter.
  73   *
  74   * @since 2.5.0
  75   *
  76   * @return string Default feed, or for example 'rss2', 'atom', etc.
  77   */
  78  function get_default_feed() {
  79      /**
  80       * Filters the default feed type.
  81       *
  82       * @since 2.5.0
  83       *
  84       * @param string $feed_type Type of default feed. Possible values include 'rss2', 'atom'.
  85       *                          Default 'rss2'.
  86       */
  87      $default_feed = apply_filters( 'default_feed', 'rss2' );
  88      return 'rss' == $default_feed ? 'rss2' : $default_feed;
  89  }
  90  
  91  /**
  92   * Retrieve the blog title for the feed title.
  93   *
  94   * @since 2.2.0
  95   * @since 4.4.0 The optional `$sep` parameter was deprecated and renamed to `$deprecated`.
  96   *
  97   * @param string $deprecated Unused..
  98   * @return string The document title.
  99   */
 100  function get_wp_title_rss( $deprecated = '&#8211;' ) {
 101      if ( '&#8211;' !== $deprecated ) {
 102          /* translators: %s: 'document_title_separator' filter name. */
 103          _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) );
 104      }
 105  
 106      /**
 107       * Filters the blog title for use as the feed title.
 108       *
 109       * @since 2.2.0
 110       * @since 4.4.0 The `$sep` parameter was deprecated and renamed to `$deprecated`.
 111       *
 112       * @param string $title      The current blog title.
 113       * @param string $deprecated Unused.
 114       */
 115      return apply_filters( 'get_wp_title_rss', wp_get_document_title(), $deprecated );
 116  }
 117  
 118  /**
 119   * Display the blog title for display of the feed title.
 120   *
 121   * @since 2.2.0
 122   * @since 4.4.0 The optional `$sep` parameter was deprecated and renamed to `$deprecated`.
 123   *
 124   * @param string $deprecated Unused.
 125   */
 126  function wp_title_rss( $deprecated = '&#8211;' ) {
 127      if ( '&#8211;' !== $deprecated ) {
 128          /* translators: %s: 'document_title_separator' filter name. */
 129          _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) );
 130      }
 131  
 132      /**
 133       * Filters the blog title for display of the feed title.
 134       *
 135       * @since 2.2.0
 136       * @since 4.4.0 The `$sep` parameter was deprecated and renamed to `$deprecated`.
 137       *
 138       * @see get_wp_title_rss()
 139       *
 140       * @param string $wp_title_rss The current blog title.
 141       * @param string $deprecated   Unused.
 142       */
 143      echo apply_filters( 'wp_title_rss', get_wp_title_rss(), $deprecated );
 144  }
 145  
 146  /**
 147   * Retrieve the current post title for the feed.
 148   *
 149   * @since 2.0.0
 150   *
 151   * @return string Current post title.
 152   */
 153  function get_the_title_rss() {
 154      $title = get_the_title();
 155  
 156      /**
 157       * Filters the post title for use in a feed.
 158       *
 159       * @since 1.2.0
 160       *
 161       * @param string $title The current post title.
 162       */
 163      $title = apply_filters( 'the_title_rss', $title );
 164      return $title;
 165  }
 166  
 167  /**
 168   * Display the post title in the feed.
 169   *
 170   * @since 0.71
 171   */
 172  function the_title_rss() {
 173      echo get_the_title_rss();
 174  }
 175  
 176  /**
 177   * Retrieve the post content for feeds.
 178   *
 179   * @since 2.9.0
 180   * @see get_the_content()
 181   *
 182   * @param string $feed_type The type of feed. rss2 | atom | rss | rdf
 183   * @return string The filtered content.
 184   */
 185  function get_the_content_feed( $feed_type = null ) {
 186      if ( ! $feed_type ) {
 187          $feed_type = get_default_feed();
 188      }
 189  
 190      /** This filter is documented in wp-includes/post-template.php */
 191      $content = apply_filters( 'the_content', get_the_content() );
 192      $content = str_replace( ']]>', ']]&gt;', $content );
 193      /**
 194       * Filters the post content for use in feeds.
 195       *
 196       * @since 2.9.0
 197       *
 198       * @param string $content   The current post content.
 199       * @param string $feed_type Type of feed. Possible values include 'rss2', 'atom'.
 200       *                          Default 'rss2'.
 201       */
 202      return apply_filters( 'the_content_feed', $content, $feed_type );
 203  }
 204  
 205  /**
 206   * Display the post content for feeds.
 207   *
 208   * @since 2.9.0
 209   *
 210   * @param string $feed_type The type of feed. rss2 | atom | rss | rdf
 211   */
 212  function the_content_feed( $feed_type = null ) {
 213      echo get_the_content_feed( $feed_type );
 214  }
 215  
 216  /**
 217   * Display the post excerpt for the feed.
 218   *
 219   * @since 0.71
 220   */
 221  function the_excerpt_rss() {
 222      $output = get_the_excerpt();
 223      /**
 224       * Filters the post excerpt for a feed.
 225       *
 226       * @since 1.2.0
 227       *
 228       * @param string $output The current post excerpt.
 229       */
 230      echo apply_filters( 'the_excerpt_rss', $output );
 231  }
 232  
 233  /**
 234   * Display the permalink to the post for use in feeds.
 235   *
 236   * @since 2.3.0
 237   */
 238  function the_permalink_rss() {
 239      /**
 240       * Filters the permalink to the post for use in feeds.
 241       *
 242       * @since 2.3.0
 243       *
 244       * @param string $post_permalink The current post permalink.
 245       */
 246      echo esc_url( apply_filters( 'the_permalink_rss', get_permalink() ) );
 247  }
 248  
 249  /**
 250   * Outputs the link to the comments for the current post in an xml safe way
 251   *
 252   * @since 3.0.0
 253   */
 254  function comments_link_feed() {
 255      /**
 256       * Filters the comments permalink for the current post.
 257       *
 258       * @since 3.6.0
 259       *
 260       * @param string $comment_permalink The current comment permalink with
 261       *                                  '#comments' appended.
 262       */
 263      echo esc_url( apply_filters( 'comments_link_feed', get_comments_link() ) );
 264  }
 265  
 266  /**
 267   * Display the feed GUID for the current comment.
 268   *
 269   * @since 2.5.0
 270   *
 271   * @param int|WP_Comment $comment_id Optional comment object or id. Defaults to global comment object.
 272   */
 273  function comment_guid( $comment_id = null ) {
 274      echo esc_url( get_comment_guid( $comment_id ) );
 275  }
 276  
 277  /**
 278   * Retrieve the feed GUID for the current comment.
 279   *
 280   * @since 2.5.0
 281   *
 282   * @param int|WP_Comment $comment_id Optional comment object or id. Defaults to global comment object.
 283   * @return false|string false on failure or guid for comment on success.
 284   */
 285  function get_comment_guid( $comment_id = null ) {
 286      $comment = get_comment( $comment_id );
 287  
 288      if ( ! is_object( $comment ) ) {
 289          return false;
 290      }
 291  
 292      return get_the_guid( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
 293  }
 294  
 295  /**
 296   * Display the link to the comments.
 297   *
 298   * @since 1.5.0
 299   * @since 4.4.0 Introduced the `$comment` argument.
 300   *
 301   * @param int|WP_Comment $comment Optional. Comment object or id. Defaults to global comment object.
 302   */
 303  function comment_link( $comment = null ) {
 304      /**
 305       * Filters the current comment's permalink.
 306       *
 307       * @since 3.6.0
 308       *
 309       * @see get_comment_link()
 310       *
 311       * @param string $comment_permalink The current comment permalink.
 312       */
 313      echo esc_url( apply_filters( 'comment_link', get_comment_link( $comment ) ) );
 314  }
 315  
 316  /**
 317   * Retrieve the current comment author for use in the feeds.
 318   *
 319   * @since 2.0.0
 320   *
 321   * @return string Comment Author
 322   */
 323  function get_comment_author_rss() {
 324      /**
 325       * Filters the current comment author for use in a feed.
 326       *
 327       * @since 1.5.0
 328       *
 329       * @see get_comment_author()
 330       *
 331       * @param string $comment_author The current comment author.
 332       */
 333      return apply_filters( 'comment_author_rss', get_comment_author() );
 334  }
 335  
 336  /**
 337   * Display the current comment author in the feed.
 338   *
 339   * @since 1.0.0
 340   */
 341  function comment_author_rss() {
 342      echo get_comment_author_rss();
 343  }
 344  
 345  /**
 346   * Display the current comment content for use in the feeds.
 347   *
 348   * @since 1.0.0
 349   */
 350  function comment_text_rss() {
 351      $comment_text = get_comment_text();
 352      /**
 353       * Filters the current comment content for use in a feed.
 354       *
 355       * @since 1.5.0
 356       *
 357       * @param string $comment_text The content of the current comment.
 358       */
 359      $comment_text = apply_filters( 'comment_text_rss', $comment_text );
 360      echo $comment_text;
 361  }
 362  
 363  /**
 364   * Retrieve all of the post categories, formatted for use in feeds.
 365   *
 366   * All of the categories for the current post in the feed loop, will be
 367   * retrieved and have feed markup added, so that they can easily be added to the
 368   * RSS2, Atom, or RSS1 and RSS0.91 RDF feeds.
 369   *
 370   * @since 2.1.0
 371   *
 372   * @param string $type Optional, default is the type returned by get_default_feed().
 373   * @return string All of the post categories for displaying in the feed.
 374   */
 375  function get_the_category_rss( $type = null ) {
 376      if ( empty( $type ) ) {
 377          $type = get_default_feed();
 378      }
 379      $categories = get_the_category();
 380      $tags       = get_the_tags();
 381      $the_list   = '';
 382      $cat_names  = array();
 383  
 384      $filter = 'rss';
 385      if ( 'atom' == $type ) {
 386          $filter = 'raw';
 387      }
 388  
 389      if ( ! empty( $categories ) ) {
 390          foreach ( (array) $categories as $category ) {
 391              $cat_names[] = sanitize_term_field( 'name', $category->name, $category->term_id, 'category', $filter );
 392          }
 393      }
 394  
 395      if ( ! empty( $tags ) ) {
 396          foreach ( (array) $tags as $tag ) {
 397              $cat_names[] = sanitize_term_field( 'name', $tag->name, $tag->term_id, 'post_tag', $filter );
 398          }
 399      }
 400  
 401      $cat_names = array_unique( $cat_names );
 402  
 403      foreach ( $cat_names as $cat_name ) {
 404          if ( 'rdf' == $type ) {
 405              $the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
 406          } elseif ( 'atom' == $type ) {
 407              $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) );
 408          } else {
 409              $the_list .= "\t\t<category><![CDATA[" . html_entity_decode( $cat_name, ENT_COMPAT, get_option( 'blog_charset' ) ) . "]]></category>\n";
 410          }
 411      }
 412  
 413      /**
 414       * Filters all of the post categories for display in a feed.
 415       *
 416       * @since 1.2.0
 417       *
 418       * @param string $the_list All of the RSS post categories.
 419       * @param string $type     Type of feed. Possible values include 'rss2', 'atom'.
 420       *                         Default 'rss2'.
 421       */
 422      return apply_filters( 'the_category_rss', $the_list, $type );
 423  }
 424  
 425  /**
 426   * Display the post categories in the feed.
 427   *
 428   * @since 0.71
 429   * @see get_the_category_rss() For better explanation.
 430   *
 431   * @param string $type Optional, default is the type returned by get_default_feed().
 432   */
 433  function the_category_rss( $type = null ) {
 434      echo get_the_category_rss( $type );
 435  }
 436  
 437  /**
 438   * Display the HTML type based on the blog setting.
 439   *
 440   * The two possible values are either 'xhtml' or 'html'.
 441   *
 442   * @since 2.2.0
 443   */
 444  function html_type_rss() {
 445      $type = get_bloginfo( 'html_type' );
 446      if ( strpos( $type, 'xhtml' ) !== false ) {
 447          $type = 'xhtml';
 448      } else {
 449          $type = 'html';
 450      }
 451      echo $type;
 452  }
 453  
 454  /**
 455   * Display the rss enclosure for the current post.
 456   *
 457   * Uses the global $post to check whether the post requires a password and if
 458   * the user has the password for the post. If not then it will return before
 459   * displaying.
 460   *
 461   * Also uses the function get_post_custom() to get the post's 'enclosure'
 462   * metadata field and parses the value to display the enclosure(s). The
 463   * enclosure(s) consist of enclosure HTML tag(s) with a URI and other
 464   * attributes.
 465   *
 466   * @since 1.5.0
 467   */
 468  function rss_enclosure() {
 469      if ( post_password_required() ) {
 470          return;
 471      }
 472  
 473      foreach ( (array) get_post_custom() as $key => $val ) {
 474          if ( $key == 'enclosure' ) {
 475              foreach ( (array) $val as $enc ) {
 476                  $enclosure = explode( "\n", $enc );
 477  
 478                  // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3'
 479                  $t    = preg_split( '/[ \t]/', trim( $enclosure[2] ) );
 480                  $type = $t[0];
 481  
 482                  /**
 483                   * Filters the RSS enclosure HTML link tag for the current post.
 484                   *
 485                   * @since 2.2.0
 486                   *
 487                   * @param string $html_link_tag The HTML link tag with a URI and other attributes.
 488                   */
 489                  echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "\n" );
 490              }
 491          }
 492      }
 493  }
 494  
 495  /**
 496   * Display the atom enclosure for the current post.
 497   *
 498   * Uses the global $post to check whether the post requires a password and if
 499   * the user has the password for the post. If not then it will return before
 500   * displaying.
 501   *
 502   * Also uses the function get_post_custom() to get the post's 'enclosure'
 503   * metadata field and parses the value to display the enclosure(s). The
 504   * enclosure(s) consist of link HTML tag(s) with a URI and other attributes.
 505   *
 506   * @since 2.2.0
 507   */
 508  function atom_enclosure() {
 509      if ( post_password_required() ) {
 510          return;
 511      }
 512  
 513      foreach ( (array) get_post_custom() as $key => $val ) {
 514          if ( $key == 'enclosure' ) {
 515              foreach ( (array) $val as $enc ) {
 516                  $enclosure = explode( "\n", $enc );
 517                  /**
 518                   * Filters the atom enclosure HTML link tag for the current post.
 519                   *
 520                   * @since 2.2.0
 521                   *
 522                   * @param string $html_link_tag The HTML link tag with a URI and other attributes.
 523                   */
 524                  echo apply_filters( 'atom_enclosure', '<link href="' . esc_url( trim( $enclosure[0] ) ) . '" rel="enclosure" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( trim( $enclosure[2] ) ) . '" />' . "\n" );
 525              }
 526          }
 527      }
 528  }
 529  
 530  /**
 531   * Determine the type of a string of data with the data formatted.
 532   *
 533   * Tell whether the type is text, html, or xhtml, per RFC 4287 section 3.1.
 534   *
 535   * In the case of WordPress, text is defined as containing no markup,
 536   * xhtml is defined as "well formed", and html as tag soup (i.e., the rest).
 537   *
 538   * Container div tags are added to xhtml values, per section 3.1.1.3.
 539   *
 540   * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
 541   *
 542   * @since 2.5.0
 543   *
 544   * @param string $data Input string
 545   * @return array array(type, value)
 546   */
 547  function prep_atom_text_construct( $data ) {
 548      if ( strpos( $data, '<' ) === false && strpos( $data, '&' ) === false ) {
 549          return array( 'text', $data );
 550      }
 551  
 552      if ( ! function_exists( 'xml_parser_create' ) ) {
 553          trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
 554  
 555          return array( 'html', "<![CDATA[$data]]>" );
 556      }
 557  
 558      $parser = xml_parser_create();
 559      xml_parse( $parser, '<div>' . $data . '</div>', true );
 560      $code = xml_get_error_code( $parser );
 561      xml_parser_free( $parser );
 562  
 563      if ( ! $code ) {
 564          if ( strpos( $data, '<' ) === false ) {
 565              return array( 'text', $data );
 566          } else {
 567              $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
 568              return array( 'xhtml', $data );
 569          }
 570      }
 571  
 572      if ( strpos( $data, ']]>' ) === false ) {
 573          return array( 'html', "<![CDATA[$data]]>" );
 574      } else {
 575          return array( 'html', htmlspecialchars( $data ) );
 576      }
 577  }
 578  
 579  /**
 580   * Displays Site Icon in atom feeds.
 581   *
 582   * @since 4.3.0
 583   *
 584   * @see get_site_icon_url()
 585   */
 586  function atom_site_icon() {
 587      $url = get_site_icon_url( 32 );
 588      if ( $url ) {
 589          echo '<icon>' . convert_chars( $url ) . "</icon>\n";
 590      }
 591  }
 592  
 593  /**
 594   * Displays Site Icon in RSS2.
 595   *
 596   * @since 4.3.0
 597   */
 598  function rss2_site_icon() {
 599      $rss_title = get_wp_title_rss();
 600      if ( empty( $rss_title ) ) {
 601          $rss_title = get_bloginfo_rss( 'name' );
 602      }
 603  
 604      $url = get_site_icon_url( 32 );
 605      if ( $url ) {
 606          echo '
 607  <image>
 608      <url>' . convert_chars( $url ) . '</url>
 609      <title>' . $rss_title . '</title>
 610      <link>' . get_bloginfo_rss( 'url' ) . '</link>
 611      <width>32</width>
 612      <height>32</height>
 613  </image> ' . "\n";
 614      }
 615  }
 616  
 617  /**
 618   * Returns the link for the currently displayed feed.
 619   *
 620   * @since 5.3.0
 621   *
 622   * @return string Correct link for the atom:self element.
 623   */
 624  function get_self_link() {
 625      $host = @parse_url( home_url() );
 626      return set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) );
 627  }
 628  
 629  /**
 630   * Display the link for the currently displayed feed in a XSS safe way.
 631   *
 632   * Generate a correct link for the atom:self element.
 633   *
 634   * @since 2.5.0
 635   */
 636  function self_link() {
 637      /**
 638       * Filters the current feed URL.
 639       *
 640       * @since 3.6.0
 641       *
 642       * @see set_url_scheme()
 643       * @see wp_unslash()
 644       *
 645       * @param string $feed_link The link for the feed with set URL scheme.
 646       */
 647      echo esc_url( apply_filters( 'self_link', get_self_link() ) );
 648  }
 649  
 650  /**
 651   * Get the timestamp of the most recently modified post from WP_Query.
 652   *
 653   * If viewing a comment feed, the timestamp of the most recently modified
 654   * comment will be returned.
 655   *
 656   * @global WP_Query $wp_query WordPress Query object.
 657   *
 658   * @since 5.2.0
 659   *
 660   * @param string $format Format of the timestamp to return, passed to mysql2date.
 661   *
 662   * @return string The timestamp.
 663   */
 664  function get_feed_build_date( $format ) {
 665      global $wp_query;
 666  
 667      if ( empty( $wp_query ) || ! $wp_query->have_posts() ) {
 668          // Fallback to last time any post was modified or published.
 669          return get_lastpostmodified( 'GMT' );
 670      }
 671  
 672      // Extract the post modified times from the posts.
 673      $modified_times = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' );
 674  
 675      // If this is a comment feed, check those objects too.
 676      if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) {
 677          // Extract the comment modified times from the comments.
 678          $comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' );
 679  
 680          // Add the comment times to the post times for comparison.
 681          $modified_times = array_merge( $modified_times, $comment_times );
 682      }
 683  
 684      // Determine the maximum modified time.
 685      $max_modified_time = mysql2date( $format, max( $modified_times ), false );
 686  
 687      /**
 688       * Filters the date the last post or comment in the query was modified.
 689       *
 690       * @since 5.2.0
 691       *
 692       * @param string $max_modified_time Date the last post or comment was modified in the query.
 693       * @param string $format            The date format requested in get_feed_build_date.
 694       */
 695      return apply_filters( 'get_feed_build_date', $max_modified_time, $format );
 696  }
 697  
 698  /**
 699   * Return the content type for specified feed type.
 700   *
 701   * @since 2.8.0
 702   *
 703   * @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'.
 704   */
 705  function feed_content_type( $type = '' ) {
 706      if ( empty( $type ) ) {
 707          $type = get_default_feed();
 708      }
 709  
 710      $types = array(
 711          'rss'      => 'application/rss+xml',
 712          'rss2'     => 'application/rss+xml',
 713          'rss-http' => 'text/xml',
 714          'atom'     => 'application/atom+xml',
 715          'rdf'      => 'application/rdf+xml',
 716      );
 717  
 718      $content_type = ( ! empty( $types[ $type ] ) ) ? $types[ $type ] : 'application/octet-stream';
 719  
 720      /**
 721       * Filters the content type for a specific feed type.
 722       *
 723       * @since 2.8.0
 724       *
 725       * @param string $content_type Content type indicating the type of data that a feed contains.
 726       * @param string $type         Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'.
 727       */
 728      return apply_filters( 'feed_content_type', $content_type, $type );
 729  }
 730  
 731  /**
 732   * Build SimplePie object based on RSS or Atom feed from URL.
 733   *
 734   * @since 2.8.0
 735   *
 736   * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged
 737   * using SimplePie's multifeed feature.
 738   * See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
 739   *
 740   * @return SimplePie|WP_Error SimplePie object on success or WP_Error object on failure.
 741   */
 742  function fetch_feed( $url ) {
 743      if ( ! class_exists( 'SimplePie', false ) ) {
 744          require_once ( ABSPATH . WPINC . '/class-simplepie.php' );
 745      }
 746  
 747      require_once ( ABSPATH . WPINC . '/class-wp-feed-cache.php' );
 748      require_once ( ABSPATH . WPINC . '/class-wp-feed-cache-transient.php' );
 749      require_once ( ABSPATH . WPINC . '/class-wp-simplepie-file.php' );
 750      require_once ( ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.php' );
 751  
 752      $feed = new SimplePie();
 753  
 754      $feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );
 755      // We must manually overwrite $feed->sanitize because SimplePie's
 756      // constructor sets it before we have a chance to set the sanitization class
 757      $feed->sanitize = new WP_SimplePie_Sanitize_KSES();
 758  
 759      $feed->set_cache_class( 'WP_Feed_Cache' );
 760      $feed->set_file_class( 'WP_SimplePie_File' );
 761  
 762      $feed->set_feed_url( $url );
 763      /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
 764      $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
 765      /**
 766       * Fires just before processing the SimplePie feed object.
 767       *
 768       * @since 3.0.0
 769       *
 770       * @param object $feed SimplePie feed object (passed by reference).
 771       * @param mixed  $url  URL of feed to retrieve. If an array of URLs, the feeds are merged.
 772       */
 773      do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
 774      $feed->init();
 775      $feed->set_output_encoding( get_option( 'blog_charset' ) );
 776  
 777      if ( $feed->error() ) {
 778          return new WP_Error( 'simplepie-error', $feed->error() );
 779      }
 780  
 781      return $feed;
 782  }


Generated: Mon Nov 18 01:00:04 2019 Cross-referenced by PHPXref 0.7.1