display-conditions
6 years ago
helpers
6 years ago
metas
6 years ago
provider
6 years ago
providers
6 years ago
update
6 years ago
class-hustle-admin-page-abstract.php
6 years ago
class-hustle-condition-factory.php
6 years ago
class-hustle-dashboard-admin.php
6 years ago
class-hustle-data.php
6 years ago
class-hustle-db.php
6 years ago
class-hustle-module-collection.php
6 years ago
class-hustle-module-page-abstract.php
6 years ago
class-hustle-notifications.php
6 years ago
class-hustle-wp-dashboard-page.php
6 years ago
hustle-admin-common.php
6 years ago
hustle-collection.php
6 years ago
hustle-deletion.php
6 years ago
hustle-embedded-admin.php
6 years ago
hustle-entries-admin.php
6 years ago
hustle-entry-model.php
6 years ago
hustle-general-data-protection.php
6 years ago
hustle-init.php
6 years ago
hustle-mail.php
6 years ago
hustle-meta.php
6 years ago
hustle-migration.php
6 years ago
hustle-model.php
6 years ago
hustle-module-admin.php
6 years ago
hustle-module-decorator.php
6 years ago
hustle-module-front-ajax.php
6 years ago
hustle-module-front.php
6 years ago
hustle-module-model.php
6 years ago
hustle-module-renderer.php
6 years ago
hustle-module-widget-legacy.php
6 years ago
hustle-module-widget.php
6 years ago
hustle-modules-common-admin-ajax.php
6 years ago
hustle-modules-common-admin.php
6 years ago
hustle-popup-admin.php
6 years ago
hustle-providers-admin.php
6 years ago
hustle-providers.php
6 years ago
hustle-renderer-abstract.php
6 years ago
hustle-renderer-sshare.php
6 years ago
hustle-settings-admin-ajax.php
6 years ago
hustle-settings-admin.php
6 years ago
hustle-settings-page.php
6 years ago
hustle-slidein-admin.php
6 years ago
hustle-sshare-admin.php
6 years ago
hustle-sshare-model.php
6 years ago
hustle-tracking-model.php
6 years ago
opt-in-geo.php
6 years ago
opt-in-utils.php
6 years ago
opt-in-wpmudev-api.php
6 years ago
hustle-module-admin.php
698 lines
| 1 | <?php |
| 2 | if ( ! class_exists( 'Hustle_Module_Admin' ) ) : |
| 3 | |
| 4 | /** |
| 5 | * Class Hustle_Module_Admin |
| 6 | */ |
| 7 | class Hustle_Module_Admin { |
| 8 | |
| 9 | const ADMIN_PAGE = 'hustle'; |
| 10 | const DASHBOARD_PAGE = 'hustle_dashboard'; |
| 11 | const POPUP_LISTING_PAGE = 'hustle_popup_listing'; |
| 12 | const POPUP_WIZARD_PAGE = 'hustle_popup'; |
| 13 | const SLIDEIN_LISTING_PAGE = 'hustle_slidein_listing'; |
| 14 | const SLIDEIN_WIZARD_PAGE = 'hustle_slidein'; |
| 15 | const EMBEDDED_LISTING_PAGE = 'hustle_embedded_listing'; |
| 16 | const EMBEDDED_WIZARD_PAGE = 'hustle_embedded'; |
| 17 | const SOCIAL_SHARING_LISTING_PAGE = 'hustle_sshare_listing'; |
| 18 | const SOCIAL_SHARING_WIZARD_PAGE = 'hustle_sshare'; |
| 19 | const INTEGRATIONS_PAGE = 'hustle_integrations'; |
| 20 | const ENTRIES_PAGE = 'hustle_entries'; |
| 21 | const SETTINGS_PAGE = 'hustle_settings'; |
| 22 | const UPGRADE_MODAL_PARAM = 'requires-pro'; |
| 23 | |
| 24 | /** |
| 25 | * Hustle_Module_Admin constructor |
| 26 | */ |
| 27 | public function __construct() { |
| 28 | |
| 29 | add_action( 'admin_init', array( $this, 'init' ) ); |
| 30 | add_action( 'current_screen', array( $this, 'set_proper_current_screen' ) ); |
| 31 | |
| 32 | $admin_notices = Hustle_Notifications::get_instance(); |
| 33 | |
| 34 | if ( $this->_is_admin_module() ) { |
| 35 | |
| 36 | add_action( 'admin_enqueue_scripts', array( $this, 'sui_scripts' ), 99 ); |
| 37 | add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ), 99 ); |
| 38 | add_action( 'admin_print_styles', array( $this, 'register_styles' ) ); |
| 39 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ), 99 ); |
| 40 | |
| 41 | // geodirectory plugin compatibility. |
| 42 | add_action( 'wp_super_duper_widget_init', array( $this, 'geo_directory_compat' ), 10, 2 ); |
| 43 | |
| 44 | /** |
| 45 | * Add SUI classes to the pages' wrappers. |
| 46 | */ |
| 47 | add_filter( 'hustle_sui_wrap_class', array( $this, 'sui_wrap_class' ) ); |
| 48 | |
| 49 | // remove Get params for notices. |
| 50 | add_filter( 'removable_query_args', array( $this, 'remove_notice_params' ) ); |
| 51 | |
| 52 | /** |
| 53 | * Renders the recommended plugins notice when the conditions are correct. |
| 54 | * This is shown when: |
| 55 | * -The current version is Free |
| 56 | * -The admin isn't logged to WPMU Dev dashboard |
| 57 | * -The notice hasn't been dismissed |
| 58 | * -The majority of our plugins aren't installed |
| 59 | * -A month has passed since the plugin was installed |
| 60 | * There are filters to force the display. |
| 61 | * |
| 62 | * @see https://bitbucket.org/incsub/recommended-plugins-notice/src/master/ |
| 63 | * |
| 64 | * @since 4.2.0 |
| 65 | */ |
| 66 | if ( Opt_In_Utils::_is_free() ) { |
| 67 | require_once Opt_In::$plugin_path . 'lib/plugin-notice/notice.php'; |
| 68 | do_action( |
| 69 | 'wpmudev-recommended-plugins-register-notice', // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
| 70 | Opt_In::$plugin_base_file, |
| 71 | __( 'Hustle', 'hustle' ), |
| 72 | self::get_hustle_admin_pages(), |
| 73 | array( 'after', '.sui-wrap .sui-header' ) |
| 74 | ); |
| 75 | } |
| 76 | $admin_notices->add_in_hustle_notices(); |
| 77 | } else { |
| 78 | |
| 79 | $this->handle_non_hustle_pages(); |
| 80 | } |
| 81 | |
| 82 | if ( $this->_is_admin_module() || wp_doing_ajax() ) { |
| 83 | Hustle_Provider_Autoload::initiate_providers(); |
| 84 | } |
| 85 | |
| 86 | Hustle_Provider_Autoload::load_block_editor(); |
| 87 | |
| 88 | if ( wp_doing_ajax() ) { |
| 89 | $admin_notices->add_ajax_actions(); |
| 90 | } |
| 91 | |
| 92 | add_filter( 'w3tc_save_options', array( $this, 'filter_w3tc_save_options' ), 10, 1 ); |
| 93 | add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 4 ); |
| 94 | add_filter( 'network_admin_plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 4 ); |
| 95 | add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 ); |
| 96 | |
| 97 | add_action( 'upgrader_process_complete', array( $this, 'upgrader_process_complete' ), 10, 2 ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Flags the previous version on upgrade so we can handle notices and modals. |
| 102 | * This action runs in the old version of the plugin, not the new one. |
| 103 | * |
| 104 | * @since 4.2.0 |
| 105 | * |
| 106 | * @param WP_Upgrader $upgrader_object Instance of the WP_Upgrader class. |
| 107 | * @param array $data Upgrade data. |
| 108 | */ |
| 109 | public function upgrader_process_complete( $upgrader_object, $data ) { |
| 110 | |
| 111 | if ( 'update' === $data['action'] && 'plugin' === $data['type'] && ! empty( $data['plugins'] ) ) { |
| 112 | |
| 113 | foreach ( $data['plugins'] as $plugin ) { |
| 114 | |
| 115 | // Make sure our plugin is among the ones being updated and set the flag for the previous version. |
| 116 | if ( Opt_In::$plugin_base_file === $plugin ) { |
| 117 | update_site_option( 'hustle_previous_version', Opt_In::VERSION ); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Handles the scripts for non-hustle pages. |
| 125 | * |
| 126 | * @since 4.2.0 |
| 127 | */ |
| 128 | public function handle_non_hustle_pages() { |
| 129 | |
| 130 | global $pagenow; |
| 131 | |
| 132 | if ( 'index.php' === $pagenow || wp_doing_ajax() ) { |
| 133 | |
| 134 | $analytic_settings = Hustle_Settings_Admin::get_hustle_settings( 'analytics' ); |
| 135 | $analytics_enabled = ! empty( $analytic_settings['enabled'] ) && ! empty( $analytic_settings['modules'] ); |
| 136 | |
| 137 | // Only initialize if the analytics are enabled. |
| 138 | // That's the only use for this class for now. |
| 139 | if ( $analytics_enabled && current_user_can( 'hustle_analytics' ) ) { |
| 140 | new Hustle_Wp_Dashboard_Page( $analytic_settings ); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Remove Get parameters for Hustle notices |
| 147 | * |
| 148 | * @param array $vars |
| 149 | * @return array |
| 150 | */ |
| 151 | public function remove_notice_params( $vars ) { |
| 152 | $vars[] = 'show-notice'; |
| 153 | $vars[] = 'notice'; |
| 154 | $vars[] = 'notice-close'; |
| 155 | |
| 156 | return $vars; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Handle SUI wrapper container classes. |
| 161 | * |
| 162 | * @since 4.0.0 |
| 163 | * @since 4.1.2 Moved from Hustle_Settings_Page to this class. |
| 164 | */ |
| 165 | public function sui_wrap_class( $classes ) { |
| 166 | if ( is_string( $classes ) ) { |
| 167 | $classes = array( $classes ); |
| 168 | } |
| 169 | if ( ! is_array( $classes ) ) { |
| 170 | $classes = array(); |
| 171 | } |
| 172 | $classes[] = 'sui-wrap'; |
| 173 | $classes[] = 'sui-wrap-hustle'; |
| 174 | /** |
| 175 | * Add high contrast mode. |
| 176 | */ |
| 177 | $accessibility = Hustle_Settings_Admin::get_hustle_settings( 'accessibility' ); |
| 178 | $is_high_contrast_mode = !empty( $accessibility['accessibility_color'] ); |
| 179 | if ( $is_high_contrast_mode ) { |
| 180 | $classes[] = 'sui-color-accessible'; |
| 181 | } |
| 182 | /** |
| 183 | * Set hide branding |
| 184 | * |
| 185 | * @since 4.0.0 |
| 186 | */ |
| 187 | $hide_branding = apply_filters( 'wpmudev_branding_hide_branding', false ); |
| 188 | if ( $hide_branding ) { |
| 189 | $classes[] = 'no-hustle'; |
| 190 | } |
| 191 | /** |
| 192 | * hero image |
| 193 | * |
| 194 | * @since 4.0.0 |
| 195 | */ |
| 196 | $image = apply_filters( 'wpmudev_branding_hero_image', 'hustle-default' ); |
| 197 | if ( empty( $image ) ) { |
| 198 | $classes[] = 'no-hustle-hero'; |
| 199 | } |
| 200 | return $classes; |
| 201 | } |
| 202 | |
| 203 | // force reject minify for hustle js and css |
| 204 | public function filter_w3tc_save_options( $config ) { |
| 205 | |
| 206 | // reject js |
| 207 | $defined_rejected_js = $config['new_config']->get( 'minify.reject.files.js' ); |
| 208 | $reject_js = array( |
| 209 | Opt_In::$plugin_url . 'assets/js/admin.min.js', |
| 210 | Opt_In::$plugin_url . 'assets/js/ad.js', |
| 211 | Opt_In::$plugin_url . 'assets/js/front.min.js', |
| 212 | ); |
| 213 | foreach ( $reject_js as $r_js ) { |
| 214 | if ( ! in_array( $r_js, $defined_rejected_js, true ) ) { |
| 215 | array_push( $defined_rejected_js, $r_js ); |
| 216 | } |
| 217 | } |
| 218 | $config['new_config']->set( 'minify.reject.files.js', $defined_rejected_js ); |
| 219 | |
| 220 | // reject css |
| 221 | $defined_rejected_css = $config['new_config']->get( 'minify.reject.files.css' ); |
| 222 | $reject_css = array( |
| 223 | Opt_In::$plugin_url . 'assets/css/front.min.css', |
| 224 | ); |
| 225 | foreach ( $reject_css as $r_css ) { |
| 226 | if ( ! in_array( $r_css, $defined_rejected_css, true ) ) { |
| 227 | array_push( $defined_rejected_css, $r_css ); |
| 228 | } |
| 229 | } |
| 230 | $config['new_config']->set( 'minify.reject.files.css', $defined_rejected_css ); |
| 231 | |
| 232 | return $config; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Inits admin |
| 237 | * |
| 238 | * @since 3.0 |
| 239 | */ |
| 240 | public function init() { |
| 241 | $this->add_privacy_message(); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Register scripts for the admin page |
| 246 | * |
| 247 | * @since 1.0 |
| 248 | */ |
| 249 | public function register_scripts( $page_slug ) { |
| 250 | |
| 251 | // add_filter( 'script_loader_tag', array( $this, 'handle_specific_script' ), 10, 2 ); |
| 252 | // add_filter( 'style_loader_tag', array( $this, 'handle_specific_style' ), 10, 2 ); |
| 253 | |
| 254 | $optin_vars = array( |
| 255 | 'module_page' => array( |
| 256 | 'popup' => self::POPUP_LISTING_PAGE, |
| 257 | 'slidein' => self::SLIDEIN_LISTING_PAGE, |
| 258 | 'embedded' => self::EMBEDDED_LISTING_PAGE, |
| 259 | 'social_sharing' => self::SOCIAL_SHARING_LISTING_PAGE, |
| 260 | ), |
| 261 | 'messages' => array( |
| 262 | 'dont_navigate_away' => __( 'Changes are not saved, are you sure you want to navigate away?', 'hustle' ), // loaded everywhere but only used in wizards maybe? |
| 263 | 'something_went_wrong' => __( 'Something went wrong. Please try again', 'hustle' ), // everywhere. |
| 264 | 'something_went_wrong_reload' => '<label class="wpmudev-label--notice"><span>' . __( 'Something went wrong. Please reload this page and try again.', 'hustle' ) . '</span></label>', // everywhere. |
| 265 | 'aweber_migration_success' => sprintf( esc_html__( '%s integration successfully migrated to the oAuth 2.0.', 'hustle' ), '<strong>' . esc_html__( 'Aweber', 'hustle' ) . '</strong>' ), // everywhere. views.js. |
| 266 | 'integraiton_required' => '<label class="wpmudev-label--notice"><span>' . __( 'An integration is required on opt-in module.', 'hustle' ) . '</span></label>', // wizard and integrations. |
| 267 | 'module_deleted' => __( 'Module successfully deleted.', 'hustle' ), // listing and dashboard. |
| 268 | 'shortcode_copied' => __( 'Shortcode copied successfully.', 'hustle' ), // listing and dashboard. |
| 269 | 'commons' => array( |
| 270 | 'published' => __( 'Published', 'hustle' ), // dashboard and wizard. |
| 271 | 'draft' => __( 'Draft', 'hustle' ), // dashboard and wizard. |
| 272 | 'dismiss' => __( 'Dismiss', 'hustle' ), // everywhere, views.js. |
| 273 | ), |
| 274 | ), |
| 275 | ); |
| 276 | |
| 277 | $optin_vars['urlParams'] = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification |
| 278 | |
| 279 | /** |
| 280 | * The variables specific to each page are added via this hook. |
| 281 | */ |
| 282 | $optin_vars = apply_filters( 'hustle_optin_vars', $optin_vars ); |
| 283 | |
| 284 | $url_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'debug' : 'min'; |
| 285 | wp_register_script( |
| 286 | 'optin_admin_scripts', |
| 287 | Opt_In::$plugin_url . 'assets/js/admin.' . $url_suffix . '.js', |
| 288 | array( 'jquery', 'backbone', 'jquery-effects-core' ), |
| 289 | Opt_In::VERSION, |
| 290 | true |
| 291 | ); |
| 292 | wp_localize_script( 'optin_admin_scripts', 'optinVars', $optin_vars ); |
| 293 | wp_enqueue_script( 'optin_admin_scripts' ); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Register shared-ui scripts |
| 298 | * |
| 299 | * @since 4.0.0 |
| 300 | */ |
| 301 | public function sui_scripts() { |
| 302 | |
| 303 | $sanitize_version = str_replace( '.', '-', HUSTLE_SUI_VERSION ); |
| 304 | $sui_body_class = "sui-$sanitize_version"; |
| 305 | |
| 306 | wp_enqueue_script( |
| 307 | 'shared-ui', |
| 308 | Opt_In::$plugin_url . 'assets/js/shared-ui.min.js', |
| 309 | array( 'jquery' ), |
| 310 | $sui_body_class, |
| 311 | true |
| 312 | ); |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Determine what admin section for Pop-up module |
| 317 | * |
| 318 | * @since 3.0.0. |
| 319 | * |
| 320 | * @param boolean/string $default Default value. |
| 321 | * |
| 322 | * @return mixed, string or boolean |
| 323 | */ |
| 324 | public static function get_current_section( $default = false ) { |
| 325 | $section = filter_input( INPUT_GET, 'section', FILTER_SANITIZE_STRING ); |
| 326 | return ( is_null( $section ) || empty( $section ) ) |
| 327 | ? $default |
| 328 | : $section; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Handling specific scripts for each scenario |
| 333 | */ |
| 334 | // public function handle_specific_script( $tag, $handle ) { |
| 335 | // if ( 'optin_admin_fitie' === $handle ) { |
| 336 | // $tag = "<!--[if IE]>$tag<![endif]-->"; |
| 337 | // } |
| 338 | // return $tag; |
| 339 | // } |
| 340 | |
| 341 | /** |
| 342 | * Handling specific style for each scenario |
| 343 | */ |
| 344 | // public function handle_specific_style( $tag, $handle ) { |
| 345 | // if ( 'hustle_admin_ie' === $handle ) { |
| 346 | // $tag = '<!--[if IE]>'. $tag .'<![endif]-->'; |
| 347 | // } |
| 348 | // return $tag; |
| 349 | // } |
| 350 | |
| 351 | public function set_proper_current_screen( $current ) { |
| 352 | global $current_screen; |
| 353 | if ( ! Opt_In_Utils::_is_free() ) { |
| 354 | $current_screen->id = Opt_In_Utils::clean_current_screen( $current_screen->id ); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Registers styles for the admin |
| 360 | */ |
| 361 | public function register_styles( $page_slug ) { |
| 362 | |
| 363 | $sanitize_version = str_replace( '.', '-', HUSTLE_SUI_VERSION ); |
| 364 | $sui_body_class = "sui-$sanitize_version"; |
| 365 | |
| 366 | wp_enqueue_style( 'thickbox' ); |
| 367 | |
| 368 | wp_register_style( |
| 369 | 'hstl-roboto', |
| 370 | 'https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i|Roboto:300,300i,400,400i,500,500i,700,700i', |
| 371 | array(), |
| 372 | Opt_In::VERSION |
| 373 | ); |
| 374 | wp_register_style( |
| 375 | 'hstl-opensans', |
| 376 | 'https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i', |
| 377 | array(), |
| 378 | Opt_In::VERSION |
| 379 | ); |
| 380 | wp_register_style( |
| 381 | 'hstl-source', |
| 382 | 'https://fonts.googleapis.com/css?family=Source+Code+Pro', |
| 383 | array(), |
| 384 | Opt_In::VERSION |
| 385 | ); |
| 386 | |
| 387 | wp_enqueue_style( 'wp-color-picker' ); |
| 388 | wp_enqueue_style( 'wdev_ui' ); |
| 389 | wp_enqueue_style( 'wdev_notice' ); |
| 390 | wp_enqueue_style( 'hstl-roboto' ); |
| 391 | wp_enqueue_style( 'hstl-opensans' ); |
| 392 | wp_enqueue_style( 'hstl-source' ); |
| 393 | |
| 394 | wp_enqueue_style( |
| 395 | 'sui_styles', |
| 396 | Opt_In::$plugin_url . 'assets/css/shared-ui.min.css', |
| 397 | array(), |
| 398 | $sui_body_class |
| 399 | ); |
| 400 | } |
| 401 | |
| 402 | |
| 403 | /** |
| 404 | * Checks if it's module admin page |
| 405 | * |
| 406 | * @return bool |
| 407 | */ |
| 408 | private function _is_admin_module() { |
| 409 | $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING ); |
| 410 | return in_array( |
| 411 | $page, |
| 412 | array( |
| 413 | self::ADMIN_PAGE, |
| 414 | self::DASHBOARD_PAGE, |
| 415 | self::POPUP_LISTING_PAGE, |
| 416 | self::POPUP_WIZARD_PAGE, |
| 417 | self::SLIDEIN_LISTING_PAGE, |
| 418 | self::SLIDEIN_WIZARD_PAGE, |
| 419 | self::EMBEDDED_LISTING_PAGE, |
| 420 | self::EMBEDDED_WIZARD_PAGE, |
| 421 | self::SOCIAL_SHARING_LISTING_PAGE, |
| 422 | self::SOCIAL_SHARING_WIZARD_PAGE, |
| 423 | self::INTEGRATIONS_PAGE, |
| 424 | self::ENTRIES_PAGE, |
| 425 | self::SETTINGS_PAGE, |
| 426 | ), |
| 427 | true |
| 428 | ); |
| 429 | |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Return an array with the slugs of the admin pages |
| 434 | * |
| 435 | * @since 4.1.1 |
| 436 | * @return array |
| 437 | */ |
| 438 | public static function get_hustle_admin_pages() { |
| 439 | return array( |
| 440 | 'toplevel_page_hustle', |
| 441 | 'hustle_page_' . self::ADMIN_PAGE, |
| 442 | 'hustle_page_' . self::DASHBOARD_PAGE, |
| 443 | 'hustle_page_' . self::POPUP_LISTING_PAGE, |
| 444 | 'hustle_page_' . self::POPUP_WIZARD_PAGE, |
| 445 | 'hustle_page_' . self::SLIDEIN_LISTING_PAGE, |
| 446 | 'hustle_page_' . self::SLIDEIN_WIZARD_PAGE, |
| 447 | 'hustle_page_' . self::EMBEDDED_LISTING_PAGE, |
| 448 | 'hustle_page_' . self::EMBEDDED_WIZARD_PAGE, |
| 449 | 'hustle_page_' . self::SOCIAL_SHARING_LISTING_PAGE, |
| 450 | 'hustle_page_' . self::SOCIAL_SHARING_WIZARD_PAGE, |
| 451 | 'hustle_page_' . self::INTEGRATIONS_PAGE, |
| 452 | 'hustle_page_' . self::ENTRIES_PAGE, |
| 453 | 'hustle_page_' . self::SETTINGS_PAGE, |
| 454 | ); |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Modify admin body class to our own advantage! |
| 459 | * |
| 460 | * @param $classes |
| 461 | * @return mixed |
| 462 | */ |
| 463 | public function admin_body_class( $classes ) { |
| 464 | |
| 465 | $sanitize_version = str_replace( '.', '-', HUSTLE_SUI_VERSION ); |
| 466 | $sui_body_class = "sui-$sanitize_version"; |
| 467 | |
| 468 | $screen = get_current_screen(); |
| 469 | |
| 470 | $classes = ''; |
| 471 | |
| 472 | // Do nothing if not a hustle page |
| 473 | if ( strpos( $screen->base, '_page_hustle' ) === false ) { |
| 474 | return $classes; |
| 475 | } |
| 476 | |
| 477 | $classes .= $sui_body_class; |
| 478 | |
| 479 | return $classes; |
| 480 | |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Add Privacy Messages |
| 485 | * |
| 486 | * @since 3.0.6 |
| 487 | */ |
| 488 | public function add_privacy_message() { |
| 489 | if ( function_exists( 'wp_add_privacy_policy_content' ) ) { |
| 490 | $external_integrations_list = ''; |
| 491 | $external_integrations_privacy_url_list = ''; |
| 492 | $params = array( |
| 493 | 'external_integrations_list' => apply_filters( 'hustle_privacy_external_integrations_list', $external_integrations_list ), |
| 494 | 'external_integrations_privacy_url_list' => apply_filters( 'hustle_privacy_url_external_integrations_list', $external_integrations_privacy_url_list ), |
| 495 | ); |
| 496 | // TODO: get the name from a variable instead. |
| 497 | $renderer = new Hustle_Layout_Helper(); |
| 498 | $content = $renderer->render( 'general/policy-text', $params, true ); |
| 499 | wp_add_privacy_policy_content( 'Hustle', wp_kses_post( $content ) ); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * Adds custom links on plugin page |
| 505 | */ |
| 506 | public function add_plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) { |
| 507 | static $plugin; |
| 508 | |
| 509 | if ( ! isset( $plugin ) ) { |
| 510 | $plugin = Opt_In::$plugin_base_file; } |
| 511 | |
| 512 | if ( $plugin === $plugin_file ) { |
| 513 | if ( is_network_admin() ) { |
| 514 | $admin_url = network_admin_url( 'admin.php' ); |
| 515 | } else { |
| 516 | $admin_url = admin_url( 'admin.php' ); |
| 517 | } |
| 518 | $settings_url = add_query_arg( 'page', 'hustle_settings', $admin_url ); |
| 519 | $links = array( |
| 520 | 'settings' => '<a href="' . $settings_url . '">' . esc_html__( 'Settings', 'hustle' ) . '</a>', |
| 521 | 'docs' => '<a href="https://premium.wpmudev.org/project/hustle/#wpmud-hg-project-documentation?utm_source=hustle&utm_medium=plugin&utm_campaign=hustle_pluginlist_docs" target="_blank">' . esc_html__( 'Docs', 'hustle' ) . '</a>', |
| 522 | ); |
| 523 | |
| 524 | // Upgrade link. |
| 525 | if ( Opt_In_Utils::_is_free() ) { |
| 526 | if ( ! lib3()->is_member() ) { |
| 527 | $url = 'https://premium.wpmudev.org/?utm_source=hustle&utm_medium=plugin&utm_campaign=hustle_pluginlist_upgrade'; |
| 528 | } else { |
| 529 | $url = lib3()->get_link( 'hustle', 'install_plugin', '' ); |
| 530 | } |
| 531 | if ( is_network_admin() || ! is_multisite() ) { |
| 532 | $links['upgrade'] = '<a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( __( 'Upgrade to Hustle Pro', 'hustle' ) ) . '" target="_blank" style="color: #8D00B1;">' . esc_html__( 'Upgrade', 'hustle' ) . '</a>'; |
| 533 | } |
| 534 | } else { |
| 535 | if ( ! lib3()->is_member() ) { |
| 536 | $links['renew'] = '<a href="https://premium.wpmudev.org/?utm_source=hustle&utm_medium=plugin&utm_campaign=hustle_pluginlist_renew" target="_blank" style="color: #8D00B1;">' . esc_html__( 'Renew Membership', 'hustle' ) . '</a>'; |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | // Display only on site's plugins page, not network's. |
| 541 | if ( current_user_can( 'activate_plugins' ) && ( ! is_network_admin() || ! is_multisite() ) ) { |
| 542 | |
| 543 | $migration = Hustle_Migration::get_instance(); |
| 544 | $has_404_backup = $migration->migration_410->is_backup_created(); |
| 545 | |
| 546 | // Add a "Rollback to 404" link if we have its backup. |
| 547 | if ( $has_404_backup ) { |
| 548 | $args = array( |
| 549 | 'page' => self::SETTINGS_PAGE, |
| 550 | '404-downgrade-modal' => 'true', |
| 551 | ); |
| 552 | $url = add_query_arg( $args, 'admin.php' ); |
| 553 | $version = Opt_In_Utils::_is_free() ? 'v7.0.4' : 'v4.0.4'; |
| 554 | |
| 555 | $links['rollback_404'] = '<a href="' . esc_url_raw( $url ) . '">' . sprintf( esc_html( 'Rollback to %s', 'hustle' ), $version ) . '</a>'; |
| 556 | } |
| 557 | $actions = array_merge( $links, $actions ); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | return $actions; |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * Links next to version number |
| 566 | * |
| 567 | * @param array $plugin_meta |
| 568 | * @param string $plugin_file |
| 569 | * @return array |
| 570 | */ |
| 571 | public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) { |
| 572 | if ( Opt_In::$plugin_base_file === $plugin_file ) { |
| 573 | if ( Opt_In_Utils::_is_free() ) { |
| 574 | $row_meta = array( |
| 575 | 'rate' => '<a href="https://wordpress.org/support/plugin/wordpress-popup/reviews/#new-post" target="_blank">' . esc_html__( 'Rate Hustle', 'hustle' ) . '</a>', |
| 576 | 'support' => '<a href="https://wordpress.org/support/plugin/wordpress-popup/" target="_blank">' . esc_html__( 'Support', 'hustle' ) . '</a>', |
| 577 | ); |
| 578 | } else { |
| 579 | $row_meta = array( |
| 580 | 'support' => '<a href="https://premium.wpmudev.org/hub/support/#wpmud-chat-pre-survey-modal" target="_blank">' . esc_html__( 'Premium Support', 'hustle' ) . '</a>', |
| 581 | ); |
| 582 | } |
| 583 | |
| 584 | $row_meta['roadmap'] = '<a href="https://premium.wpmudev.org/roadmap/" target="_blank">' . esc_html__( 'Roadmap', 'hustle' ) . '</a>'; |
| 585 | |
| 586 | $plugin_meta = array_merge( $plugin_meta, $row_meta ); |
| 587 | } |
| 588 | |
| 589 | return $plugin_meta; |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Get the listing page by the module type. |
| 594 | * |
| 595 | * @since 4.0 |
| 596 | * |
| 597 | * @param string $module_type |
| 598 | * @return string |
| 599 | */ |
| 600 | public static function get_listing_page_by_module_type( $module_type ) { |
| 601 | |
| 602 | switch ( $module_type ) { |
| 603 | case Hustle_Module_Model::POPUP_MODULE: |
| 604 | return self::POPUP_LISTING_PAGE; |
| 605 | |
| 606 | case Hustle_Module_Model::SLIDEIN_MODULE: |
| 607 | return self::SLIDEIN_LISTING_PAGE; |
| 608 | |
| 609 | case Hustle_Module_Model::EMBEDDED_MODULE: |
| 610 | return self::EMBEDDED_LISTING_PAGE; |
| 611 | |
| 612 | case Hustle_Module_Model::SOCIAL_SHARING_MODULE: |
| 613 | return self::SOCIAL_SHARING_LISTING_PAGE; |
| 614 | |
| 615 | default: |
| 616 | return self::POPUP_LISTING_PAGE; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | /** |
| 621 | * Get the wizard page by the module type. |
| 622 | * |
| 623 | * @since 4.0 |
| 624 | * |
| 625 | * @param string $module_type |
| 626 | * @return string |
| 627 | */ |
| 628 | public static function get_wizard_page_by_module_type( $module_type ) { |
| 629 | |
| 630 | switch ( $module_type ) { |
| 631 | case Hustle_Module_Model::POPUP_MODULE: |
| 632 | return self::POPUP_WIZARD_PAGE; |
| 633 | |
| 634 | case Hustle_Module_Model::SLIDEIN_MODULE: |
| 635 | return self::SLIDEIN_WIZARD_PAGE; |
| 636 | |
| 637 | case Hustle_Module_Model::EMBEDDED_MODULE: |
| 638 | return self::EMBEDDED_WIZARD_PAGE; |
| 639 | |
| 640 | case Hustle_Module_Model::SOCIAL_SHARING_MODULE: |
| 641 | return self::SOCIAL_SHARING_WIZARD_PAGE; |
| 642 | |
| 643 | default: |
| 644 | return self::POPUP_WIZARD_PAGE; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * Check whether a new module of this type can be created. |
| 650 | * If it's free and there's already 3 modules of this type, then it's a nope. |
| 651 | * |
| 652 | * @since 4.0 |
| 653 | * |
| 654 | * @param string $module_type |
| 655 | * @return boolean |
| 656 | */ |
| 657 | public static function can_create_new_module( $module_type ) { |
| 658 | |
| 659 | // If it's Pro, the sky's the limit. |
| 660 | if ( ! Opt_In_Utils::_is_free() ) { |
| 661 | return true; |
| 662 | } |
| 663 | |
| 664 | // Check the Module's type is valid. |
| 665 | if ( ! in_array( $module_type, Hustle_Module_Model::get_module_types(), true ) ) { |
| 666 | return false; |
| 667 | } |
| 668 | |
| 669 | $collection_args = array( |
| 670 | 'module_type' => $module_type, |
| 671 | 'count_only' => true, |
| 672 | ); |
| 673 | $total_modules = Hustle_Module_Collection::instance()->get_all( null, $collection_args ); |
| 674 | |
| 675 | // If we have less than 3 modules of this type, can create another one. |
| 676 | if ( $total_modules >= 3 ) { |
| 677 | return false; |
| 678 | } else { |
| 679 | return true; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Geodirectory compatibility issues. |
| 685 | * |
| 686 | * @since 4.0.1 |
| 687 | * |
| 688 | * @param array $options |
| 689 | * @param object $class WP_Super_Duper class instance |
| 690 | */ |
| 691 | public function geo_directory_compat( $options, $class ) { |
| 692 | remove_action( 'media_buttons', array( $class, 'shortcode_insert_button' ) ); |
| 693 | } |
| 694 | |
| 695 | } |
| 696 | |
| 697 | endif; |
| 698 |