Plugin Directory

Changeset 3391879


Ignore:
Timestamp:
11/07/2025 05:29:18 PM (5 weeks ago)
Author:
stevengliebe
Message:

Releasing 2.7

Location:
church-theme-content
Files:
106 added
5 edited

Legend:

Unmodified
Added
Removed
  • church-theme-content/trunk/church-theme-content.php

    r3039815 r3391879  
    11<?php
     2
    23/**
    34 * Plugin Name: Church Content
    45 * Plugin URI: https://churchthemes.com/plugins/church-content/
    56 * Description: Provides an interface for managing sermons, events, people and locations. A <strong>compatible theme is required</strong> for presenting content from these church-centric post types in a tightly-integrated manner.
    6  * Version: 2.6.2
     7 * Version: 2.7
    78 * Author: ChurchThemes.com
    89 * Author URI: https://churchthemes.com
     
    1213 *
    1314 * @package   Church_Theme_Content
    14  * @copyright Copyright (c) 2013 - 2024, ChurchThemes.com, LLC
     15 * @copyright Copyright (c) 2013 - 2025, ChurchThemes.com, LLC
    1516 * @link      https://github.com/churchthemes/church-theme-content
    1617 * @license   GPLv2 or later
     
    1819
    1920// No direct access
    20 if (! defined( 'ABSPATH' )) exit;
     21if (! defined('ABSPATH')) exit;
    2122
    2223/**
     
    2526 * @since 0.9
    2627 */
    27 class Church_Theme_Content {
     28class Church_Theme_Content
     29{
    2830
    2931    /**
     
    5153     * @access public
    5254     */
    53     public function __construct() {
     55    public function __construct()
     56    {
    5457
    5558        // Set plugin data.
    56         add_action( 'plugins_loaded', array( $this, 'set_plugin_data' ), 1 );
     59        add_action('plugins_loaded', array($this, 'set_plugin_data'), 1);
    5760
    5861        // Define constants.
    59         add_action( 'plugins_loaded', array( $this, 'define_constants' ), 1 );
     62        add_action('plugins_loaded', array($this, 'define_constants'), 1);
    6063
    6164        // Load language file for old versions of WordPress.
    62         add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 1 );
     65        add_action('plugins_loaded', array($this, 'load_textdomain'), 1);
    6366
    6467        // Set includes.
    65         add_action( 'plugins_loaded', array( $this, 'set_includes' ), 1 );
     68        add_action('plugins_loaded', array($this, 'set_includes'), 1);
    6669
    6770        // Load includes.
    68         add_action( 'plugins_loaded', array( $this, 'load_includes' ), 1 );
     71        add_action('plugins_loaded', array($this, 'load_includes'), 1);
    6972
    7073        // Trigger flushing of rewrite rules on plugin activation.
    7174        // This must be done early (not on plugins_loaded or init).
    72         register_activation_hook( __FILE__, array( &$this, 'trigger_flush_rewrite_rules' ) );
     75        register_activation_hook(__FILE__, array(&$this, 'trigger_flush_rewrite_rules'));
    7376
    7477        // Check if rewrite rules should be flushed.
    75         add_action( 'init', array( $this, 'ctc_check_flush_rewrite_rules' ), 1 );
    76 
     78        add_action('init', array($this, 'ctc_check_flush_rewrite_rules'), 1);
    7779    }
    7880
     
    8587     * @access public
    8688     */
    87     public function set_plugin_data() {
     89    public function set_plugin_data()
     90    {
    8891
    8992        // Load plugin.php if get_plugins() not available
    90         if (! function_exists( 'get_plugins' )) {
     93        if (! function_exists('get_plugins')) {
    9194            require_once ABSPATH . 'wp-admin/includes/plugin.php';
    9295        }
    9396
    9497        // Get path to plugin's directory
    95         $plugin_dir = plugin_basename( dirname( __FILE__ ) );
     98        $plugin_dir = plugin_basename(dirname(__FILE__));
    9699
    97100        // Get plugin data
    98         $plugin_data = current( get_plugins( '/' . $plugin_dir ) );
     101        $plugin_data = current(get_plugins('/' . $plugin_dir));
    99102
    100103        // Set plugin data
    101         $this->plugin_data = apply_filters( 'ctc_plugin_data', $plugin_data );
    102 
     104        $this->plugin_data = apply_filters('ctc_plugin_data', $plugin_data);
    103105    }
    104106
     
    109111     * @access public
    110112     */
    111     public function define_constants() {
     113    public function define_constants()
     114    {
    112115
    113116        // Plugin details
    114         define( 'CTC_VERSION',      $this->plugin_data['Version'] );                    // plugin version
    115         define( 'CTC_NAME',         $this->plugin_data['Name'] );                       // plugin name
    116         define( 'CTC_AUTHOR',       strip_tags( $this->plugin_data['Author'] ) );       // plugin author
    117         define( 'CTC_INFO_URL',     $this->plugin_data['PluginURI'] );                  // plugin's info page URL
    118         define( 'CTC_FILE',         __FILE__ );                                         // plugin's main file absolute path
    119         define( 'CTC_FILE_BASE',    plugin_basename( CTC_FILE ) );                      // plugin's main file path relative to plugin directory
    120         define( 'CTC_DIR',          dirname( CTC_FILE_BASE ) );                         // plugin's directory
    121         define( 'CTC_PATH',         untrailingslashit( plugin_dir_path( CTC_FILE ) ) ); // plugin's absolute path
    122         define( 'CTC_URL',          untrailingslashit( plugin_dir_url( CTC_FILE ) ) );  // plugin's directory URL
     117        define('CTC_VERSION',       $this->plugin_data['Version']);                 // plugin version
     118        define('CTC_NAME',      $this->plugin_data['Name']);                        // plugin name
     119        define('CTC_AUTHOR',        strip_tags($this->plugin_data['Author']));      // plugin author
     120        define('CTC_INFO_URL',      $this->plugin_data['PluginURI']);                   // plugin's info page URL
     121        define('CTC_FILE',      __FILE__);                                          // plugin's main file absolute path
     122        define('CTC_FILE_BASE',     plugin_basename(CTC_FILE));                     // plugin's main file path relative to plugin directory
     123        define('CTC_DIR',           dirname(CTC_FILE_BASE));                            // plugin's directory
     124        define('CTC_PATH',          untrailingslashit(plugin_dir_path(CTC_FILE)));  // plugin's absolute path
     125        define('CTC_URL',           untrailingslashit(plugin_dir_url(CTC_FILE)));   // plugin's directory URL
    123126
    124127        // Directories
    125         define( 'CTC_INC_DIR',      'includes' );                   // includes directory
    126         define( 'CTC_ADMIN_DIR',    CTC_INC_DIR . '/admin' );       // admin directory
    127         define( 'CTC_CLASS_DIR',    CTC_INC_DIR . '/classes' );     // classes directory
    128         define( 'CTC_LIB_DIR',      CTC_INC_DIR . '/libraries' );   // libraries directory
    129         define( 'CTC_CSS_DIR',      'css' );                        // stylesheets directory
    130         define( 'CTC_JS_DIR',       'js' );                         // JavaScript directory
    131         define( 'CTC_IMG_DIR',      'images' );                     // images directory
    132         define( 'CTC_LANG_DIR',     'languages' );                  // languages directory
     128        define('CTC_INC_DIR',       'includes');                    // includes directory
     129        define('CTC_ADMIN_DIR', CTC_INC_DIR . '/admin');        // admin directory
     130        define('CTC_CLASS_DIR',     CTC_INC_DIR . '/classes');      // classes directory
     131        define('CTC_LIB_DIR',       CTC_INC_DIR . '/libraries');    // libraries directory
     132        define('CTC_CSS_DIR',       'css');                     // stylesheets directory
     133        define('CTC_JS_DIR',        'js');                          // JavaScript directory
     134        define('CTC_IMG_DIR',       'images');                      // images directory
     135        define('CTC_LANG_DIR',  'languages');                   // languages directory
    133136
    134137        // CT Meta Box
    135         if (! defined( 'CTMB_URL' )) { // in case also used in theme or other plugin
    136             define( 'CTMB_URL', CTC_URL . '/' . CTC_LIB_DIR . '/ct-meta-box' ); // for enqueueing JS/CSS
    137         }
    138 
     138        if (! defined('CTMB_URL')) { // in case also used in theme or other plugin
     139            define('CTMB_URL', CTC_URL . '/' . CTC_LIB_DIR . '/ct-meta-box'); // for enqueueing JS/CSS
     140        }
    139141    }
    140142
     
    154156     * @access public
    155157     */
    156     public function load_textdomain() {
     158    public function load_textdomain()
     159    {
    157160
    158161        // Get version of WordPress in use.
    159         $wp_version = get_bloginfo( 'version' );
     162        $wp_version = get_bloginfo('version');
    160163
    161164        // Textdomain.
     
    163166
    164167        // WordPress core locale filter.
    165         $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
     168        $locale = apply_filters('plugin_locale', get_locale(), $domain);
    166169
    167170        // WordPress 3.6 and earlier don't auto-load from wp-content/languages, so check and load manually: http://core.trac.wordpress.org/changeset/22346.
    168171        $external_mofile = WP_LANG_DIR . '/plugins/' . $domain . '-' . $locale . '.mo';
    169         if (version_compare( $wp_version, '3.6', '<=' ) && file_exists( $external_mofile )) { // external translation exists.
    170             load_textdomain( $domain, $external_mofile );
     172        if (version_compare($wp_version, '3.6', '<=') && file_exists($external_mofile)) { // external translation exists.
     173            load_textdomain($domain, $external_mofile);
    171174        }
    172175
     
    174177        // Either using WordPress 3.7+ or older version with external translation.
    175178        else {
    176             $languages_dir = CTC_DIR . '/' . trailingslashit( CTC_LANG_DIR ); // ensure trailing slash.
    177             load_plugin_textdomain( $domain, false, $languages_dir );
    178         }
    179 
     179            $languages_dir = CTC_DIR . '/' . trailingslashit(CTC_LANG_DIR); // ensure trailing slash.
     180            load_plugin_textdomain($domain, false, $languages_dir);
     181        }
    180182    }
    181183
     
    186188     * @access public
    187189     */
    188     public function set_includes() {
    189 
    190         $this->includes = apply_filters( 'ctc_includes', array(
     190    public function set_includes()
     191    {
     192
     193        $this->includes = apply_filters('ctc_includes', array(
    191194
    192195            // Frontend or admin
     
    252255            */
    253256
    254         ) );
    255 
     257        ));
    256258    }
    257259
     
    259261     * Load includes
    260262     *
    261      * Include files based on whether or not condition is met.
    262      *
    263      * @since 0.9
    264      * @access public
    265      */
    266     public function load_includes() {
     263     * Include files based on whether or not condition is met.
     264     *
     265     * @since 0.9
     266     * @access public
     267     */
     268    public function load_includes()
     269    {
    267270
    268271        // Get includes
     
    275278
    276279            // Check condition
    277             switch($condition) {
     280            switch ($condition) {
    278281
    279282                // Admin Only
     
    301304
    302305                    break;
    303 
    304306            }
    305307
     
    308310
    309311                foreach ($files as $file) {
    310                     require_once trailingslashit( CTC_PATH ) . $file;
     312                    require_once trailingslashit(CTC_PATH) . $file;
    311313                }
    312 
    313314            }
    314 
    315         }
    316 
     315        }
    317316    }
    318317
     
    325324     * @access public
    326325     */
    327     public static function trigger_flush_rewrite_rules() {
     326    public static function trigger_flush_rewrite_rules()
     327    {
    328328
    329329        // Tell to flush rules after post types registered.
    330         update_option( 'ctc_flush_rewrite_rules', '1' );
    331 
     330        update_option('ctc_flush_rewrite_rules', '1');
    332331    }
    333332
     
    338337     * so that the rewrite rules can be flushed later.
    339338     */
    340     public function ctc_check_flush_rewrite_rules() {
     339    public function ctc_check_flush_rewrite_rules()
     340    {
    341341
    342342        // Check if option was set.
    343         if (get_option( 'ctc_flush_rewrite_rules' )) {
     343        if (get_option('ctc_flush_rewrite_rules')) {
    344344
    345345            // Flush rewrite rules.
     
    347347
    348348            // Delete option so this doesn't run again.
    349             delete_option( 'ctc_flush_rewrite_rules' );
    350 
    351         }
    352 
    353     }
    354 
     349            delete_option('ctc_flush_rewrite_rules');
     350        }
     351    }
    355352}
    356353
  • church-theme-content/trunk/includes/add-ons.php

    r1949935 r3391879  
    11<?php
     2
    23/**
    34 * Add-ons (Global)
     
    67 *
    78 * @package    Church_Theme_Content
    8  * @copyright  Copyright (c) 2014, ChurchThemes.com
     9 * @copyright  Copyright (c) 2014 - 2025, ChurchThemes.com
    910 * @link       https://github.com/churchthemes/church-theme-content
    1011 * @license    GPLv2 or later
     
    1314
    1415// No direct access
    15 if ( ! defined( 'ABSPATH' ) ) exit;
     16if (! defined('ABSPATH')) exit;
    1617
    1718/*************************************************
     
    3435 *          ctc_register_add_on( array(
    3536 *              'plugin_file'       => __FILE__,                                                    // Full path to plugin main file (__FILE__ if this code is in main file)
    36  *              'store_url'         => 'https://churchthemes.com',                                  // URL of store running EDD with Software Licensing extension
     37 *              'store_url'         => 'https://churchthemes.com',                                  // URL of store running EDD with Software Licensing extension (or proxy)
    3738 *              'renewal_url'       => 'https://churchthemes.com/renew/?license_key={license_key}', // It is recommended to provide a URL for renewal links (ie. redirecting to EDD checkout); {license_key} will be replaced with key
    3839 *              'renewal_info_url'  => 'https://churchthemes.com/go/license-renewal',               // Optional URL for renewal information
     
    5253 * @global array $ctc_add_ons
    5354 */
    54 function ctc_register_add_on( $args ) {
     55function ctc_register_add_on($args)
     56{
    5557
    5658    global $ctc_add_ons;
    5759
    5860    // Prepare array to receive add-ons
    59     if ( ! isset( $ctc_add_ons ) ) {
     61    if (! isset($ctc_add_ons)) {
    6062        $ctc_add_ons = array();
    6163    }
    6264
    6365    // Add add-on to global
    64     if ( ! empty( $args['plugin_file'] ) ) {
     66    if (! empty($args['plugin_file'])) {
    6567
    6668        // Plugin file relative path
    6769        // plugin-name/plugin-name.php
    68         $args['plugin_file_base'] = plugin_basename( $args['plugin_file'] );
     70        $args['plugin_file_base'] = plugin_basename($args['plugin_file']);
    6971
    7072        // Plugin's directory name (e.g. plugin-name)
    7173        // This serves as a nice clean, unique slug -- good for use in settings
    72         $args['plugin_dir'] = dirname( $args['plugin_file_base'] ) ;
     74        $args['plugin_dir'] = dirname($args['plugin_file_base']);
    7375
    7476        // Get plugin data
    7577        // wp-admin/includes/plugin.php is already included by Church_Theme_Content class
    76         $plugin_data = current( get_plugins( '/' . $args['plugin_dir'] ) );
     78        $plugin_data = current(get_plugins('/' . $args['plugin_dir']));
    7779
    7880        // Plugin name
    7981        $args['name_full'] = $plugin_data['Name'];
    80         $name_short = str_replace( array( CTC_NAME . ' - ', 'Church Theme Content - ' ), '', $args['name_full'] ); // with "Church Content - " or "Church Theme Content - " prefix removed
     82        $name_short = str_replace(array(CTC_NAME . ' - ', 'Church Theme Content - '), '', $args['name_full']); // with "Church Content - " or "Church Theme Content - " prefix removed
    8183
    8284        // Plugin author
    83         $author = strip_tags( $plugin_data['Author'] );
     85        $author = strip_tags($plugin_data['Author']);
    8486
    8587        // Apply defaults
    86         $args = wp_parse_args( $args, array(
     88        $args = wp_parse_args($args, array(
    8789
    8890            // Add-on Information
     
    9597            // EDD Software Licensing
    9698            // The translation strings are automatically escaped on use in edd-license.php
    97             'store_url'                 => '',                              // URL of store running EDD with Software Licensing extension
     99            'store_url'                 => '',                              // URL of store running EDD with Software Licensing extension (or proxy)
    98100            'version'                   => $plugin_data['Version'],         // current version of the add-on plugin; default is to auto-determine
    99101            'item_name'                 => $name_short,                     // must match download's name in EDD store
     
    104106            'renewal_info_url'          => '',                              // optional URL for renewal information
    105107            'changelog_url'             => '',                              // optional URL for external changelog
    106             'activate_success_notice'   => __( '<strong>License key activated.</strong>', 'church-theme-content' ),
    107             'activate_fail_notice'      => __( '<strong>License key could not be activated.</strong>', 'church-theme-content' ),
    108             'deactivate_success_notice' => __( '<strong>License key deactivated.</strong>', 'church-theme-content' ),
    109             'deactivate_fail_notice'    => __( '<strong>License key could not be deactivated.</strong>', 'church-theme-content' ),
    110             'inactive_notice'           => __( '<strong>Add-on License Inactive:</strong> <a href="%1$s">Activate Your Add-on License</a> to enable updates for <strong>%2$s</strong>.', 'church-theme-content' ),
    111             'expired_notice'            => __( '<strong>Add-on License Expired:</strong> <a href="%1$s">Renew Your Add-on License</a> for <strong>%2$s</strong> to re-enable updates (expired on <strong>%3$s</strong>).', 'church-theme-content' ),
    112             'expiring_soon_notice'      => __( '<strong>Add-on License Expiring Soon:</strong> <a href="%1$s">Renew Your Add-on License</a> for <strong>%2$s</strong> to continue receiving updates (expires on <strong>%3$s</strong>).', 'church-theme-content' ),
     108            'activate_success_notice'   => __('<strong>License key activated.</strong>', 'church-theme-content'),
     109            'activate_fail_notice'      => __('<strong>License key could not be activated.</strong>', 'church-theme-content'),
     110            'deactivate_success_notice' => __('<strong>License key deactivated.</strong>', 'church-theme-content'),
     111            'deactivate_fail_notice'    => __('<strong>License key could not be deactivated.</strong>', 'church-theme-content'),
     112            'inactive_notice'           => __('<strong>Add-on License Inactive:</strong> <a href="%1$s">Activate Your Add-on License</a> to enable updates for <strong>%2$s</strong>.', 'church-theme-content'),
     113            'expired_notice'            => __('<strong>Add-on License Expired:</strong> <a href="%1$s">Renew Your Add-on License</a> for <strong>%2$s</strong> to re-enable updates (expired on <strong>%3$s</strong>).', 'church-theme-content'),
     114            'expiring_soon_notice'      => __('<strong>Add-on License Expiring Soon:</strong> <a href="%1$s">Renew Your Add-on License</a> for <strong>%2$s</strong> to continue receiving updates (expires on <strong>%3$s</strong>).', 'church-theme-content'),
    113115
    114         ) );
     116        ));
    115117
    116118        // Add add-on to global array
    117119        $ctc_add_ons[$args['plugin_dir']] = $args;
    118 
    119120    }
    120 
    121121}
  • church-theme-content/trunk/includes/admin/edd-license.php

    r2187690 r3391879  
    11<?php
     2
    23/**
    34 * EDD License Handling
     
    1516 * @package    Church_Theme_Content
    1617 * @subpackage Admin
    17  * @copyright  Copyright (c) 2014 - 2019, ChurchThemes.com
     18 * @copyright  Copyright (c) 2014 - 2025, ChurchThemes.com
    1819 * @link       https://github.com/churchthemes/church-theme-content
    1920 * @license    GPLv2 or later
     
    2223
    2324// No direct access
    24 if ( ! defined( 'ABSPATH' ) ) {
     25if (! defined('ABSPATH')) {
    2526    exit;
    2627}
     
    3637 * @param string $add_on_dir Add-on to work with
    3738 */
    38 function ctc_edd_license_supported( $add_on_dir ) {
     39function ctc_edd_license_supported($add_on_dir)
     40{
    3941
    4042    $supported = false;
     
    4244    // Store URL is all that is required
    4345    // Everything else can be auto-detected
    44     if ( ctc_get_add_on( $add_on_dir, 'store_url' ) ) {
     46    if (ctc_get_add_on($add_on_dir, 'store_url')) {
    4547        $supported = true;
    4648    }
    4749
    48     return apply_filters( 'ctc_edd_license_supported', $supported, $add_on_dir );
    49 
     50    return apply_filters('ctc_edd_license_supported', $supported, $add_on_dir);
    5051}
    5152
     
    6364 * @return array Modified setting fields with license key fields inserted
    6465 */
    65 function ctc_edd_license_settings( $section ) {
     66function ctc_edd_license_settings($section)
     67{
    6668
    6769    // Get registered add-ons
     
    6971
    7072    // Any add-ons registered?
    71     if ( $add_ons ) {
     73    if ($add_ons) {
    7274
    7375        // Loop add-ons
    7476        $fields = array();
    75         foreach ( $add_ons as $add_on ) {
     77        foreach ($add_ons as $add_on) {
    7678
    7779            // Add-on supports EDD licensing?
    78             if ( ! ctc_edd_license_supported( $add_on['plugin_dir'] ) ) {
     80            if (! ctc_edd_license_supported($add_on['plugin_dir'])) {
    7981                continue;
    8082            }
     
    8486
    8587            // License Key
    86             $fields[ $key ] = array(
     88            $fields[$key] = array(
    8789                'name'              => $add_on['name'],
    8890                'desc'              => '',
     
    9799                'custom_sanitize'   => 'ctc_edd_license_sanitize', // function to do additional sanitization
    98100            );
    99 
    100101        }
    101102
    102103        // Make fields filterable.
    103         $fields = apply_filters( 'ctc_edd_license_settings_fields', $fields );
     104        $fields = apply_filters('ctc_edd_license_settings_fields', $fields);
    104105
    105106        // Add fields to section.
    106         $section['fields'] = array_merge( $fields, $section['fields'] );
     107        $section['fields'] = array_merge($fields, $section['fields']);
    107108
    108109        // Hide Church Content Pro content field if it is active and showing license field.
    109         if ( isset( $section['fields'][ 'church_content_pro_note' ] ) && ctc_pro_is_active() ) {
    110             unset( $section['fields'][ 'church_content_pro_note' ] );
    111         }
    112 
     110        if (isset($section['fields']['church_content_pro_note']) && ctc_pro_is_active()) {
     111            unset($section['fields']['church_content_pro_note']);
     112        }
    113113    }
    114114
    115115    // No add-ons.
    116116    else {
    117 
    118117    }
    119118
    120119    return $section;
    121 
    122 }
    123 
    124 add_filter( 'ctps_section-licenses', 'ctc_edd_license_settings' );
     120}
     121
     122add_filter('ctps_section-licenses', 'ctc_edd_license_settings');
    125123
    126124/**
     
    136134 * @return string HTML for field output
    137135 */
    138 function ctc_edd_license_key_field( $args, $data ) {
     136function ctc_edd_license_key_field($args, $data)
     137{
    139138
    140139    // Get add-on
    141     $add_on_dir = str_replace( '_license_key', '', $data['id'] );
     140    $add_on_dir = str_replace('_license_key', '', $data['id']);
    142141
    143142    // License key and status
    144     $license = ctc_edd_license_key( $add_on_dir );
    145     $status = ctc_edd_license_status( $add_on_dir ); // local status
     143    $license = ctc_edd_license_key($add_on_dir);
     144    $status = ctc_edd_license_status($add_on_dir); // local status
    146145
    147146    // Renewal URL
    148     $renewal_url = ctc_edd_license_renewal_url( $add_on_dir );
     147    $renewal_url = ctc_edd_license_renewal_url($add_on_dir);
    149148
    150149    // Text Input.
    151150    $input = '<input type="text" ' . $data['common_atts'] . ' id="' . $data['esc_element_id'] . '" value="' . $data['esc_value'] . '" />';
    152     $input = apply_filters( 'ctc_edd_license_key_input', $input, $args, $data );
     151    $input = apply_filters('ctc_edd_license_key_input', $input, $args, $data);
    153152    $html = $input;
    154153
     
    157156
    158157    // Licensed provided? Show button and information
    159     if ( $license ) {
     158    if ($license) {
    160159
    161160        // Show Activate/Deactivate buttons unless expired (in that case show Renew alone)
    162         if ( ! ctc_edd_license_expired( $add_on_dir ) ) {
     161        if (! ctc_edd_license_expired($add_on_dir)) {
    163162
    164163            // Activate Button (license is not active)
    165             if ( ! ctc_edd_license_active( $add_on_dir ) ) {
    166                 $html .= '<input type="submit" class="button button-primary ctc-license-button ctc-license-activate-button" name="ctc_edd_license_activate[' . esc_attr( $add_on_dir ) . ']" value="' . esc_attr__( 'Activate License', 'church-theme-content' ). '" />';
     164            if (! ctc_edd_license_active($add_on_dir)) {
     165                $html .= '<input type="submit" class="button button-primary ctc-license-button ctc-license-activate-button" name="ctc_edd_license_activate[' . esc_attr($add_on_dir) . ']" value="' . esc_attr__('Activate License', 'church-theme-content') . '" />';
    167166            }
    168167
    169168            // Deactivate Button (license is active)
    170169            else {
    171                 $html .= '<input type="submit" class="button button ctc-license-button ctc-license-deactivate-button" name="ctc_edd_license_deactivate[' . esc_attr( $add_on_dir ) . ']" value="' . esc_attr__( 'Deactivate License', 'church-theme-content' ) . '" />';
    172             }
    173 
     170                $html .= '<input type="submit" class="button button ctc-license-button ctc-license-deactivate-button" name="ctc_edd_license_deactivate[' . esc_attr($add_on_dir) . ']" value="' . esc_attr__('Deactivate License', 'church-theme-content') . '" />';
     171            }
    174172        }
    175173
    176174        // Renew Button
    177175        // Show only if renewal URL provided and license is active or expired
    178         if ( ctc_edd_license_renewal_url( $add_on_dir ) && ( ctc_edd_license_active( $add_on_dir ) || ctc_edd_license_expired( $add_on_dir ) ) ) {
    179             $html .= '<a href="' . esc_url( $renewal_url ) . '" class="button button' . ( ctc_edd_license_expired( $add_on_dir ) || ctc_edd_license_expiring_soon( $add_on_dir ) ? '-primary' : '' ) . ' ctc-license-button ctc-license-renew-button" target="_blank" />' . esc_html__( 'Renew License', 'church-theme-content' ) . '</a>';
     176        if (ctc_edd_license_renewal_url($add_on_dir) && (ctc_edd_license_active($add_on_dir) || ctc_edd_license_expired($add_on_dir))) {
     177            $html .= '<a href="' . esc_url($renewal_url) . '" class="button button' . (ctc_edd_license_expired($add_on_dir) || ctc_edd_license_expiring_soon($add_on_dir) ? '-primary' : '') . ' ctc-license-button ctc-license-renew-button" target="_blank" />' . esc_html__('Renew License', 'church-theme-content') . '</a>';
    180178        }
    181179
     
    183181        //$license_info .= '<span class="ctc-license-info-label ctc-license-status-label">' . esc_html_x( 'Status:', 'license key', 'church-theme-content' ) . '</span> ';
    184182
    185             // Status value
    186             if ( ctc_edd_license_active( $add_on_dir ) ) {
    187 
    188                 // Active
    189                 $license_info .= '<span class="ctc-license-active">' . esc_html_x( 'Active', 'license key', 'church-theme-content' ) . '</span>';
    190 
    191                 // Expiring soon
    192                 if ( ctc_edd_license_expiring_soon( $add_on_dir ) ) {
    193                     $license_info .= ' / <span class="ctc-license-expiring-soon">' . esc_html_x( 'Expiring Soon', 'license status', 'church-theme-content' ) . '</span>';
    194                 }
    195 
    196             } elseif ( ctc_edd_license_expired( $add_on_dir ) ) {
    197 
    198                 // Expired
    199                 $license_info .= '<span class="ctc-license-expired">' . esc_html_x( 'Expired', 'license key', 'church-theme-content' ) . '</span>';
    200 
    201             } else {
    202 
    203                 // Inactive
    204                 $license_info .= '<span class="ctc-license-inactive">' . esc_html_x( 'Inactive', 'license key', 'church-theme-content' ) . '</span>';
    205 
    206             }
     183        // Status value
     184        if (ctc_edd_license_active($add_on_dir)) {
     185
     186            // Active
     187            $license_info .= '<span class="ctc-license-active">' . esc_html_x('Active', 'license key', 'church-theme-content') . '</span>';
     188
     189            // Expiring soon
     190            if (ctc_edd_license_expiring_soon($add_on_dir)) {
     191                $license_info .= ' / <span class="ctc-license-expiring-soon">' . esc_html_x('Expiring Soon', 'license status', 'church-theme-content') . '</span>';
     192            }
     193        } elseif (ctc_edd_license_expired($add_on_dir)) {
     194
     195            // Expired
     196            $license_info .= '<span class="ctc-license-expired">' . esc_html_x('Expired', 'license key', 'church-theme-content') . '</span>';
     197        } else {
     198
     199            // Inactive
     200            $license_info .= '<span class="ctc-license-inactive">' . esc_html_x('Inactive', 'license key', 'church-theme-content') . '</span>';
     201        }
    207202
    208203        // Expiration
    209204        // Show expiration only if license is active or expired, not just if have the data
    210         if ( ctc_edd_license_expiration( $add_on_dir ) && ( ctc_edd_license_active( $add_on_dir ) || ctc_edd_license_expired( $add_on_dir ) ) ) {
     205        if (ctc_edd_license_expiration($add_on_dir) && (ctc_edd_license_active($add_on_dir) || ctc_edd_license_expired($add_on_dir))) {
    211206
    212207            // Expiration label
    213             $license_info .= '<span class="ctc-license-info-label ctc-license-expiration-label">' . esc_html_x( 'Expiration:', 'license key', 'church-theme-content' ) . '</span> ';
     208            $license_info .= '<span class="ctc-license-info-label ctc-license-expiration-label">' . esc_html_x('Expiration:', 'license key', 'church-theme-content') . '</span> ';
    214209
    215210            // Expiration value
    216             $license_info .= '<span class="ctc-license-expiration">' . esc_html( ctc_edd_license_expiration_formatted( $add_on_dir ) ) . '</span>';
    217 
    218         }
    219 
     211            $license_info .= '<span class="ctc-license-expiration">' . esc_html(ctc_edd_license_expiration_formatted($add_on_dir)) . '</span>';
     212        }
    220213    }
    221214
    222215    // License key not provided
    223216    else {
    224         $license_info .= '<p><span class="ctc-license-key-missing">' . esc_html__( 'Key Not Entered', 'church-theme-content' ) . '</span></p>';
     217        $license_info .= '<p><span class="ctc-license-key-missing">' . esc_html__('Key Not Entered', 'church-theme-content') . '</span></p>';
    225218    }
    226219
    227220    // Append license info
    228     if ( ! empty( $license_info ) ) {
     221    if (! empty($license_info)) {
    229222        $html .= '<p class="ctc-edd-license-info">' . $license_info . '</p>';
    230223    }
    231224
    232225    return $html;
    233 
    234226}
    235227
     
    245237 * @return string Sanitized key
    246238 */
    247 function ctc_edd_license_sanitize( $new, $field ) {
     239function ctc_edd_license_sanitize($new, $field)
     240{
    248241
    249242    // Get add-on
    250     $add_on_dir = str_replace( '_license_key', '', $field['id'] );
     243    $add_on_dir = str_replace('_license_key', '', $field['id']);
    251244
    252245    // Get old license key value
    253     $old = ctc_edd_license_key( $add_on_dir );
     246    $old = ctc_edd_license_key($add_on_dir);
    254247
    255248    // Unset local status as active and expiration date when changing key -- need to activate new key
    256     if ( $old && $old != $new ) {
     249    if ($old && $old != $new) {
    257250
    258251        // Note: status and expiration stored in their own options
    259252        // Not in plugin settings array (easier management and these are not user settings)
    260         delete_option( $add_on_dir . '_license_status' );
    261         delete_option( $add_on_dir . '_license_expiration' );
    262 
     253        delete_option($add_on_dir . '_license_status');
     254        delete_option($add_on_dir . '_license_expiration');
    263255    }
    264256
    265257    return $new;
    266 
    267258}
    268259
     
    282273 * @return string Option value
    283274 */
    284 function ctc_edd_license_key( $add_on_dir ) {
     275function ctc_edd_license_key($add_on_dir)
     276{
    285277
    286278    // Get license key setting
    287     $license_key = trim( ctc_setting( $add_on_dir . '_license_key' ) );
     279    $license_key = trim(ctc_setting($add_on_dir . '_license_key'));
    288280
    289281    // Return filtered
    290     return apply_filters( 'ctc_edd_license_key', $license_key, $add_on_dir );
    291 
     282    return apply_filters('ctc_edd_license_key', $license_key, $add_on_dir);
    292283}
    293284
     
    301292 * @return string status active, expired or empty (inactive)
    302293 */
    303 function ctc_edd_license_status( $add_on_dir ) {
    304 
    305     $status = get_option( $add_on_dir . '_license_status' );
    306 
    307     return apply_filters( 'ctc_edd_license_status', $status, $add_on_dir );
    308 
     294function ctc_edd_license_status($add_on_dir)
     295{
     296
     297    $status = get_option($add_on_dir . '_license_status');
     298
     299    return apply_filters('ctc_edd_license_status', $status, $add_on_dir);
    309300}
    310301
     
    316307 * @return bool True if active
    317308 */
    318 function ctc_edd_license_active( $add_on_dir ) {
     309function ctc_edd_license_active($add_on_dir)
     310{
    319311
    320312    $active = false;
    321313
    322     if ( 'active' == ctc_edd_license_status( $add_on_dir ) ) {
     314    if ('active' == ctc_edd_license_status($add_on_dir)) {
    323315        $active = true;
    324316    }
    325317
    326     return apply_filters( 'ctc_edd_license_active', $active, $add_on_dir );
    327 
     318    return apply_filters('ctc_edd_license_active', $active, $add_on_dir);
    328319}
    329320
     
    335326 * @return bool True if inactive
    336327 */
    337 function ctc_edd_license_inactive( $add_on_dir ) {
     328function ctc_edd_license_inactive($add_on_dir)
     329{
    338330
    339331    $inactive = false;
    340332
    341     if ( ! ctc_edd_license_status( $add_on_dir ) ) {
     333    if (! ctc_edd_license_status($add_on_dir)) {
    342334        $inactive = true;
    343335    }
    344336
    345     return apply_filters( 'ctc_edd_license_inactive', $inactive, $add_on_dir );
    346 
     337    return apply_filters('ctc_edd_license_inactive', $inactive, $add_on_dir);
    347338}
    348339
     
    354345 * @return bool True if expired
    355346 */
    356 function ctc_edd_license_expired( $add_on_dir ) {
     347function ctc_edd_license_expired($add_on_dir)
     348{
    357349
    358350    $expired = false;
    359351
    360     if ( 'expired' == ctc_edd_license_status( $add_on_dir ) ) {
     352    if ('expired' == ctc_edd_license_status($add_on_dir)) {
    361353        $expired = true;
    362354    }
    363355
    364     return apply_filters( 'ctc_edd_license_expired', $expired, $add_on_dir );
    365 
     356    return apply_filters('ctc_edd_license_expired', $expired, $add_on_dir);
    366357}
    367358
     
    373364 * @return bool True if expiring within X days
    374365 */
    375 function ctc_edd_license_expiring_soon( $add_on_dir ) {
     366function ctc_edd_license_expiring_soon($add_on_dir)
     367{
    376368
    377369    $expiring_soon = false;
    378370
    379     $expiration_data = ctc_edd_license_expiration_data( $add_on_dir );
    380 
    381     if ( ! empty( $expiration_data['expiring_soon'] ) ) {
     371    $expiration_data = ctc_edd_license_expiration_data($add_on_dir);
     372
     373    if (! empty($expiration_data['expiring_soon'])) {
    382374        $expiring_soon = true;
    383375    }
    384376
    385     return apply_filters( 'ctc_edd_license_expiring_soon', $expiring_soon, $add_on_dir );
    386 
     377    return apply_filters('ctc_edd_license_expiring_soon', $expiring_soon, $add_on_dir);
    387378}
    388379
     
    397388 * @return string Expiration YYYY-MM-DD
    398389 */
    399 function ctc_edd_license_update_expiration( $add_on_dir, $expiration ) {
     390function ctc_edd_license_update_expiration($add_on_dir, $expiration)
     391{
    400392
    401393    // Only if have a value (old value better than no value)
    402     if ( ! empty( $expiration ) ) {
     394    if (! empty($expiration)) {
    403395
    404396        // Remove seconds so stored value is YYYY-MM-DD
    405         list( $expiration ) = explode( ' ', $expiration );
    406         $expiration = trim( $expiration );
     397        list($expiration) = explode(' ', $expiration);
     398        $expiration = trim($expiration);
    407399
    408400        // Not an invalid key?
    409         if ( $expiration != '1970-01-01' ) {
     401        if ($expiration != '1970-01-01') {
    410402
    411403            // Update local value
    412             update_option( $add_on_dir . '_license_expiration', $expiration );
    413 
    414         }
    415 
    416     }
    417 
     404            update_option($add_on_dir . '_license_expiration', $expiration);
     405        }
     406    }
    418407}
    419408
     
    425414 * @return string Expiration YYYY-MM-DD
    426415 */
    427 function ctc_edd_license_expiration( $add_on_dir ) {
    428 
    429     $expiration = get_option( $add_on_dir . '_license_expiration' );
    430 
    431     return apply_filters( 'ctc_edd_license_expiration', $expiration, $add_on_dir );
    432 
     416function ctc_edd_license_expiration($add_on_dir)
     417{
     418
     419    $expiration = get_option($add_on_dir . '_license_expiration');
     420
     421    return apply_filters('ctc_edd_license_expiration', $expiration, $add_on_dir);
    433422}
    434423
     
    441430 * @return string Expiration date formatted
    442431 */
    443 function ctc_edd_license_expiration_formatted( $add_on_dir, $none_text = false ) {
    444 
    445     $expiration = ctc_edd_license_expiration( $add_on_dir );
     432function ctc_edd_license_expiration_formatted($add_on_dir, $none_text = false)
     433{
     434
     435    $expiration = ctc_edd_license_expiration($add_on_dir);
    446436
    447437    $date = '';
    448438
    449     if ( $expiration ) {
    450         $date = date_i18n( get_option( 'date_format' ), strtotime( $expiration ) );
    451     } elseif ( ! empty( $none_text ) ) {
     439    if ($expiration) {
     440        $date = date_i18n(get_option('date_format'), strtotime($expiration));
     441    } elseif (! empty($none_text)) {
    452442        $date = $none_text;
    453443    }
    454444
    455     return apply_filters( 'ctc_edd_license_expiration_formatted', $date, $add_on_dir );
    456 
     445    return apply_filters('ctc_edd_license_expiration_formatted', $date, $add_on_dir);
    457446}
    458447
     
    464453 * @return array date in various formats and whether it is expiring soon or not
    465454 */
    466 function ctc_edd_license_expiration_data( $add_on_dir ) {
     455function ctc_edd_license_expiration_data($add_on_dir)
     456{
    467457
    468458    $data = array();
    469459
    470     $data['expiration'] = ctc_edd_license_expiration( $add_on_dir );
    471     $data['expiration_date'] = ctc_edd_license_expiration_formatted( $add_on_dir, esc_html_x( 'unknown date', 'license expiration', 'church-theme-content' ) );
    472     $data['expiration_ts'] = ! empty( $data['expiration'] ) ? strtotime( $data['expiration'] ) : '';
    473     $data['expiring_soon_days'] = ctc_get_add_on( $add_on_dir, 'expiring_soon_days' );
    474     $data['expiring_soon_ts'] = time() + ( DAY_IN_SECONDS * $data['expiring_soon_days'] );
    475     $data['expiring_soon'] = ( ! ctc_edd_license_expired( $add_on_dir ) && ! empty( $data['expiration_ts'] ) && $data['expiration_ts'] < $data['expiring_soon_ts'] ) ? true : false;
    476 
    477     return apply_filters( 'ctc_edd_license_expiration_data', $data, $add_on_dir );
    478 
     460    $data['expiration'] = ctc_edd_license_expiration($add_on_dir);
     461    $data['expiration_date'] = ctc_edd_license_expiration_formatted($add_on_dir, esc_html_x('unknown date', 'license expiration', 'church-theme-content'));
     462    $data['expiration_ts'] = ! empty($data['expiration']) ? strtotime($data['expiration']) : '';
     463    $data['expiring_soon_days'] = ctc_get_add_on($add_on_dir, 'expiring_soon_days');
     464    $data['expiring_soon_ts'] = time() + (DAY_IN_SECONDS * $data['expiring_soon_days']);
     465    $data['expiring_soon'] = (! ctc_edd_license_expired($add_on_dir) && ! empty($data['expiration_ts']) && $data['expiration_ts'] < $data['expiring_soon_ts']) ? true : false;
     466
     467    return apply_filters('ctc_edd_license_expiration_data', $data, $add_on_dir);
    479468}
    480469
     
    494483 * @return string $result Result such as 'activate_success' or 'activate_fail' (not every action has result)
    495484 */
    496 function ctc_edd_license_activation( $add_on_dir, $action ) {
     485function ctc_edd_license_activation($add_on_dir, $action)
     486{
    497487
    498488    $result = '';
    499489
    500490    // Add-on supports licensing?
    501     if ( ! ctc_edd_license_supported( $add_on_dir ) ) {
     491    if (! ctc_edd_license_supported($add_on_dir)) {
    502492        return $result;
    503493    }
    504494
    505495    // Continue to activate or deactivate
    506     if ( $action && $add_on_dir ) {
     496    if ($action && $add_on_dir) {
    507497
    508498        // Get license data
    509         $license_data = ctc_edd_license_action( $add_on_dir, $action );
     499        $license_data = ctc_edd_license_action($add_on_dir, $action);
    510500
    511501        // Call action via API
    512         if ( $license_data ) {
     502        if ($license_data) {
    513503
    514504            // If activated remotely, set local status; or set local status if was already active remotely -- keep in sync
    515             if ( 'activate_license' == $action ) {
     505            if ('activate_license' == $action) {
    516506
    517507                // Success
    518                 if ( 'valid' == $license_data->license || 'valid' == ctc_edd_license_check( $add_on_dir ) ) {
    519 
    520                     update_option( $add_on_dir . '_license_status', 'active' );
     508                if ('valid' == $license_data->license || 'valid' == ctc_edd_license_check($add_on_dir)) {
     509
     510                    update_option($add_on_dir . '_license_status', 'active');
    521511
    522512                    $result = 'activate_success';
    523 
    524513                }
    525514
     
    528517                    $result = 'activate_fail';
    529518                }
    530 
    531519            }
    532520
     
    538526                    || 'disabled' == $license_data->license // if disabled would return failed... (leaving this just in case)
    539527                    || 'failed' == $license_data->license // likely means deactivation failed because it's disabled
    540                     || 'inactive' == ctc_edd_license_check( $add_on_dir )
     528                    || 'inactive' == ctc_edd_license_check($add_on_dir)
    541529                )
    542530            ) {
    543531
    544532                // Success or failure?
    545                 if ( 'deactivated' == $license_data->license ) {
     533                if ('deactivated' == $license_data->license) {
    546534                    $result = 'deactivate_success';
    547535                } else {
     
    550538
    551539                // Delete license status
    552                 delete_option( $add_on_dir . '_license_status' );
    553 
     540                delete_option($add_on_dir . '_license_status');
    554541            }
    555542
    556543            // Set current expiration locally
    557544            // Local will be synced to remote daily in case changes
    558             if ( isset( $license_data->expires ) ) {
    559                 ctc_edd_license_update_expiration( $add_on_dir, $license_data->expires );
    560             }
    561 
    562         }
    563 
     545            if (isset($license_data->expires)) {
     546                ctc_edd_license_update_expiration($add_on_dir, $license_data->expires);
     547            }
     548        }
    564549    }
    565550
    566551    return $result;
    567 
    568552}
    569553
     
    583567 * @return array Settings to save
    584568 */
    585 function ctc_edd_license_detect_user_action( $settings, $old_settings ) {
     569function ctc_edd_license_detect_user_action($settings, $old_settings)
     570{
    586571
    587572    // Activate button clicked
    588     if ( ! empty( $_POST['ctc_edd_license_activate'] ) ) {
     573    if (! empty($_POST['ctc_edd_license_activate'])) {
    589574        $action = 'activate_license'; // for EDD Software Licensing API
    590         $add_on_dir = key( $_POST['ctc_edd_license_activate'] );
     575        $add_on_dir = key($_POST['ctc_edd_license_activate']);
    591576    }
    592577
    593578    // Deactivate button clicked
    594     elseif ( ! empty( $_POST['ctc_edd_license_deactivate'] ) ) {
     579    elseif (! empty($_POST['ctc_edd_license_deactivate'])) {
    595580        $action = 'deactivate_license'; // for EDD Software Licensing API
    596         $add_on_dir = key( $_POST['ctc_edd_license_deactivate'] );
     581        $add_on_dir = key($_POST['ctc_edd_license_deactivate']);
    597582    }
    598583
    599584    // Has action, add-on and license key?
    600     if ( ! empty( $action ) && ! empty( $settings[$add_on_dir . '_license_key'] ) ) {
     585    if (! empty($action) && ! empty($settings[$add_on_dir . '_license_key'])) {
    601586
    602587        // Set transient with license key data
    603588        // ctc_edd_license_activation() will run this after redirect occurs
    604589        // It is done after everything is saved in case license key value changed
    605         set_transient( 'ctc_edd_license_activation', array(
     590        set_transient('ctc_edd_license_activation', array(
    606591            'action'        => $action,
    607592            'add_on_dir'    => $add_on_dir,
    608         ), 30 ); // expires when first run or after 30 seconds in case of timeout
     593        ), 30); // expires when first run or after 30 seconds in case of timeout
    609594
    610595    }
     
    613598    // Otherwise plugin settings will be wiped
    614599    return $settings;
    615 
    616600}
    617601
    618602// Using pre_update_option instead of update_option action because update_option
    619603// will not fire unless values changed -- and we need $_POST to detect button action
    620 add_filter( 'pre_update_option_ctc_settings', 'ctc_edd_license_detect_user_action', 10, 2 );
     604add_filter('pre_update_option_ctc_settings', 'ctc_edd_license_detect_user_action', 10, 2);
    621605
    622606/**
     
    632616 * @global object $ctc_settings
    633617 */
    634 function ctc_edd_license_activation_after_user_action() {
     618function ctc_edd_license_activation_after_user_action()
     619{
    635620
    636621    global $ctc_settings;
    637622
    638623    // Is this plugin settings page?
    639     if ( ! $ctc_settings->is_settings_page() ) {
     624    if (! $ctc_settings->is_settings_page()) {
    640625        return;
    641626    }
    642627
    643628    // Get transient with add-on to activate license for
    644     $activation_data = get_transient( 'ctc_edd_license_activation' );
     629    $activation_data = get_transient('ctc_edd_license_activation');
    645630
    646631    // Is a an add-on's license to be activated/deactivated?
    647     if ( ! empty( $activation_data ) ) {
     632    if (! empty($activation_data)) {
    648633
    649634        // Delete transient so this is run once
    650         delete_transient( 'ctc_edd_license_activation' );
     635        delete_transient('ctc_edd_license_activation');
    651636
    652637        // Prepare data
     
    655640
    656641        // Attempt activation/deactivation remotely and set the result locally
    657         $result = ctc_edd_license_activation( $add_on_dir, $action );
     642        $result = ctc_edd_license_activation($add_on_dir, $action);
    658643
    659644        // Activation result
    660         if ( $result ) {
     645        if ($result) {
    661646
    662647            // Set transient so notice shows on next settings page load
    663             set_transient( 'ctc_edd_license_activation_result', array(
     648            set_transient('ctc_edd_license_activation_result', array(
    664649                'result'        => $result,
    665650                'add_on_dir'    => $add_on_dir,
    666             ), 15 ); // will be deleted after shown or in 15 seconds
    667 
    668         }
    669 
    670     }
    671 
    672 }
    673 
    674 add_action( 'ctps_after_save', 'ctc_edd_license_activation_after_user_action' );
     651            ), 15); // will be deleted after shown or in 15 seconds
     652
     653        }
     654    }
     655}
     656
     657add_action('ctps_after_save', 'ctc_edd_license_activation_after_user_action');
    675658
    676659/**
     
    680663 * @global object $ctc_settings
    681664 */
    682 function ctc_edd_license_activation_result_notice() {
     665function ctc_edd_license_activation_result_notice()
     666{
    683667
    684668    global $ctc_settings;
    685669
    686670    // Only on plugin settings
    687     if ( ! $ctc_settings->is_settings_page() ) {
     671    if (! $ctc_settings->is_settings_page()) {
    688672        return;
    689673    }
    690674
    691675    // Have a result transient?
    692     $result = get_transient( 'ctc_edd_license_activation_result' );
    693     if ( $result ) {
     676    $result = get_transient('ctc_edd_license_activation_result');
     677    if ($result) {
    694678
    695679        // Get result data?
     
    698682
    699683        // Have result data?
    700         if ( ! empty( $add_on_dir ) && ! empty( $result ) ) {
     684        if (! empty($add_on_dir) && ! empty($result)) {
    701685
    702686            // Get notice message
    703             $notice_message = ctc_get_add_on( $add_on_dir, $result . '_notice' );
     687            $notice_message = ctc_get_add_on($add_on_dir, $result . '_notice');
    704688
    705689            // Output notice
    706             if ( $notice_message ) {
     690            if ($notice_message) {
    707691
    708692                // Show notice and hide "Settings saved." notice beneath
    709                 ?>
    710 
    711                 <div id="ctc-license-notice-<?php echo esc_attr( $result ); ?>" class="notice notice-<?php if ( preg_match( '/success/', $result ) ) : ?>success<?php else : ?>error<?php endif; ?>">
     693?>
     694
     695                <div id="ctc-license-notice-<?php echo esc_attr($result); ?>" class="notice notice-<?php if (preg_match('/success/', $result)) : ?>success<?php else : ?>error<?php endif; ?>">
    712696                    <p>
    713697                        <?php
     
    730714
    731715                <style type="text/css">
    732                 #setting-error-settings_updated {
    733                     display: none;
    734                 }
     716                    #setting-error-settings_updated {
     717                        display: none;
     718                    }
    735719                </style>
    736720
    737                 <?php
    738 
    739             }
    740 
     721<?php
     722
     723            }
    741724        }
    742725
    743726        // Delete transient after showing notice once
    744         delete_transient( 'ctc_edd_license_activation_result' );
    745 
    746     }
    747 
    748 }
    749 
    750 add_action( 'admin_notices', 'ctc_edd_license_activation_result_notice' );
     727        delete_transient('ctc_edd_license_activation_result');
     728    }
     729}
     730
     731add_action('admin_notices', 'ctc_edd_license_activation_result_notice');
    751732
    752733/*******************************************
     
    760741 * @global object $ctc_settings
    761742 */
    762 function ctc_edd_license_notices() {
     743function ctc_edd_license_notices()
     744{
    763745
    764746    global $ctc_settings;
     
    766748    // User can manage plugins?
    767749    // Keeps notices from showing to non-admin users
    768     if ( ! current_user_can( 'install_plugins' ) ) {
     750    if (! current_user_can('install_plugins')) {
    769751        return;
    770752    }
     
    773755    // Don't show on settings page (redundant on Licenses tab and irrelevants/distracting on others)
    774756    $screen = get_current_screen();
    775     if ( ! in_array( $screen->base, array( 'dashboard', 'plugins', 'update-core' ) ) ) {
     757    if (! in_array($screen->base, array('dashboard', 'plugins', 'update-core'))) {
    776758        return;
    777759    }
     
    781763
    782764    // Have add-ons?
    783     if ( $add_ons ) {
     765    if ($add_ons) {
    784766
    785767        // Collect add-ons requiring a notice
     
    789771
    790772        // Loop add-ons
    791         foreach( $add_ons as $add_on_dir => $add_on ) {
     773        foreach ($add_ons as $add_on_dir => $add_on) {
    792774
    793775            // Add-on supports EDD licensing?
    794             if ( ! ctc_edd_license_supported( $add_on_dir ) ) {
     776            if (! ctc_edd_license_supported($add_on_dir)) {
    795777                continue;
    796778            }
    797779
    798780            // Get expiration data
    799             $expiration_data = ctc_edd_license_expiration_data( $add_on_dir );
     781            $expiration_data = ctc_edd_license_expiration_data($add_on_dir);
    800782
    801783            // Active But Expiring Soon
    802784            // Show a reminder notice 30 days before expiration
    803             if ( ctc_edd_license_active( $add_on_dir ) && $expiration_data['expiring_soon'] ) {
     785            if (ctc_edd_license_active($add_on_dir) && $expiration_data['expiring_soon']) {
    804786                $expiring_soon_add_ons[$add_on_dir] = $add_on;
    805787            }
     
    807789            // Expired
    808790            // This shows as error not notice, since it has come to pass
    809             elseif ( ctc_edd_license_expired( $add_on_dir ) ) {
     791            elseif (ctc_edd_license_expired($add_on_dir)) {
    810792                $expired_add_ons[$add_on_dir] = $add_on;
    811793            }
    812794
    813795            // Inactive
    814             elseif ( ! ctc_edd_license_active( $add_on_dir ) ) {
     796            elseif (! ctc_edd_license_active($add_on_dir)) {
    815797                $inactive_add_ons[$add_on_dir] = $add_on;
    816798            }
    817 
    818799        }
    819800
    820801        // Get notices.
    821802        $notices = '';
    822         $notices .= ctc_edd_license_notice_content( 'inactive', $inactive_add_ons );
    823         $notices .= ctc_edd_license_notice_content( 'expired', $expired_add_ons );
    824         $notices .= ctc_edd_license_notice_content( 'expiring_soon', $expiring_soon_add_ons );
     803        $notices .= ctc_edd_license_notice_content('inactive', $inactive_add_ons);
     804        $notices .= ctc_edd_license_notice_content('expired', $expired_add_ons);
     805        $notices .= ctc_edd_license_notice_content('expiring_soon', $expiring_soon_add_ons);
    825806
    826807        // Filter notices.
    827         $notices = apply_filters( 'ctc_edd_license_notices', $notices );
     808        $notices = apply_filters('ctc_edd_license_notices', $notices);
    828809
    829810        // Output notices.
    830811        echo $notices;
    831 
    832     }
    833 
    834 }
    835 
    836 add_action( 'admin_notices', 'ctc_edd_license_notices', 8 ); // higher priority than regular notices (10) but lower than theme license notice (7)
     812    }
     813}
     814
     815add_action('admin_notices', 'ctc_edd_license_notices', 8); // higher priority than regular notices (10) but lower than theme license notice (7)
    837816
    838817/**
     
    844823 * @return string HTML output for admin_notice
    845824 */
    846 function ctc_edd_license_notice_content( $notice, $add_ons ) {
     825function ctc_edd_license_notice_content($notice, $add_ons)
     826{
    847827
    848828    $content = '';
    849829
    850830    // Count add-ons
    851     $count = count( $add_ons );
     831    $count = count($add_ons);
    852832
    853833    // Have at least one?
    854     if ( $count ) {
     834    if ($count) {
    855835
    856836        // Empty vars.
     
    865845
    866846        // One add-on
    867         if ( 1 == $count ) {
     847        if (1 == $count) {
    868848
    869849            // Message to use.
     
    871851
    872852            // Get first and only add-on in array.
    873             $values = array_values( $add_ons );
    874             $first_add_on = array_shift( $values );
     853            $values = array_values($add_ons);
     854            $first_add_on = array_shift($values);
    875855
    876856            // Add-on data.
    877857            $add_on_dir = $first_add_on['plugin_dir'];
    878858            $add_on_names = $first_add_on['name']; // single name
    879             $expiration_data = ctc_edd_license_expiration_data( $add_on_dir );
     859            $expiration_data = ctc_edd_license_expiration_data($add_on_dir);
    880860            $expiration_date = $expiration_data['expiration_date'];
    881861
    882862            // URLs for add-on overriding default notices during registration
    883             $renewal_url = ctc_edd_license_renewal_url( $add_on_dir );
    884             $renewal_info_url = ctc_get_add_on( $add_on_dir, 'renewal_info_url' );
     863            $renewal_url = ctc_edd_license_renewal_url($add_on_dir);
     864            $renewal_info_url = ctc_get_add_on($add_on_dir, 'renewal_info_url');
    885865
    886866            // Is this Pro add-on? Check if theme uses same license key.
    887867
    888             if ( 'church-content-pro' === $add_on_dir ) {
     868            if ('church-content-pro' === $add_on_dir) {
    889869
    890870                // Get Pro license key.
    891                 $pro_license_key = ctc_edd_license_key( $add_on_dir );
     871                $pro_license_key = ctc_edd_license_key($add_on_dir);
    892872
    893873                // Get ChurchThemes.com theme license key.
    894874                $active_theme = wp_get_theme();
    895                 if ( function_exists( 'ctfw_edd_license_key' ) ) {
     875                if (function_exists('ctfw_edd_license_key')) {
    896876                    $theme_license_key = ctfw_edd_license_key();
    897877                }
    898878
    899879                // Have theme from ChurchTheme.com and license key is same as Pro.
    900                 if ( $theme_license_key && $theme_license_key === $pro_license_key ) {
     880                if ($theme_license_key && $theme_license_key === $pro_license_key) {
    901881
    902882                    // Message to use
     
    904884
    905885                    // Theme name.
    906                     $theme_name = $active_theme->get( 'Name' );
     886                    $theme_name = $active_theme->get('Name');
    907887
    908888                    // Prevent the theme's notice from showing.
     
    910890
    911891                }
    912 
    913             }
    914 
     892            }
    915893        }
    916894
     
    924902            $i = 0;
    925903            $add_on_names = '';
    926             foreach ( $add_ons as $add_on ) {
     904            foreach ($add_ons as $add_on) {
    927905
    928906                $i++;
    929907
    930908                // Separate with comma or "and"
    931                 if ( $i == $count ) {
     909                if ($i == $count) {
    932910
    933911                    /* translators: separator between last and second to last add-ons in inactive/expired admin notice (instead of comma) */
    934                     $add_on_names .= esc_html_x( ' and ', 'license notice', 'church-theme-content' );
    935 
    936                 } elseif ( 1 != $i ) {
     912                    $add_on_names .= esc_html_x(' and ', 'license notice', 'church-theme-content');
     913                } elseif (1 != $i) {
    937914
    938915                    /* translators: separator between add-on names in inactive/expired admin notice */
    939                     $add_on_names .= esc_html_x( ', ', 'license notice', 'church-theme-content' );
    940 
     916                    $add_on_names .= esc_html_x(', ', 'license notice', 'church-theme-content');
    941917                }
    942918
    943919                // Append name to list
    944920                $add_on_names .= '<strong>' . $add_on['name'] . '</strong>';
    945 
    946             }
    947 
     921            }
    948922        }
    949923
     
    957931
    958932            /* translators: %1$s is URL to add-on license settings, %2$s is name of add-on */
    959             'inactive'                      => ctc_get_add_on( $add_on_dir, 'inactive_notice' ),
     933            'inactive'                      => ctc_get_add_on($add_on_dir, 'inactive_notice'),
    960934
    961935            /* translators: %1$s is URL to add-on license settings, %2$s is names of add-ons */
    962             'inactive_multiple'             => __( '<strong>Add-on Licenses Inactive:</strong> <a href="%1$s">Activate Your Add-on Licenses</a> to enable updates for %2$s.', 'church-theme-content' ),
     936            'inactive_multiple'             => __('<strong>Add-on Licenses Inactive:</strong> <a href="%1$s">Activate Your Add-on Licenses</a> to enable updates for %2$s.', 'church-theme-content'),
    963937
    964938            /* translators: %1$s is URL to add-on license settings, %2$s is name of add-on, %3$s is expiration date, %7$s agency name. */
    965             'expired'                       => ctc_get_add_on( $add_on_dir, 'expired_notice' ),
    966             'expired_agency_mode'           => __( '<strong>Add-on License Expired:</strong> Ask %7$s to renew their <a href="%1$s">Add-on License</a> for <strong>%2$s</strong> to re-enable updates for your site (expired <strong>%3$s</strong>). <a href="%5$s" target="_blank">Learn More</a>', 'church-content-pro' ),
     939            'expired'                       => ctc_get_add_on($add_on_dir, 'expired_notice'),
     940            'expired_agency_mode'           => __('<strong>Add-on License Expired:</strong> Ask %7$s to renew their <a href="%1$s">Add-on License</a> for <strong>%2$s</strong> to re-enable updates for your site (expired <strong>%3$s</strong>). <a href="%5$s" target="_blank">Learn More</a>', 'church-content-pro'),
    967941
    968942            /* translators: %1$s is URL to add-on license settings, %2$s is names of add-ons, %7$s agency name. */
    969             'expired_multiple'              => __( '<strong>Add-on Licenses Expired:</strong> <a href="%1$s">Renew Your Add-on Licenses</a> for %2$s to re-enable updates.', 'church-theme-content' ),
    970             'expired_multiple_agency_mode'  => __( '<strong>Add-on Licenses Expired:</strong> Ask %7$s to renew their <a href="%1$s">Add-on Licenses</a> for %2$s to re-enable updates for your site.', 'church-theme-content' ),
     943            'expired_multiple'              => __('<strong>Add-on Licenses Expired:</strong> <a href="%1$s">Renew Your Add-on Licenses</a> for %2$s to re-enable updates.', 'church-theme-content'),
     944            'expired_multiple_agency_mode'  => __('<strong>Add-on Licenses Expired:</strong> Ask %7$s to renew their <a href="%1$s">Add-on Licenses</a> for %2$s to re-enable updates for your site.', 'church-theme-content'),
    971945
    972946            /* translators: %2$s is name of Pro plugin, %3$s is expiration date, %4$s is link to renew, %5$s is link to learn more, %6$s is name of theme sharing same license as add-on, %7$s agency name. */
    973947            // This shows only for ChurchThemes.com themes when license key is same for theme and Pro plugin.
    974             'expired_theme_pro'             => __( '<strong>License Expired:</strong> <a href="%4$s">Renew Your License</a> for the <b>%6$s</b> theme and <b>%2$s</b> add-on to reactivate updates and support (expired <b>%3$s</b>). <a href="%5$s" target="_blank">Learn More</a>', 'church-theme-content' ),
    975             'expired_theme_pro_agency_mode' => __( '<strong>License Expired:</strong> Ask %7$s to renew their license for the <b>%6$s</b> theme and <b>%2$s</b> add-on to reactivate updates for your site (expired <b>%3$s</b>). <a href="%5$s" target="_blank">Learn More</a>', 'church-theme-content' ),
     948            'expired_theme_pro'             => __('<strong>License Expired:</strong> <a href="%4$s">Renew Your License</a> for the <b>%6$s</b> theme and <b>%2$s</b> add-on to reactivate updates and support (expired <b>%3$s</b>). <a href="%5$s" target="_blank">Learn More</a>', 'church-theme-content'),
     949            'expired_theme_pro_agency_mode' => __('<strong>License Expired:</strong> Ask %7$s to renew their license for the <b>%6$s</b> theme and <b>%2$s</b> add-on to reactivate updates for your site (expired <b>%3$s</b>). <a href="%5$s" target="_blank">Learn More</a>', 'church-theme-content'),
    976950
    977951            /* translators: %1$s is URL to add-on license settings, %2$s is name of add-on, %3$s is expiration date */
    978             'expiring_soon'                 => ctc_get_add_on( $add_on_dir, 'expiring_soon_notice' ),
     952            'expiring_soon'                 => ctc_get_add_on($add_on_dir, 'expiring_soon_notice'),
    979953
    980954            /* translators: %1$s is URL to add-on license settings, %2$s is names of add-ons */
    981             'expiring_soon_multiple'        => __( '<strong>Add-on Licenses Expiring Soon:</strong> <a href="%1$s">Renew Your Add-on Licenses</a> for %2$s to continue receiving updates.', 'church-theme-content' ),
     955            'expiring_soon_multiple'        => __('<strong>Add-on Licenses Expiring Soon:</strong> <a href="%1$s">Renew Your Add-on Licenses</a> for %2$s to continue receiving updates.', 'church-theme-content'),
    982956
    983957            /* translators: %2$s is name of Pro plugin, %3$s is expiration date, %4$s is link to renew, %5$s is link to learn more, %6$s is name of theme sharing same license as add-on. */
    984958            // This shows only for ChurchThemes.com themes when license key is same for theme and Pro plugin.
    985959            // Note that "Expiring Soon" notices not shown when Agency Mode is enabled.
    986             'expiring_soon_theme_pro'       => __( '<strong>License Expiring Soon:</strong> <a href="%4$s">Renew Your License</a> for the <b>%6$s</b> theme and <b>%2$s</b> add-on before expiration on <b>%3$s</b>. <a href="%5$s" target="_blank">Learn More</a>', 'church-theme-content' ),
     960            'expiring_soon_theme_pro'       => __('<strong>License Expiring Soon:</strong> <a href="%4$s">Renew Your License</a> for the <b>%6$s</b> theme and <b>%2$s</b> add-on before expiration on <b>%3$s</b>. <a href="%5$s" target="_blank">Learn More</a>', 'church-theme-content'),
    987961
    988962        );
     
    990964        // Filter notice_key.
    991965        // Pro add-on can do this to append _agency_mode to an expired notice.
    992         $notice_key = apply_filters( 'ctc_edd_license_notice_key', $notice_key, $notices );
     966        $notice_key = apply_filters('ctc_edd_license_notice_key', $notice_key, $notices);
    993967
    994968        // Have notice message.
    995         if ( isset( $notices[$notice_key] ) ) {
     969        if (isset($notices[$notice_key])) {
    996970
    997971            // Notice message.
     
    1001975            // notice-warning (yellow) for expiring soon.
    1002976            // notice-error (red) for inactive and expired (everything else).
    1003             $notice_class = preg_match( '/expiring_soon/', $notice_key ) ? 'notice-warning' : 'notice-error';
     977            $notice_class = preg_match('/expiring_soon/', $notice_key) ? 'notice-warning' : 'notice-error';
    1004978
    1005979            // Class to denote license status.
    1006             $notice_class .= ' ctc-license-notice-' . str_replace( '_', '-', $notice_key );
     980            $notice_class .= ' ctc-license-notice-' . str_replace('_', '-', $notice_key);
    1007981
    1008982            // Agency name.
    1009983            /* translators: This is used in place of agency name for Agency Mode when no agency name available */
    1010             $agency_name = __( 'your website provider', 'church-theme-content');
    1011             if ( function_exists( 'ccp_agency_mode_name_linked' ) ) {
     984            $agency_name = __('your website provider', 'church-theme-content');
     985            if (function_exists('ccp_agency_mode_name_linked')) {
    1012986                $agency_name = ccp_agency_mode_name_linked();
    1013987            }
    1014988
    1015989            // Build notice HTML.
    1016             $content .= '<div class="ctc-license-status-notice notice ' . esc_attr( $notice_class ) . '">';
     990            $content .= '<div class="ctc-license-status-notice notice ' . esc_attr($notice_class) . '">';
    1017991            $content .= '   <p>';
    1018992            $content .= sprintf(
    1019993
    1020                             wp_kses(
    1021                                 $message,
    1022                                 array(
    1023                                     'strong' => array(),
    1024                                     'b' => array(),
    1025                                     'em' => array(),
    1026                                     'i' => array(),
    1027                                     'a' => array(
    1028                                         'href' => array(),
    1029                                         'target' => array(),
    1030                                     ),
    1031                                 )
    1032                             ),
    1033 
    1034                             esc_url( admin_url( 'options-general.php?page=' . CTC_DIR ) . '#licenses' ),
    1035                             $add_on_names, // or single name
    1036 
    1037                             // These are available only when the notice is for a single add-on
    1038                             // Default notices should not use renewal URLs because they may not be available
    1039                             // An add-on can, however, use the renewal URLs it provides
    1040                             $expiration_date,
    1041                             $renewal_url,
    1042                             $renewal_info_url,
    1043                             $theme_name,
    1044                             $agency_name
    1045 
    1046                         );
     994                wp_kses(
     995                    $message,
     996                    array(
     997                        'strong' => array(),
     998                        'b' => array(),
     999                        'em' => array(),
     1000                        'i' => array(),
     1001                        'a' => array(
     1002                            'href' => array(),
     1003                            'target' => array(),
     1004                        ),
     1005                    )
     1006                ),
     1007
     1008                esc_url(admin_url('options-general.php?page=' . CTC_DIR) . '#licenses'),
     1009                $add_on_names, // or single name
     1010
     1011                // These are available only when the notice is for a single add-on
     1012                // Default notices should not use renewal URLs because they may not be available
     1013                // An add-on can, however, use the renewal URLs it provides
     1014                $expiration_date,
     1015                $renewal_url,
     1016                $renewal_info_url,
     1017                $theme_name,
     1018                $agency_name
     1019
     1020            );
    10471021            $content .= '   </p>';
    10481022            $content .= '</div>';
    10491023
    10501024            // Hide theme expired/expiring notice.
    1051             if ( ! empty( $hide_theme_expiration_notice ) ) {
     1025            if (! empty($hide_theme_expiration_notice)) {
    10521026                $content .= '<style type="text/css">';
    10531027                $content .= '#ctfw-license-notice {';
     
    10561030                $content .= '</style>';
    10571031            }
    1058 
    1059         }
    1060 
    1061     }
    1062 
    1063     return apply_filters( 'ctc_edd_license_notice_content', $content, $notice, $add_ons );
    1064 
     1032        }
     1033    }
     1034
     1035    return apply_filters('ctc_edd_license_notice_content', $content, $notice, $add_ons);
    10651036}
    10661037
     
    10781049 * @return string Renewal URl with license key replaced
    10791050 */
    1080 function ctc_edd_license_renewal_url( $add_on_dir ) {
     1051function ctc_edd_license_renewal_url($add_on_dir)
     1052{
    10811053
    10821054    // Get raw renewal URL
    1083     $renewal_url = ctc_get_add_on( $add_on_dir, 'renewal_url' );
     1055    $renewal_url = ctc_get_add_on($add_on_dir, 'renewal_url');
    10841056
    10851057    // Have URL
    1086     if ( $renewal_url ) {
     1058    if ($renewal_url) {
    10871059
    10881060        // Replace {license_key} with license key
    1089         $renewal_url = str_replace( '{license_key}', ctc_edd_license_key( $add_on_dir ), $renewal_url );
    1090 
     1061        $renewal_url = str_replace('{license_key}', ctc_edd_license_key($add_on_dir), $renewal_url);
    10911062    }
    10921063
    10931064    // Return filtered
    1094     return apply_filters( 'ctc_edd_license_renewal_url', $renewal_url, $add_on_dir );
    1095 
     1065    return apply_filters('ctc_edd_license_renewal_url', $renewal_url, $add_on_dir);
    10961066}
    10971067
     
    11111081 * @return object License data from remote server
    11121082 */
    1113 function ctc_edd_license_action( $add_on_dir, $action ) {
     1083function ctc_edd_license_action($add_on_dir, $action)
     1084{
    11141085
    11151086    $license_data = array();
    11161087
    11171088    // Add-on supports EDD licensing
    1118     if ( ctc_edd_license_supported( $add_on_dir ) ) {
     1089    if (ctc_edd_license_supported($add_on_dir)) {
    11191090
    11201091        // Valid action?
    1121         $actions = array( 'activate_license', 'deactivate_license', 'check_license' );
    1122         if ( in_array( $action, $actions ) ) {
     1092        $actions = array('activate_license', 'deactivate_license', 'check_license');
     1093        if (in_array($action, $actions)) {
    11231094
    11241095            // Get license
    1125             $license = ctc_edd_license_key( $add_on_dir );
     1096            $license = ctc_edd_license_key($add_on_dir);
    11261097
    11271098            // Have license
    1128             if ( $license ) {
    1129 
    1130                 // Data to send in API request
    1131                 $api_params = array(
    1132                     'edd_action'    => $action,
    1133                     'license'       => $license,
    1134                     'item_name'     => urlencode( ctc_get_add_on( $add_on_dir, 'item_name' ) ), // name of download in EDD
    1135                     'url'           => urlencode( home_url() ) // URL of this site activated for license
    1136                 );
     1099            if ($license) {
    11371100
    11381101                // Call the API
    1139                 $response = wp_remote_get( esc_url_raw( add_query_arg( $api_params, ctc_get_add_on( $add_on_dir, 'store_url' ) ) ), array( 'timeout' => 15, 'sslverify' => false ) );
     1102                $remote_api_url = ctc_get_add_on($add_on_dir, 'store_url');
     1103                $remote_api_url = trailingslashit($remote_api_url);
     1104                $response = wp_remote_post($remote_api_url, [
     1105                    'body' => [
     1106                        'edd_action'    => $action,
     1107                        'license'       => $license,
     1108                        'item_name'     => ctc_get_add_on($add_on_dir, 'item_name'), // name of download in EDD
     1109                        'url'           => home_url(), // URL of this site activated for license
     1110                        'no_cache'      => md5(microtime(true)),
     1111                    ],
     1112                    'timeout' => 15,
     1113                    'sslverify' => true,
     1114                ]);
    11401115
    11411116                // Got a valid response?
    1142                 if ( ! is_wp_error( $response ) ) {
     1117                if (! is_wp_error($response)) {
    11431118
    11441119                    // Decode the license data
    1145                     $license_data = json_decode( wp_remote_retrieve_body( $response ) );
    1146 
     1120                    $license_data = json_decode(wp_remote_retrieve_body($response));
    11471121                }
    1148 
    1149             }
    1150 
    1151         }
    1152 
    1153     }
    1154 
    1155     return apply_filters( 'ctc_edd_license_action', $license_data, $add_on_dir, $action );
    1156 
     1122            }
     1123        }
     1124    }
     1125
     1126    return apply_filters('ctc_edd_license_action', $license_data, $add_on_dir, $action);
    11571127}
    11581128
     
    11671137 * @return array License data array or single value for key
    11681138 */
    1169 function ctc_edd_license_check_data( $add_on_dir, $key = false ) {
     1139function ctc_edd_license_check_data($add_on_dir, $key = false)
     1140{
    11701141
    11711142    // Get remote license data
    1172     $data = ctc_edd_license_action( $add_on_dir, 'check_license' );
     1143    $data = ctc_edd_license_action($add_on_dir, 'check_license');
    11731144
    11741145    // Convert data to array
     
    11761147
    11771148    // Get value for specific key?
    1178     if ( isset( $data[$key] ) ) { // key is given
     1149    if (isset($data[$key])) { // key is given
    11791150
    11801151        // Value exists for key in object
    1181         if ( ! empty( $data[$key] ) ) {
     1152        if (! empty($data[$key])) {
    11821153            $data = $data[$key];
    11831154        }
     
    11881159            $data = '';
    11891160        }
    1190 
    1191     }
    1192 
    1193     return apply_filters( 'ctc_edd_license_check_data', $data, $add_on_dir, $key );
    1194 
     1161    }
     1162
     1163    return apply_filters('ctc_edd_license_check_data', $data, $add_on_dir, $key);
    11951164}
    11961165
     
    12041173 * @return string Remote license status
    12051174 */
    1206 function ctc_edd_license_check( $add_on_dir ) {
    1207 
    1208     $status = ctc_edd_license_check_data( $add_on_dir, 'license' );
    1209 
    1210     return apply_filters( 'ctc_edd_license_check', $status, $add_on_dir );
    1211 
     1175function ctc_edd_license_check($add_on_dir)
     1176{
     1177
     1178    $status = ctc_edd_license_check_data($add_on_dir, 'license');
     1179
     1180    return apply_filters('ctc_edd_license_check', $status, $add_on_dir);
    12121181}
    12131182
     
    12261195 * @param string $add_on_dir Add-on to work with
    12271196 */
    1228 function ctc_edd_license_sync( $add_on_dir ) {
     1197function ctc_edd_license_sync($add_on_dir)
     1198{
    12291199
    12301200    // Plugin supports EDD licensing?
    1231     if ( ! ctc_edd_license_supported( $add_on_dir ) ) {
     1201    if (! ctc_edd_license_supported($add_on_dir)) {
    12321202        return;
    12331203    }
    12341204
    12351205    // Get remote license data
    1236     $license_data = ctc_edd_license_check_data( $add_on_dir );
     1206    $license_data = ctc_edd_license_check_data($add_on_dir);
    12371207
    12381208    // Continue only if got a response
    1239     if ( ! empty( $license_data ) ) { // don't do anything if times out
     1209    if (! empty($license_data)) { // don't do anything if times out
    12401210
    12411211        // Get remote status
    1242         $status = isset( $license_data['license'] ) ? $license_data['license'] : false;
     1212        $status = isset($license_data['license']) ? $license_data['license'] : false;
    12431213
    12441214        // Active remotely
    12451215        // This will activate locally if had been inactive or expired locally
    1246         if ( 'valid' == $status ) {
     1216        if ('valid' == $status) {
    12471217
    12481218            // Activate locally
    1249             update_option( $add_on_dir . '_license_status', 'active' );
    1250 
     1219            update_option($add_on_dir . '_license_status', 'active');
    12511220        }
    12521221
    12531222        // Inactive remotely
    1254         elseif ( in_array( $status, array( 'inactive', 'site_inactive', 'disabled' ) ) ) { // status is not valid
     1223        elseif (in_array($status, array('inactive', 'site_inactive', 'disabled'))) { // status is not valid
    12551224
    12561225            // Deactivate locally
    1257             delete_option( $add_on_dir . '_license_status' );
    1258 
     1226            delete_option($add_on_dir . '_license_status');
    12591227        }
    12601228
    12611229        // Expired remotely
    1262         elseif ( 'expired' == $status ) {
     1230        elseif ('expired' == $status) {
    12631231
    12641232            // Set status expired locally
    1265             update_option( $add_on_dir . '_license_status', 'expired' );
    1266 
     1233            update_option($add_on_dir . '_license_status', 'expired');
    12671234        }
    12681235
    12691236        // Update expiration data
    12701237        // This helps the user know when to renew
    1271         if ( isset( $license_data['expires'] ) ) {
    1272             ctc_edd_license_update_expiration( $add_on_dir, $license_data['expires'] );
    1273         }
    1274 
    1275     }
    1276 
     1238        if (isset($license_data['expires'])) {
     1239            ctc_edd_license_update_expiration($add_on_dir, $license_data['expires']);
     1240        }
     1241    }
    12771242}
    12781243
     
    12881253 * @global object $ctc_settings
    12891254 */
    1290 function ctc_edd_license_auto_sync() {
     1255function ctc_edd_license_auto_sync()
     1256{
    12911257
    12921258    global $ctc_settings;
    12931259
    12941260    // Admin only
    1295     if ( ! is_admin() ) {
     1261    if (! is_admin()) {
    12961262        return;
    12971263    }
     
    12991265    // Periodically in relevant areas or always on Plugin Settings page (where license key status shown)
    13001266    $screen = get_current_screen();
    1301     if ( ! $ctc_settings->is_settings_page() && ! in_array( $screen->base, array( 'dashboard', 'update-core', 'plugins' ) ) ) {
     1267    if (! $ctc_settings->is_settings_page() && ! in_array($screen->base, array('dashboard', 'update-core', 'plugins'))) {
    13021268        return;
    13031269    }
     
    13081274    // Had add-ons?
    13091275    // No need to run if no add-ons registered
    1310     if ( ! $add_ons ) {
     1276    if (! $add_ons) {
    13111277        return;
    13121278    }
     
    13141280    // Has this been checked in last day or is it plugin settings page?
    13151281    // Settings page always runs this
    1316     if ( get_transient( 'ctc_edd_license_auto_sync' ) && ! $ctc_settings->is_settings_page() ) {
     1282    if (get_transient('ctc_edd_license_auto_sync') && ! $ctc_settings->is_settings_page()) {
    13171283        return;
    13181284    } else {
     
    13201286        // Set transient to prevent check until next day
    13211287        // Once per day is enough to keep notice on dashboard and updates pages without hammering remote server
    1322         set_transient( 'ctc_edd_license_auto_sync', true, DAY_IN_SECONDS );
    1323 
     1288        set_transient('ctc_edd_license_auto_sync', true, DAY_IN_SECONDS);
    13241289    }
    13251290
    13261291    // Loop add-ons
    1327     foreach( $add_ons as $add_on_dir => $add_on ) {
     1292    foreach ($add_ons as $add_on_dir => $add_on) {
    13281293
    13291294        // Add-on supports EDD licensing?
    1330         if ( ! ctc_edd_license_supported( $add_on_dir ) ) {
     1295        if (! ctc_edd_license_supported($add_on_dir)) {
    13311296            return;
    13321297        }
    13331298
    13341299        // Check remote status and sync both ways if necessary
    1335         ctc_edd_license_sync( $add_on_dir );
    1336 
    1337     }
    1338 
    1339 }
    1340 
    1341 add_action( 'current_screen', 'ctc_edd_license_auto_sync' );
     1300        ctc_edd_license_sync($add_on_dir);
     1301    }
     1302}
     1303
     1304add_action('current_screen', 'ctc_edd_license_auto_sync');
    13421305
    13431306/*******************************************
     
    13521315 * @since 1.2
    13531316 */
    1354 function ctc_edd_license_updater() {
     1317function ctc_edd_license_updater()
     1318{
    13551319
    13561320    // Get add-ons
     
    13581322
    13591323    // Have add-ons?
    1360     if ( $add_ons ) {
     1324    if ($add_ons) {
    13611325
    13621326        // Include Easy Digital Downloads Software Licensing plugin updater class
    1363         if ( ! class_exists( 'CTC_EDD_SL_Plugin_Updater' ) ) {
     1327        if (! class_exists('CTC_EDD_SL_Plugin_Updater')) {
    13641328            require CTC_PATH . '/' . CTC_CLASS_DIR . '/CTC_EDD_SL_Plugin_Updater.php';
    13651329        }
    13661330
    13671331        // Loop add-ons
    1368         foreach ( $add_ons as $add_on_dir => $add_on ) {
     1332        foreach ($add_ons as $add_on_dir => $add_on) {
    13691333
    13701334            // Supports licensing and updates?
    1371             if ( ! ctc_edd_license_supported( $add_on_dir ) || empty( $add_on['updates'] ) ) {
     1335            if (! ctc_edd_license_supported($add_on_dir) || empty($add_on['updates'])) {
    13721336                continue;
    13731337            }
    13741338
    13751339            // License is active?
    1376             if ( ! ctc_edd_license_active( $add_on_dir ) ) {
     1340            if (! ctc_edd_license_active($add_on_dir)) {
    13771341                continue;
    13781342            }
    13791343
    13801344            // Get license key
    1381             $license_key = ctc_edd_license_key( $add_on_dir );
     1345            $license_key = ctc_edd_license_key($add_on_dir);
    13821346
    13831347            // Make sure we have the data necessary for using the updater class
    13841348            if (
    13851349                $license_key
    1386                 && ! empty( $add_on['store_url'] )
    1387                 && ! empty( $add_on['item_name'] )
    1388                 && ! empty( $add_on['author'] )
     1350                && ! empty($add_on['store_url'])
     1351                && ! empty($add_on['item_name'])
     1352                && ! empty($add_on['author'])
    13891353            ) {
    13901354
     
    14001364                    )
    14011365                );
    1402 
    1403             }
    1404 
    1405         }
    1406 
    1407     }
    1408 
    1409 }
    1410 
    1411 add_action( 'admin_init', 'ctc_edd_license_updater', 0 ); // after add-on registration on plugins_loaded, but before other things
     1366            }
     1367        }
     1368    }
     1369}
     1370
     1371add_action('admin_init', 'ctc_edd_license_updater', 0); // after add-on registration on plugins_loaded, but before other things
    14121372
    14131373/**
     
    14251385 * @return array Modified request.
    14261386 */
    1427 function ctc_prevent_wporg_plugin_update( $r, $url ) {
     1387function ctc_prevent_wporg_plugin_update($r, $url)
     1388{
    14281389
    14291390    // Stop if it's not a plugin update request.
    1430     if ( 0 !== strpos( $url, 'https://api.wordpress.org/plugins/update-check/' ) ) {
     1391    if (0 !== strpos($url, 'https://api.wordpress.org/plugins/update-check/')) {
    14311392        return $r;
    14321393    }
     
    14341395    // Get add-ons and stop if don't have any.
    14351396    $add_ons = ctc_get_add_ons();
    1436     if ( ! $add_ons ) {
     1397    if (! $add_ons) {
    14371398        return $r;
    14381399    }
    14391400
    14401401    // Require response with plugins.
    1441     if ( ! isset( $r['body']['plugins'] ) ) {
     1402    if (! isset($r['body']['plugins'])) {
    14421403        return $r;
    14431404    }
    14441405
    14451406    // Decode the JSON response.
    1446     $plugins = json_decode( $r['body']['plugins'], true ); // as array.
     1407    $plugins = json_decode($r['body']['plugins'], true); // as array.
    14471408
    14481409    // Have plugins array.
    1449     if ( ! empty( $plugins ) && is_array( $plugins ) ) {
     1410    if (! empty($plugins) && is_array($plugins)) {
    14501411
    14511412        // Loop to remove add-on plugins that use EDD Software Licensing from the check.
    1452         foreach ( $add_ons as $add_on_dir => $add_on ) {
     1413        foreach ($add_ons as $add_on_dir => $add_on) {
    14531414
    14541415            // Skip if doesn't support licensing and updates.
    1455             if ( ! ctc_edd_license_supported( $add_on_dir ) || empty( $add_on['updates'] ) ) {
     1416            if (! ctc_edd_license_supported($add_on_dir) || empty($add_on['updates'])) {
    14561417                continue;
    14571418            }
    14581419
    14591420            // Make sure have necessary data (prevent errors if response ever changes).
    1460             if ( empty( $add_on['plugin_file'] ) || empty( $plugins['active'] ) || ! is_array( $plugins['active'] ) || empty( $plugins['plugins'] ) || ! is_array( $plugins['plugins'] ) ) {
     1421            if (empty($add_on['plugin_file']) || empty($plugins['active']) || ! is_array($plugins['active']) || empty($plugins['plugins']) || ! is_array($plugins['plugins'])) {
    14611422                continue;
    14621423            }
    14631424
    14641425            // Plugin basename.
    1465             $plugin_basename = plugin_basename( $add_on['plugin_file'] );
     1426            $plugin_basename = plugin_basename($add_on['plugin_file']);
    14661427
    14671428            // Plugin key.
    14681429            $plugin_key = '';
    1469             if ( $plugin_basename ) {
    1470                 $plugin_key  = array_search( $plugin_basename, $plugins['active'] );
     1430            if ($plugin_basename) {
     1431                $plugin_key  = array_search($plugin_basename, $plugins['active']);
    14711432            } else {
    14721433                continue; // basename and key required to continue.
     
    14741435
    14751436            // Remove add-on from the plugins object.
    1476             if ( isset( $plugins['plugins'][ $plugin_basename ] ) ) {
    1477                 unset( $plugins['plugins'][ $plugin_basename ] );
     1437            if (isset($plugins['plugins'][$plugin_basename])) {
     1438                unset($plugins['plugins'][$plugin_basename]);
    14781439            }
    14791440
    14801441            // Remove add-on from the active plugins array.
    1481             if ( isset( $plugins['active'][ $plugin_key ] ) ) {
    1482                 unset( $plugins['active'][ $plugin_key ] );
    1483             }
    1484 
    1485         }
    1486 
     1442            if (isset($plugins['active'][$plugin_key])) {
     1443                unset($plugins['active'][$plugin_key]);
     1444            }
     1445        }
    14871446    }
    14881447
    14891448    // Encode the updated JSON response.
    1490     $r['body']['plugins'] = wp_json_encode( $plugins );
     1449    $r['body']['plugins'] = wp_json_encode($plugins);
    14911450
    14921451    // Return updated response.
    14931452    return $r;
    1494 
    1495 }
    1496 
    1497 add_filter( 'http_request_args', 'ctc_prevent_wporg_plugin_update', 5, 2 );
     1453}
     1454
     1455add_filter('http_request_args', 'ctc_prevent_wporg_plugin_update', 5, 2);
  • church-theme-content/trunk/includes/classes/CTC_EDD_SL_Plugin_Updater.php

    r2090032 r3391879  
    11<?php
     2
    23/**
    34 * Easy Digital Downloads Software Licensing Plugin Updater
     
    1415
    1516// Exit if accessed directly
    16 if ( ! defined( 'ABSPATH' ) ) exit;
     17if (! defined('ABSPATH')) exit;
    1718
    1819/**
     
    2223 * @version 1.6.14
    2324 */
    24 class CTC_EDD_SL_Plugin_Updater {
    25 
    26     private $api_url     = '';
    27     private $api_data    = array();
    28     private $name        = '';
    29     private $slug        = '';
    30     private $version     = '';
    31     private $wp_override = false;
    32     private $cache_key   = '';
    33 
    34     /**
    35      * Class constructor.
    36      *
    37      * @uses plugin_basename()
    38      * @uses hook()
    39      *
    40      * @param string  $_api_url     The URL pointing to the custom API endpoint.
    41      * @param string  $_plugin_file Path to the plugin file.
    42      * @param array   $_api_data    Optional data to send with API calls.
    43      */
    44     public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
    45 
    46         global $edd_plugin_data;
    47 
    48         $this->api_url     = trailingslashit( $_api_url );
    49         $this->api_data    = $_api_data;
    50         $this->name        = plugin_basename( $_plugin_file );
    51         $this->slug        = basename( $_plugin_file, '.php' );
    52         $this->version     = $_api_data['version'];
    53         $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
    54         $this->beta        = ! empty( $this->api_data['beta'] ) ? true : false;
    55         $this->cache_key   = md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
    56 
    57         $edd_plugin_data[ $this->slug ] = $this->api_data;
    58 
    59         // Set up hooks.
    60         $this->init();
    61 
    62     }
    63 
    64     /**
    65      * Set up WordPress filters to hook into WP's update process.
    66      *
    67      * @uses add_filter()
    68      *
    69      * @return void
    70      */
    71     public function init() {
    72 
    73         add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
    74         add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
    75         remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 );
    76         add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
    77         add_action( 'admin_init', array( $this, 'show_changelog' ) );
    78 
    79     }
    80 
    81     /**
    82      * Check for Updates at the defined API endpoint and modify the update array.
    83      *
    84      * This function dives into the update API just when WordPress creates its update array,
    85      * then adds a custom API call and injects the custom plugin data retrieved from the API.
    86      * It is reassembled from parts of the native WordPress plugin update code.
    87      * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
    88      *
    89      * @uses api_request()
    90      *
    91      * @param array   $_transient_data Update array build by WordPress.
    92      * @return array Modified update array with custom plugin data.
    93      */
    94     public function check_update( $_transient_data ) {
    95 
    96         global $pagenow;
    97 
    98         if ( ! is_object( $_transient_data ) ) {
    99             $_transient_data = new stdClass;
    100         }
    101 
    102         if ( 'plugins.php' == $pagenow && is_multisite() ) {
    103             return $_transient_data;
    104         }
    105 
    106         if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
    107             return $_transient_data;
    108         }
    109 
    110         $version_info = $this->get_cached_version_info();
    111 
    112         if ( false === $version_info ) {
    113             $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
    114 
    115             $this->set_version_info_cache( $version_info );
    116 
    117         }
    118 
    119         if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
    120 
    121             if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
    122 
    123                 $_transient_data->response[ $this->name ] = $version_info;
    124 
    125             }
    126 
    127             $_transient_data->last_checked           = current_time( 'timestamp' );
    128             $_transient_data->checked[ $this->name ] = $this->version;
    129 
    130         }
    131 
    132         return $_transient_data;
    133     }
    134 
    135     /**
    136      * show update notification row -- needed for multisite subsites, because WP won't tell you otherwise!
    137      *
    138      * @param string  $file
    139      * @param array   $plugin
    140      */
    141     public function show_update_notification( $file, $plugin ) {
    142 
    143         if ( is_network_admin() ) {
    144             return;
    145         }
    146 
    147         if( ! current_user_can( 'update_plugins' ) ) {
    148             return;
    149         }
    150 
    151         if( ! is_multisite() ) {
    152             return;
    153         }
    154 
    155         if ( $this->name != $file ) {
    156             return;
    157         }
    158 
    159         // Remove our filter on the site transient
    160         remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 );
    161 
    162         $update_cache = get_site_transient( 'update_plugins' );
    163 
    164         $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
    165 
    166         if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
    167 
    168             $version_info = $this->get_cached_version_info();
    169 
    170             if ( false === $version_info ) {
    171                 $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
    172 
    173                 $this->set_version_info_cache( $version_info );
    174             }
    175 
    176             if ( ! is_object( $version_info ) ) {
    177                 return;
    178             }
    179 
    180             if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
    181 
    182                 $update_cache->response[ $this->name ] = $version_info;
    183 
    184             }
    185 
    186             $update_cache->last_checked = current_time( 'timestamp' );
    187             $update_cache->checked[ $this->name ] = $this->version;
    188 
    189             set_site_transient( 'update_plugins', $update_cache );
    190 
    191         } else {
    192 
    193             $version_info = $update_cache->response[ $this->name ];
    194 
    195         }
    196 
    197         // Restore our filter
    198         add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
    199 
    200         if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
    201 
    202             // build a plugin list row, with update notification
    203             $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
    204             # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
    205             echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">';
    206             echo '<td colspan="3" class="plugin-update colspanchange">';
    207             echo '<div class="update-message notice inline notice-warning notice-alt">';
    208 
    209             $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' );
    210 
    211             // CT Mod
    212             // Use external changelog URL instead of post-provided changelog embedded in modal
    213             $ctc_changelog_url = ctc_get_add_on( $this->slug, 'changelog_url' );
    214             $ctc_changelog_link_class = 'thickbox';
    215             if ( $ctc_changelog_url ) {
    216                 $changelog_link = $ctc_changelog_url;
    217                 $ctc_changelog_link_class = '';
    218             }
    219 
    220             // CT Mod
    221             // 1. Added CTC textdomain
    222             // 2. Added class replacement. If $changelog_link provided, class is none; otherwise class for modal is used
    223             if ( empty( $version_info->download_link ) ) {
    224                 printf(
    225                     wp_kses( // CTC Mod - escape translation string
    226                         __( 'There is a new version of %1$s available. <a target="_blank" class="%4$s" href="%2$s">View version %3$s details</a>.', 'church-theme-content' ), // CTC Mod textdomain
    227                         array(
    228                             'a' => array(
    229                                 'href' => array(),
    230                                 'target' => array(),
    231                                 'class' => array(),
    232                             )
    233                         )
    234                     ),
    235                     esc_html( $version_info->name ),
    236                     esc_url( $changelog_link ),
    237                     esc_html( $version_info->new_version ),
    238                     $ctc_changelog_link_class
    239                 );
    240             } else {
    241                 printf(
    242                     wp_kses( // CTC Mod - escape translation string
    243                         __( 'There is a new version of %1$s available. <a target="_blank" class="%5$s" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'church-theme-content' ), // CTC Mod textdomain
    244                         array(
    245                             'a' => array(
    246                                 'href' => array(),
    247                                 'target' => array(),
    248                                 'class' => array(),
    249                             )
    250                         )
    251                     ),
    252                     esc_html( $version_info->name ),
    253                     esc_url( $changelog_link ),
    254                     esc_html( $version_info->new_version ),
    255                     esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ),
    256                     $ctc_changelog_link_class
    257                 );
    258             }
    259 
    260             do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
    261 
    262             echo '</div></td></tr>';
    263         }
    264     }
    265 
    266     /**
    267      * Updates information on the "View version x.x details" page with custom data.
    268      *
    269      * @uses api_request()
    270      *
    271      * @param mixed  $_data
    272      * @param string  $_action
    273      * @param object  $_args
    274      * @return object $_data
    275      */
    276     public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
    277 
    278         if ( $_action != 'plugin_information' ) {
    279 
    280             return $_data;
    281 
    282         }
    283 
    284         if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) {
    285 
    286             return $_data;
    287 
    288         }
    289 
    290         $to_send = array(
    291             'slug'   => $this->slug,
    292             'is_ssl' => is_ssl(),
    293             'fields' => array(
    294                 'banners' => array(),
    295                 'reviews' => false
    296             )
    297         );
    298 
    299         $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
    300 
    301         // Get the transient where we store the api request for this plugin for 24 hours
    302         $edd_api_request_transient = $this->get_cached_version_info( $cache_key );
    303 
    304         //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
    305         if ( empty( $edd_api_request_transient ) ) {
    306 
    307             $api_response = $this->api_request( 'plugin_information', $to_send );
    308 
    309             // Expires in 3 hours
    310             $this->set_version_info_cache( $api_response, $cache_key );
    311 
    312             if ( false !== $api_response ) {
    313                 $_data = $api_response;
    314             }
    315 
    316         } else {
    317             $_data = $edd_api_request_transient;
    318         }
    319 
    320         // Convert sections into an associative array, since we're getting an object, but Core expects an array.
    321         if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
    322             $new_sections = array();
    323             foreach ( $_data->sections as $key => $value ) {
    324                 $new_sections[ $key ] = $value;
    325             }
    326 
    327             $_data->sections = $new_sections;
    328         }
    329 
    330         // Convert banners into an associative array, since we're getting an object, but Core expects an array.
    331         if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
    332             $new_banners = array();
    333             foreach ( $_data->banners as $key => $value ) {
    334                 $new_banners[ $key ] = $value;
    335             }
    336 
    337             $_data->banners = $new_banners;
    338         }
    339 
    340         return $_data;
    341     }
    342 
    343     /**
    344      * Disable SSL verification in order to prevent download update failures
    345      *
    346      * @param array   $args
    347      * @param string  $url
    348      * @return object $array
    349      */
    350     public function http_request_args( $args, $url ) {
    351 
    352         $verify_ssl = $this->verify_ssl();
    353         if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
    354             $args['sslverify'] = $verify_ssl;
    355         }
    356         return $args;
    357 
    358     }
    359 
    360     /**
    361      * Calls the API and, if successful, returns the object delivered by the API.
    362      *
    363      * @uses get_bloginfo()
    364      * @uses wp_remote_post()
    365      * @uses is_wp_error()
    366      *
    367      * @param string  $_action The requested action.
    368      * @param array   $_data   Parameters for the API action.
    369      * @return false|object
    370      */
    371     private function api_request( $_action, $_data ) {
    372 
    373         global $wp_version;
    374 
    375         $data = array_merge( $this->api_data, $_data );
    376 
    377         if ( $data['slug'] != $this->slug ) {
    378             return;
    379         }
    380 
    381         if( $this->api_url == trailingslashit (home_url() ) ) {
    382             return false; // Don't allow a plugin to ping itself
    383         }
    384 
    385         $api_params = array(
    386             'edd_action' => 'get_version',
    387             'license'    => ! empty( $data['license'] ) ? $data['license'] : '',
    388             'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
    389             'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
    390             'version'    => isset( $data['version'] ) ? $data['version'] : false,
    391             'slug'       => $data['slug'],
    392             'author'     => $data['author'],
    393             'url'        => home_url(),
    394             'beta'       => ! empty( $data['beta'] ),
    395         );
    396 
    397         $verify_ssl = $this->verify_ssl();
    398         $request    = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
    399 
    400         if ( ! is_wp_error( $request ) ) {
    401             $request = json_decode( wp_remote_retrieve_body( $request ) );
    402         }
    403 
    404         if ( $request && isset( $request->sections ) ) {
    405             $request->sections = maybe_unserialize( $request->sections );
    406         } else {
    407             $request = false;
    408         }
    409 
    410         if ( $request && isset( $request->banners ) ) {
    411             $request->banners = maybe_unserialize( $request->banners );
    412         }
    413 
    414         if( ! empty( $request->sections ) ) {
    415             foreach( $request->sections as $key => $section ) {
    416                 $request->$key = (array) $section;
    417             }
    418         }
    419 
    420         return $request;
    421     }
    422 
    423     public function show_changelog() {
    424 
    425         global $edd_plugin_data;
    426 
    427         if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
    428             return;
    429         }
    430 
    431         if( empty( $_REQUEST['plugin'] ) ) {
    432             return;
    433         }
    434 
    435         if( empty( $_REQUEST['slug'] ) ) {
    436             return;
    437         }
    438 
    439         if( ! current_user_can( 'update_plugins' ) ) {
    440             wp_die( __( 'You do not have permission to install plugin updates', 'church-theme-content' ), __( 'Error', 'church-theme-content' ), array( 'response' => 403 ) );
    441         }
    442 
    443         $data         = $edd_plugin_data[ $_REQUEST['slug'] ];
    444         $beta         = ! empty( $data['beta'] ) ? true : false;
    445         $cache_key    = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' );
    446         $version_info = $this->get_cached_version_info( $cache_key );
    447 
    448         if( false === $version_info ) {
    449 
    450             $api_params = array(
    451                 'edd_action' => 'get_version',
    452                 'item_name'  => isset( $data['item_name'] ) ? $data['item_name'] : false,
    453                 'item_id'    => isset( $data['item_id'] ) ? $data['item_id'] : false,
    454                 'slug'       => $_REQUEST['slug'],
    455                 'author'     => $data['author'],
    456                 'url'        => home_url(),
    457                 'beta'       => ! empty( $data['beta'] )
    458             );
    459 
    460             $verify_ssl = $this->verify_ssl();
    461             $request    = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
    462 
    463             if ( ! is_wp_error( $request ) ) {
    464                 $version_info = json_decode( wp_remote_retrieve_body( $request ) );
    465             }
    466 
    467 
    468             if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
    469                 $version_info->sections = maybe_unserialize( $version_info->sections );
    470             } else {
    471                 $version_info = false;
    472             }
    473 
    474             if( ! empty( $version_info ) ) {
    475                 foreach( $version_info->sections as $key => $section ) {
    476                     $version_info->$key = (array) $section;
    477                 }
    478             }
    479 
    480             $this->set_version_info_cache( $version_info, $cache_key );
    481 
    482         }
    483 
    484         if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
    485             echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
    486         }
    487 
    488         exit;
    489     }
    490 
    491     public function get_cached_version_info( $cache_key = '' ) {
    492 
    493         if( empty( $cache_key ) ) {
    494             $cache_key = $this->cache_key;
    495         }
    496 
    497         $cache = get_option( $cache_key );
    498 
    499         if( empty( $cache['timeout'] ) || current_time( 'timestamp' ) > $cache['timeout'] ) {
    500             return false; // Cache is expired
    501         }
    502 
    503         return json_decode( $cache['value'] );
    504 
    505     }
    506 
    507     public function set_version_info_cache( $value = '', $cache_key = '' ) {
    508 
    509         if( empty( $cache_key ) ) {
    510             $cache_key = $this->cache_key;
    511         }
    512 
    513         $data = array(
    514             'timeout' => strtotime( '+3 hours', current_time( 'timestamp' ) ),
    515             'value'   => json_encode( $value )
    516         );
    517 
    518         update_option( $cache_key, $data, 'no' );
    519 
    520     }
    521 
    522     /**
    523     * Returns if the SSL of the store should be verified.
    524     *
    525     * @since  1.6.13
    526     * @return bool
    527     */
    528     private function verify_ssl() {
    529         return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
    530     }
    531 
     25class CTC_EDD_SL_Plugin_Updater
     26{
     27
     28    private $api_url     = '';
     29    private $api_data    = array();
     30    private $name        = '';
     31    private $slug        = '';
     32    private $version     = '';
     33    private $wp_override = false;
     34    private $cache_key   = '';
     35
     36    /**
     37     * Class constructor.
     38     *
     39     * @uses plugin_basename()
     40     * @uses hook()
     41     *
     42     * @param string  $_api_url     The URL pointing to the custom API endpoint.
     43     * @param string  $_plugin_file Path to the plugin file.
     44     * @param array   $_api_data    Optional data to send with API calls.
     45     */
     46    public function __construct($_api_url, $_plugin_file, $_api_data = null)
     47    {
     48
     49        global $edd_plugin_data;
     50
     51        $this->api_url     = trailingslashit($_api_url);
     52        $this->api_data    = $_api_data;
     53        $this->name        = plugin_basename($_plugin_file);
     54        $this->slug        = basename($_plugin_file, '.php');
     55        $this->version     = $_api_data['version'];
     56        $this->wp_override = isset($_api_data['wp_override']) ? (bool) $_api_data['wp_override'] : false;
     57        $this->beta        = ! empty($this->api_data['beta']) ? true : false;
     58        $this->cache_key   = md5(serialize($this->slug . $this->api_data['license'] . $this->beta));
     59
     60        $edd_plugin_data[$this->slug] = $this->api_data;
     61
     62        // Set up hooks.
     63        $this->init();
     64    }
     65
     66    /**
     67     * Set up WordPress filters to hook into WP's update process.
     68     *
     69     * @uses add_filter()
     70     *
     71     * @return void
     72     */
     73    public function init()
     74    {
     75
     76        add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'));
     77        add_filter('plugins_api', array($this, 'plugins_api_filter'), 10, 3);
     78        remove_action('after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10);
     79        add_action('after_plugin_row_' . $this->name, array($this, 'show_update_notification'), 10, 2);
     80        add_action('admin_init', array($this, 'show_changelog'));
     81    }
     82
     83    /**
     84     * Check for Updates at the defined API endpoint and modify the update array.
     85     *
     86     * This function dives into the update API just when WordPress creates its update array,
     87     * then adds a custom API call and injects the custom plugin data retrieved from the API.
     88     * It is reassembled from parts of the native WordPress plugin update code.
     89     * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
     90     *
     91     * @uses api_request()
     92     *
     93     * @param array   $_transient_data Update array build by WordPress.
     94     * @return array Modified update array with custom plugin data.
     95     */
     96    public function check_update($_transient_data)
     97    {
     98
     99        global $pagenow;
     100
     101        if (! is_object($_transient_data)) {
     102            $_transient_data = new stdClass;
     103        }
     104
     105        if ('plugins.php' == $pagenow && is_multisite()) {
     106            return $_transient_data;
     107        }
     108
     109        if (! empty($_transient_data->response) && ! empty($_transient_data->response[$this->name]) && false === $this->wp_override) {
     110            return $_transient_data;
     111        }
     112
     113        $version_info = $this->get_cached_version_info();
     114
     115        if (false === $version_info) {
     116            $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug, 'beta' => $this->beta));
     117
     118            $this->set_version_info_cache($version_info);
     119        }
     120
     121        if (false !== $version_info && is_object($version_info) && isset($version_info->new_version)) {
     122
     123            if (version_compare($this->version, $version_info->new_version, '<')) {
     124
     125                $_transient_data->response[$this->name] = $version_info;
     126            }
     127
     128            $_transient_data->last_checked           = current_time('timestamp');
     129            $_transient_data->checked[$this->name] = $this->version;
     130        }
     131
     132        return $_transient_data;
     133    }
     134
     135    /**
     136     * show update notification row -- needed for multisite subsites, because WP won't tell you otherwise!
     137     *
     138     * @param string  $file
     139     * @param array   $plugin
     140     */
     141    public function show_update_notification($file, $plugin)
     142    {
     143
     144        if (is_network_admin()) {
     145            return;
     146        }
     147
     148        if (! current_user_can('update_plugins')) {
     149            return;
     150        }
     151
     152        if (! is_multisite()) {
     153            return;
     154        }
     155
     156        if ($this->name != $file) {
     157            return;
     158        }
     159
     160        // Remove our filter on the site transient
     161        remove_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'), 10);
     162
     163        $update_cache = get_site_transient('update_plugins');
     164
     165        $update_cache = is_object($update_cache) ? $update_cache : new stdClass();
     166
     167        if (empty($update_cache->response) || empty($update_cache->response[$this->name])) {
     168
     169            $version_info = $this->get_cached_version_info();
     170
     171            if (false === $version_info) {
     172                $version_info = $this->api_request('plugin_latest_version', array('slug' => $this->slug, 'beta' => $this->beta));
     173
     174                $this->set_version_info_cache($version_info);
     175            }
     176
     177            if (! is_object($version_info)) {
     178                return;
     179            }
     180
     181            if (version_compare($this->version, $version_info->new_version, '<')) {
     182
     183                $update_cache->response[$this->name] = $version_info;
     184            }
     185
     186            $update_cache->last_checked = current_time('timestamp');
     187            $update_cache->checked[$this->name] = $this->version;
     188
     189            set_site_transient('update_plugins', $update_cache);
     190        } else {
     191
     192            $version_info = $update_cache->response[$this->name];
     193        }
     194
     195        // Restore our filter
     196        add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'));
     197
     198        if (! empty($update_cache->response[$this->name]) && version_compare($this->version, $version_info->new_version, '<')) {
     199
     200            // build a plugin list row, with update notification
     201            $wp_list_table = _get_list_table('WP_Plugins_List_Table');
     202            # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
     203            echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">';
     204            echo '<td colspan="3" class="plugin-update colspanchange">';
     205            echo '<div class="update-message notice inline notice-warning notice-alt">';
     206
     207            $changelog_link = self_admin_url('index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911');
     208
     209            // CT Mod
     210            // Use external changelog URL instead of post-provided changelog embedded in modal
     211            $ctc_changelog_url = ctc_get_add_on($this->slug, 'changelog_url');
     212            $ctc_changelog_link_class = 'thickbox';
     213            if ($ctc_changelog_url) {
     214                $changelog_link = $ctc_changelog_url;
     215                $ctc_changelog_link_class = '';
     216            }
     217
     218            // CT Mod
     219            // 1. Added CTC textdomain
     220            // 2. Added class replacement. If $changelog_link provided, class is none; otherwise class for modal is used
     221            if (empty($version_info->download_link)) {
     222                printf(
     223                    wp_kses( // CTC Mod - escape translation string
     224                        __('There is a new version of %1$s available. <a target="_blank" class="%4$s" href="%2$s">View version %3$s details</a>.', 'church-theme-content'), // CTC Mod textdomain
     225                        array(
     226                            'a' => array(
     227                                'href' => array(),
     228                                'target' => array(),
     229                                'class' => array(),
     230                            )
     231                        )
     232                    ),
     233                    esc_html($version_info->name),
     234                    esc_url($changelog_link),
     235                    esc_html($version_info->new_version),
     236                    $ctc_changelog_link_class
     237                );
     238            } else {
     239                printf(
     240                    wp_kses( // CTC Mod - escape translation string
     241                        __('There is a new version of %1$s available. <a target="_blank" class="%5$s" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'church-theme-content'), // CTC Mod textdomain
     242                        array(
     243                            'a' => array(
     244                                'href' => array(),
     245                                'target' => array(),
     246                                'class' => array(),
     247                            )
     248                        )
     249                    ),
     250                    esc_html($version_info->name),
     251                    esc_url($changelog_link),
     252                    esc_html($version_info->new_version),
     253                    esc_url(wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=') . $this->name, 'upgrade-plugin_' . $this->name)),
     254                    $ctc_changelog_link_class
     255                );
     256            }
     257
     258            do_action("in_plugin_update_message-{$file}", $plugin, $version_info);
     259
     260            echo '</div></td></tr>';
     261        }
     262    }
     263
     264    /**
     265     * Updates information on the "View version x.x details" page with custom data.
     266     *
     267     * @uses api_request()
     268     *
     269     * @param mixed   $_data
     270     * @param string  $_action
     271     * @param object  $_args
     272     * @return object $_data
     273     */
     274    public function plugins_api_filter($_data, $_action = '', $_args = null)
     275    {
     276
     277        if ($_action != 'plugin_information') {
     278
     279            return $_data;
     280        }
     281
     282        if (! isset($_args->slug) || ($_args->slug != $this->slug)) {
     283
     284            return $_data;
     285        }
     286
     287        $to_send = array(
     288            'slug'   => $this->slug,
     289            'is_ssl' => is_ssl(),
     290            'fields' => array(
     291                'banners' => array(),
     292                'reviews' => false
     293            )
     294        );
     295
     296        $cache_key = 'edd_api_request_' . md5(serialize($this->slug . $this->api_data['license'] . $this->beta));
     297
     298        // Get the transient where we store the api request for this plugin for 24 hours
     299        $edd_api_request_transient = $this->get_cached_version_info($cache_key);
     300
     301        //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
     302        if (empty($edd_api_request_transient)) {
     303
     304            $api_response = $this->api_request('plugin_information', $to_send);
     305
     306            // Expires in 3 hours
     307            $this->set_version_info_cache($api_response, $cache_key);
     308
     309            if (false !== $api_response) {
     310                $_data = $api_response;
     311            }
     312        } else {
     313            $_data = $edd_api_request_transient;
     314        }
     315
     316        // Convert sections into an associative array, since we're getting an object, but Core expects an array.
     317        if (isset($_data->sections) && ! is_array($_data->sections)) {
     318            $new_sections = array();
     319            foreach ($_data->sections as $key => $value) {
     320                $new_sections[$key] = $value;
     321            }
     322
     323            $_data->sections = $new_sections;
     324        }
     325
     326        // Convert banners into an associative array, since we're getting an object, but Core expects an array.
     327        if (isset($_data->banners) && ! is_array($_data->banners)) {
     328            $new_banners = array();
     329            foreach ($_data->banners as $key => $value) {
     330                $new_banners[$key] = $value;
     331            }
     332
     333            $_data->banners = $new_banners;
     334        }
     335
     336        return $_data;
     337    }
     338
     339    /**
     340     * Disable SSL verification in order to prevent download update failures
     341     *
     342     * @param array   $args
     343     * @param string  $url
     344     * @return object $array
     345     */
     346    public function http_request_args($args, $url)
     347    {
     348
     349        $verify_ssl = $this->verify_ssl();
     350        if (strpos($url, 'https://') !== false && strpos($url, 'edd_action=package_download')) {
     351            $args['sslverify'] = $verify_ssl;
     352        }
     353        return $args;
     354    }
     355
     356    /**
     357     * Calls the API and, if successful, returns the object delivered by the API.
     358     *
     359     * @uses get_bloginfo()
     360     * @uses wp_remote_post()
     361     * @uses is_wp_error()
     362     *
     363     * @param string  $_action The requested action.
     364     * @param array   $_data   Parameters for the API action.
     365     * @return false|object
     366     */
     367    private function api_request($_action, $_data)
     368    {
     369
     370        global $wp_version;
     371
     372        $data = array_merge($this->api_data, $_data);
     373
     374        if ($data['slug'] != $this->slug) {
     375            return;
     376        }
     377
     378        if ($this->api_url == trailingslashit(home_url())) {
     379            return false; // Don't allow a plugin to ping itself
     380        }
     381
     382        $request = wp_remote_post($this->api_url, [
     383            'body' => [
     384                'edd_action'    => 'get_version',
     385                'license'       => ! empty($data['license']) ? $data['license'] : '',
     386                'item_name'     => isset($data['item_name']) ? $data['item_name'] : false,
     387                'item_id'       => isset($data['item_id']) ? $data['item_id'] : false,
     388                'version'       => isset($data['version']) ? $data['version'] : false,
     389                'slug'          => $data['slug'],
     390                'author'        => $data['author'],
     391                'url'           => home_url(),
     392                'beta'          => ! empty($data['beta']),
     393                'no_cache'      => md5(microtime(true)),
     394            ],
     395            'timeout' => 15,
     396            'sslverify' => $this->verify_ssl(),
     397        ]);
     398
     399        if (! is_wp_error($request)) {
     400            $request = json_decode(wp_remote_retrieve_body($request));
     401        }
     402
     403        if ($request && isset($request->sections)) {
     404            $request->sections = maybe_unserialize($request->sections);
     405        } else {
     406            $request = false;
     407        }
     408
     409        if ($request && isset($request->banners)) {
     410            $request->banners = maybe_unserialize($request->banners);
     411        }
     412
     413        if (! empty($request->sections)) {
     414            foreach ($request->sections as $key => $section) {
     415                $request->$key = (array) $section;
     416            }
     417        }
     418
     419        return $request;
     420    }
     421
     422    public function show_changelog()
     423    {
     424
     425        global $edd_plugin_data;
     426
     427        if (empty($_REQUEST['edd_sl_action']) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action']) {
     428            return;
     429        }
     430
     431        if (empty($_REQUEST['plugin'])) {
     432            return;
     433        }
     434
     435        if (empty($_REQUEST['slug'])) {
     436            return;
     437        }
     438
     439        if (! current_user_can('update_plugins')) {
     440            wp_die(__('You do not have permission to install plugin updates', 'church-theme-content'), __('Error', 'church-theme-content'), array('response' => 403));
     441        }
     442
     443        $data         = $edd_plugin_data[$_REQUEST['slug']];
     444        $beta         = ! empty($data['beta']) ? true : false;
     445        $cache_key    = md5('edd_plugin_' . sanitize_key($_REQUEST['plugin']) . '_' . $beta . '_version_info');
     446        $version_info = $this->get_cached_version_info($cache_key);
     447
     448        if (false === $version_info) {
     449
     450            $request = wp_remote_post($this->api_url, [
     451                'body' => [
     452                    'edd_action' => 'get_version',
     453                    'item_name'  => isset($data['item_name']) ? $data['item_name'] : false,
     454                    'item_id'    => isset($data['item_id']) ? $data['item_id'] : false,
     455                    'slug'       => $_REQUEST['slug'],
     456                    'author'     => $data['author'],
     457                    'url'        => home_url(),
     458                    'beta'       => ! empty($data['beta']),
     459                    'no_cache'   => md5(microtime(true)),
     460                ],
     461                'timeout' => 15,
     462                'sslverify' => $this->verify_ssl(),
     463            ]);
     464
     465            if (! is_wp_error($request)) {
     466                $version_info = json_decode(wp_remote_retrieve_body($request));
     467            }
     468
     469
     470            if (! empty($version_info) && isset($version_info->sections)) {
     471                $version_info->sections = maybe_unserialize($version_info->sections);
     472            } else {
     473                $version_info = false;
     474            }
     475
     476            if (! empty($version_info)) {
     477                foreach ($version_info->sections as $key => $section) {
     478                    $version_info->$key = (array) $section;
     479                }
     480            }
     481
     482            $this->set_version_info_cache($version_info, $cache_key);
     483        }
     484
     485        if (! empty($version_info) && isset($version_info->sections['changelog'])) {
     486            echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
     487        }
     488
     489        exit;
     490    }
     491
     492    public function get_cached_version_info($cache_key = '')
     493    {
     494
     495        if (empty($cache_key)) {
     496            $cache_key = $this->cache_key;
     497        }
     498
     499        $cache = get_option($cache_key);
     500
     501        if (empty($cache['timeout']) || current_time('timestamp') > $cache['timeout']) {
     502            return false; // Cache is expired
     503        }
     504
     505        return json_decode($cache['value']);
     506    }
     507
     508    public function set_version_info_cache($value = '', $cache_key = '')
     509    {
     510
     511        if (empty($cache_key)) {
     512            $cache_key = $this->cache_key;
     513        }
     514
     515        $data = array(
     516            'timeout' => strtotime('+3 hours', current_time('timestamp')),
     517            'value'   => json_encode($value)
     518        );
     519
     520        update_option($cache_key, $data, 'no');
     521    }
     522
     523    /**
     524    * Returns if the SSL of the store should be verified.
     525    *
     526    * @since  1.6.13
     527    * @return bool
     528    */
     529    private function verify_ssl()
     530    {
     531        return (bool) apply_filters('edd_sl_api_request_verify_ssl', true, $this); // could be made false for local self-signed SSL
     532    }
    532533}
  • church-theme-content/trunk/readme.txt

    r3208663 r3391879  
    33Tags: church, churches, sermon, sermons, ministry, ministries, event, events, calendar, location, locations
    44Requires at least: 3.6
    5 Tested up to: 6.7
     5Tested up to: 6.8.3
    66Requires PHP: 7.4
    7 Stable tag: 2.6.2
     7Stable tag: 2.7
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.