PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.13
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.13
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.13, at includes/Core/Admin.php

276 lines 9.5 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_menu', [ $this, 'admin_menu' ] );
30
31 self::$cache_bank = CacheBank::get_instance();
32
33 try {
34 add_action( 'admin_init', [ $this, 'notices' ], 11 );
35 } catch ( Exception $e ) {
36 unset( $e );
37 }
38
39 // Remove OLD notice from 1.0.0 (if other WPDeveloper plugin has notice)
40 NoticeRemover::get_instance( '1.0.0' );
41 }
42
43 /**
44 * Enqueuing Assets
45 *
46 * @param string $hook
47 *
48 * @return void
49 */
50 public function scripts( $hook ) {
51 if ( ! in_array( $hook, [ 'toplevel_page_templately', 'elementor', 'gutenberg' ], true ) ) {
52 return;
53 }
54
55 $script_dependencies = [];
56 $_localize_handle = 'templately';
57 $_current_screen = 'templately';
58
59 if ( $hook === 'elementor' || $hook === 'gutenberg' ) {
60 $_current_screen = $hook;
61 $_localize_handle = 'templately-' . $hook;
62 $script_dependencies = [ $_localize_handle ];
63 }
64
65 if ( $hook === 'toplevel_page_templately' ) {
66 templately()->assets->enqueue( 'templately-admin', 'css/admin.css', [ 'templately' ] );
67 }
68
69 // Google Font Enqueueing
70 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' ) );
71
72 templately()->assets->enqueue( 'templately', 'js/templately.js', $script_dependencies, true );
73 templately()->assets->enqueue( 'templately', 'css/templately.css', [ 'templately-dmsans' ] );
74
75 /**
76 * @var Elementor|Gutenberg $platform
77 */
78 $platform = $this->platform( $_current_screen );
79
80 templately()->assets->localize( $_localize_handle, 'templately', [
81 'url' => home_url(),
82 'site_url' => site_url(),
83 'nonce' => wp_create_nonce( 'templately_nonce' ),
84 'rest_args' => [
85 'nonce' => wp_create_nonce( 'wp_rest' ),
86 'endpoint' => get_rest_url( null, 'templately/v1/' )
87 ],
88 'log' => defined( 'TEMPLATELY_DEBUG_LOG' ) && TEMPLATELY_DEBUG_LOG,
89 'dev_mode' => defined( 'TEMPLATELY_DEV' ) && TEMPLATELY_DEV,
90 "icons" => [
91 'profile' => templately()->assets->icon( 'icons/profile.svg' ),
92 'warning' => templately()->assets->icon( 'icons/warning.png' )
93 ],
94 'promo_image' => templately()->assets->icon( 'single-page-promo.png' ),
95 'default_image' => templately()->assets->icon( 'clouds/cloud-item.svg' ),
96 'not_found' => templately()->assets->icon( 'no-item-found.png' ),
97 'no_items' => templately()->assets->icon( 'no-items.png' ),
98 'loadingImage' => templately()->assets->icon( 'logos/loading-logo.gif' ),
99 'current_url' => admin_url( 'admin.php?page=templately' ),
100 'is_signed' => Login::is_signed(),
101 'is_globally_signed' => Login::is_globally_signed(),
102 'signed_as_global' => Login::signed_as_global(),
103 'current_screen' => $_current_screen,
104 'has_elementor_pro' => rest_sanitize_boolean( is_plugin_active( 'elementor-pro/elementor-pro.php' ) ),
105 'theme' => $_current_screen == 'templately' ? 'light' : $platform->ui_theme()
106 ] );
107 }
108
109 /**
110 * Admin notices for Review and others.
111 *
112 * @return void
113 * @throws Exception
114 * @since 2.0.0
115 */
116 public function notices() {
117 $notices = new Notices( [
118 'id' => 'templately',
119 'storage_key' => 'notices',
120 'lifetime' => 3,
121 'stylesheet_url' => TEMPLATELY_ASSETS . 'css/notices.css',
122 'styles' => TEMPLATELY_ASSETS . 'css/notices.css',
123 'priority' => 2,
124 ] );
125
126 $global_user = Options::get_instance()->get( 'user', false, get_current_user_id() );
127 $download_counts = Options::get_instance()->get( 'total_download_counts', 0, get_current_user_id() );
128 $cloud_items = 0;
129 if ( isset( $global_user['my_cloud']['usages'] ) ) {
130 $cloud_items = intval( $global_user['my_cloud']['usages'] );
131 }
132
133 if ( $cloud_items >= 5 || $download_counts >= 4 ) {
134 $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>' );
135
136 $_review_notice = [
137 'thumbnail' => templately()->assets->icon( 'logos/logo.svg' ),
138 'html' => '<p>' . $message . '</p>',
139 'links' => [
140 'later' => [
141 'link' => 'https://wordpress.org/support/plugin/templately/reviews/#new-post',
142 'target' => '_blank',
143 'label' => __( 'Sure, you deserve it!', 'templately' ),
144 'icon_class' => 'dashicons dashicons-external'
145 ],
146 'allready' => [
147 'label' => __( 'I already did', 'templately' ),
148 'icon_class' => 'dashicons dashicons-smiley',
149 'attributes' => [
150 'data-dismiss' => true
151 ]
152 ],
153 'maybe_later' => [
154 'label' => __( 'Maybe Later', 'templately' ),
155 'icon_class' => 'dashicons dashicons-calendar-alt',
156 'attributes' => [
157 'data-later' => true,
158 'class' => 'dismiss-btn'
159 ]
160 ],
161 'support' => [
162 'link' => 'https://wpdeveloper.com/support',
163 'attributes' => [
164 'target' => '_blank'
165 ],
166 'label' => __( 'I need help', 'templately' ),
167 'icon_class' => 'dashicons dashicons-sos'
168 ],
169 'never_show_again' => [
170 'label' => __( 'Never show again', 'templately' ),
171 'icon_class' => 'dashicons dashicons-dismiss',
172 'attributes' => [
173 'data-dismiss' => true
174 ]
175 ]
176 ]
177 ];
178
179 $notices->add( 'review', $_review_notice, [
180 'start' => $notices->strtotime(),
181 'recurrence' => 20,
182 'dismissible' => true,
183 'refresh' => TEMPLATELY_VERSION,
184 'screens' => [
185 'dashboard',
186 'plugins',
187 'themes',
188 'edit-page',
189 'edit-post',
190 'users',
191 'tools',
192 'options-general',
193 'nav-menus'
194 ]
195 ] );
196 }
197
198 if ( $global_user === false || isset( $global_user['plan'] ) && $global_user['plan'] == 'free' ) {
199 $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' ), [
200 'start' => $notices->strtotime( '+10 day' ),
201 'dismissible' => true,
202 'refresh' => TEMPLATELY_VERSION,
203 'screens' => [
204 'dashboard',
205 'plugins',
206 'themes',
207 'edit-page',
208 'edit-post',
209 'users',
210 'tools',
211 'options-general',
212 'nav-menus'
213 ]
214 ] );
215
216 $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>
217 <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>';
218
219 $_black_friday = [
220 'thumbnail' => templately()->assets->icon( 'logos/logo-full.svg' ),
221 'html' => $notice_text,
222 ];
223
224 $notices->add( 'black_friday', $_black_friday, [
225 'start' => $notices->time(),
226 'recurrence' => false,
227 'dismissible' => true,
228 'refresh' => TEMPLATELY_VERSION,
229 "expire" => strtotime( '11:59:59pm 2nd December, 2023' ),
230 ] );
231 }
232
233 self::$cache_bank->create_account( $notices );
234 self::$cache_bank->calculate_deposits( $notices );
235 }
236
237 /**
238 * Adding Menu In Sidebar ( WordPress Left-side Dashboard Menu )
239 *
240 * @return void
241 */
242 public function admin_menu() {
243 // TODO: Role Management
244 add_menu_page( 'Templately', 'Templately', 'delete_posts', 'templately', [
245 $this,
246 'display'
247 ], templately()->assets->icon( 'logos/logo-icon.svg' ), '58.7' );
248 }
249
250 public function display() {
251 Helper::views( 'settings' );
252 }
253
254 /**
255 * If Elementor doesn't exists.
256 *
257 * @return void
258 */
259 public static function has_no_elementor() {
260 $plugin_url = \wp_nonce_url( \self_admin_url( 'update.php?action=install-plugin&amp;plugin=elementor' ), 'install-plugin_elementor' );
261 $button_text = 'Install Elementor';
262 if ( isset( Helper::get_plugins()['elementor/elementor.php'] ) ) {
263 $plugin_url = \wp_nonce_url( 'plugins.php?action=activate&amp;plugin=elementor/elementor.php', 'activate-plugin_elementor/elementor.php' );
264 $button_text = 'Activate Elementor';
265 }
266 $output = '<div class="notice notice-error">';
267 $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' ) );
268 $output .= '</div>';
269 echo $output;
270 }
271
272 public function header() {
273 Helper::views( 'header' );
274 }
275 }
276