@@ -401,44 +401,61 @@ function nginx_settings_link( $links )
401401 add_filter ( "plugin_action_links_ " . plugin_basename ( __FILE__ ), 'nginx_settings_link ' );
402402 }
403403
404- function get_feeds ( $ feed_url = 'http://rtcamp.com/blog/feed/ ' )
405- {
406- // Get RSS Feed(s)
404+ /**
405+ * Get latest news from https://rtcamp.com
406+ *
407+ * @return void
408+ */
409+ function rt_nginx_get_news () {
410+
411+ $ is_rt_news_request = sanitize_text_field ( filter_input ( INPUT_GET , 'action ' ) );
412+
413+ if ( empty ( $ is_rt_news_request ) || 'rt_nginx_get_news ' !== $ is_rt_news_request ) {
414+ return ;
415+ }
416+
417+ $ feed_url = 'http://rtcamp.com/blog/feed/ ' ;
418+
419+ // Get RSS Feed.
407420 require_once ( ABSPATH . WPINC . '/feed.php ' );
421+
408422 $ maxitems = 0 ;
423+
409424 // Get a SimplePie feed object from the specified feed source.
410425 $ rss = fetch_feed ( $ feed_url );
411- if ( !is_wp_error ( $ rss ) ) { // Checks that the object is created correctly
426+
427+ // Checks that the object is created correctly.
428+ if ( ! is_wp_error ( $ rss ) ) {
429+
412430 // Figure out how many total items there are, but limit it to 5.
413431 $ maxitems = $ rss ->get_item_quantity ( 5 );
414432
415433 // Build an array of all the items, starting with element 0 (first element).
416434 $ rss_items = $ rss ->get_items ( 0 , $ maxitems );
417435 }
418- ?>
419- <ul role="list"><?php
420- if ( $ maxitems == 0 ) {
421- echo '<li role="listitem"> ' . __ ( 'No items ' , 'nginx-helper ' ) . '.</li> ' ;
436+ ?>
437+ <ul role="list">
438+ <?php
439+ if ( 0 === $ maxitems ) {
440+ echo '<li role="listitem"> ' . esc_html__ ( 'No items ' , 'nginx-helper ' ) . '.</li> ' ;
422441 } else {
423442 // Loop through each feed item and display each item as a hyperlink.
424443 foreach ( $ rss_items as $ item ) {
425- ?>
444+ ?>
426445 <li role="listitem">
427- <a href='<?php echo $ item ->get_permalink (); ?> ' title='<?php echo __ ( 'Posted ' , 'nginx-helper ' ) . $ item ->get_date ( 'j F Y | g:i a ' ); ?> '><?php echo $ item ->get_title (); ?> </a>
428- </li><?php
446+ <a href='<?php echo esc_url ( $ item ->get_permalink () ); ?> ' title='<?php echo esc_attr__ ( 'Posted ' , 'nginx-helper ' ) . esc_attr ( $ item ->get_date ( 'j F Y | g:i a ' ) ); ?> '>
447+ <?php echo esc_html ( $ item ->get_title () ); ?>
448+ </a>
449+ </li>
450+ <?php
429451 }
430452 }
431453 ?>
432- </ul><?php
454+ </ul>
455+ <?php
456+ die ();
433457 }
434458
435- function fetch_feeds ()
436- {
437- if ( isset ( $ _GET ['get_feeds ' ] ) && $ _GET ['get_feeds ' ] == '1 ' ) {
438- get_feeds ();
439- die ();
440- }
441- }
459+ add_action ( 'wp_ajax_rt_nginx_get_news ' , 'rt_nginx_get_news ' );
442460
443- add_action ( 'init ' , 'fetch_feeds ' );
444461}
0 commit comments