@@ -401,44 +401,58 @@ 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
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+
407417 require_once ( ABSPATH . WPINC . '/feed.php ' );
418+
408419 $ maxitems = 0 ;
420+
409421 // Get a SimplePie feed object from the specified feed source.
410- $ rss = fetch_feed ( $ feed_url );
411- if ( !is_wp_error ( $ rss ) ) { // Checks that the object is created correctly
422+ $ rss = fetch_feed ( 'http://rtcamp.com/blog/feed/ ' );
423+
424+ // Checks that the object is created correctly.
425+ if ( ! is_wp_error ( $ rss ) ) {
426+
412427 // Figure out how many total items there are, but limit it to 5.
413428 $ maxitems = $ rss ->get_item_quantity ( 5 );
414429
415430 // Build an array of all the items, starting with element 0 (first element).
416431 $ rss_items = $ rss ->get_items ( 0 , $ maxitems );
417432 }
418- ?>
419- <ul role="list"><?php
420- if ( $ maxitems == 0 ) {
421- echo '<li role="listitem"> ' . __ ( 'No items ' , 'nginx-helper ' ) . '.</li> ' ;
433+ ?>
434+ <ul role="list">
435+ <?php
436+ if ( 0 === $ maxitems ) {
437+ echo '<li role="listitem"> ' . esc_html__ ( 'No items ' , 'nginx-helper ' ) . '.</li> ' ;
422438 } else {
423439 // Loop through each feed item and display each item as a hyperlink.
424440 foreach ( $ rss_items as $ item ) {
425- ?>
441+ ?>
426442 <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
443+ <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 ' ) ); ?> '>
444+ <?php echo esc_html ( $ item ->get_title () ); ?>
445+ </a>
446+ </li>
447+ <?php
429448 }
430449 }
431450 ?>
432- </ul><?php
451+ </ul>
452+ <?php
453+ die ();
433454 }
434455
435- function fetch_feeds ()
436- {
437- if ( isset ( $ _GET ['get_feeds ' ] ) && $ _GET ['get_feeds ' ] == '1 ' ) {
438- get_feeds ();
439- die ();
440- }
441- }
456+ add_action ( 'wp_ajax_rt_nginx_get_news ' , 'rt_nginx_get_news ' );
442457
443- add_action ( 'init ' , 'fetch_feeds ' );
444458}
0 commit comments