| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Scroll Down Arrow |
| 4 |
* Plugin URI: https://www.echoknowledgebase.com/documentation/how-to-use-scroll-down-arrow/ |
| 5 |
* Description: Give users a visual clue that there is more content further down the page. |
| 6 |
* Version: 1.2.0 |
| 7 |
* Author: Echo Plugins |
| 8 |
* Author URI: https://www.echoknowledgebase.com |
| 9 |
* Text Domain: scroll-down-arrow |
| 10 |
* Domain Path: /languages |
| 11 |
* License: GPLv2 or later |
| 12 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 13 |
* |
| 14 |
* Scroll Down Arrow is distributed under the terms of the GNU General Public License as published by |
| 15 |
* the Free Software Foundation, either version 2 of the License, or |
| 16 |
* any later version. |
| 17 |
* |
| 18 |
* Scroll Down Arrow is distributed in the hope that it will be useful, |
| 19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
* GNU General Public License for more details. |
| 22 |
* |
| 23 |
* You should have received a copy of the GNU General Public License |
| 24 |
* along with Down Arrow. If not, see <http://www.gnu.org/licenses/>. |
| 25 |
* |
| 26 |
*/ |
| 27 |
|
| 28 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 29 |
|
| 30 |
if ( ! defined( 'EPDA_PLUGIN_NAME' ) ) { |
| 31 |
define( 'EPDA_PLUGIN_NAME', 'Scroll Down Arrow' ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Main class to load the plugin. |
| 36 |
* |
| 37 |
* Singleton |
| 38 |
*/ |
| 39 |
final class EPDA_Scroll_Down_Arrow { |
| 40 |
|
| 41 |
/* @var EPDA_Scroll_Down_Arrow */ |
| 42 |
private static $instance; |
| 43 |
|
| 44 |
public static $version = '1.2.0'; |
| 45 |
public static $plugin_dir; |
| 46 |
public static $plugin_url; |
| 47 |
public static $plugin_file = __FILE__; |
| 48 |
|
| 49 |
/* @var EPDA_Config_DB */ |
| 50 |
public $da_config_obj; |
| 51 |
|
| 52 |
/** |
| 53 |
* Initialise the plugin |
| 54 |
*/ |
| 55 |
private function __construct() { |
| 56 |
self::$plugin_dir = plugin_dir_path( __FILE__ ); |
| 57 |
self::$plugin_url = plugin_dir_url( __FILE__ ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Retrieve or create a new instance of this main class (avoid global vars) |
| 62 |
* |
| 63 |
* @static |
| 64 |
* @return EPDA_Scroll_Down_Arrow |
| 65 |
*/ |
| 66 |
public static function instance() { |
| 67 |
|
| 68 |
if ( ! empty( self::$instance ) && ( self::$instance instanceof EPDA_Scroll_Down_Arrow ) ) { |
| 69 |
return self::$instance; |
| 70 |
} |
| 71 |
|
| 72 |
self::$instance = new EPDA_Scroll_Down_Arrow(); |
| 73 |
self::$instance->setup_system(); |
| 74 |
self::$instance->setup_plugin(); |
| 75 |
|
| 76 |
add_action( 'plugins_loaded', array( self::$instance, 'load_text_domain' ), 11 ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Setup class autoloading and other support functions. Setup custom core features. |
| 81 |
*/ |
| 82 |
private function setup_system() { |
| 83 |
|
| 84 |
// autoload classes ONLY when needed by executed code rather than on every page request |
| 85 |
require_once self::$plugin_dir . 'includes/system/class-epda-autoloader.php'; |
| 86 |
|
| 87 |
// register settings |
| 88 |
self::$instance->da_config_obj = new EPDA_Config_DB(); |
| 89 |
|
| 90 |
// load non-classes |
| 91 |
require_once self::$plugin_dir . 'includes/system/plugin-setup.php'; |
| 92 |
require_once self::$plugin_dir . 'includes/system/scripts-registration.php'; |
| 93 |
require_once self::$plugin_dir . 'includes/system/plugin-links.php'; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Setup plugin before it runs. Include functions and instantiate classes based on user action |
| 98 |
*/ |
| 99 |
private function setup_plugin() { |
| 100 |
|
| 101 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 102 |
new EPDA_Config_Ctrl(); |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
// ADMIN or CLI |
| 107 |
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
| 108 |
$this->setup_backend_classes(); |
| 109 |
return; |
| 110 |
} |
| 111 |
|
| 112 |
// FRONT-END with admin-bar |
| 113 |
|
| 114 |
// FRONT-END (no ajax, possibly admin bar) |
| 115 |
|
| 116 |
new EPDA_Arrow_View(); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Setup up classes when on ADMIN pages |
| 121 |
*/ |
| 122 |
private function setup_backend_classes() { |
| 123 |
|
| 124 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Verified elsewhere. |
| 125 |
$request_page = empty( $_REQUEST['page'] ) ? '' : sanitize_key( $_REQUEST['page'] ); |
| 126 |
|
| 127 |
// admin core classes |
| 128 |
require_once self::$plugin_dir . 'includes/admin/admin-menu.php'; |
| 129 |
require_once self::$plugin_dir . 'includes/admin/admin-functions.php'; |
| 130 |
|
| 131 |
// Down Arrow request |
| 132 |
if ( in_array( $request_page, ['epda-down-arrow', 'epda-down-arrow-config'] ) ) { |
| 133 |
|
| 134 |
add_action( 'admin_enqueue_scripts', 'epda_load_admin_plugin_pages_resources' ); |
| 135 |
|
| 136 |
switch ( $request_page ) { |
| 137 |
// Configuration page |
| 138 |
case 'epda-down-arrow-config': |
| 139 |
add_action( 'admin_enqueue_scripts', 'epda_load_admin_config_script' ); |
| 140 |
break; |
| 141 |
|
| 142 |
default: break; |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
/** |
| 149 |
* Loads the plugin language files from ./languages directory. |
| 150 |
*/ |
| 151 |
public function load_text_domain() { |
| 152 |
load_plugin_textdomain( 'scroll-down-arrow', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 153 |
} |
| 154 |
|
| 155 |
// Don't allow this singleton to be cloned. |
| 156 |
public function __clone() { |
| 157 |
_doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' ); |
| 158 |
} |
| 159 |
|
| 160 |
// Don't allow un-serializing of the class except when testing |
| 161 |
public function __wakeup() { |
| 162 |
_doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' ); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Returns the single instance of this class |
| 168 |
* @return EPDA_Scroll_Down_Arrow - this class instance |
| 169 |
*/ |
| 170 |
function epda_get_instance() { |
| 171 |
return EPDA_Scroll_Down_Arrow::instance(); |
| 172 |
} |
| 173 |
epda_get_instance(); |