| @@ -2,13 +2,12 @@ | ||
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: LoftLoader |
| 4 | 4 | Plugin URI: http://www.loftocean.com/ |
| 5 | 5 | Description: An easy to use plugin to add an animated preloader to your website with fully customisations. |
| 6 | -Version: 1.0.1 | |
| 7 | -Author: Loft Ocean | |
| 6 | +Version: 2.3.3 | |
| 7 | +Author: Loft.Ocean | |
| 8 | 8 | Author URI: http://www.loftocean.com/ |
| 9 | 9 | Text Domain: loftloader |
| 10 | -Domain Path: /languages | |
| 11 | 10 | License: GPLv2 |
| 12 | 11 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 | 12 | */ |
| 14 | 13 | |
| @@ -14,79 +13,129 @@ | ||
| 14 | 13 | |
| 15 | 14 | |
| 16 | 15 | /** |
| 17 | 16 | * LoftLoader main file |
| 18 | - * | |
| 17 | + * | |
| 19 | 18 | * @package LoftLoader |
| 20 | - * @version 1.0 | |
| 21 | 19 | * @link http://www.loftocean.com/ |
| 22 | 20 | * @author Suihai Huang from Loft Ocean Team |
| 23 | 21 | */ |
| 24 | 22 | |
| 25 | 23 | // Not allowed by directly accessing. |
| 26 | -if(!defined('ABSPATH')){ | |
| 27 | - die('Access not allowed!'); | |
| 24 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 25 | + die( esc_html__( 'Access not allowed!', 'loftloader' ) ); | |
| 28 | 26 | } |
| 29 | 27 | |
| 30 | -if(!class_exists('LoftLoader')){ | |
| 31 | - register_activation_hook(__FILE__, 'loftloader_activate'); // | |
| 32 | - register_deactivation_hook(__FILE__, 'loftloader_deactivate'); | |
| 33 | - /* | |
| 34 | - * Update the plugin version for initial version | |
| 35 | - */ | |
| 36 | - function loftloader_activate(){ | |
| 37 | - update_option('loftloader_plugin_version', '1.0.0'); | |
| 38 | - } | |
| 28 | +if ( ! class_exists( 'LoftLoader' ) ) { | |
| 39 | 29 | /** |
| 40 | - * Do nothing for initial version | |
| 41 | - */ | |
| 42 | - function loftloader_deactivate(){ } | |
| 43 | - /** | |
| 44 | 30 | * Define the constant used in this plugin |
| 45 | 31 | */ |
| 46 | - define('LOFTLOADER_ROOT', dirname(__FILE__) . '/'); | |
| 47 | - define('LOFTLOADER_NAME', plugin_basename( __FILE__ )); | |
| 48 | - define('LOFTLOADER_URI', plugin_dir_url( __FILE__ )); | |
| 49 | - define('LOFTLOADER_JS_URI', LOFTLOADER_URI . 'js/'); | |
| 50 | - define('LOFTLOADER_CSS_URI', LOFTLOADER_URI . 'css/'); | |
| 32 | + define( 'LOFTLOADER_ROOT', dirname( __FILE__ ) . '/' ); | |
| 33 | + define( 'LOFTLOADER_NAME', plugin_basename( __FILE__ ) ); | |
| 34 | + define( 'LOFTLOADER_URI', plugin_dir_url( __FILE__ ) ); | |
| 35 | + define( 'LOFTLOADER_ASSET_VERSION', '2020081301' ); | |
| 51 | 36 | |
| 52 | - /** | |
| 53 | - * Main plugin class | |
| 54 | - * @since version 1.0.0 | |
| 55 | - */ | |
| 56 | - class LoftLoader{ | |
| 57 | - public function __construct(){ | |
| 58 | - load_plugin_textdomain('loftloader', false, dirname(plugin_basename(__FILE__)) . '/languages/'); // Load the text domain | |
| 59 | - $this->load_configs(); | |
| 60 | - add_action('init', array($this, 'load_settings')); // Load the plugin settings | |
| 61 | - add_action('wp', array($this, 'load_front')); // Load the front main class | |
| 62 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_loader_styles')); | |
| 63 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_loader_styles')); | |
| 37 | + class LoftLoader { | |
| 38 | + public function __construct() { | |
| 39 | + load_plugin_textdomain( 'loftloader' ); | |
| 40 | + | |
| 41 | + $this->load_upgrade(); | |
| 42 | + $this->load_customize(); | |
| 43 | + | |
| 44 | + add_action( 'wp', array( $this, 'load_front' ) ); | |
| 45 | + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); | |
| 46 | + add_filter( 'plugin_action_links_' . LOFTLOADER_NAME, array( $this, 'plugin_action_links' ) ); | |
| 64 | 47 | } |
| 65 | 48 | /** |
| 66 | - * @description load configuration files | |
| 49 | + * For LoftLoader customize, load the customize related functions | |
| 67 | 50 | */ |
| 68 | - public function load_configs(){ | |
| 69 | - require_once LOFTLOADER_ROOT . 'configs/loftloader-config.php'; | |
| 51 | + function load_upgrade() { | |
| 52 | + require_once LOFTLOADER_ROOT . 'inc/class-loftloader-upgrade.php'; | |
| 70 | 53 | } |
| 71 | 54 | /** |
| 72 | - * @description load plugin settings main class | |
| 73 | - */ | |
| 74 | - public function load_settings(){ | |
| 75 | - is_admin() ? require_once LOFTLOADER_ROOT . 'settings/class-loftloader-settings.php' : ''; | |
| 55 | + * For LoftLoader upgrade, load the upgrade related functions | |
| 56 | + */ | |
| 57 | + function load_customize() { | |
| 58 | + require_once LOFTLOADER_ROOT . 'inc/class-loftloader-customize.php'; | |
| 76 | 59 | } |
| 60 | + | |
| 77 | 61 | /** |
| 78 | - * @description load plugin front main class | |
| 79 | - */ | |
| 80 | - public function load_front(){ | |
| 81 | - !is_admin() ? require_once LOFTLOADER_ROOT . 'front/class-loftloader-front.php' : ''; | |
| 62 | + * For LoftLoader front, load the front end related functions | |
| 63 | + */ | |
| 64 | + function load_front() { | |
| 65 | + require_once LOFTLOADER_ROOT . 'inc/class-loftloader-front.php'; | |
| 82 | 66 | } |
| 67 | + | |
| 83 | 68 | /** |
| 84 | - * @description register the loader style css for both plugin setting page and front end | |
| 69 | + * Add new setting link to loftloader | |
| 85 | 70 | */ |
| 86 | - public function enqueue_loader_styles(){ | |
| 87 | - wp_register_style('loftloader-animation', LOFTLOADER_CSS_URI . 'loftloader-animation.css', array(), '1.0'); | |
| 71 | + function plugin_action_links( $links ) { | |
| 72 | + $customize_url = $this->get_customize_uri(); | |
| 73 | + $action_links = array( | |
| 74 | + 'settings' => '<a href="' . $customize_url . '" title="' . esc_attr__('View LoftLoader Settings', 'loftloader') . '">' . esc_html__('Settings', 'loftloader') . '</a>' | |
| 75 | + ); | |
| 76 | + return array_merge( $action_links, $links ); | |
| 88 | 77 | } |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Add an admin menu for loftloader | |
| 81 | + */ | |
| 82 | + function admin_menu() { | |
| 83 | + global $submenu; | |
| 84 | + $customize_url = $this->get_customize_uri(); | |
| 85 | + $submenu['options-general.php'][] = array( esc_html__( 'LoftLoader Lite', 'loftloader' ), 'manage_options', $customize_url, 'hide-if-no-customize' ); | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * Helper function to get loftloader customize url | |
| 90 | + * @return url loftloader customize uri | |
| 91 | + */ | |
| 92 | + function get_customize_uri() { | |
| 93 | + $return_url = ''; | |
| 94 | + if ( ! empty( $_SERVER['REQUEST_URI'] ) ) { | |
| 95 | + $return_url = urlencode( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); | |
| 96 | + } | |
| 97 | + return add_query_arg( array('return' => $return_url, 'plugin' => 'loftloader-lite' ), 'customize.php' ); | |
| 98 | + } | |
| 89 | 99 | } |
| 90 | - new LoftLoader(); // Enable LoftLoader | |
| 100 | + | |
| 101 | + // Init loftloader lite | |
| 102 | + add_action( 'after_setup_theme', 'loftloader_init' ); | |
| 103 | + function loftloader_init() { | |
| 104 | + if ( ! class_exists( 'LoftLoader_Pro' ) ) { | |
| 105 | + new LoftLoader(); | |
| 106 | + } | |
| 107 | + } | |
| 108 | + | |
| 109 | + add_action( 'plugins_loaded', 'loftloader_any_page' ); | |
| 110 | + function loftloader_any_page() { | |
| 111 | + if ( ! class_exists( 'LoftLoader_Pro' ) ) { | |
| 112 | + $enable_any_page = get_option( 'loftloader_enable_any_page', '' ); | |
| 113 | + if ( $enable_any_page === 'on' ) { | |
| 114 | + require_once LOFTLOADER_ROOT . 'inc/any-page/class-loftloader-any-page.php'; | |
| 115 | + } | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + // Remove widget panels | |
| 120 | + add_filter( 'customize_loaded_components', 'loftloader_remove_widget_panels', 1000 ); | |
| 121 | + function loftloader_remove_widget_panels( $components ) { | |
| 122 | + if ( ! class_exists( 'LoftLoader_Pro' ) && ( isset( $_GET['plugin'] ) && ( $_GET['plugin'] === 'loftloader-lite' ) ) ) { | |
| 123 | + foreach ( $components as $i => $c ) { | |
| 124 | + if ( false !== $i ) { | |
| 125 | + unset( $components[ $i ] ); | |
| 126 | + } | |
| 127 | + } | |
| 128 | + } | |
| 129 | + return $components; | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * Helper function to test on loftloader customize page | |
| 134 | + * | |
| 135 | + * @return boolean | |
| 136 | + */ | |
| 137 | + function loftloader_is_customize() { | |
| 138 | + global $wp_customize; | |
| 139 | + return ( isset($_GET['plugin'] ) && ( $_GET['plugin'] === 'loftloader-lite') ) || ( isset( $wp_customize ) && $wp_customize->is_preview() && ! is_admin() ) || defined( 'DOING_AJAX' ); | |
| 140 | + } | |
| 91 | 141 | } |
| 92 | -?> | |