class-astra-sites-admin.php
198 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin Notices |
| 4 | * |
| 5 | * @since 2.3.7 |
| 6 | * @package Astra Sites |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | if ( ! class_exists( 'Astra_Sites_Admin' ) ) : |
| 14 | |
| 15 | /** |
| 16 | * Admin |
| 17 | */ |
| 18 | class Astra_Sites_Admin { |
| 19 | |
| 20 | /** |
| 21 | * Instance of Astra_Sites_Admin |
| 22 | * |
| 23 | * @since 2.3.7 |
| 24 | * @var (Object) Astra_Sites_Admin |
| 25 | */ |
| 26 | private static $instance = null; |
| 27 | |
| 28 | /** |
| 29 | * Instance of Astra_Sites_Admin. |
| 30 | * |
| 31 | * @since 2.3.7 |
| 32 | * |
| 33 | * @return object Class object. |
| 34 | */ |
| 35 | public static function get_instance() { |
| 36 | if ( ! isset( self::$instance ) ) { |
| 37 | self::$instance = new self(); |
| 38 | } |
| 39 | |
| 40 | return self::$instance; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Constructor. |
| 45 | * |
| 46 | * @since 2.3.7 |
| 47 | */ |
| 48 | private function __construct() { |
| 49 | add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 50 | add_action( 'astra_notice_before_markup', array( $this, 'notice_assets' ) ); |
| 51 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) ); |
| 52 | add_action( 'astra_sites_after_site_grid', array( $this, 'custom_upgrade_cta' ) ); |
| 53 | add_filter( 'astra_sites_quick_links', array( $this, 'change_quick_links' ) ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Change quick links |
| 58 | * |
| 59 | * @since 2.6.18 |
| 60 | * @param array $links All quick links. |
| 61 | * @return array |
| 62 | */ |
| 63 | public function change_quick_links( $links = array() ) { |
| 64 | |
| 65 | if ( ! isset( $links['links']['upgrade'] ) ) { |
| 66 | return $links; |
| 67 | } |
| 68 | |
| 69 | // Change default call to action link. |
| 70 | $links['links']['upgrade']['url'] = Astra_Sites::get_instance()->get_cta_link( 'quick-links-corner' ); |
| 71 | |
| 72 | return $links; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Admin Assets |
| 77 | */ |
| 78 | public function admin_assets() { |
| 79 | $current_screen = get_current_screen(); |
| 80 | |
| 81 | if ( 'appearance_page_starter-templates' !== $current_screen->id ) { |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | if ( Astra_Sites_White_Label::get_instance()->is_white_labeled() ) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | wp_enqueue_style( 'astra-sites-admin-page', ASTRA_SITES_URI . 'assets/css/admin.css', ASTRA_SITES_VER, true ); |
| 90 | wp_enqueue_script( 'astra-sites-admin-js', ASTRA_SITES_URI . 'assets/js/admin.js', array( 'astra-sites-admin-page', 'jquery' ), ASTRA_SITES_VER, true ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Add Custom CTA Infobar. |
| 95 | */ |
| 96 | public function custom_upgrade_cta() { |
| 97 | $current_screen = get_current_screen(); |
| 98 | |
| 99 | if ( 'appearance_page_starter-templates' !== $current_screen->id ) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | if ( Astra_Sites_White_Label::get_instance()->is_white_labeled() ) { |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | $custom_cta_content_data = apply_filters( |
| 108 | 'astra_sites_custom_cta_vars', |
| 109 | array( |
| 110 | 'text' => __( 'Get unlimited access to all premium Starter Templates and more, at a single low cost!', 'astra-sites' ), |
| 111 | 'button_text' => __( 'Get Essential Bundle', 'astra-sites' ), |
| 112 | 'cta_link' => Astra_Sites::get_instance()->get_cta_link(), |
| 113 | ) |
| 114 | ); |
| 115 | |
| 116 | $html = '<div class="astra-sites-custom-cta-wrap">'; |
| 117 | $html .= '<span class="astra-sites-cta-title">' . esc_html( $custom_cta_content_data['text'] ) . '</span>'; |
| 118 | $html .= '<span class="astra-sites-cta-btn">'; |
| 119 | $html .= '<a class="astra-sites-cta-link" href="' . esc_url( $custom_cta_content_data['cta_link'] ) . '" target="_blank" >' . esc_html( $custom_cta_content_data['button_text'] ) . '</a>'; |
| 120 | $html .= '</span>'; |
| 121 | $html .= '</div>'; |
| 122 | echo wp_kses_post( $html ); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Admin Notices |
| 127 | * |
| 128 | * @since 2.3.7 |
| 129 | * @return void |
| 130 | */ |
| 131 | public function admin_notices() { |
| 132 | |
| 133 | $image_path = esc_url( ASTRA_SITES_URI . 'inc/assets/images/logo.svg' ); |
| 134 | |
| 135 | $complete = get_option( 'astra_sites_import_complete', '' ); |
| 136 | |
| 137 | Astra_Notices::add_notice( |
| 138 | array( |
| 139 | 'id' => 'astra-sites-5-start-notice', |
| 140 | 'type' => 'info', |
| 141 | 'class' => 'astra-sites-5-star', |
| 142 | 'show_if' => ( 'yes' === $complete && false === Astra_Sites_White_Label::get_instance()->is_white_labeled() ), |
| 143 | /* translators: %1$s white label plugin name and %2$s deactivation link */ |
| 144 | 'message' => sprintf( |
| 145 | '<div class="notice-image" style="display: flex;"> |
| 146 | <img src="%1$s" class="custom-logo" alt="Starter Templates" itemprop="logo" style="max-width: 90px;"></div> |
| 147 | <div class="notice-content"> |
| 148 | <div class="notice-heading"> |
| 149 | %2$s |
| 150 | </div> |
| 151 | %3$s<br /> |
| 152 | <div class="astra-review-notice-container"> |
| 153 | <a href="%4$s" class="astra-notice-close astra-review-notice button-primary" target="_blank"> |
| 154 | %5$s |
| 155 | </a> |
| 156 | <span class="dashicons dashicons-calendar"></span> |
| 157 | <a href="#" data-repeat-notice-after="%6$s" class="astra-notice-close astra-review-notice"> |
| 158 | %7$s |
| 159 | </a> |
| 160 | <span class="dashicons dashicons-smiley"></span> |
| 161 | <a href="#" class="astra-notice-close astra-review-notice"> |
| 162 | %8$s |
| 163 | </a> |
| 164 | </div> |
| 165 | </div>', |
| 166 | $image_path, |
| 167 | __( 'Hello! Seems like you have used Starter Templates to build this website — Thanks a ton!', 'astra-sites' ), |
| 168 | __( 'Could you please do us a BIG favor and give it a 5-star rating on WordPress? This would boost our motivation and help other users make a comfortable decision while choosing the Starter Templates.', 'astra-sites' ), |
| 169 | 'https://wordpress.org/support/plugin/astra-sites/reviews/?filter=5#new-post', |
| 170 | __( 'Ok, you deserve it', 'astra-sites' ), |
| 171 | MONTH_IN_SECONDS, |
| 172 | __( 'Nope, maybe later', 'astra-sites' ), |
| 173 | __( 'I already did', 'astra-sites' ) |
| 174 | ), |
| 175 | ) |
| 176 | ); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Enqueue Astra Notices CSS. |
| 181 | * |
| 182 | * @since 2.3.7 |
| 183 | * |
| 184 | * @return void |
| 185 | */ |
| 186 | public static function notice_assets() { |
| 187 | $file = is_rtl() ? 'astra-notices-rtl.css' : 'astra-notices.css'; |
| 188 | wp_enqueue_style( 'astra-sites-notices', ASTRA_SITES_URI . 'assets/css/' . $file, array(), ASTRA_SITES_VER ); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Kicking this off by calling 'get_instance()' method |
| 194 | */ |
| 195 | Astra_Sites_Admin::get_instance(); |
| 196 | |
| 197 | endif; |
| 198 |