The Word" scripture columns on Sunday readings from America magazine. Author: America Media Version: 1.0 Author URI: https://www.americamagazine.org License: GPL2 */ // Don't call the file directly if ( !defined( 'ABSPATH' ) ) exit; /* Define */ define( 'AM_WORD_URL', plugins_url('/') . plugin_basename( dirname( __FILE__ ) ) . '/' ); define( 'AM_WORD_PATH', plugin_dir_path( __FILE__ ) ); class America_Magazine_The_Word_Widget extends WP_Widget{ public function am_register_widget_styles() { wp_enqueue_style( 'america-styles', AM_WORD_URL . 'source/css/style.css' ); } public function __construct() { parent::__construct( 'america-magazine-the-word-widget','America magazine\'s The Word', array('description' => 'A widget that displays links to the next two columns for America magazine\'s "The Word" scripture column.')); add_action( 'wp_enqueue_scripts', array( $this, 'amword_register_widget_styles' ) ); } public function amword_register_widget_styles() { wp_enqueue_style( 'am-the-word-style', AM_WORD_URL . 'source/css/style.css' ); } public function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title'] ); $template = apply_filters('template', $instance['template'] ); echo $before_widget; $output = ''; if ( $title ) echo $before_title . $title . $after_title; // Update plugin version number for tracking $ver = 'v1'; // // Start building the contents of the widget // This week $twurl = 'https://www.americamagazine.org/rest/views/theword-thisweek?utm_source=wpplugin&utm_medium=' . $ver ; $twresponse = wp_remote_get( esc_url_raw( $twurl ) ); if( is_wp_error( $twresponse ) ) { return false; // Do not render widget } else { $twapi_response = json_decode( wp_remote_retrieve_body( $twresponse ), true ); } // Next week $nwurl = 'https://www.americamagazine.org/rest/views/theword-nextweek?utm_source=wpplugin&utm_medium=' . $ver; $nwresponse = wp_remote_get( esc_url_raw( $nwurl ) ); if( is_wp_error( $nwresponse ) ) { return false; // Do not render widget } else { $nwapi_response = json_decode( wp_remote_retrieve_body( $nwresponse ), true ); } // Display $output .= '
'; $output .= '
'; $output .= '

' . $twapi_response[0]['field_liturgical_date'] . '

'; $output .= '
' . $twapi_response[0]['readings'] . '
'; $output .= '

Go deeper into this Sunday’s Mass readings

'; $output .= '
'; $output .= '
'; $output .= '

This week

'; $output .= '

' . $twapi_response[0]['title'] . '

'; $output .= '
'; $output .= '
'; $output .= '

Next week

'; $output .= '

' . $nwapi_response[0]['title'] . '

'; $output .= '
'; $output .= '
'; $output .= '

Visit America and sign up for our newsletters for scripture and smart, Catholic content on faith and culture.

'; $output .= '
'; // end display build echo $output; echo $after_widget; } public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['template'] = strip_tags( $new_instance['template'] ); return $instance; } public function form($instance) { $defaults = array( 'title' => '', 'template' => 'america' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>

'america','Simple' => 'none') ; if ( isset( $instance['template'] ) ) { $template = $instance['template']; } ?>