|
1
|
|
|
<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
2
|
|
|
/** |
|
3
|
|
|
* File for installer control class definition |
|
4
|
|
|
* |
|
5
|
|
|
* @author Development team <[email protected]> |
|
6
|
|
|
* @version 1.0 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class for installer control |
|
12
|
|
|
* |
|
13
|
|
|
* @author Development team <[email protected]> |
|
14
|
|
|
* @version 1.0 |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
class wps_installer_ctr { |
|
18
|
|
|
|
|
19
|
|
|
/** Get the current step of installation */ |
|
20
|
|
|
private $current_installation_step; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Instanciate the module controller |
|
24
|
|
|
*/ |
|
25
|
|
|
function __construct() { |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** Call administration style definition & scripts */ |
|
28
|
|
|
add_action( 'admin_init', array( &$this, 'admin_scripts' ) ); |
|
29
|
|
|
|
|
30
|
|
|
$current_step = ( !empty( $_GET['wps-installation-step'] ) ) ? sanitize_title( $_GET['wps-installation-step'] ) : $this->current_installation_step; |
|
31
|
|
|
|
|
32
|
|
|
/** Instanciate datas saver components */ |
|
33
|
|
|
$wps_installer_model = new wps_installer_model(); |
|
34
|
|
|
|
|
35
|
|
|
$action = !empty( $_POST[ 'action' ] ) ? sanitize_text_field( $_POST[ 'action' ] ) : ''; |
|
36
|
|
|
/** Call datas saver */ |
|
37
|
|
|
if ( !empty( $current_step ) && !empty( $action ) && ( "wps-installation" == $action ) ) { |
|
38
|
|
|
$step_to_save = $current_step - 1; |
|
39
|
|
|
$wps_installer_model->save_step( $step_to_save ); |
|
40
|
|
|
if ( WPSINSTALLER_STEPS_COUNT == $current_step ) { |
|
41
|
|
|
add_action( 'init', array( &$this, 'go_to_wpshop_about' ) ); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** Set the current installatino step */ |
|
46
|
|
|
$this->current_installation_step = get_option( 'wps-installation-current-step', 1 ); |
|
47
|
|
|
|
|
48
|
|
|
/** Get current version for wpshop plugin */ |
|
49
|
|
|
$wps_current_db_version = get_option( 'wpshop_db_options', 0 ); |
|
50
|
|
|
|
|
51
|
|
|
/** Check the configuration state */ |
|
52
|
|
|
$installation_state = !empty( $_GET[ 'installation_state' ] ) ? sanitize_text_field( $_GET[ 'installation_state' ] ) : ''; |
|
53
|
|
|
if ( isset( $installation_state ) && !empty( $installation_state ) && !empty( $wps_current_db_version ) |
|
54
|
|
|
&& (empty( $wps_current_db_version[ 'installation_state' ] ) || ( $wps_current_db_version[ 'installation_state' ] != 'completed' ) ) ) { |
|
55
|
|
|
$wps_current_db_version = $wps_installer_model->installer_state_saver( $installation_state, $wps_current_db_version ); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** Do verification for shop who are configured for being sale shop */ |
|
59
|
|
|
$current_page = strstr( $_SERVER[ "REQUEST_URI" ], 'wps-about'); |
|
60
|
|
|
if ( isset( $wps_current_db_version['installation_state'] ) && ( $wps_current_db_version[ 'installation_state' ] == 'completed' ) && ( WPSHOP_DEFINED_SHOP_TYPE == 'sale' ) && empty( $current_page ) ) { |
|
61
|
|
|
add_action( 'admin_notices', array( 'wpshop_notices' , 'sale_shop_notice' ) ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** Create an administration menu */ |
|
65
|
|
|
add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
66
|
|
|
|
|
67
|
|
|
/** In case that configuration have not been done and that instalation is not asked to be ignored */ |
|
68
|
|
|
if ( empty( $wps_current_db_version ) || empty( $wps_current_db_version[ 'installation_state' ] ) || ( !empty( $wps_current_db_version[ 'installation_state' ] ) && !in_array( $wps_current_db_version[ 'installation_state' ], array( 'completed', 'ignored' ) ) ) ) { |
|
69
|
|
|
/* Check the db installation state for admin message output */ |
|
70
|
|
|
$current_page = strstr( $_SERVER[ "REQUEST_URI" ], 'wps-installer'); |
|
71
|
|
|
if( ( WPSINSTALLER_STEPS_COUNT > $this->current_installation_step ) && ( empty( $current_page ) ) ) { |
|
72
|
|
|
add_action( 'admin_notices', array( &$this, 'install_admin_notice' ) ); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** Hook wpshop dashboard in order to display the notice banner with quick links - wordpress like */ |
|
77
|
|
|
add_filter( 'wps-dashboard-notice', array( $this, 'wps_dashboard_notice' ), 10, 1 ); |
|
78
|
|
|
|
|
79
|
|
|
/** Hook ajax action when clicking on hide welcome banner on wpshop dashboard */ |
|
80
|
|
|
add_action( 'wp_ajax_wps-hide-welcome-panel', array( $this, 'wps_hide_welcome_panel' ) ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Enqueue style definition |
|
86
|
|
|
* Enqueue scripts definition |
|
87
|
|
|
*/ |
|
88
|
|
View Code Duplication |
function admin_scripts($hook_suffix) { |
|
|
|
|
|
|
89
|
|
|
if ( 'wps-installer.php' !== $hook_suffix ) |
|
90
|
|
|
return; |
|
91
|
|
|
|
|
92
|
|
|
wp_register_style( 'wps_installer_style', WPS_INSTALLER_URL . WPS_INSTALLER_DIR . '/assets/css/backend-styles.css', '', WPS_INSTALLER_VERSION ); |
|
93
|
|
|
wp_enqueue_style( 'wps_installer_style' ); |
|
94
|
|
|
wp_enqueue_script( 'wps-installer-admin-scripts', WPS_INSTALLER_URL . WPS_INSTALLER_DIR . '/assets/js/backend-scripts.js', array( 'jquery' ), WPS_INSTALLER_VERSION ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Call the menu for displaying installer interface |
|
99
|
|
|
*/ |
|
100
|
|
|
function admin_menu() { |
|
|
|
|
|
|
101
|
|
|
/** Get current version for wpshop plugin */ |
|
102
|
|
|
$wps_current_db_version = get_option( 'wpshop_db_options', 0 ); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
add_menu_page( __( 'Install WPShop', 'wpshop' ), __( 'WPShop - install', 'wpshop' ), 'manage_options', 'wps-installer', array( &$this, 'installer_main_page' ) ); |
|
105
|
|
|
remove_menu_page( 'wps-installer' ); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Display the installer interface |
|
110
|
|
|
*/ |
|
111
|
|
|
function installer_main_page() { |
|
|
|
|
|
|
112
|
|
|
$current_step = ( !empty( $_GET['wps-installation-step'] ) ) ? wpshop_tools::varSanitizer( $_GET['wps-installation-step'] ) : $this->current_installation_step; |
|
113
|
|
|
$steps = unserialize( WPSINSTALLER_STEPS ); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
/** Get the defined shop type in order to display the different element to */ |
|
116
|
|
|
$wps_shop_type = get_option( 'wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE ); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
/** Check the current step to display */ |
|
119
|
|
|
$current_step_output = ''; |
|
|
|
|
|
|
120
|
|
|
$the_step_file = ''; |
|
|
|
|
|
|
121
|
|
|
switch( $current_step ) { |
|
122
|
|
|
case 2: |
|
123
|
|
|
$the_step_file = 'step_two'; |
|
124
|
|
|
break; |
|
125
|
|
|
|
|
126
|
|
|
default: |
|
127
|
|
|
$the_step_file = 'step_one'; |
|
128
|
|
|
break; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** Create display for current step */ |
|
132
|
|
|
ob_start(); |
|
133
|
|
|
require_once( wpshop_tools::get_template_part( WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", $the_step_file ) ); |
|
134
|
|
|
$current_step_output = ob_get_contents(); |
|
|
|
|
|
|
135
|
|
|
ob_end_clean(); |
|
136
|
|
|
|
|
137
|
|
|
require_once( wpshop_tools::get_template_part( WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "installer" ) ); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Create a notice for admin user when plugin is activated and not yet configured |
|
142
|
|
|
*/ |
|
143
|
|
|
function install_admin_notice() { |
|
|
|
|
|
|
144
|
|
|
require_once( wpshop_tools::get_template_part( WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "notice" ) ); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Redirect the user automatically to the wpshop about page |
|
149
|
|
|
*/ |
|
150
|
|
|
function go_to_wpshop_about() { |
|
|
|
|
|
|
151
|
|
|
wp_redirect( admin_url( 'admin.php?page=wpshop_about' ) ); |
|
152
|
|
|
exit(); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* DISPLAY - Output the about page for wpshop |
|
157
|
|
|
*/ |
|
158
|
|
|
function wps_about_page() { |
|
|
|
|
|
|
159
|
|
|
require_once( wpshop_tools::get_template_part( WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "about" ) ); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* DISPLAY - Display a banner on wpshop dashboard |
|
164
|
|
|
*/ |
|
165
|
|
|
function wps_dashboard_notice() { |
|
|
|
|
|
|
166
|
|
|
$user_pref = get_user_meta( get_current_user_id(), '_wps_hide_notice_messages_indicator', true ); |
|
167
|
|
|
|
|
168
|
|
|
if ( empty( $user_pref ) || empty( $user_pref[ 'welcome-banner' ] ) ) { |
|
169
|
|
|
/** Get current shop type */ |
|
170
|
|
|
$shop_type = get_option( 'wpshop_shop_type' ); |
|
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
/** Get the current number of product created */ |
|
173
|
|
|
$nb_products = 0; |
|
174
|
|
|
$created_products = wp_count_posts( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ); |
|
175
|
|
|
if ( !empty( $created_products ) ) { |
|
176
|
|
|
foreach ( $created_products as $created_product_type => $created_product_nb) { |
|
177
|
|
|
/** Don't count product that are automatically created and not accessible through amin interface */ |
|
178
|
|
|
if ( !in_array( $created_product_type, array( 'auto-draft', 'inherit' ) ) ) { |
|
179
|
|
|
$nb_products += $created_product_nb; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** Get configuration about payment method */ |
|
185
|
|
|
$no_payment_mode_configurated = true; |
|
|
|
|
|
|
186
|
|
View Code Duplication |
if ( !empty($paymentMethod ) && !empty($paymentMethod['mode']) ) { |
|
|
|
|
|
|
187
|
|
|
foreach( $paymentMethod['mode'] as $k => $pm ) { |
|
188
|
|
|
if ( !empty($pm['active'] ) ) { |
|
189
|
|
|
$no_payment_mode_configurated = false; |
|
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** Get configuration about emails */ |
|
195
|
|
|
$emails = get_option('wpshop_emails', array() ); |
|
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
require_once( wpshop_tools::get_template_part( WPS_INSTALLER_DIR, WPSINSTALLER_TPL_DIR, "backend", "welcome" ) ); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* AJAX - Launch ajax action allowing to hide welcome panel for current user |
|
203
|
|
|
*/ |
|
204
|
|
|
function wps_hide_welcome_panel() { |
|
|
|
|
|
|
205
|
|
|
$wpshop_ajax_nonce = !empty( $_REQUEST['wpshop_ajax_nonce'] ) ? sanitize_text_field( $_REQUEST['wpshop_ajax_nonce'] ) : ''; |
|
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
if ( !wp_verify_nonce( $_wpnonce, 'wps-installer-welcome-panel-close' ) ) |
|
|
|
|
|
|
208
|
|
|
wp_die(); |
|
209
|
|
|
|
|
210
|
|
|
$user_pref = get_user_meta( get_current_user_id(), '_wps_hide_notice_messages_indicator', true ); |
|
211
|
|
|
$user_pref[ 'welcome-banner' ] = true; |
|
212
|
|
|
|
|
213
|
|
|
$response = array( |
|
214
|
|
|
'status' => false, |
|
215
|
|
|
); |
|
216
|
|
|
|
|
217
|
|
|
$user_pref = update_user_meta( get_current_user_id(), '_wps_hide_notice_messages_indicator', $user_pref ); |
|
218
|
|
|
if ( false !== $user_pref ) { |
|
219
|
|
|
$response[ 'status' ] = true; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
wp_die( json_encode( $response ) ); |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
?> |
|
|
|
|
|
|
227
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.