PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.10
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.10
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Core / Admin.php

Admin.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 2.2.10, at includes/Core/Admin.php

297 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Core;
4
5 use Exception;
6 use PriyoMukul\WPNotice\Notices;
7 use PriyoMukul\WPNotice\Utils\CacheBank;
8 use PriyoMukul\WPNotice\Utils\NoticeRemover;
9 use Templately\API\Login;
10 use Templately\Core\Platform\Elementor;
11 use Templately\Core\Platform\Gutenberg;
12 use Templately\Utils\Base;
13 use Templately\Utils\Helper;
14 use Templately\Utils\Options;
15
16 class Admin extends Base {
17
18 /**
19 * @var CacheBank
20 */
21 private static $cache_bank;
22
23 /**
24 * Initially invoked function.
25 * Menu, Assets and maybe redirect on plugin activation is initialized.
26 */
27 public function __construct() {
28 add_action( 'admin_enqueue_scripts', [ $this, 'scripts' ] );
29 add_action( 'admin_init', [ $this, 'maybe_redirect_templately' ] );
30 add_action( 'admin_menu', [ $this, 'admin_menu' ] );
31
32 self::$cache_bank = CacheBank::get_instance();
33
34 try {
35 add_action( 'admin_init', [ $this, 'notices' ], 11 );
36 } catch ( Exception $e ) {
37 unset( $e );
38 }
39
40 // Remove OLD notice from 1.0.0 (if other WPDeveloper plugin has notice)
41 NoticeRemover::get_instance( '1.0.0' );
42 }
43
44 /**
45 * Enqueuing Assets
46 *
47 * @param string $hook
48 *
49 * @return void
50 */
51 public function scripts( $hook ) {
52 if ( ! in_array( $hook, [ 'toplevel_page_templately', 'elementor', 'gutenberg' ], true ) ) {
53 return;
54 }
55
56 $script_dependencies = [];
57 $_localize_handle = 'templately';
58 $_current_screen = 'templately';
59
60 if ( $hook === 'elementor' || $hook === 'gutenberg' ) {
61 $_current_screen = $hook;
62 $_localize_handle = 'templately-' . $hook;
63 $script_dependencies = [ $_localize_handle ];
64 }
65
66 if ( $hook === 'toplevel_page_templately' ) {
67 templately()->assets->enqueue( 'templately-admin', 'css/admin.css', [ 'templately' ] );
68 }
69
70 // Google Font Enqueueing
71 templately()->assets->enqueue( 'templately-dmsans', set_url_scheme( '//fonts.googleapis.com/css2?family=DM+Sans:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap' ) );
72
73 templately()->assets->enqueue( 'templately', 'js/templately.js', $script_dependencies, true );
74 templately()->assets->enqueue( 'templately', 'css/templately.css', [ 'templately-dmsans' ] );
75
76 /**
77 * @var Elementor|Gutenberg $platform
78 */
79 $platform = $this->platform( $_current_screen );
80
81 templately()->assets->localize( $_localize_handle, 'templately', [
82 'url' => home_url(),
83 'site_url' => site_url(),
84 'nonce' => wp_create_nonce( 'templately_nonce' ),
85 'rest_args' => [
86 'nonce' => wp_create_nonce( 'wp_rest' ),
87 'endpoint' => get_rest_url( null, 'templately/v1/' )
88 ],
89 'log' => defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG,
90 'dev_mode' => defined( 'TEMPLATELY_DEV' ) && TEMPLATELY_DEV,
91 "icons" => [
92 'profile' => templately()->assets->icon( 'icons/profile.svg' ),
93 'warning' => templately()->assets->icon( 'icons/warning.png' )
94 ],
95 'promo_image' => templately()->assets->icon( 'single-page-promo.png' ),
96 'default_image' => templately()->assets->icon( 'clouds/cloud-item.svg' ),
97 'not_found' => templately()->assets->icon( 'no-item-found.png' ),
98 'no_items' => templately()->assets->icon( 'no-items.png' ),
99 'loadingImage' => templately()->assets->icon( 'logos/loading-logo.gif' ),
100 'current_url' => admin_url( 'admin.php?page=templately' ),
101 'is_signed' => Login::is_signed(),
102 'is_globally_signed' => Login::is_globally_signed(),
103 'signed_as_global' => Login::signed_as_global(),
104 'current_screen' => $_current_screen,
105 'has_elementor_pro' => rest_sanitize_boolean( is_plugin_active( 'elementor-pro/elementor-pro.php' ) ),
106 'theme' => $_current_screen == 'templately' ? 'light' : $platform->ui_theme()
107 ] );
108 }
109
110 /**
111 * Admin notices for Review and others.
112 *
113 * @return void
114 * @throws Exception
115 * @since 2.0.0
116 */
117 public function notices() {
118 $notices = new Notices( [
119 'id' => 'templately',
120 'storage_key' => 'notices',
121 'lifetime' => 3,
122 'stylesheet_url' => TEMPLATELY_ASSETS . 'css/notices.css',
123 'styles' => TEMPLATELY_ASSETS . 'css/notices.css',
124 'priority' => 2,
125 ] );
126
127 $global_user = Options::get_instance()->get( 'user', false, get_current_user_id() );
128 $download_counts = Options::get_instance()->get( 'total_download_counts', 0, get_current_user_id() );
129 $cloud_items = 0;
130 if ( isset( $global_user['my_cloud']['usages'] ) ) {
131 $cloud_items = intval( $global_user['my_cloud']['usages'] );
132 }
133
134 if ( $cloud_items >= 5 || $download_counts >= 4 ) {
135 $message = sprintf( __( "We hope you're enjoying %s! Could you please do us a favor and give us a review on %s to help us spread the word and boost our motivation?", 'templately' ), '<strong>Templately</strong>', '<strong>WordPress</strong>' );
136
137 $_review_notice = [
138 'thumbnail' => templately()->assets->icon( 'logos/logo.svg' ),
139 'html' => '<p>' . $message . '</p>',
140 'links' => [
141 'later' => [
142 'link' => 'https://wordpress.org/support/plugin/templately/reviews/#new-post',
143 'target' => '_blank',
144 'label' => __( 'Sure, you deserve it!', 'templately' ),
145 'icon_class' => 'dashicons dashicons-external'
146 ],
147 'allready' => [
148 'label' => __( 'I already did', 'templately' ),
149 'icon_class' => 'dashicons dashicons-smiley',
150 'attributes' => [
151 'data-dismiss' => true
152 ]
153 ],
154 'maybe_later' => [
155 'label' => __( 'Maybe Later', 'templately' ),
156 'icon_class' => 'dashicons dashicons-calendar-alt',
157 'attributes' => [
158 'data-later' => true,
159 'class' => 'dismiss-btn'
160 ]
161 ],
162 'support' => [
163 'link' => 'https://wpdeveloper.com/support',
164 'attributes' => [
165 'target' => '_blank'
166 ],
167 'label' => __( 'I need help', 'templately' ),
168 'icon_class' => 'dashicons dashicons-sos'
169 ],
170 'never_show_again' => [
171 'label' => __( 'Never show again', 'templately' ),
172 'icon_class' => 'dashicons dashicons-dismiss',
173 'attributes' => [
174 'data-dismiss' => true
175 ]
176 ]
177 ]
178 ];
179
180 $notices->add( 'review', $_review_notice, [
181 'start' => $notices->strtotime(),
182 'recurrence' => 20,
183 'dismissible' => true,
184 'refresh' => TEMPLATELY_VERSION,
185 'screens' => [
186 'dashboard',
187 'plugins',
188 'themes',
189 'edit-page',
190 'edit-post',
191 'users',
192 'tools',
193 'options-general',
194 'nav-menus'
195 ]
196 ] );
197 }
198
199 if ( $global_user === false || isset( $global_user['plan'] ) && $global_user['plan'] == 'free' ) {
200 $notices->add( 'upsale', wp_sprintf( '<p>%1$s <a target="_blank" href="%3$s">%2$s</a>.</p>', __( '🔥 Get access to 5,000+ Ready Templates & save up to 65% OFF now', 'templately' ), __( 'Upgrade to Pro', 'templately' ), 'https://templately.com/#pricing' ), [
201 'start' => $notices->strtotime( '+10 day' ),
202 'dismissible' => true,
203 'refresh' => TEMPLATELY_VERSION,
204 'screens' => [
205 'dashboard',
206 'plugins',
207 'themes',
208 'edit-page',
209 'edit-post',
210 'users',
211 'tools',
212 'options-general',
213 'nav-menus'
214 ]
215 ] );
216
217 $notice_text = '<p style="margin-top: 0; margin-bottom: 10px;">Black Friday Sale: Save up to 70% and <strong>get access to 5000+ ready templates</strong> to design amazing websites ✨</p>
218 <a class="button button-primary" href="https://wpdeveloper.com/upgrade/templately-bfcm" target="_blank">Upgrade to pro</a> <button data-dismiss="true" class="dismiss-btn button button-link">I don’t want to save money</button>';
219
220 $_black_friday = [
221 'thumbnail' => templately()->assets->icon( 'logos/logo-full.svg' ),
222 'html' => $notice_text,
223 ];
224
225 $notices->add( 'black_friday', $_black_friday, [
226 'start' => $notices->time(),
227 'recurrence' => false,
228 'dismissible' => true,
229 'refresh' => TEMPLATELY_VERSION,
230 "expire" => strtotime( '11:59:59pm 2nd December, 2023' ),
231 ] );
232 }
233
234 self::$cache_bank->create_account( $notices );
235 self::$cache_bank->calculate_deposits( $notices );
236 }
237
238 /**
239 * Adding Menu In Sidebar ( WordPress Left-side Dashboard Menu )
240 *
241 * @return void
242 */
243 public function admin_menu() {
244 // TODO: Role Management
245 add_menu_page( 'Templately', 'Templately', 'delete_posts', 'templately', [
246 $this,
247 'display'
248 ], templately()->assets->icon( 'logos/logo-icon.svg' ), '58.7' );
249 }
250
251 public function display() {
252 Helper::views( 'settings' );
253 }
254
255 /**
256 * Redirect on Active
257 */
258 public function maybe_redirect_templately() {
259 if ( ! get_transient( 'templately_activation_redirect' ) ) {
260 return;
261 }
262 if ( wp_doing_ajax() ) {
263 return;
264 }
265
266 delete_transient( 'templately_activation_redirect' );
267 if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
268 return;
269 }
270 // Safe Redirect to Templately Page
271 wp_safe_redirect( admin_url( 'admin.php?page=templately' ) );
272 exit;
273 }
274
275 /**
276 * If Elementor doesn't exists.
277 *
278 * @return void
279 */
280 public static function has_no_elementor() {
281 $plugin_url = \wp_nonce_url( \self_admin_url( 'update.php?action=install-plugin&amp;plugin=elementor' ), 'install-plugin_elementor' );
282 $button_text = 'Install Elementor';
283 if ( isset( Helper::get_plugins()['elementor/elementor.php'] ) ) {
284 $plugin_url = \wp_nonce_url( 'plugins.php?action=activate&amp;plugin=elementor/elementor.php', 'activate-plugin_elementor/elementor.php' );
285 $button_text = 'Activate Elementor';
286 }
287 $output = '<div class="notice notice-error">';
288 $output .= sprintf( "<p><strong>%s</strong> %s <strong>%s</strong> %s &nbsp;&nbsp;<a class='button-primary' href='%s'>%s</a></p>", __( 'Templately', 'templately' ), __( 'requires', 'templately' ), __( 'Elementor', 'templately' ), __( 'plugin to be installed and activated. Please install Elementor to continue.', 'templately' ), esc_url( $plugin_url ), __( $button_text, 'templately' ) );
289 $output .= '</div>';
290 echo $output;
291 }
292
293 public function header() {
294 Helper::views( 'header' );
295 }
296 }
297