display-conditions
3 years ago
front
9 months ago
helpers
9 months ago
metas
3 years ago
multisite
3 years ago
palettes
3 years ago
provider
3 years ago
providers
9 months ago
templates
3 years ago
update
3 years ago
class-hustle-admin-page-abstract.php
9 months ago
class-hustle-black-friday-campaign.php
7 months ago
class-hustle-condition-factory.php
6 years ago
class-hustle-cross-sell.php
9 months ago
class-hustle-dashboard-admin.php
3 years ago
class-hustle-data.php
3 years ago
class-hustle-db.php
2 years ago
class-hustle-installer.php
4 years ago
class-hustle-meta.php
3 years ago
class-hustle-module-admin.php
9 months ago
class-hustle-module-collection.php
3 years ago
class-hustle-module-page-abstract.php
2 years ago
class-hustle-notifications.php
3 years ago
class-hustle-settings-admin.php
3 years ago
class-hustle-tutorials-page.php
4 years ago
class-hustle-wp-dashboard-page.php
3 years ago
hustle-deletion.php
3 years ago
hustle-embedded-admin.php
3 years ago
hustle-entries-admin.php
3 years ago
hustle-entry-model.php
3 years ago
hustle-general-data-protection.php
3 years ago
hustle-init.php
7 months ago
hustle-mail.php
3 years ago
hustle-migration.php
3 years ago
hustle-model.php
3 years ago
hustle-module-model.php
9 months ago
hustle-module-widget-legacy.php
3 years ago
hustle-module-widget.php
3 years ago
hustle-modules-common-admin-ajax.php
9 months ago
hustle-popup-admin.php
3 years ago
hustle-providers-admin.php
3 years ago
hustle-providers.php
3 years ago
hustle-settings-admin-ajax.php
3 years ago
hustle-settings-page.php
3 years ago
hustle-slidein-admin.php
3 years ago
hustle-sshare-admin.php
3 years ago
hustle-sshare-model.php
3 years ago
hustle-tracking-model.php
3 years ago
opt-in-geo.php
9 months ago
opt-in-utils.php
3 years ago
opt-in-wpmudev-api.php
3 years ago
class-hustle-module-admin.php
342 lines
| 1 | <?php |
| 2 | /** |
| 3 | * File for Hustle_Module_Admin class. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | * @since unknown |
| 7 | */ |
| 8 | |
| 9 | if ( ! class_exists( 'Hustle_Module_Admin' ) ) : |
| 10 | |
| 11 | /** |
| 12 | * Class Hustle_Module_Admin |
| 13 | */ |
| 14 | class Hustle_Module_Admin { |
| 15 | |
| 16 | const UPGRADE_MODAL_PARAM = 'requires-pro'; |
| 17 | |
| 18 | /** |
| 19 | * Hustle_Module_Admin constructor |
| 20 | */ |
| 21 | public function __construct() { |
| 22 | $admin_notices = Hustle_Notifications::get_instance(); |
| 23 | |
| 24 | if ( $this->is_hustle_page() ) { |
| 25 | $admin_notices->add_in_hustle_notices(); |
| 26 | $this->maybe_add_recommended_plugins_notice(); |
| 27 | } else { |
| 28 | $this->handle_non_hustle_pages(); |
| 29 | } |
| 30 | |
| 31 | if ( $this->is_hustle_page() || wp_doing_ajax() ) { |
| 32 | Hustle_Provider_Autoload::initiate_providers(); |
| 33 | } |
| 34 | |
| 35 | Hustle_Provider_Autoload::load_block_editor(); |
| 36 | |
| 37 | add_action( 'admin_init', array( $this, 'add_privacy_message' ) ); |
| 38 | |
| 39 | if ( Opt_In_Utils::is_free() ) { |
| 40 | add_action( 'admin_menu', array( $this, 'add_upsell_menu_item' ), 99 ); |
| 41 | add_action( 'admin_print_styles', array( $this, 'print_upsell_menu_item_styles' ) ); |
| 42 | add_action( 'admin_print_footer_scripts', array( $this, 'print_upsell_menu_item_script' ) ); |
| 43 | } |
| 44 | |
| 45 | add_filter( 'w3tc_save_options', array( $this, 'filter_w3tc_save_options' ), 10, 1 ); |
| 46 | add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 2 ); |
| 47 | add_filter( 'network_admin_plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 2 ); |
| 48 | add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 ); |
| 49 | |
| 50 | add_action( 'upgrader_process_complete', array( $this, 'upgrader_process_complete' ), 10, 2 ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Add Privacy Messages |
| 55 | * |
| 56 | * @since 3.0.6 |
| 57 | */ |
| 58 | public function add_privacy_message() { |
| 59 | if ( function_exists( 'wp_add_privacy_policy_content' ) ) { |
| 60 | $external_integrations_list = ''; |
| 61 | $external_integrations_privacy_url_list = ''; |
| 62 | $params = array( |
| 63 | 'external_integrations_list' => apply_filters( 'hustle_privacy_external_integrations_list', $external_integrations_list ), |
| 64 | 'external_integrations_privacy_url_list' => apply_filters( 'hustle_privacy_url_external_integrations_list', $external_integrations_privacy_url_list ), |
| 65 | ); |
| 66 | |
| 67 | $renderer = new Hustle_Layout_Helper(); |
| 68 | $content = $renderer->render( 'general/policy-text', $params, true ); |
| 69 | wp_add_privacy_policy_content( 'Hustle', wp_kses_post( $content ) ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Adds Upsell menu item. |
| 75 | * |
| 76 | * @since 7.8.8 |
| 77 | */ |
| 78 | public function add_upsell_menu_item() { |
| 79 | add_submenu_page( |
| 80 | 'hustle', |
| 81 | __( 'Limited-time Offer', 'hustle' ), |
| 82 | __( 'Limited-time Offer', 'hustle' ), |
| 83 | 'hustle_menu', |
| 84 | 'https://wpmudev.com/project/hustle/?utm_source=hustle&utm_medium=plugin&utm_campaign=hustle_submenu_upsell', |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Prints styles for Upsell menu item. |
| 90 | * |
| 91 | * @since 7.8.8 |
| 92 | */ |
| 93 | public function print_upsell_menu_item_styles() { |
| 94 | ?> |
| 95 | <style id="hustle-upsell"> |
| 96 | #adminmenu #toplevel_page_hustle .wp-submenu li:last-child a[href^="https://wpmudev.com"] { |
| 97 | background-color: #8d00b1 !important; color: #fff !important; font-weight: 500 !important; letter-spacing: -0.2px; |
| 98 | } |
| 99 | </style> |
| 100 | <?php |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Prints scripts for Upsell menu item. |
| 105 | * |
| 106 | * @since 7.8.8 |
| 107 | */ |
| 108 | public function print_upsell_menu_item_script() { |
| 109 | ?> |
| 110 | <script> |
| 111 | jQuery( document ).ready( function ( $ ) { |
| 112 | /** |
| 113 | * Open the upsell link in a new tab. |
| 114 | */ |
| 115 | $( '#toplevel_page_hustle .wp-submenu li:last-child a[href^="https://wpmudev.com"]' ).on( 'click', function ( e ) { |
| 116 | e.preventDefault(); |
| 117 | window.open( $( this ).attr( 'href' ), '_blank' ); |
| 118 | } ); |
| 119 | } ); |
| 120 | </script> |
| 121 | <?php |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Forcefully rejects the minify for Hustle's js and css. |
| 126 | * |
| 127 | * @since unknown |
| 128 | * |
| 129 | * @param array $config w3tc configs. |
| 130 | * @return array |
| 131 | */ |
| 132 | public function filter_w3tc_save_options( $config ) { |
| 133 | |
| 134 | // Reject js. |
| 135 | $defined_rejected_js = $config['new_config']->get( 'minify.reject.files.js' ); |
| 136 | $reject_js = array( |
| 137 | Opt_In::$plugin_url . 'assets/js/admin.min.js', |
| 138 | Opt_In::$plugin_url . 'assets/js/ad.js', |
| 139 | Opt_In::$plugin_url . 'assets/js/front.min.js', |
| 140 | ); |
| 141 | foreach ( $reject_js as $r_js ) { |
| 142 | if ( ! in_array( $r_js, $defined_rejected_js, true ) ) { |
| 143 | array_push( $defined_rejected_js, $r_js ); |
| 144 | } |
| 145 | } |
| 146 | $config['new_config']->set( 'minify.reject.files.js', $defined_rejected_js ); |
| 147 | |
| 148 | // Reject css. |
| 149 | $defined_rejected_css = $config['new_config']->get( 'minify.reject.files.css' ); |
| 150 | $reject_css = array( |
| 151 | Opt_In::$plugin_url . 'assets/css/front.min.css', |
| 152 | ); |
| 153 | foreach ( $reject_css as $r_css ) { |
| 154 | if ( ! in_array( $r_css, $defined_rejected_css, true ) ) { |
| 155 | array_push( $defined_rejected_css, $r_css ); |
| 156 | } |
| 157 | } |
| 158 | $config['new_config']->set( 'minify.reject.files.css', $defined_rejected_css ); |
| 159 | |
| 160 | return $config; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Adds custom links on "Plugins" page. |
| 165 | * |
| 166 | * @since unknown |
| 167 | * |
| 168 | * @param array $actions Array of plugin actions links. |
| 169 | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 170 | * @return array |
| 171 | */ |
| 172 | public function add_plugin_action_links( $actions, $plugin_file ) { |
| 173 | static $plugin; |
| 174 | |
| 175 | if ( ! isset( $plugin ) ) { |
| 176 | $plugin = Opt_In::$plugin_base_file; |
| 177 | } |
| 178 | |
| 179 | if ( $plugin === $plugin_file ) { |
| 180 | $admin_url = admin_url( 'admin.php' ); |
| 181 | $settings_url = add_query_arg( 'page', 'hustle', $admin_url ); |
| 182 | $links = array( |
| 183 | 'settings' => '<a href="' . esc_url( $settings_url ) . '">' . esc_html__( 'Dashboard', 'hustle' ) . '</a>', |
| 184 | 'docs' => '<a href="' . esc_url( Opt_In_Utils::get_link( 'docs', 'hustle_pluginlist_docs' ) ) . '" target="_blank">' . esc_html__( 'Docs', 'hustle' ) . '</a>', |
| 185 | ); |
| 186 | |
| 187 | // Upgrade link. |
| 188 | if ( Opt_In_Utils::is_free() ) { |
| 189 | if ( ! Opt_In_Utils::is_hustle_included_in_membership() ) { |
| 190 | $url = Opt_In_Utils::get_link( 'plugin', 'hustle_pluginlist_upgrade' ); |
| 191 | $label = __( 'Limited-time Offer', 'hustle' ); |
| 192 | } else { |
| 193 | $url = Opt_In_Utils::get_link( 'install_plugin' ); |
| 194 | $label = __( 'Upgrade', 'hustle' ); |
| 195 | } |
| 196 | if ( is_network_admin() || ! is_multisite() ) { |
| 197 | $links['upgrade'] = '<a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '" target="_blank" style="color: #8D00B1;">' . esc_html( $label ) . '</a>'; |
| 198 | } |
| 199 | } else { |
| 200 | $status = Opt_In_Utils::get_membership_status(); |
| 201 | if ( in_array( $status, array( 'expired', 'free', 'paused', '' ), true ) ) { |
| 202 | $links['renew'] = '<a href="' . esc_url( Opt_In_Utils::get_link( 'wpmudev', 'hustle_pluginlist_renew' ) ) . '" target="_blank" style="color: #8D00B1;">' . esc_html__( 'Renew Membership', 'hustle' ) . '</a>'; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | $actions = array_merge( $links, $actions ); |
| 207 | } |
| 208 | |
| 209 | return $actions; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Links next to version number in the "Plugins" page. |
| 214 | * |
| 215 | * @since unknown |
| 216 | * |
| 217 | * @param array $plugin_meta An array of the plugin's metadata. |
| 218 | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 219 | * @return array |
| 220 | */ |
| 221 | public function add_plugin_meta_links( $plugin_meta, $plugin_file ) { |
| 222 | if ( Opt_In::$plugin_base_file === $plugin_file ) { |
| 223 | $row_meta = array(); |
| 224 | |
| 225 | if ( Opt_In_Utils::is_free() ) { |
| 226 | $row_meta['rate'] = '<a href="https://wordpress.org/support/plugin/wordpress-popup/reviews/#new-post" target="_blank">' . esc_html__( 'Rate Hustle', 'hustle' ) . '</a>'; |
| 227 | } |
| 228 | |
| 229 | $support_text = 'full' === Opt_In_Utils::get_membership_status() ? esc_html__( 'Premium Support', 'hustle' ) : esc_html__( 'Support', 'hustle' ); |
| 230 | |
| 231 | // Returns the wp.org link when ! is_member(), and the premium link otherwise. |
| 232 | $row_meta['support'] = '<a href="' . esc_url( Opt_In_Utils::get_link( 'support' ) ) . '" target="_blank">' . $support_text . '</a>'; |
| 233 | |
| 234 | $row_meta['roadmap'] = '<a href="' . esc_url( Opt_In_Utils::get_link( 'roadmap' ) ) . '" target="_blank">' . esc_html__( 'Roadmap', 'hustle' ) . '</a>'; |
| 235 | $plugin_meta = array_merge( $plugin_meta, $row_meta ); |
| 236 | } |
| 237 | |
| 238 | return $plugin_meta; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Flags the previous version on upgrade so we can handle notices and modals. |
| 243 | * This action runs in the old version of the plugin, not the new one. |
| 244 | * |
| 245 | * @since 4.2.0 |
| 246 | * |
| 247 | * @param WP_Upgrader $upgrader_object Instance of the WP_Upgrader class. |
| 248 | * @param array $data Upgrade data. |
| 249 | */ |
| 250 | public function upgrader_process_complete( $upgrader_object, $data ) { |
| 251 | |
| 252 | if ( 'update' === $data['action'] && 'plugin' === $data['type'] && ! empty( $data['plugins'] ) ) { |
| 253 | |
| 254 | foreach ( $data['plugins'] as $plugin ) { |
| 255 | |
| 256 | // Make sure our plugin is among the ones being updated and set the flag for the previous version. |
| 257 | if ( Opt_In::$plugin_base_file === $plugin ) { |
| 258 | update_site_option( 'hustle_previous_version', Opt_In::VERSION ); |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Handles the scripts for non-hustle pages. |
| 266 | * |
| 267 | * @since 4.2.0 |
| 268 | */ |
| 269 | private function handle_non_hustle_pages() { |
| 270 | global $pagenow; |
| 271 | |
| 272 | if ( 'index.php' === $pagenow || wp_doing_ajax() ) { |
| 273 | |
| 274 | $analytic_settings = Hustle_Settings_Admin::get_hustle_settings( 'analytics' ); |
| 275 | $analytics_enabled = ! empty( $analytic_settings['enabled'] ) && ! empty( $analytic_settings['modules'] ); |
| 276 | |
| 277 | // Only initialize if the analytics are enabled. |
| 278 | // That's the only use for this class for now. |
| 279 | if ( $analytics_enabled && current_user_can( 'hustle_analytics' ) ) { |
| 280 | new Hustle_Wp_Dashboard_Page( $analytic_settings ); |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Renders the recommended plugins notice when the conditions are correct. |
| 287 | * This is shown when: |
| 288 | * -The current version is Free |
| 289 | * -The admin isn't logged to WPMU Dev dashboard |
| 290 | * -The notice hasn't been dismissed |
| 291 | * -The majority of our plugins aren't installed |
| 292 | * -A month has passed since the plugin was installed |
| 293 | * There are filters to force the display. |
| 294 | * |
| 295 | * @see https://bitbucket.org/incsub/recommended-plugins-notice/src/master/ |
| 296 | * |
| 297 | * @since 4.2.0 |
| 298 | */ |
| 299 | private function maybe_add_recommended_plugins_notice() { |
| 300 | if ( ! Opt_In_Utils::is_free() ) { |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | require_once Opt_In::$plugin_path . 'lib/plugin-notice/notice.php'; |
| 305 | do_action( |
| 306 | 'wpmudev-recommended-plugins-register-notice', // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
| 307 | Opt_In::$plugin_base_file, |
| 308 | __( 'Hustle', 'hustle' ), |
| 309 | $this->get_admin_pages_for_free(), |
| 310 | array( 'after', '.sui-wrap .sui-header' ) |
| 311 | ); |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Checks if it's module admin page |
| 316 | * |
| 317 | * @return bool |
| 318 | */ |
| 319 | private function is_hustle_page() { |
| 320 | $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_SPECIAL_CHARS ); |
| 321 | return in_array( $page, Hustle_Data::get_hustle_pages(), true ); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Return an array with the slugs of the admin pages |
| 326 | * |
| 327 | * @since 4.1.1 |
| 328 | * @return array |
| 329 | */ |
| 330 | private function get_admin_pages_for_free() { |
| 331 | $names = Hustle_Data::get_hustle_pages(); |
| 332 | $with_prefix = array( 'toplevel_page_hustle' ); |
| 333 | |
| 334 | foreach ( $names as $name ) { |
| 335 | $with_prefix[] = 'hustle_page_' . $name; |
| 336 | } |
| 337 | return $with_prefix; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | endif; |
| 342 |