Plugin Directory

Changeset 1798690


Ignore:
Timestamp:
01/08/2018 01:46:49 AM (8 years ago)
Author:
jaredcobb
Message:

1.0.0 Very Stable Genius

Location:
church-community-builder-core-api
Files:
88 added
12 deleted
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • church-community-builder-core-api/tags/1.0.0/README.txt

    r1259359 r1798690  
    22Contributors: jaredcobb
    33Tags: ccb, church, api, chms
    4 Requires at least: 3.0.1
    5 Tested up to: 4.3.1
    6 Stable tag: 0.9.6
     4Requires at least: 4.6.0
     5Tested up to: 4.9.1
     6Stable tag: 1.0.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1313
    1414Church Community Builder Core API *synchronizes* your church data to WordPress [custom post types](https://codex.wordpress.org/Custom_Post_Types).
    15 This plugin is geared toward developers (or advanced WordPress users who aren't afraid to get into a little bit of code).
    1615
    17 Find out more at [http://www.wpccb.com/](http://www.wpccb.com).
     16This plugin is geared toward Developers, Designers, and Site Administrators who aren't afraid to get into a little bit of code.
     17
     18Find out more at [https://www.wpccb.com](https://www.wpccb.com) and [https://github.com/jaredcobb/ccb-core](https://github.com/jaredcobb/ccb-core).
    1819
    1920= Why Use This Plugin? =
    2021
    21 One of the biggest challenges with getting your Church Community Builder data onto your site is the actual API integration.
    22 This plugin does all of the heavy lifting for you. Once your church data is securely synchronized you can use it freely in
    23 your theme, widgets, or even your own plugins!
     22One of the biggest challenges with getting your Church Community Builder data onto your site is the actual API integration.  This plugin does all of the heavy lifting for you. Once your church data is securely synchronized you can use it freely in your theme, widgets, or even your own plugins!
    2423
    2524= Features =
     
    3534= Documentation =
    3635
    37 The [http://www.wpccb.com/documentation/](official documentation) has more information, including code samples, hooks, filters, and links to tutorials.
     36Extensive developer documentation is available on the [GitHub wiki](https://github.com/jaredcobb/ccb-core/wiki).
    3837
    3938== Installation ==
     
    5049= I installed this plugin and my site doesn't look any different =
    5150
    52 This plugin has a very specific task: It gets some of your Church Community Builder data and imports it into your
    53 WordPress database (as custom post types). A developer (or advanced WordPress administrator) will need to
    54 alter your theme to *take advantage* of this data.
     51This plugin has a very specific task: It gets some of your Church Community Builder data and imports it into your WordPress database (as custom post types). A developer (or advanced WordPress administrator) will need to alter your theme to *take advantage* of this data.
    5552
    5653= Some of my groups in Church Community Builder aren't being synchronized =
    5754
    58 You'll need to ensure your [group settings](https://support.churchcommunitybuilder.com/customer/portal/articles/361764-editing-groups)
    59 allow the group to be publicly listed. A great way to cross reference if your group is publicly visible is to visit
    60 *yoursubdomain*.ccbchurch.com/w_group_list.php and see if the missing group shows up there.
     55You'll need to ensure your [group settings](https://churchcommunitybuilder.force.com/s/article/2102903) allow the group to be publicly listed. A great way to cross reference if your group is publicly visible is to visit *yoursubdomain*.ccbchurch.com/w_group_list.php and see if the missing group shows up there.
    6156
    6257== Screenshots ==
     
    6661
    6762== Changelog ==
     63
     64= 1.0.0 =
     65* Official stable release
     66* *Breaking Changes* - Please note that post type and custom taxonomy names have changed (see [release notes](https://github.com/jaredcobb/ccb-core/wiki/1.0.0-Stable-Release) )
     67* Fixed broken group images (CCB API query parameter `include_image_link=true`)
     68* Refactored code to be faster, simpler, and easier to extend
    6869
    6970= 0.9.6 =
     
    9091* Added tooltips to some settings to help explain the functionality
    9192* Added better defaults for date ranges
    92 * Updated the plugin web site to http://www.wpccb.com
     93* Updated the plugin web site to https://www.wpccb.com
    9394
    9495= 0.9.1 =
  • church-community-builder-core-api/tags/1.0.0/ccb-core.php

    r1259359 r1798690  
    33 * Church Community Builder Core API
    44 *
    5  * @link              http://www.wpccb.com
     5 * @link              https://www.wpccb.com
    66 * @since             0.9.0
    77 * @package           CCB_Core
     
    99 * @wordpress-plugin
    1010 * Plugin Name:       Church Community Builder Core API
    11  * Plugin URI:        http://www.wpccb.com
     11 * Plugin URI:        https://www.wpccb.com
    1212 * Description:       A plugin to provide a core integration of the Church Community Builder API into WordPress custom post types
    13  * Version:           0.9.6
     13 * Version:           1.0.0
    1414 * Author:            Jared Cobb
    15  * Author URI:        http://jaredcobb.com/
     15 * Author URI:        https://www.jaredcobb.com/
    1616 * License:           GPL-2.0+
    1717 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     
    2020 */
    2121
    22 // do not allow direct access to this file
     22// Do not allow direct access to this file.
    2323if ( ! defined( 'WPINC' ) ) {
    2424    die;
    2525}
    2626
    27 // parent class for entire plugin (name, version, other helpful properties and utility methods)
    28 require_once plugin_dir_path( __FILE__ ) . 'includes/class-ccb-core-plugin.php';
     27define( 'CCB_CORE_PATH', plugin_dir_path( __FILE__ ) );
     28define( 'CCB_CORE_URL', plugin_dir_url( __FILE__ ) );
     29define( 'CCB_CORE_BASENAME', plugin_basename( __FILE__ ) );
     30define( 'CCB_CORE_VERSION', '1.0.0' );
    2931
    30 // code that runs during plugin activation
    31 require_once plugin_dir_path( __FILE__ ) . 'includes/class-ccb-core-activator.php';
    32 register_activation_hook( __FILE__, array( 'CCB_Core_Activator', 'activate' ) );
     32// Code that runs during plugin activation and deactivation.
     33require_once CCB_CORE_PATH . 'includes/class-ccb-core-activator.php';
     34register_activation_hook( __FILE__, [ 'CCB_Core_Activator', 'activate' ] );
     35register_deactivation_hook( __FILE__, [ 'CCB_Core_Activator', 'deactivate' ] );
    3336
    34 // internationalization, dashboard-specific hooks, and public-facing site hooks.
    35 require_once plugin_dir_path( __FILE__ ) . 'includes/class-ccb-core.php';
     37// Internationalization, dashboard-specific hooks, and public-facing site hooks.
     38require_once CCB_CORE_PATH . 'includes/class-ccb-core.php';
    3639
    3740/**
    3841 * Begin execution of the plugin.
    3942 *
    40  * @since    0.9.0
     43 * @access public
     44 * @return void
    4145 */
    4246function run_ccb_core() {
    43 
    44     $plugin_basename = plugin_basename( __FILE__ );
    45     $plugin = new CCB_Core( $plugin_basename );
    46     $plugin->run();
     47    $plugin = new CCB_Core();
    4748
    4849}
  • church-community-builder-core-api/tags/1.0.0/includes/class-ccb-core-activator.php

    r1189910 r1798690  
    33 * Fired during plugin activation
    44 *
    5  * @link       http://jaredcobb.com/ccb-core
     5 * @link       https://www.wpccb.com
    66 * @since      0.9.0
    77 *
     
    2020 * @author     Jared Cobb <wordpress@jaredcobb.com>
    2121 */
    22 class CCB_Core_Activator extends CCB_Core_Plugin {
     22class CCB_Core_Activator {
    2323
    2424    /**
     
    2828     */
    2929    public static function activate() {
    30         // TODO: check dependencies like mcrypt and memory limits
     30        // TODO: check dependencies like mcrypt and memory limits.
     31    }
     32
     33    /**
     34     * Deactivation code
     35     *
     36     * @since    1.0.0
     37     */
     38    public static function deactivate() {
     39        // Ensure we do not have a scheduled hook.
     40        $timestamp = wp_next_scheduled( 'ccb_core_auto_sync_hook' );
     41        if ( $timestamp ) {
     42            wp_unschedule_event( $timestamp, 'ccb_core_auto_sync_hook' );
     43        }
    3144    }
    3245
  • church-community-builder-core-api/tags/1.0.0/includes/class-ccb-core.php

    r1259359 r1798690  
    66 * public-facing side of the site and the dashboard.
    77 *
    8  * @link       http://jaredcobb.com/ccb-core
    9  * @since      0.9.0
    10  *
    11  * @package    CCB_Core
    12  * @subpackage CCB_Core/includes
     8 * @link          https://www.wpccb.com
     9 * @package       CCB_Core
     10 * @subpackage    CCB_Core/includes
    1311 */
    1412
     
    2220 * version of the plugin.
    2321 *
    24  * @since      0.9.0
    2522 * @package    CCB_Core
    2623 * @subpackage CCB_Core/includes
    2724 * @author     Jared Cobb <wordpress@jaredcobb.com>
    2825 */
    29 class CCB_Core extends CCB_Core_Plugin {
    30 
    31     /**
    32      * The loader that's responsible for maintaining and registering all hooks that power
    33      * the plugin.
    34      *
    35      * @since    0.9.0
    36      * @access   protected
    37      * @var      CCB_Core_Loader    $loader    Maintains and registers all hooks for the plugin.
    38      */
    39     protected $loader;
    40 
    41     /**
    42      * A helper for getting the plugin_basename
    43      *
    44      * @since    0.9.0
    45      * @access   protected
    46      * @var      CCB_Core_Loader    $loader    Maintains and registers all hooks for the plugin.
    47      */
    48     protected $plugin_basename;
     26class CCB_Core {
    4927
    5028    /**
     
    5735     * @since    0.9.0
    5836     */
    59     public function __construct( $plugin_basename ) {
    60 
    61         parent::__construct();
    62         $this->plugin_basename = $plugin_basename;
     37    public function __construct() {
    6338        $this->load_dependencies();
    64         $this->set_locale();
    65         $this->define_admin_hooks();
    66 
     39        $this->define_hooks();
    6740    }
    6841
     
    7043     * Load the required dependencies for this plugin.
    7144     *
    72      * Also create an instance of the loader which will be used to register the hooks
    73      * with WordPress.
     45     * @since  0.9.0
     46     * @access private
     47     */
     48    private function load_dependencies() {
     49
     50        // Encryption class to provide better security and ease of use.
     51        require_once CCB_CORE_PATH . 'lib/class-ccb-core-vendor-encryption.php';
     52
     53        // A generic helper class with commonly used mehtods.
     54        require_once CCB_CORE_PATH . 'includes/class-ccb-core-helpers.php';
     55
     56        // The classes that define options and settings for the plugin.
     57        require_once CCB_CORE_PATH . 'includes/class-ccb-core-settings.php';
     58        require_once CCB_CORE_PATH . 'includes/class-ccb-core-settings-page.php';
     59        require_once CCB_CORE_PATH . 'includes/class-ccb-core-settings-section.php';
     60        require_once CCB_CORE_PATH . 'includes/class-ccb-core-settings-field.php';
     61
     62        // The class that handles communication with the CCB API.
     63        require_once CCB_CORE_PATH . 'includes/class-ccb-core-api.php';
     64
     65        // The class that handles synchronization logic.
     66        require_once CCB_CORE_PATH . 'includes/class-ccb-core-synchronizer.php';
     67
     68        // Custom Post Type classes.
     69        require_once CCB_CORE_PATH . 'includes/post-types/class-ccb-core-cpt.php';
     70        require_once CCB_CORE_PATH . 'includes/post-types/class-ccb-core-group.php';
     71        require_once CCB_CORE_PATH . 'includes/post-types/class-ccb-core-calendar.php';
     72
     73        // Custom Taxonomy classes.
     74        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-taxonomy.php';
     75        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-calendar-event-type.php';
     76        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-calendar-group-name.php';
     77        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-calendar-grouping-name.php';
     78        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-area.php';
     79        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-day.php';
     80        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-department.php';
     81        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-tag.php';
     82        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-time.php';
     83        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-type.php';
     84
     85        // Admin AJAX methods.
     86        require_once CCB_CORE_PATH . 'includes/class-ccb-core-admin-ajax.php';
     87
     88        // Cron Management.
     89        require_once CCB_CORE_PATH . 'includes/class-ccb-core-cron.php';
     90
     91    }
     92
     93    /**
     94     * Register all of the hooks related to the dashboard functionality
     95     * of the plugin.
    7496     *
    7597     * @since    0.9.0
    7698     * @access   private
    7799     */
    78     private function load_dependencies() {
    79 
    80         // encryption class to provide better security and ease of use
    81         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'lib/Encryption/Encryption.php';
    82 
    83         // the class responsible for orchestrating the actions and filters of the core plugin.
    84         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ccb-core-loader.php';
    85 
    86         // the class responsible for defining internationalization functionality of the plugin.
    87         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ccb-core-i18n.php';
    88 
    89         // the class that defines options and settings for the plugin
    90         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-settings.php';
    91         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-settings-page.php';
    92         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-settings-section.php';
    93         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-settings-field.php';
    94 
    95         // the class responsible for defining all actions that occur in the Dashboard.
    96         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-admin.php';
    97 
    98         // the class that handles data synchronization between CCB and the local cache
    99         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-sync.php';
    100 
    101         // the class that handles data synchronization between CCB and the local cache
    102         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-cpts.php';
    103 
    104         // instantiate the loader
    105         $this->loader = new CCB_Core_Loader();
    106 
    107     }
    108 
    109     /**
    110      * Define the locale for this plugin for internationalization.
    111      *
    112      * Uses the CCB_Core_i18n class in order to set the domain and to register the hook
    113      * with WordPress.
    114      *
     100    private function define_hooks() {
     101
     102        // Internationalization.
     103        add_action( 'plugins_loaded', [ $this, 'load_plugin_textdomain' ] );
     104
     105        // Check the plugin / database version and run any required upgrades.
     106        add_action( 'plugins_loaded', [ $this, 'check_version' ] );
     107
     108        // Plugin settings, menus, options.
     109        add_filter( 'plugin_action_links_' . CCB_CORE_BASENAME, [ $this, 'add_settings_link' ] );
     110
     111        // Setup settings pages.
     112        add_action( 'admin_menu', [ $this, 'initialize_settings_menu' ] );
     113        add_action( 'admin_init', [ $this, 'initialize_settings' ] );
     114
     115        // Callback for after the options are saved.
     116        add_action( 'update_option_ccb_core_settings', [ $this, 'updated_options' ], 10, 2 );
     117
     118        // Determine if the rewrite rules need to be flushed.
     119        add_action( 'init', [ $this, 'check_rewrite_rules' ] );
     120
     121        add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] );
     122        add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
     123
     124    }
     125
     126    /**
     127     * Load the plugin text domain for translation.
     128     *
     129     * @since   0.9.0
     130     */
     131    public function load_plugin_textdomain() {
     132
     133        load_plugin_textdomain(
     134            'ccb-core',
     135            false,
     136            dirname( CCB_CORE_BASENAME ) . '/languages/'
     137        );
     138
     139    }
     140
     141    /**
     142     * Check the current plugin version and kick off any applicable upgrades.
     143     *
     144     * @return void
     145     */
     146    public function check_version() {
     147        $current_version = get_option( 'ccb_core_version' );
     148
     149        // We are currently up to date.
     150        if ( version_compare( $current_version, CCB_CORE_VERSION, '>=' ) ) {
     151            return;
     152        }
     153
     154        // Upgrade to version 1.0.0.
     155        if ( version_compare( $current_version, '1.0.0', '<' ) ) {
     156            $this->upgrade_to_1_0_0();
     157        }
     158
     159        // Update the DB version.
     160        update_option( 'ccb_core_version', CCB_CORE_VERSION );
     161    }
     162
     163    /**
     164     * Create a helpful settings link on the plugin page
     165     *
     166     * @param    array $links An array of links.
     167     * @access   public
    115168     * @since    0.9.0
    116      * @access   private
    117      */
    118     private function set_locale() {
    119 
    120         $plugin_i18n = new CCB_Core_i18n();
    121         $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
    122 
    123     }
    124 
    125     /**
    126      * Register all of the hooks related to the dashboard functionality
    127      * of the plugin.
    128      *
     169     * @return   array
     170     */
     171    public function add_settings_link( $links ) {
     172        $links[] = '<a href="' . esc_url( get_admin_url( null, 'admin.php?page=ccb_core_settings' ) ) . '">' . esc_html__( 'Settings', 'ccb-core' ) . '</a>';
     173        return $links;
     174    }
     175
     176    /**
     177     * Initialize the Settings Menu and Page
     178     *
     179     * @access   public
    129180     * @since    0.9.0
    130      * @access   private
    131      */
    132     private function define_admin_hooks() {
    133 
    134         $plugin_admin = new CCB_Core_Admin();
    135 
    136         $this->loader->add_action( 'init', $plugin_admin, 'initialize_custom_post_types' );
    137         $this->loader->add_action( 'admin_menu', $plugin_admin, 'initialize_settings_menu' );
    138         $this->loader->add_action( 'admin_init', $plugin_admin, 'initialize_settings' );
    139         $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
    140         $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    141         $this->loader->add_filter( 'plugin_action_links_' . $this->plugin_basename, $plugin_admin, 'add_settings_link' );
    142         $this->loader->add_action( 'schedule_auto_refresh', $plugin_admin, 'auto_sync' );
    143         $this->loader->add_action( 'wp_loaded', $plugin_admin, 'check_auto_refresh' );
    144         $this->loader->add_action( 'pre_update_option_' . $this->plugin_settings_name, $plugin_admin, 'update_settings_callback', 10, 2 );
    145         $this->loader->add_action( 'schedule_flush_rewrite_rules', $plugin_admin, 'flush_rewrite_rules_event' );
    146 
    147         // all backend ajax hooks
    148         $this->loader->add_action( 'wp_ajax_sync', $plugin_admin, 'ajax_sync' );
    149         $this->loader->add_action( 'wp_ajax_poll_sync', $plugin_admin, 'ajax_poll_sync' );
    150         $this->loader->add_action( 'wp_ajax_test_credentials', $plugin_admin, 'ajax_test_credentials' );
    151         $this->loader->add_action( 'wp_ajax_get_latest_sync', $plugin_admin, 'ajax_get_latest_sync' );
    152 
    153     }
    154 
    155     /**
    156      * Run the loader to execute all of the hooks with WordPress.
    157      *
     181     * @return   void
     182     */
     183    public function initialize_settings_menu() {
     184
     185        $settings = new CCB_Core_Settings();
     186        $settings_page = new CCB_Core_Settings_Page( 'ccb_core_settings' );
     187
     188        add_menu_page(
     189            __( 'Church Community Builder Core API', 'ccb-core' ),
     190            __( 'CCB Core API', 'ccb-core' ),
     191            /**
     192             * Defines the capability that is required for the user
     193             * to access the settings page.
     194             *
     195             * @since 1.0.0
     196             *
     197             * @param string $capability The capability required to access the page.
     198             */
     199            apply_filters( 'ccb_core_settings_capability', 'manage_options' ),
     200            'ccb_core_settings',
     201            '__return_null',
     202            'dashicons-update',
     203            '80.9'
     204        );
     205
     206        foreach ( $settings->get_settings_definitions() as $page_id => $page ) {
     207            $settings_page = new CCB_Core_Settings_Page( $page_id );
     208            add_submenu_page(
     209                'ccb_core_settings',
     210                $page['page_title'],
     211                $page['page_title'],
     212                apply_filters( 'ccb_core_settings_capability', 'manage_options' ),
     213                $page_id,
     214                [
     215                    $settings_page,
     216                    'render_page',
     217                ]
     218            );
     219        }
     220    }
     221
     222    /**
     223     * Initialize the Settings
     224     *
     225     * @access   public
    158226     * @since    0.9.0
    159      */
    160     public function run() {
    161         $this->loader->run();
    162     }
    163 
    164     /**
    165      * The reference to the class that orchestrates the hooks with the plugin.
    166      *
    167      * @since     0.9.0
    168      * @return    CCB_Core_Loader    Orchestrates the hooks of the plugin.
    169      */
    170     public function get_loader() {
    171         return $this->loader;
     227     * @return   void
     228     */
     229    public function initialize_settings() {
     230
     231        $settings = new CCB_Core_Settings();
     232
     233        foreach ( $settings->get_settings_definitions() as $page_id => $page ) {
     234
     235            register_setting( $page_id, 'ccb_core_settings', [ $settings, 'validate_settings' ] );
     236
     237            foreach ( $page['sections'] as $section_id => $section ) {
     238
     239                $settings_section = new CCB_Core_Settings_Section( $section_id, $section );
     240                add_settings_section(
     241                    $section_id,
     242                    $section['section_title'],
     243                    [
     244                        $settings_section,
     245                        'render_section',
     246                    ],
     247                    $page_id
     248                );
     249
     250                if ( ! empty( $section['fields'] ) ) {
     251                    foreach ( $section['fields'] as $field_id => $field ) {
     252
     253                        $settings_field = new CCB_Core_Settings_Field( $field_id, $field );
     254                        add_settings_field(
     255                            $field_id,
     256                            $field['field_title'],
     257                            [
     258                                $settings_field,
     259                                'render_field',
     260                            ],
     261                            $page_id,
     262                            $section_id
     263                        );
     264
     265                    }
     266                }
     267
     268            }
     269
     270        }
     271
     272    }
     273
     274    /**
     275     * After the options are saved, check to see if we
     276     * should flush the rewrite rules.
     277     *
     278     * @param    array $old_value The previous option value.
     279     * @param    array $value The new option value.
     280     * @access   public
     281     * @since    1.0.0
     282     * @return   void
     283     */
     284    public function updated_options( $old_value, $value ) {
     285
     286        // Create a collection of settings that, if they change, should
     287        // trigger a flush_rewrite_rules event.
     288        $setting_array = [
     289            'groups_enabled',
     290            'groups_slug',
     291            'calendar_enabled',
     292            'calendar_slug',
     293        ];
     294
     295        foreach ( $setting_array as $setting ) {
     296            if ( isset( $value[ $setting ] ) ) {
     297                if ( ! isset( $old_value[ $setting ] ) || $value[ $setting ] !== $old_value[ $setting ] ) {
     298                    // At least one option requires a flush, so set the transient and return.
     299                    set_transient( 'ccb_core_flush_rewrite_rules', true );
     300                    return;
     301                }
     302            }
     303        }
     304
     305    }
     306
     307    /**
     308     * Checks for a flag that may have been previously
     309     * set in order to flush the rewrite rules.
     310     *
     311     * @return void
     312     */
     313    public function check_rewrite_rules() {
     314        if ( get_transient( 'ccb_core_flush_rewrite_rules' ) ) {
     315            delete_transient( 'ccb_core_flush_rewrite_rules' );
     316            flush_rewrite_rules();
     317        }
     318    }
     319
     320    /**
     321     * Register the stylesheets for the dashboard.
     322     *
     323     * @param string $hook Current admin page.
     324     * @return void
     325     */
     326    public function enqueue_styles( $hook ) {
     327
     328        if ( false !== stristr( $hook, 'ccb_core_settings' ) ) {
     329            wp_enqueue_style( 'ccb-core', CCB_CORE_URL . 'css/ccb-core-admin.css', [], CCB_CORE_VERSION, 'all' );
     330            wp_enqueue_style( 'switchery', CCB_CORE_URL . 'css/vendor/switchery.min.css', [], CCB_CORE_VERSION, 'all' );
     331            wp_enqueue_style( 'powerange', CCB_CORE_URL . 'css/vendor/powerange.min.css', [], CCB_CORE_VERSION, 'all' );
     332            wp_enqueue_style( 'picker', CCB_CORE_URL . 'css/vendor/default.css', [], CCB_CORE_VERSION, 'all' );
     333            wp_enqueue_style( 'picker-date', CCB_CORE_URL . 'css/vendor/default.date.css', [], CCB_CORE_VERSION, 'all' );
     334            wp_enqueue_style( 'tipr', CCB_CORE_URL . 'css/vendor/tipr.css', [], CCB_CORE_VERSION, 'all' );
     335        }
     336
     337    }
     338
     339    /**
     340     * Register the scripts for the dashboard.
     341     *
     342     * @param string $hook Current admin page.
     343     * @return void
     344     */
     345    public function enqueue_scripts( $hook ) {
     346
     347        if ( false !== stristr( $hook, 'ccb_core_settings' ) ) {
     348            wp_enqueue_script( 'ccb-core', CCB_CORE_URL . 'js/ccb-core-admin.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     349            wp_enqueue_script( 'switchery', CCB_CORE_URL . 'js/vendor/switchery.min.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     350            wp_enqueue_script( 'powerange', CCB_CORE_URL . 'js/vendor/powerange.min.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     351            wp_enqueue_script( 'picker', CCB_CORE_URL . 'js/vendor/picker.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     352            wp_enqueue_script( 'picker-date', CCB_CORE_URL . 'js/vendor/picker.date.js', [ 'picker' ], CCB_CORE_VERSION, false );
     353            wp_enqueue_script( 'tipr', CCB_CORE_URL . 'js/vendor/tipr.min.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     354            wp_localize_script(
     355                'ccb-core',
     356                'CCB_CORE_SETTINGS',
     357                [
     358                    'nonce' => wp_create_nonce( 'ccb_core_nonce' ),
     359                    'translations' => [
     360                        'credentialsSuccessful' => esc_html__( 'The credentials were successfully authenticated.', 'ccb-core' ),
     361                        'credentialsFailed' => esc_html__( 'The credentials failed authentication', 'ccb-core' ),
     362                        'syncInProgress' => esc_html__( 'Syncronization in progress... You can safely navigate away from this page while we work in the background.', 'ccb-core' ),
     363                    ],
     364                ]
     365            );
     366        }
     367
     368    }
     369
     370    /**
     371     * Converts any legacy options to the new format
     372     *
     373     * @return void
     374     */
     375    private function upgrade_to_1_0_0() {
     376        $current_options = CCB_Core_Helpers::instance()->get_options();
     377        $updated_options = [];
     378        $options_hash = [
     379            'subdomain' => 'subdomain',
     380            'credentials' => 'credentials',
     381            'groups-enabled' => 'groups_enabled',
     382            'groups-name' => 'groups_name',
     383            'groups-slug' => 'groups_slug',
     384            'groups-import-images' => 'groups_import_images',
     385            'groups-advanced' => 'groups_advanced',
     386            'groups-exclude-from-search' => 'groups_exclude_from_search',
     387            'groups-publicly-queryable' => 'groups_publicly_queryable',
     388            'groups-show-ui' => 'groups_show_ui',
     389            'groups-show-in-nav-menus' => 'groups_show_in_nav_menus',
     390            'calendar-enabled' => 'calendar_enabled',
     391            'calendar-name' => 'calendar_name',
     392            'calendar-slug' => 'calendar_slug',
     393            'calendar-advanced' => 'calendar_advanced',
     394            'calendar-date-range-type' => 'calendar_date_range_type',
     395            'calendar-relative-weeks-past' => 'calendar_relative_weeks_past',
     396            'calendar-relative-weeks-future' => 'calendar_relative_weeks_future',
     397            'calendar-specific-start' => 'calendar_specific_start',
     398            'calendar-specific-end' => 'calendar_specific_end',
     399            'calendar-exclude-from-search' => 'calendar_exclude_from_search',
     400            'calendar-publicly-queryable' => 'calendar_publicly_queryable',
     401            'calendar-show-ui' => 'calendar_show_ui',
     402            'calendar-show-in-nav-menus' => 'calendar_show_in_nav_menus',
     403        ];
     404
     405        if ( ! empty( $current_options ) ) {
     406            foreach ( $options_hash as $old => $new ) {
     407                if ( isset( $current_options[ $old ] ) ) {
     408                    $updated_options[ $new ] = $current_options[ $old ];
     409                }
     410            }
     411            update_option( 'ccb_core_settings', $updated_options );
     412        }
    172413    }
    173414
  • church-community-builder-core-api/tags/1.0.0/index.php

    r1189910 r1798690  
    1 <?php // Silence is golden
     1<?php // phpcs:disable
  • church-community-builder-core-api/trunk/README.txt

    r1259359 r1798690  
    22Contributors: jaredcobb
    33Tags: ccb, church, api, chms
    4 Requires at least: 3.0.1
    5 Tested up to: 4.3.1
    6 Stable tag: 0.9.6
     4Requires at least: 4.6.0
     5Tested up to: 4.9.1
     6Stable tag: 1.0.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1313
    1414Church Community Builder Core API *synchronizes* your church data to WordPress [custom post types](https://codex.wordpress.org/Custom_Post_Types).
    15 This plugin is geared toward developers (or advanced WordPress users who aren't afraid to get into a little bit of code).
    1615
    17 Find out more at [http://www.wpccb.com/](http://www.wpccb.com).
     16This plugin is geared toward Developers, Designers, and Site Administrators who aren't afraid to get into a little bit of code.
     17
     18Find out more at [https://www.wpccb.com](https://www.wpccb.com) and [https://github.com/jaredcobb/ccb-core](https://github.com/jaredcobb/ccb-core).
    1819
    1920= Why Use This Plugin? =
    2021
    21 One of the biggest challenges with getting your Church Community Builder data onto your site is the actual API integration.
    22 This plugin does all of the heavy lifting for you. Once your church data is securely synchronized you can use it freely in
    23 your theme, widgets, or even your own plugins!
     22One of the biggest challenges with getting your Church Community Builder data onto your site is the actual API integration.  This plugin does all of the heavy lifting for you. Once your church data is securely synchronized you can use it freely in your theme, widgets, or even your own plugins!
    2423
    2524= Features =
     
    3534= Documentation =
    3635
    37 The [http://www.wpccb.com/documentation/](official documentation) has more information, including code samples, hooks, filters, and links to tutorials.
     36Extensive developer documentation is available on the [GitHub wiki](https://github.com/jaredcobb/ccb-core/wiki).
    3837
    3938== Installation ==
     
    5049= I installed this plugin and my site doesn't look any different =
    5150
    52 This plugin has a very specific task: It gets some of your Church Community Builder data and imports it into your
    53 WordPress database (as custom post types). A developer (or advanced WordPress administrator) will need to
    54 alter your theme to *take advantage* of this data.
     51This plugin has a very specific task: It gets some of your Church Community Builder data and imports it into your WordPress database (as custom post types). A developer (or advanced WordPress administrator) will need to alter your theme to *take advantage* of this data.
    5552
    5653= Some of my groups in Church Community Builder aren't being synchronized =
    5754
    58 You'll need to ensure your [group settings](https://support.churchcommunitybuilder.com/customer/portal/articles/361764-editing-groups)
    59 allow the group to be publicly listed. A great way to cross reference if your group is publicly visible is to visit
    60 *yoursubdomain*.ccbchurch.com/w_group_list.php and see if the missing group shows up there.
     55You'll need to ensure your [group settings](https://churchcommunitybuilder.force.com/s/article/2102903) allow the group to be publicly listed. A great way to cross reference if your group is publicly visible is to visit *yoursubdomain*.ccbchurch.com/w_group_list.php and see if the missing group shows up there.
    6156
    6257== Screenshots ==
     
    6661
    6762== Changelog ==
     63
     64= 1.0.0 =
     65* Official stable release
     66* *Breaking Changes* - Please note that post type and custom taxonomy names have changed (see [release notes](https://github.com/jaredcobb/ccb-core/wiki/1.0.0-Stable-Release) )
     67* Fixed broken group images (CCB API query parameter `include_image_link=true`)
     68* Refactored code to be faster, simpler, and easier to extend
    6869
    6970= 0.9.6 =
     
    9091* Added tooltips to some settings to help explain the functionality
    9192* Added better defaults for date ranges
    92 * Updated the plugin web site to http://www.wpccb.com
     93* Updated the plugin web site to https://www.wpccb.com
    9394
    9495= 0.9.1 =
  • church-community-builder-core-api/trunk/ccb-core.php

    r1259359 r1798690  
    33 * Church Community Builder Core API
    44 *
    5  * @link              http://www.wpccb.com
     5 * @link              https://www.wpccb.com
    66 * @since             0.9.0
    77 * @package           CCB_Core
     
    99 * @wordpress-plugin
    1010 * Plugin Name:       Church Community Builder Core API
    11  * Plugin URI:        http://www.wpccb.com
     11 * Plugin URI:        https://www.wpccb.com
    1212 * Description:       A plugin to provide a core integration of the Church Community Builder API into WordPress custom post types
    13  * Version:           0.9.6
     13 * Version:           1.0.0
    1414 * Author:            Jared Cobb
    15  * Author URI:        http://jaredcobb.com/
     15 * Author URI:        https://www.jaredcobb.com/
    1616 * License:           GPL-2.0+
    1717 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     
    2020 */
    2121
    22 // do not allow direct access to this file
     22// Do not allow direct access to this file.
    2323if ( ! defined( 'WPINC' ) ) {
    2424    die;
    2525}
    2626
    27 // parent class for entire plugin (name, version, other helpful properties and utility methods)
    28 require_once plugin_dir_path( __FILE__ ) . 'includes/class-ccb-core-plugin.php';
     27define( 'CCB_CORE_PATH', plugin_dir_path( __FILE__ ) );
     28define( 'CCB_CORE_URL', plugin_dir_url( __FILE__ ) );
     29define( 'CCB_CORE_BASENAME', plugin_basename( __FILE__ ) );
     30define( 'CCB_CORE_VERSION', '1.0.0' );
    2931
    30 // code that runs during plugin activation
    31 require_once plugin_dir_path( __FILE__ ) . 'includes/class-ccb-core-activator.php';
    32 register_activation_hook( __FILE__, array( 'CCB_Core_Activator', 'activate' ) );
     32// Code that runs during plugin activation and deactivation.
     33require_once CCB_CORE_PATH . 'includes/class-ccb-core-activator.php';
     34register_activation_hook( __FILE__, [ 'CCB_Core_Activator', 'activate' ] );
     35register_deactivation_hook( __FILE__, [ 'CCB_Core_Activator', 'deactivate' ] );
    3336
    34 // internationalization, dashboard-specific hooks, and public-facing site hooks.
    35 require_once plugin_dir_path( __FILE__ ) . 'includes/class-ccb-core.php';
     37// Internationalization, dashboard-specific hooks, and public-facing site hooks.
     38require_once CCB_CORE_PATH . 'includes/class-ccb-core.php';
    3639
    3740/**
    3841 * Begin execution of the plugin.
    3942 *
    40  * @since    0.9.0
     43 * @access public
     44 * @return void
    4145 */
    4246function run_ccb_core() {
    43 
    44     $plugin_basename = plugin_basename( __FILE__ );
    45     $plugin = new CCB_Core( $plugin_basename );
    46     $plugin->run();
     47    $plugin = new CCB_Core();
    4748
    4849}
  • church-community-builder-core-api/trunk/includes/class-ccb-core-activator.php

    r1189910 r1798690  
    33 * Fired during plugin activation
    44 *
    5  * @link       http://jaredcobb.com/ccb-core
     5 * @link       https://www.wpccb.com
    66 * @since      0.9.0
    77 *
     
    2020 * @author     Jared Cobb <wordpress@jaredcobb.com>
    2121 */
    22 class CCB_Core_Activator extends CCB_Core_Plugin {
     22class CCB_Core_Activator {
    2323
    2424    /**
     
    2828     */
    2929    public static function activate() {
    30         // TODO: check dependencies like mcrypt and memory limits
     30        // TODO: check dependencies like mcrypt and memory limits.
     31    }
     32
     33    /**
     34     * Deactivation code
     35     *
     36     * @since    1.0.0
     37     */
     38    public static function deactivate() {
     39        // Ensure we do not have a scheduled hook.
     40        $timestamp = wp_next_scheduled( 'ccb_core_auto_sync_hook' );
     41        if ( $timestamp ) {
     42            wp_unschedule_event( $timestamp, 'ccb_core_auto_sync_hook' );
     43        }
    3144    }
    3245
  • church-community-builder-core-api/trunk/includes/class-ccb-core.php

    r1259359 r1798690  
    66 * public-facing side of the site and the dashboard.
    77 *
    8  * @link       http://jaredcobb.com/ccb-core
    9  * @since      0.9.0
    10  *
    11  * @package    CCB_Core
    12  * @subpackage CCB_Core/includes
     8 * @link          https://www.wpccb.com
     9 * @package       CCB_Core
     10 * @subpackage    CCB_Core/includes
    1311 */
    1412
     
    2220 * version of the plugin.
    2321 *
    24  * @since      0.9.0
    2522 * @package    CCB_Core
    2623 * @subpackage CCB_Core/includes
    2724 * @author     Jared Cobb <wordpress@jaredcobb.com>
    2825 */
    29 class CCB_Core extends CCB_Core_Plugin {
    30 
    31     /**
    32      * The loader that's responsible for maintaining and registering all hooks that power
    33      * the plugin.
    34      *
    35      * @since    0.9.0
    36      * @access   protected
    37      * @var      CCB_Core_Loader    $loader    Maintains and registers all hooks for the plugin.
    38      */
    39     protected $loader;
    40 
    41     /**
    42      * A helper for getting the plugin_basename
    43      *
    44      * @since    0.9.0
    45      * @access   protected
    46      * @var      CCB_Core_Loader    $loader    Maintains and registers all hooks for the plugin.
    47      */
    48     protected $plugin_basename;
     26class CCB_Core {
    4927
    5028    /**
     
    5735     * @since    0.9.0
    5836     */
    59     public function __construct( $plugin_basename ) {
    60 
    61         parent::__construct();
    62         $this->plugin_basename = $plugin_basename;
     37    public function __construct() {
    6338        $this->load_dependencies();
    64         $this->set_locale();
    65         $this->define_admin_hooks();
    66 
     39        $this->define_hooks();
    6740    }
    6841
     
    7043     * Load the required dependencies for this plugin.
    7144     *
    72      * Also create an instance of the loader which will be used to register the hooks
    73      * with WordPress.
     45     * @since  0.9.0
     46     * @access private
     47     */
     48    private function load_dependencies() {
     49
     50        // Encryption class to provide better security and ease of use.
     51        require_once CCB_CORE_PATH . 'lib/class-ccb-core-vendor-encryption.php';
     52
     53        // A generic helper class with commonly used mehtods.
     54        require_once CCB_CORE_PATH . 'includes/class-ccb-core-helpers.php';
     55
     56        // The classes that define options and settings for the plugin.
     57        require_once CCB_CORE_PATH . 'includes/class-ccb-core-settings.php';
     58        require_once CCB_CORE_PATH . 'includes/class-ccb-core-settings-page.php';
     59        require_once CCB_CORE_PATH . 'includes/class-ccb-core-settings-section.php';
     60        require_once CCB_CORE_PATH . 'includes/class-ccb-core-settings-field.php';
     61
     62        // The class that handles communication with the CCB API.
     63        require_once CCB_CORE_PATH . 'includes/class-ccb-core-api.php';
     64
     65        // The class that handles synchronization logic.
     66        require_once CCB_CORE_PATH . 'includes/class-ccb-core-synchronizer.php';
     67
     68        // Custom Post Type classes.
     69        require_once CCB_CORE_PATH . 'includes/post-types/class-ccb-core-cpt.php';
     70        require_once CCB_CORE_PATH . 'includes/post-types/class-ccb-core-group.php';
     71        require_once CCB_CORE_PATH . 'includes/post-types/class-ccb-core-calendar.php';
     72
     73        // Custom Taxonomy classes.
     74        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-taxonomy.php';
     75        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-calendar-event-type.php';
     76        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-calendar-group-name.php';
     77        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-calendar-grouping-name.php';
     78        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-area.php';
     79        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-day.php';
     80        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-department.php';
     81        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-tag.php';
     82        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-time.php';
     83        require_once CCB_CORE_PATH . 'includes/taxonomies/class-ccb-core-group-type.php';
     84
     85        // Admin AJAX methods.
     86        require_once CCB_CORE_PATH . 'includes/class-ccb-core-admin-ajax.php';
     87
     88        // Cron Management.
     89        require_once CCB_CORE_PATH . 'includes/class-ccb-core-cron.php';
     90
     91    }
     92
     93    /**
     94     * Register all of the hooks related to the dashboard functionality
     95     * of the plugin.
    7496     *
    7597     * @since    0.9.0
    7698     * @access   private
    7799     */
    78     private function load_dependencies() {
    79 
    80         // encryption class to provide better security and ease of use
    81         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'lib/Encryption/Encryption.php';
    82 
    83         // the class responsible for orchestrating the actions and filters of the core plugin.
    84         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ccb-core-loader.php';
    85 
    86         // the class responsible for defining internationalization functionality of the plugin.
    87         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ccb-core-i18n.php';
    88 
    89         // the class that defines options and settings for the plugin
    90         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-settings.php';
    91         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-settings-page.php';
    92         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-settings-section.php';
    93         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-settings-field.php';
    94 
    95         // the class responsible for defining all actions that occur in the Dashboard.
    96         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-admin.php';
    97 
    98         // the class that handles data synchronization between CCB and the local cache
    99         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-sync.php';
    100 
    101         // the class that handles data synchronization between CCB and the local cache
    102         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ccb-core-cpts.php';
    103 
    104         // instantiate the loader
    105         $this->loader = new CCB_Core_Loader();
    106 
    107     }
    108 
    109     /**
    110      * Define the locale for this plugin for internationalization.
    111      *
    112      * Uses the CCB_Core_i18n class in order to set the domain and to register the hook
    113      * with WordPress.
    114      *
     100    private function define_hooks() {
     101
     102        // Internationalization.
     103        add_action( 'plugins_loaded', [ $this, 'load_plugin_textdomain' ] );
     104
     105        // Check the plugin / database version and run any required upgrades.
     106        add_action( 'plugins_loaded', [ $this, 'check_version' ] );
     107
     108        // Plugin settings, menus, options.
     109        add_filter( 'plugin_action_links_' . CCB_CORE_BASENAME, [ $this, 'add_settings_link' ] );
     110
     111        // Setup settings pages.
     112        add_action( 'admin_menu', [ $this, 'initialize_settings_menu' ] );
     113        add_action( 'admin_init', [ $this, 'initialize_settings' ] );
     114
     115        // Callback for after the options are saved.
     116        add_action( 'update_option_ccb_core_settings', [ $this, 'updated_options' ], 10, 2 );
     117
     118        // Determine if the rewrite rules need to be flushed.
     119        add_action( 'init', [ $this, 'check_rewrite_rules' ] );
     120
     121        add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] );
     122        add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
     123
     124    }
     125
     126    /**
     127     * Load the plugin text domain for translation.
     128     *
     129     * @since   0.9.0
     130     */
     131    public function load_plugin_textdomain() {
     132
     133        load_plugin_textdomain(
     134            'ccb-core',
     135            false,
     136            dirname( CCB_CORE_BASENAME ) . '/languages/'
     137        );
     138
     139    }
     140
     141    /**
     142     * Check the current plugin version and kick off any applicable upgrades.
     143     *
     144     * @return void
     145     */
     146    public function check_version() {
     147        $current_version = get_option( 'ccb_core_version' );
     148
     149        // We are currently up to date.
     150        if ( version_compare( $current_version, CCB_CORE_VERSION, '>=' ) ) {
     151            return;
     152        }
     153
     154        // Upgrade to version 1.0.0.
     155        if ( version_compare( $current_version, '1.0.0', '<' ) ) {
     156            $this->upgrade_to_1_0_0();
     157        }
     158
     159        // Update the DB version.
     160        update_option( 'ccb_core_version', CCB_CORE_VERSION );
     161    }
     162
     163    /**
     164     * Create a helpful settings link on the plugin page
     165     *
     166     * @param    array $links An array of links.
     167     * @access   public
    115168     * @since    0.9.0
    116      * @access   private
    117      */
    118     private function set_locale() {
    119 
    120         $plugin_i18n = new CCB_Core_i18n();
    121         $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
    122 
    123     }
    124 
    125     /**
    126      * Register all of the hooks related to the dashboard functionality
    127      * of the plugin.
    128      *
     169     * @return   array
     170     */
     171    public function add_settings_link( $links ) {
     172        $links[] = '<a href="' . esc_url( get_admin_url( null, 'admin.php?page=ccb_core_settings' ) ) . '">' . esc_html__( 'Settings', 'ccb-core' ) . '</a>';
     173        return $links;
     174    }
     175
     176    /**
     177     * Initialize the Settings Menu and Page
     178     *
     179     * @access   public
    129180     * @since    0.9.0
    130      * @access   private
    131      */
    132     private function define_admin_hooks() {
    133 
    134         $plugin_admin = new CCB_Core_Admin();
    135 
    136         $this->loader->add_action( 'init', $plugin_admin, 'initialize_custom_post_types' );
    137         $this->loader->add_action( 'admin_menu', $plugin_admin, 'initialize_settings_menu' );
    138         $this->loader->add_action( 'admin_init', $plugin_admin, 'initialize_settings' );
    139         $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
    140         $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    141         $this->loader->add_filter( 'plugin_action_links_' . $this->plugin_basename, $plugin_admin, 'add_settings_link' );
    142         $this->loader->add_action( 'schedule_auto_refresh', $plugin_admin, 'auto_sync' );
    143         $this->loader->add_action( 'wp_loaded', $plugin_admin, 'check_auto_refresh' );
    144         $this->loader->add_action( 'pre_update_option_' . $this->plugin_settings_name, $plugin_admin, 'update_settings_callback', 10, 2 );
    145         $this->loader->add_action( 'schedule_flush_rewrite_rules', $plugin_admin, 'flush_rewrite_rules_event' );
    146 
    147         // all backend ajax hooks
    148         $this->loader->add_action( 'wp_ajax_sync', $plugin_admin, 'ajax_sync' );
    149         $this->loader->add_action( 'wp_ajax_poll_sync', $plugin_admin, 'ajax_poll_sync' );
    150         $this->loader->add_action( 'wp_ajax_test_credentials', $plugin_admin, 'ajax_test_credentials' );
    151         $this->loader->add_action( 'wp_ajax_get_latest_sync', $plugin_admin, 'ajax_get_latest_sync' );
    152 
    153     }
    154 
    155     /**
    156      * Run the loader to execute all of the hooks with WordPress.
    157      *
     181     * @return   void
     182     */
     183    public function initialize_settings_menu() {
     184
     185        $settings = new CCB_Core_Settings();
     186        $settings_page = new CCB_Core_Settings_Page( 'ccb_core_settings' );
     187
     188        add_menu_page(
     189            __( 'Church Community Builder Core API', 'ccb-core' ),
     190            __( 'CCB Core API', 'ccb-core' ),
     191            /**
     192             * Defines the capability that is required for the user
     193             * to access the settings page.
     194             *
     195             * @since 1.0.0
     196             *
     197             * @param string $capability The capability required to access the page.
     198             */
     199            apply_filters( 'ccb_core_settings_capability', 'manage_options' ),
     200            'ccb_core_settings',
     201            '__return_null',
     202            'dashicons-update',
     203            '80.9'
     204        );
     205
     206        foreach ( $settings->get_settings_definitions() as $page_id => $page ) {
     207            $settings_page = new CCB_Core_Settings_Page( $page_id );
     208            add_submenu_page(
     209                'ccb_core_settings',
     210                $page['page_title'],
     211                $page['page_title'],
     212                apply_filters( 'ccb_core_settings_capability', 'manage_options' ),
     213                $page_id,
     214                [
     215                    $settings_page,
     216                    'render_page',
     217                ]
     218            );
     219        }
     220    }
     221
     222    /**
     223     * Initialize the Settings
     224     *
     225     * @access   public
    158226     * @since    0.9.0
    159      */
    160     public function run() {
    161         $this->loader->run();
    162     }
    163 
    164     /**
    165      * The reference to the class that orchestrates the hooks with the plugin.
    166      *
    167      * @since     0.9.0
    168      * @return    CCB_Core_Loader    Orchestrates the hooks of the plugin.
    169      */
    170     public function get_loader() {
    171         return $this->loader;
     227     * @return   void
     228     */
     229    public function initialize_settings() {
     230
     231        $settings = new CCB_Core_Settings();
     232
     233        foreach ( $settings->get_settings_definitions() as $page_id => $page ) {
     234
     235            register_setting( $page_id, 'ccb_core_settings', [ $settings, 'validate_settings' ] );
     236
     237            foreach ( $page['sections'] as $section_id => $section ) {
     238
     239                $settings_section = new CCB_Core_Settings_Section( $section_id, $section );
     240                add_settings_section(
     241                    $section_id,
     242                    $section['section_title'],
     243                    [
     244                        $settings_section,
     245                        'render_section',
     246                    ],
     247                    $page_id
     248                );
     249
     250                if ( ! empty( $section['fields'] ) ) {
     251                    foreach ( $section['fields'] as $field_id => $field ) {
     252
     253                        $settings_field = new CCB_Core_Settings_Field( $field_id, $field );
     254                        add_settings_field(
     255                            $field_id,
     256                            $field['field_title'],
     257                            [
     258                                $settings_field,
     259                                'render_field',
     260                            ],
     261                            $page_id,
     262                            $section_id
     263                        );
     264
     265                    }
     266                }
     267
     268            }
     269
     270        }
     271
     272    }
     273
     274    /**
     275     * After the options are saved, check to see if we
     276     * should flush the rewrite rules.
     277     *
     278     * @param    array $old_value The previous option value.
     279     * @param    array $value The new option value.
     280     * @access   public
     281     * @since    1.0.0
     282     * @return   void
     283     */
     284    public function updated_options( $old_value, $value ) {
     285
     286        // Create a collection of settings that, if they change, should
     287        // trigger a flush_rewrite_rules event.
     288        $setting_array = [
     289            'groups_enabled',
     290            'groups_slug',
     291            'calendar_enabled',
     292            'calendar_slug',
     293        ];
     294
     295        foreach ( $setting_array as $setting ) {
     296            if ( isset( $value[ $setting ] ) ) {
     297                if ( ! isset( $old_value[ $setting ] ) || $value[ $setting ] !== $old_value[ $setting ] ) {
     298                    // At least one option requires a flush, so set the transient and return.
     299                    set_transient( 'ccb_core_flush_rewrite_rules', true );
     300                    return;
     301                }
     302            }
     303        }
     304
     305    }
     306
     307    /**
     308     * Checks for a flag that may have been previously
     309     * set in order to flush the rewrite rules.
     310     *
     311     * @return void
     312     */
     313    public function check_rewrite_rules() {
     314        if ( get_transient( 'ccb_core_flush_rewrite_rules' ) ) {
     315            delete_transient( 'ccb_core_flush_rewrite_rules' );
     316            flush_rewrite_rules();
     317        }
     318    }
     319
     320    /**
     321     * Register the stylesheets for the dashboard.
     322     *
     323     * @param string $hook Current admin page.
     324     * @return void
     325     */
     326    public function enqueue_styles( $hook ) {
     327
     328        if ( false !== stristr( $hook, 'ccb_core_settings' ) ) {
     329            wp_enqueue_style( 'ccb-core', CCB_CORE_URL . 'css/ccb-core-admin.css', [], CCB_CORE_VERSION, 'all' );
     330            wp_enqueue_style( 'switchery', CCB_CORE_URL . 'css/vendor/switchery.min.css', [], CCB_CORE_VERSION, 'all' );
     331            wp_enqueue_style( 'powerange', CCB_CORE_URL . 'css/vendor/powerange.min.css', [], CCB_CORE_VERSION, 'all' );
     332            wp_enqueue_style( 'picker', CCB_CORE_URL . 'css/vendor/default.css', [], CCB_CORE_VERSION, 'all' );
     333            wp_enqueue_style( 'picker-date', CCB_CORE_URL . 'css/vendor/default.date.css', [], CCB_CORE_VERSION, 'all' );
     334            wp_enqueue_style( 'tipr', CCB_CORE_URL . 'css/vendor/tipr.css', [], CCB_CORE_VERSION, 'all' );
     335        }
     336
     337    }
     338
     339    /**
     340     * Register the scripts for the dashboard.
     341     *
     342     * @param string $hook Current admin page.
     343     * @return void
     344     */
     345    public function enqueue_scripts( $hook ) {
     346
     347        if ( false !== stristr( $hook, 'ccb_core_settings' ) ) {
     348            wp_enqueue_script( 'ccb-core', CCB_CORE_URL . 'js/ccb-core-admin.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     349            wp_enqueue_script( 'switchery', CCB_CORE_URL . 'js/vendor/switchery.min.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     350            wp_enqueue_script( 'powerange', CCB_CORE_URL . 'js/vendor/powerange.min.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     351            wp_enqueue_script( 'picker', CCB_CORE_URL . 'js/vendor/picker.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     352            wp_enqueue_script( 'picker-date', CCB_CORE_URL . 'js/vendor/picker.date.js', [ 'picker' ], CCB_CORE_VERSION, false );
     353            wp_enqueue_script( 'tipr', CCB_CORE_URL . 'js/vendor/tipr.min.js', [ 'jquery' ], CCB_CORE_VERSION, false );
     354            wp_localize_script(
     355                'ccb-core',
     356                'CCB_CORE_SETTINGS',
     357                [
     358                    'nonce' => wp_create_nonce( 'ccb_core_nonce' ),
     359                    'translations' => [
     360                        'credentialsSuccessful' => esc_html__( 'The credentials were successfully authenticated.', 'ccb-core' ),
     361                        'credentialsFailed' => esc_html__( 'The credentials failed authentication', 'ccb-core' ),
     362                        'syncInProgress' => esc_html__( 'Syncronization in progress... You can safely navigate away from this page while we work in the background.', 'ccb-core' ),
     363                    ],
     364                ]
     365            );
     366        }
     367
     368    }
     369
     370    /**
     371     * Converts any legacy options to the new format
     372     *
     373     * @return void
     374     */
     375    private function upgrade_to_1_0_0() {
     376        $current_options = CCB_Core_Helpers::instance()->get_options();
     377        $updated_options = [];
     378        $options_hash = [
     379            'subdomain' => 'subdomain',
     380            'credentials' => 'credentials',
     381            'groups-enabled' => 'groups_enabled',
     382            'groups-name' => 'groups_name',
     383            'groups-slug' => 'groups_slug',
     384            'groups-import-images' => 'groups_import_images',
     385            'groups-advanced' => 'groups_advanced',
     386            'groups-exclude-from-search' => 'groups_exclude_from_search',
     387            'groups-publicly-queryable' => 'groups_publicly_queryable',
     388            'groups-show-ui' => 'groups_show_ui',
     389            'groups-show-in-nav-menus' => 'groups_show_in_nav_menus',
     390            'calendar-enabled' => 'calendar_enabled',
     391            'calendar-name' => 'calendar_name',
     392            'calendar-slug' => 'calendar_slug',
     393            'calendar-advanced' => 'calendar_advanced',
     394            'calendar-date-range-type' => 'calendar_date_range_type',
     395            'calendar-relative-weeks-past' => 'calendar_relative_weeks_past',
     396            'calendar-relative-weeks-future' => 'calendar_relative_weeks_future',
     397            'calendar-specific-start' => 'calendar_specific_start',
     398            'calendar-specific-end' => 'calendar_specific_end',
     399            'calendar-exclude-from-search' => 'calendar_exclude_from_search',
     400            'calendar-publicly-queryable' => 'calendar_publicly_queryable',
     401            'calendar-show-ui' => 'calendar_show_ui',
     402            'calendar-show-in-nav-menus' => 'calendar_show_in_nav_menus',
     403        ];
     404
     405        if ( ! empty( $current_options ) ) {
     406            foreach ( $options_hash as $old => $new ) {
     407                if ( isset( $current_options[ $old ] ) ) {
     408                    $updated_options[ $new ] = $current_options[ $old ];
     409                }
     410            }
     411            update_option( 'ccb_core_settings', $updated_options );
     412        }
    172413    }
    173414
  • church-community-builder-core-api/trunk/index.php

    r1189910 r1798690  
    1 <?php // Silence is golden
     1<?php // phpcs:disable
Note: See TracChangeset for help on using the changeset viewer.