PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.0.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.0.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / admin.php

admin.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.0.0, at includes/admin.php

208 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use StoreEngine\Utils\Helper;
10
11 class Admin {
12
13 public static function init() {
14 $self = new self();
15
16 // Load admin classes.
17 Admin\Menu::init();
18 Admin\Setup::init();
19 Admin\Notices::init();
20 Admin\ScheduledActionsTool::init();
21
22 // Dispatch insights.
23 $self->dispatch_insights();
24 $self->dispatch_hooks();
25
26 // Add hooks.
27 add_filter( 'allowed_redirect_hosts', array( $self, 'add_white_listed_redirect_hosts' ) );
28 add_filter( 'display_post_states', array( $self, 'add_display_post_states' ), 10, 2 );
29 add_filter( 'theme_page_templates', [ $self, 'load_page_templates' ] );
30
31 add_action( 'admin_init', [ $self, 'prevent_admin_access' ] );
32 add_action( 'current_screen', [ $self, 'conditional_loaded' ] );
33 add_filter( 'admin_init', array( $self, 'redirect_storeengine_product' ) );
34 }
35
36 public function dispatch_hooks() {
37 add_filter( 'plugin_action_links_' . STOREENGINE_PLUGIN_BASENAME, [ $this, 'plugin_action_links' ] );
38 }
39
40 public function plugin_action_links( $links ) {
41 $settings_link = sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'admin.php?page=storeengine-settings' ), esc_html__( 'Settings', 'storeengine' ) );
42
43 array_unshift( $links, $settings_link );
44
45 if ( ! defined( 'STOREENGINE_PRO_VERSION' ) ) {
46 $links['go_pro'] = sprintf( '<a href="%1$s" target="_blank" class="storeengine-plugins-gopro" style="color: #7b68ee; font-weight: bold;">%2$s</a>', 'https://storeengine.pro/pricing/', esc_html__( 'Get StoreEngine Pro', 'storeengine' ) );
47 }
48
49 return $links;
50 }
51
52 public function add_white_listed_redirect_hosts( $hosts ) {
53 $hosts[] = 'storeengine.pro';
54
55 return $hosts;
56 }
57
58 public function add_display_post_states( $post_states, $post ) {
59 if ( (int) Helper::get_settings( 'shop_page' ) === $post->ID ) {
60 $post_states['storeengine_page_for_shop_page'] = __( 'StoreEngine Shop Page', 'storeengine' );
61 }
62
63 if ( (int) Helper::get_settings( 'cart_page' ) === $post->ID ) {
64 $post_states['storeengine_page_for_cart_page'] = __( 'StoreEngine Cart Page', 'storeengine' );
65 }
66
67 if ( (int) Helper::get_settings( 'checkout_page' ) === $post->ID ) {
68 $post_states['storeengine_page_for_checkout_page'] = __( 'StoreEngine Checkout Page', 'storeengine' );
69 }
70
71 if ( (int) Helper::get_settings( 'thankyou_page' ) === $post->ID ) {
72 $post_states['storeengine_page_for_thankyou_page'] = __( 'StoreEngine Thank You Page', 'storeengine' );
73 }
74
75 if ( (int) Helper::get_settings( 'dashboard_page' ) === $post->ID ) {
76 $post_states['storeengine_page_for_dashboard_page'] = __( 'StoreEngine Dashboard Page', 'storeengine' );
77 }
78
79 return $post_states;
80 }
81
82 public function load_page_templates( $templates ) {
83 // Page editor error (non-fse theme) Updating failed. Invalid parameter(s): template
84 // https://github.com/Automattic/sensei/issues/7215
85 // https://github.com/Automattic/wp-calypso/issues/59570
86 // https://forum.muffingroup.com/betheme/discussion/51757/creating-a-custom-template
87
88 $templates['storeengine-canvas.php'] = esc_html__( 'StoreEngine Canvas', 'storeengine' );
89
90 return $templates;
91 }
92
93 public function prevent_admin_access() {
94 $prevent_access = false;
95
96 // Do not interfere with admin-post or admin-ajax requests.
97 $exempted_paths = [ 'admin-post.php', 'admin-ajax.php' ];
98
99 if (
100 apply_filters( 'storeengine/disable_admin_bar', true )
101 && isset( $_SERVER['SCRIPT_FILENAME'] )
102 && ! in_array( basename( sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_FILENAME'] ) ) ), $exempted_paths, true )
103 ) {
104 $has_cap = false;
105 $access_caps = [ 'edit_posts', 'manage_storeengine', 'view_admin_dashboard' ];
106
107
108 foreach ( $access_caps as $access_cap ) {
109 if ( current_user_can( $access_cap ) ) {
110 $has_cap = true;
111 break;
112 }
113 }
114
115 if ( ! $has_cap ) {
116 $prevent_access = true;
117 }
118
119 if ( 'storeengine_customer' === reset( wp_get_current_user()->roles ) ) {
120 $prevent_access = true;
121 }
122 }
123
124 if ( apply_filters( 'storeengine/prevent_admin_access', $prevent_access ) ) {
125 wp_safe_redirect( Helper::get_dashboard_url() );
126 exit;
127 }
128 }
129
130 public function conditional_loaded() {
131 $screen = get_current_screen();
132
133 if ( ! $screen ) {
134 return;
135 }
136
137 if ( $screen->id == 'storeengine_page_storeengine-get-pro' ) {
138 $link = add_query_arg(
139 [
140 'utm_source' => 'storeengine-plugin',
141 'utm_medium' => 'admin-dashboard',
142 'utm_campaign' => 'upgrade-to-pro',
143 'utm_content' => 'get-pro-button',
144 'utm_term' => 'free-user',
145 'locale' => get_locale(),
146 ],
147 'https://storeengine.pro/pricing'
148 );
149
150 wp_safe_redirect( $link );
151 exit;
152 }
153
154 if ( 'options-permalink' === $screen->id ) {
155 Admin\PermalinkSettings::init();
156 }
157 }
158
159 public function dispatch_insights() {
160 Admin\Insights::init(
161 'https://kodezen.com',
162 STOREENGINE_PLUGIN_SLUG,
163 'plugin',
164 STOREENGINE_VERSION,
165 [
166 'logo' => STOREENGINE_ASSETS_URI . 'images/logo.svg', // default logo URL
167 'optin_message' => 'Help improve StoreEngine! Allow anonymous usage tracking?',
168 'deactivation_message' => 'If you have a moment, please share why you are deactivating StoreEngine:',
169 'deactivation_reasons' => [
170 'no_longer_needed' => [
171 'label' => 'I no longer need the plugin',
172 ],
173 'found_a_better_plugin' => [
174 'label' => 'I found a better plugin',
175 'has_custom_reason' => true,
176 'custom_reason_placeholder' => 'Please share which plugin',
177 ],
178 'couldnt_get_the_plugin_to_work' => [
179 'label' => 'I couldn\'t get the plugin to work',
180 ],
181 'temporary_deactivation' => [
182 'label' => 'It\'s a temporary deactivation',
183 ],
184 'have_storeengine_pro' => [
185 'label' => 'I have StoreEngine Pro',
186 'toggle_text' => 'Wait! Don\'t deactivate StoreEngine. You have to activate both StoreEngine and StoreEngine Pro in order for the plugin to work.',
187 ],
188 'other' => [
189 'label' => 'Other',
190 'has_custom_reason' => true,
191 'custom_reason_placeholder' => 'Please share the reason',
192 ],
193 ],
194 ]
195 );
196 }
197
198 public function redirect_storeengine_product() {
199 global $pagenow;
200 $post_type = isset( $_GET['post_type'] ) ? sanitize_key( $_GET['post_type'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
201 if ( 'edit.php' === $pagenow && $post_type && 'storeengine_product' === $post_type ) {
202 $new_url = admin_url( 'admin.php?page=storeengine-products' );
203 wp_safe_redirect( $new_url );
204 exit;
205 }
206 }
207 }
208