wordpress-popup
Last commit date
assets
2 years ago
inc
2 years ago
languages
2 years ago
lib
3 years ago
vendor
3 years ago
views
2 years ago
humans.txt
2 years ago
license.txt
5 years ago
popover.php
2 years ago
readme.txt
2 years ago
uninstall.php
3 years ago
popover.php
337 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Hustle plugin. |
| 4 | * |
| 5 | * @link http://wpmudev.com/projects/hustle/ |
| 6 | * @since 1.0.0 |
| 7 | * @package Hustle |
| 8 | * |
| 9 | * @wordpress-plugin |
| 10 | * Plugin Name: Hustle |
| 11 | * Plugin URI: https://wordpress.org/plugins/wordpress-popup/ |
| 12 | * Description: Start collecting email addresses and quickly grow your mailing list with big bold pop-ups, slide-ins, widgets, or in post opt-in forms. |
| 13 | * Version: 7.8.2 |
| 14 | * Author: WPMU DEV |
| 15 | * Author URI: https://wpmudev.com |
| 16 | * Tested up to: 6.4 |
| 17 | * Requires PHP: 7.4 |
| 18 | * Text Domain: hustle |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | // +----------------------------------------------------------------------+ |
| 23 | // | Copyright Incsub (http://incsub.com/) | |
| 24 | // +----------------------------------------------------------------------+ |
| 25 | // | This program is free software; you can redistribute it and/or modify | |
| 26 | // | it under the terms of the GNU General Public License, version 2, as | |
| 27 | // | published by the Free Software Foundation. | |
| 28 | // | | |
| 29 | // | This program is distributed in the hope that it will be useful, | |
| 30 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 31 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 32 | // | GNU General Public License for more details. | |
| 33 | // | | |
| 34 | // | You should have received a copy of the GNU General Public License | |
| 35 | // | along with this program; if not, write to the Free Software | |
| 36 | // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
| 37 | // | MA 02110-1301 USA | |
| 38 | // +----------------------------------------------------------------------+ |
| 39 | |
| 40 | if ( ! defined( 'HUSTLE_MIN_PHP_VERSION' ) ) { |
| 41 | define( 'HUSTLE_MIN_PHP_VERSION', '7.4' ); |
| 42 | } |
| 43 | |
| 44 | if ( ! function_exists( 'hustle_insecure_php_version_notice' ) ) { |
| 45 | /** |
| 46 | * Display admin notice, if the site is using unsupported PHP version. |
| 47 | */ |
| 48 | function hustle_insecure_php_version_notice() { |
| 49 | |
| 50 | ?> |
| 51 | <div class="notice notice-error"> |
| 52 | <p> |
| 53 | <?php |
| 54 | printf( |
| 55 | wp_kses( /* translators: %1$s - URL to an article about our hosting benefits. */ |
| 56 | __( 'Your site is running an outdated version of PHP that is no longer supported or receiving security updates. Please update PHP to at least version %1$s at your current hosting provider in order to activate Hustle, or consider switching to <a href="%2$s" target="_blank" rel="noopener noreferrer">WPMU DEV Hosting</a>.', 'hustle' ), |
| 57 | array( |
| 58 | 'a' => array( |
| 59 | 'href' => array(), |
| 60 | 'target' => array(), |
| 61 | 'rel' => array(), |
| 62 | ), |
| 63 | 'strong' => array(), |
| 64 | ) |
| 65 | ), |
| 66 | esc_html( HUSTLE_MIN_PHP_VERSION ), |
| 67 | 'https://wpmudev.com/hosting/' |
| 68 | ); |
| 69 | ?> |
| 70 | </p> |
| 71 | </div> |
| 72 | |
| 73 | <?php |
| 74 | |
| 75 | // In case this is on plugin activation. |
| 76 | if ( isset( $_GET['activate'] ) ) { //phpcs:ignore |
| 77 | unset( $_GET['activate'] ); //phpcs:ignore |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Display admin notice and prevent plugin code execution, if the server is |
| 84 | * using old/insecure PHP version. |
| 85 | */ |
| 86 | if ( version_compare( phpversion(), HUSTLE_MIN_PHP_VERSION, '<' ) ) { |
| 87 | add_action( 'admin_notices', 'hustle_insecure_php_version_notice' ); |
| 88 | |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | add_action( 'activated_plugin', 'hustle_activated', 10, 2 ); |
| 94 | |
| 95 | if ( ! function_exists( 'hustle_activated' ) ) { |
| 96 | |
| 97 | /** |
| 98 | * Handles the deactivation of the free version if "pro" is active, and activation flags. |
| 99 | * |
| 100 | * @since unknown |
| 101 | * |
| 102 | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| 103 | * @param bool $network_activation Whether to enable the plugin for all sites in the network or just the current site. |
| 104 | */ |
| 105 | function hustle_activated( $plugin, $network_activation ) { |
| 106 | |
| 107 | if ( is_plugin_active( 'hustle/opt-in.php' ) && is_plugin_active( 'wordpress-popup/popover.php' ) ) { |
| 108 | |
| 109 | // deactivate free version. |
| 110 | deactivate_plugins( 'wordpress-popup/popover.php' ); |
| 111 | |
| 112 | if ( 'hustle/opt-in.php' === $plugin ) { |
| 113 | // Store in database about free version deactivated, in order to show a notice on page load. |
| 114 | update_site_option( 'hustle_free_deactivated', 1 ); |
| 115 | } elseif ( 'wordpress-popup/popover.php' === $plugin ) { |
| 116 | // Store in database about free version being activated even pro is already active. |
| 117 | update_site_option( 'hustle_free_activated', 1 ); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // Require autoloader. |
| 124 | if ( ! class_exists( 'ComposerAutoloaderInitda98371940d11703c56dee923bbb392f' ) ) { |
| 125 | require_once dirname( __FILE__ ) . '/vendor/autoload.php'; |
| 126 | } |
| 127 | |
| 128 | if ( ! defined( 'HUSTLE_SUI_VERSION' ) ) { |
| 129 | define( 'HUSTLE_SUI_VERSION', '2.12.22' ); |
| 130 | } |
| 131 | |
| 132 | if ( ! class_exists( 'Opt_In' ) ) { |
| 133 | |
| 134 | /** |
| 135 | * Opt_In class. |
| 136 | */ |
| 137 | class Opt_In { |
| 138 | |
| 139 | const VERSION = '4.8.2'; |
| 140 | |
| 141 | const VIEWS_FOLDER = 'views'; |
| 142 | |
| 143 | /** |
| 144 | * Base file. |
| 145 | * |
| 146 | * @since 1.0.0 |
| 147 | * @var string |
| 148 | */ |
| 149 | public static $plugin_base_file; |
| 150 | |
| 151 | /** |
| 152 | * Plugin URL. |
| 153 | * |
| 154 | * @since 1.0.0 |
| 155 | * @var string |
| 156 | */ |
| 157 | public static $plugin_url; |
| 158 | |
| 159 | /** |
| 160 | * Plugin path. |
| 161 | * |
| 162 | * @since 1.0.0 |
| 163 | * @var string |
| 164 | */ |
| 165 | public static $plugin_path; |
| 166 | |
| 167 | /** |
| 168 | * Path to "vendor". |
| 169 | * |
| 170 | * @since 1.0.0 |
| 171 | * @var string |
| 172 | */ |
| 173 | public static $vendor_path; |
| 174 | |
| 175 | /** |
| 176 | * Path to "views" files. |
| 177 | * |
| 178 | * @since 1.0.0 |
| 179 | * @var string |
| 180 | */ |
| 181 | public static $template_path; |
| 182 | |
| 183 | /** |
| 184 | * Array container for the registered providers. |
| 185 | * |
| 186 | * @since 3.0.5 |
| 187 | * @var array |
| 188 | */ |
| 189 | protected static $registered_providers = array(); |
| 190 | |
| 191 | /** |
| 192 | * Opt_In constructor. |
| 193 | * |
| 194 | * @since 1.0.0 |
| 195 | */ |
| 196 | public function __construct() { |
| 197 | |
| 198 | self::$plugin_base_file = plugin_basename( __FILE__ ); |
| 199 | self::$plugin_url = plugin_dir_url( self::$plugin_base_file ); |
| 200 | self::$plugin_path = trailingslashit( dirname( __FILE__ ) ); |
| 201 | self::$vendor_path = self::$plugin_path . 'vendor/'; |
| 202 | self::$template_path = trailingslashit( dirname( __FILE__ ) ) . 'views/'; |
| 203 | |
| 204 | $this->load_text_domain(); |
| 205 | |
| 206 | // check caps. |
| 207 | add_action( 'admin_init', array( $this, 'hustle_check_caps' ), 999 ); |
| 208 | |
| 209 | new Hustle_Init(); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Returns list of optin providers based on their declared classes that implement Opt_In_Provider_Interface |
| 214 | * |
| 215 | * @return array |
| 216 | */ |
| 217 | public function get_providers() { |
| 218 | if ( empty( self::$registered_providers ) ) { |
| 219 | self::$registered_providers = Hustle_Provider_Utils::get_activable_providers_list(); |
| 220 | } |
| 221 | return self::$registered_providers; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Loads text domain |
| 226 | * |
| 227 | * @since 1.0.0 |
| 228 | */ |
| 229 | public function load_text_domain() { |
| 230 | load_plugin_textdomain( 'hustle', false, dirname( plugin_basename( self::$plugin_base_file ) ) . '/languages/' ); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Callback function when user migrates from 3x to 4x from ftp. |
| 235 | * The activation hook won't run we'd have to check it in init. |
| 236 | * |
| 237 | * @since 4.0.0 |
| 238 | */ |
| 239 | public function hustle_check_caps() { |
| 240 | $admin = get_role( 'administrator' ); |
| 241 | $roles = get_editable_roles(); |
| 242 | if ( ( $admin && ! $admin->has_cap( 'hustle_menu' ) ) || ( ! $admin && ! empty( $roles ) ) ) { |
| 243 | hustle_activation(); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | }; |
| 249 | |
| 250 | if ( ! function_exists( 'hustle_init' ) ) { |
| 251 | |
| 252 | /** |
| 253 | * Instantiate Opt_In |
| 254 | */ |
| 255 | function hustle_init() { |
| 256 | new Opt_In(); |
| 257 | } |
| 258 | |
| 259 | add_action( 'plugins_loaded', 'hustle_init' ); |
| 260 | } |
| 261 | |
| 262 | if ( ! function_exists( 'hustle_activation' ) ) { |
| 263 | |
| 264 | /** |
| 265 | * Handle tables creating if needed. |
| 266 | * |
| 267 | * @since unknown |
| 268 | */ |
| 269 | function hustle_activation() { |
| 270 | |
| 271 | if ( ! class_exists( 'Hustle_Db' ) ) { |
| 272 | require_once trailingslashit( dirname( __FILE__ ) ) . 'inc/hustle-db.php'; |
| 273 | } |
| 274 | update_option( 'hustle_activated_flag', 1 ); |
| 275 | |
| 276 | Hustle_Db::maybe_create_tables( true ); |
| 277 | |
| 278 | /** |
| 279 | * Add Hustle's custom capabilities. |
| 280 | * |
| 281 | * @since 4.0.1 |
| 282 | */ |
| 283 | $hustle_capabilities = array( |
| 284 | 'hustle_menu', |
| 285 | 'hustle_edit_module', |
| 286 | 'hustle_create', |
| 287 | 'hustle_edit_integrations', |
| 288 | 'hustle_access_emails', |
| 289 | 'hustle_edit_settings', |
| 290 | 'hustle_analytics', |
| 291 | ); |
| 292 | |
| 293 | $admin = get_role( 'administrator' ); |
| 294 | |
| 295 | if ( $admin ) { |
| 296 | // If there's an "administrator" role. |
| 297 | foreach ( $hustle_capabilities as $cap ) { |
| 298 | $admin->add_cap( $cap ); |
| 299 | } |
| 300 | } else { |
| 301 | // If there's no "administrator". |
| 302 | $roles = get_editable_roles(); |
| 303 | |
| 304 | foreach ( $roles as $role_name => $data ) { |
| 305 | |
| 306 | // Add the capabilities to anyone who can manage options. This was the checked capability in 3.x. |
| 307 | if ( isset( $data['capabilities']['manage_options'] ) && $data['capabilities']['manage_options'] ) { |
| 308 | |
| 309 | $role = get_role( $role_name ); |
| 310 | foreach ( $hustle_capabilities as $cap ) { |
| 311 | if ( $role ) { |
| 312 | $role->add_cap( $cap ); |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | } |
| 320 | } |
| 321 | register_activation_hook( __FILE__, 'hustle_activation' ); |
| 322 | |
| 323 | |
| 324 | if ( ! function_exists( 'hustle_deactivation' ) ) { |
| 325 | /** |
| 326 | * On deactivation hook |
| 327 | * |
| 328 | * @since 4.2.0 |
| 329 | */ |
| 330 | function hustle_deactivation() { |
| 331 | // Remove the cron for data protection cleanup. |
| 332 | wp_clear_scheduled_hook( 'hustle_general_data_protection_cleanup' ); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | register_deactivation_hook( __FILE__, 'hustle_deactivation' ); |
| 337 |