class-wordpress-popup-module-admin.php
143 lines
| 1 | <?php |
| 2 | /** |
| 3 | * File for Hustle_Module_Admin class. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | * @since unknown |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; // Exit if accessed directly. |
| 11 | } |
| 12 | |
| 13 | if ( class_exists( 'WordPress_Popup_Module_Admin' ) ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Class for WordPress_Popup_Module_Admin. Adds the free-specific functionality. |
| 19 | * |
| 20 | * @package Hustle |
| 21 | * @since unknown |
| 22 | */ |
| 23 | class WordPress_Popup_Module_Admin { |
| 24 | |
| 25 | const LISTING_PAGES = array( |
| 26 | 'hustle_page_' . Hustle_Data::POPUP_LISTING_PAGE, |
| 27 | 'hustle_page_' . Hustle_Data::SLIDEIN_LISTING_PAGE, |
| 28 | 'hustle_page_' . Hustle_Data::EMBEDDED_LISTING_PAGE, |
| 29 | 'hustle_page_' . Hustle_Data::SOCIAL_SHARING_LISTING_PAGE, |
| 30 | ); |
| 31 | |
| 32 | /** |
| 33 | * Constructor. |
| 34 | * |
| 35 | * @since unknown |
| 36 | */ |
| 37 | public function __construct() { |
| 38 | add_filter( 'hustle_locate_file', array( $this, 'locate_file' ), 10, 2 ); |
| 39 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); |
| 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 | // Initialize the cross-sell class to add the cross-sell notice in the free module. |
| 44 | new Hustle_Cross_Sell(); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Locate the file for the given layout. If the file exists in the free module, it will be returned. Otherwise, the original file will be returned. |
| 49 | * |
| 50 | * @since unknown |
| 51 | * |
| 52 | * @param string $template_file The original template file path. |
| 53 | * @param string $layout The layout name, which is used to create the file name. |
| 54 | * @return string |
| 55 | */ |
| 56 | public function locate_file( $template_file, $layout ) { |
| 57 | |
| 58 | $free_template_file = trailingslashit( Opt_In::$plugin_path ) . 'free/views/' . $layout . '.php'; |
| 59 | |
| 60 | if ( file_exists( $free_template_file ) ) { |
| 61 | return $free_template_file; |
| 62 | } |
| 63 | |
| 64 | return $template_file; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Enqueue the admin scripts for the free module. |
| 69 | * |
| 70 | * @since unknown |
| 71 | */ |
| 72 | public function enqueue_admin_scripts() { |
| 73 | $screen = get_current_screen(); |
| 74 | |
| 75 | if ( ! $screen || ! in_array( $screen->base, self::LISTING_PAGES, true ) ) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | wp_enqueue_script( |
| 80 | 'wordpress-popup', |
| 81 | trailingslashit( Opt_In::$plugin_url ) . '/assets/js/wordpress-popup.min.js', |
| 82 | array( |
| 83 | 'jquery', |
| 84 | 'optin_admin_scripts', |
| 85 | 'shared-ui', |
| 86 | ), |
| 87 | '1.0.0', |
| 88 | true |
| 89 | ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Adds Upsell menu item. |
| 94 | * |
| 95 | * @since 7.8.8 |
| 96 | */ |
| 97 | public function add_upsell_menu_item() { |
| 98 | add_submenu_page( |
| 99 | 'hustle', |
| 100 | __( 'Get Hustle Pro', 'hustle' ), |
| 101 | __( 'Get Hustle Pro', 'hustle' ), |
| 102 | 'hustle_menu', |
| 103 | 'https://wpmudev.com/project/hustle/?utm_source=hustle&utm_medium=plugin&utm_campaign=hustle_submenu_upsell', |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Prints styles for Upsell menu item. |
| 109 | * |
| 110 | * @since 7.8.8 |
| 111 | */ |
| 112 | public function print_upsell_menu_item_styles() { |
| 113 | ?> |
| 114 | <style id="hustle-upsell"> |
| 115 | #adminmenu #toplevel_page_hustle .wp-submenu li:last-child a[href^="https://wpmudev.com"] { |
| 116 | background-color: #8d00b1 !important; color: #fff !important; font-weight: 500 !important; letter-spacing: -0.2px; |
| 117 | } |
| 118 | </style> |
| 119 | <?php |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Prints scripts for Upsell menu item. |
| 124 | * |
| 125 | * @since 7.8.8 |
| 126 | */ |
| 127 | public function print_upsell_menu_item_script() { |
| 128 | ?> |
| 129 | <script> |
| 130 | jQuery( document ).ready( function ( $ ) { |
| 131 | /** |
| 132 | * Open the upsell link in a new tab. |
| 133 | */ |
| 134 | $( '#toplevel_page_hustle .wp-submenu li:last-child a[href^="https://wpmudev.com"]' ).on( 'click', function ( e ) { |
| 135 | e.preventDefault(); |
| 136 | window.open( $( this ).attr( 'href' ), '_blank' ); |
| 137 | } ); |
| 138 | } ); |
| 139 | </script> |
| 140 | <?php |
| 141 | } |
| 142 | } |
| 143 |