From 3477def745857d856f061758bbf428ee466e3287 Mon Sep 17 00:00:00 2001 From: Daniel Milner Date: Tue, 8 Sep 2020 13:41:18 -0700 Subject: [PATCH] Closes #18 --- ft-rockpress.php | 140 ++++++++++++++-------------- includes/class-rockpress-import.php | 56 ++++++----- readme.txt | 7 +- 3 files changed, 110 insertions(+), 93 deletions(-) diff --git a/ft-rockpress.php b/ft-rockpress.php index c903f38..689a348 100755 --- a/ft-rockpress.php +++ b/ft-rockpress.php @@ -3,7 +3,7 @@ * Plugin Name: RockPress * Plugin URI: https://rockpresswp.com/ * Description: Display information from Rock RMS on your WordPress site. - * Version: 1.0.15 + * Version: 1.0.16 * Author: RockPress * Author URI: https://rockpresswp.com/ * Text Domain: ft-rockpress @@ -28,15 +28,15 @@ */ class RockPress { - /** - * Instance - * - * @var RockPress The one true RockPress - * @since 1.0.0 - */ + /** + * Instance + * + * @var RockPress The one true RockPress + * @since 1.0.0 + */ private static $instance; - /** + /** * RockPress Transients Object * * @var object @@ -45,11 +45,11 @@ class RockPress { public $transients; /** - * Rock Object - * - * @var object - * @since 1.0.0 - */ + * Rock Object + * + * @var object + * @since 1.0.0 + */ public $rock; /** @@ -61,45 +61,45 @@ class RockPress { public $get; /** - * RockPress Version - * - * @var string - * @since 1.0.0 - */ - public $version = '1.0.15'; + * RockPress Version + * + * @var string + * @since 1.0.0 + */ + public $version = '1.0.15'; /** - * Main RockPress Instance - * - * Insures that only one instance of RockPress exists in memory at any - * one time. - * - * @since 1.0 - * @static - * @staticvar array $instance - * @uses RockPress::includes() Include the required files - * @see RockPress() - * @return The one true RockPress - */ - public static function instance() { - - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof RockPress ) ) { - - self::$instance = new RockPress; - self::$instance->setup_constants(); - self::$instance->includes(); + * Main RockPress Instance + * + * Insures that only one instance of RockPress exists in memory at any + * one time. + * + * @since 1.0 + * @static + * @staticvar array $instance + * @uses RockPress::includes() Include the required files + * @see RockPress() + * @return The one true RockPress + */ + public static function instance() { + + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof RockPress ) ) { + + self::$instance = new RockPress(); + self::$instance->setup_constants(); + self::$instance->includes(); self::$instance->actions(); self::$instance->register_addon(); - self::$instance->transients = new RockPress_Transients(); - self::$instance->rock = new RockPress_Rock_REST_API(); - self::$instance->get = new RockPress_Background_Get(); + self::$instance->transients = new RockPress_Transients(); + self::$instance->rock = new RockPress_Rock_REST_API(); + self::$instance->get = new RockPress_Background_Get(); - } + } - return self::$instance; + return self::$instance; - } + } /** * Setup plugin constants @@ -111,21 +111,21 @@ public static function instance() { private function setup_constants() { // Plugin Version. - if ( ! defined( 'ROCKPRESS_VERSION' ) ) { - define( 'ROCKPRESS_VERSION', $this->version ); - } + if ( ! defined( 'ROCKPRESS_VERSION' ) ) { + define( 'ROCKPRESS_VERSION', $this->version ); + } // Plugin File. - if ( ! defined( 'ROCKPRESS_PLUGIN_FILE' ) ) { - define( 'ROCKPRESS_PLUGIN_FILE', __FILE__ ); - } + if ( ! defined( 'ROCKPRESS_PLUGIN_FILE' ) ) { + define( 'ROCKPRESS_PLUGIN_FILE', __FILE__ ); + } - // Plugin Folder Path. - if ( ! defined( 'ROCKPRESS_PLUGIN_DIR' ) ) { - define( 'ROCKPRESS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); - } + // Plugin Folder Path. + if ( ! defined( 'ROCKPRESS_PLUGIN_DIR' ) ) { + define( 'ROCKPRESS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); + } - // Plugin Folder URL. + // Plugin Folder URL. if ( ! defined( 'ROCKPRESS_PLUGIN_URL' ) ) { define( 'ROCKPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); } @@ -141,11 +141,13 @@ private function setup_constants() { */ private function register_addon() { - $addon = new RockPress_Addon( array( - 'controllers' => array( - 'Campuses', - ), - ) ); + $addon = new RockPress_Addon( + array( + 'controllers' => array( + 'Campuses', + ), + ) + ); } @@ -159,16 +161,16 @@ private function register_addon() { private function includes() { require_once ROCKPRESS_PLUGIN_DIR . 'includes/class-rockpress-transients.php'; - require_once ROCKPRESS_PLUGIN_DIR . 'includes/class-rockpress-rest-api.php'; + require_once ROCKPRESS_PLUGIN_DIR . 'includes/class-rockpress-rest-api.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/class-rockpress-licenses.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/class-rockpress-addon.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/class-rockpress-options.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/class-rockpress-customizer.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/class-rockpress-blocks.php'; - require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/admin-settings.php'; - require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/settings/settings-rock.php'; + require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/admin-settings.php'; + require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/settings/settings-rock.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/settings/settings-import.php'; - require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/settings/settings-rockpress.php'; + require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/settings/settings-rockpress.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/settings/settings-licenses.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/admin-ajax.php'; require_once ROCKPRESS_PLUGIN_DIR . 'lib/wp-background-processing/wp-async-request.php'; @@ -179,16 +181,16 @@ private function includes() { require_once ROCKPRESS_PLUGIN_DIR . 'includes/widgets/widget-service-times.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/widgets/widget-campus-selector.php'; - if ( is_admin() ) { + if ( is_admin() ) { require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/admin-page-tabs.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/admin-pages.php'; - require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/admin-scripts.php'; + require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/admin-scripts.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/admin-styles.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/shortcodes/class-shortcode-button.php'; require_once ROCKPRESS_PLUGIN_DIR . 'includes/admin/shortcodes/class-shortcode-generator.php'; - } + } - } + } /** * Actions @@ -210,7 +212,7 @@ private function actions() { * @return void */ public function register_styles() { - wp_register_style( 'rockpress', ROCKPRESS_PLUGIN_URL . 'assets/css/display.css' ); + wp_register_style( 'rockpress', ROCKPRESS_PLUGIN_URL . 'assets/css/display.css', array(), ROCKPRESS_VERSION ); } /** diff --git a/includes/class-rockpress-import.php b/includes/class-rockpress-import.php index e982b2d..b2de1a0 100755 --- a/includes/class-rockpress-import.php +++ b/includes/class-rockpress-import.php @@ -2,8 +2,8 @@ /** * RockPress - Import * - * @since 0.2.0 - * @package RockPress + * @since 0.2.0 + * @package RockPress */ // Exit if accessed directly. @@ -24,14 +24,14 @@ class RockPress_Import { * @return void */ public static function init() { - add_action( 'rockpress_maintenance', __CLASS__ . '::run' ); - add_action( 'rockpress_import_job_queued', __CLASS__ . '::import_job_queued' ); - add_action( 'rockpress_import_jobs_dispatched', __CLASS__ . '::import_jobs_dispatched' ); - add_action( 'rockpress_background_get_complete', __CLASS__ . '::import_complete', 1000 ); - add_action( 'wp_ajax_rockpress_import', __CLASS__ . '::ajax_run' ); - add_action( 'wp_ajax_rockpress_import_status', __CLASS__ . '::ajax_status' ); - add_action( 'wp_ajax_rockpress_last_import', __CLASS__ . '::ajax_last_import' ); - add_action( 'wp_ajax_rockpress_reset_import', __CLASS__ . '::ajax_reset_import' ); + add_action( 'rockpress_maintenance', __CLASS__ . '::run' ); + add_action( 'rockpress_import_job_queued', __CLASS__ . '::import_job_queued' ); + add_action( 'rockpress_import_jobs_dispatched', __CLASS__ . '::import_jobs_dispatched' ); + add_action( 'rockpress_background_get_complete', __CLASS__ . '::import_complete', 1000 ); + add_action( 'wp_ajax_rockpress_import', __CLASS__ . '::ajax_run' ); + add_action( 'wp_ajax_rockpress_import_status', __CLASS__ . '::ajax_status' ); + add_action( 'wp_ajax_rockpress_last_import', __CLASS__ . '::ajax_last_import' ); + add_action( 'wp_ajax_rockpress_reset_import', __CLASS__ . '::ajax_reset_import' ); } @@ -124,7 +124,7 @@ public static function import_complete() { */ public static function ajax_run() { - if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'rockpress-nonce' ) ) { + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'rockpress-nonce' ) ) { die( esc_html__( 'Insufficient Permissions', 'ft-rockpress' ) ); } @@ -144,25 +144,31 @@ public static function ajax_run() { */ public static function ajax_status() { - if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'rockpress-nonce' ) ) { + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'rockpress-nonce' ) ) { die( esc_html__( 'Insufficient Permissions', 'ft-rockpress' ) ); } - $status = array(); + $status = array(); $progress = get_option( 'rockpress_import_in_progress', false ); if ( false === $progress ) { wp_send_json( 'false' ); } - array_push( $status, array( - 'text' => $progress, - 'element' => 'strong', - ) ); - array_push( $status, array( - 'text' => esc_html__( 'Import is running in the background. Leaving this page will not interrupt the process.', 'ft-rockpress' ), - 'element' => 'i', - ) ); + array_push( + $status, + array( + 'text' => $progress, + 'element' => 'strong', + ) + ); + array_push( + $status, + array( + 'text' => esc_html__( 'Import is running in the background. Leaving this page will not interrupt the process.', 'ft-rockpress' ), + 'element' => 'i', + ) + ); wp_send_json( $status ); @@ -177,7 +183,7 @@ public static function ajax_status() { */ public static function ajax_last_import() { - if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'rockpress-nonce' ) ) { + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'rockpress-nonce' ) ) { die( esc_html__( 'Insufficient Permissions', 'ft-rockpress' ) ); } @@ -198,6 +204,12 @@ public static function ajax_last_import() { * @return void */ public static function ajax_reset_import() { + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'rockpress-nonce' ) ) { + die( esc_html__( 'Insufficient Permissions', 'ft-rockpress' ) ); + } + + delete_option( 'rockpress_import_in_progress' ); + delete_option( 'rockpress_current_import' ); delete_option( 'rockpress_last_import' ); esc_html_e( 'Never', 'rockpress' ); wp_die(); diff --git a/readme.txt b/readme.txt index 9fe3c81..4ca0dc2 100755 --- a/readme.txt +++ b/readme.txt @@ -2,9 +2,9 @@ Contributors: firetree, danielmilner Tags: church, rockrms, chms, rock rms Requires at least: 4.3 -Tested up to: 5.4 +Tested up to: 5.5 Requires PHP: 5.3 -Stable tag: 1.0.15 +Stable tag: 1.0.16 License: GPLv2 or later License URI: http://ww.gnu.org/licenses/gpl-2.0.html @@ -41,6 +41,9 @@ Extend the capabilities of RockPress with these add-ons: == Changelog == += 1.0.16 = +* Fixed an issue when resetting an import. + = 1.0.15 = * Miscellaneous bug fixes.