forked from weDevsOfficial/wp-user-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.php
185 lines (155 loc) · 6.35 KB
/
installer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* Page installer
*
* @since 2.3
*/
class WPUF_Admin_Installer {
function __construct() {
add_action( 'admin_notices', array($this, 'admin_notice') );
add_action( 'admin_init', array($this, 'handle_request') );
}
/**
* Print admin notices
*
* @return void
*/
function admin_notice() {
$page_created = get_option( '_wpuf_page_created' );
if ( $page_created != '1' && 'off' == wpuf_get_option( 'install_wpuf_pages', 'wpuf_general', 'on' ) ) {
?>
<div class="updated error">
<p>
<?php _e( 'If you have not created <strong>WP User Frontend</strong> pages yet, you can do this by one click.', 'wp-user-frontend' ); ?>
</p>
<p class="submit">
<a class="button button-primary" href="<?php echo add_query_arg( array( 'install_wpuf_pages' => true ), admin_url( 'admin.php?page=wpuf-settings' ) ); ?>"><?php _e( 'Install WPUF Pages', 'wp-user-frontend' ); ?></a>
<?php _e( 'or', 'wp-user-frontend' ); ?>
<a class="button" href="<?php echo add_query_arg( array( 'wpuf_hide_page_nag' => true ) ); ?>"><?php _e( 'Skip Setup', 'wp-user-frontend' ); ?></a>
</p>
</div>
<?php
}
if ( isset( $_GET['wpuf_page_installed'] ) && $_GET['wpuf_page_installed'] == '1' ) {
?>
<div class="updated">
<p>
<strong><?php _e( 'Congratulations!', 'wp-user-frontend' ); ?></strong> <?php _e( 'Pages for <strong>WP User Frontend</strong> has been successfully installed and saved!', 'wp-user-frontend' ); ?>
</p>
</div>
<?php
}
}
/**
* Handle the page creation button requests
*
* @return void
*/
function handle_request() {
if ( isset( $_GET['install_wpuf_pages'] ) && $_GET['install_wpuf_pages'] == '1' ) {
$this->init_pages();
}
if ( isset( $_POST['install_wpuf_pages'] ) && $_POST['install_wpuf_pages'] == '1' ) {
$this->init_pages();
}
if ( isset( $_GET['wpuf_hide_page_nag'] ) && $_GET['wpuf_hide_page_nag'] == '1' ) {
update_option( '_wpuf_page_created', '1' );
}
}
/**
* Initialize the plugin with some default page/settings
*
* @since 2.2
* @return void
*/
function init_pages() {
// create a dashboard page
$dashboard_page = $this->create_page( __( 'Dashboard', 'wp-user-frontend' ), '[wpuf_dashboard]' );
$account_page = $this->create_page( __( 'Account', 'wp-user-frontend' ), '[wpuf_account]' );
$edit_page = $this->create_page( __( 'Edit', 'wp-user-frontend' ), '[wpuf_edit]' );
// login page
$login_page = $this->create_page( __( 'Login', 'wp-user-frontend' ), '[wpuf-login]' );
$post_form = $this->create_form();
if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
// payment page
$subscr_page = $this->create_page( __( 'Subscription', 'wp-user-frontend' ), __( '[wpuf_sub_pack]', 'wp-user-frontend') );
$payment_page = $this->create_page( __( 'Payment', 'wp-user-frontend' ), __( 'Please select a gateway for payment', 'wp-user-frontend') );
$thank_page = $this->create_page( __( 'Thank You', 'wp-user-frontend' ), __( '<h1>Payment is complete</h1><p>Congratulations, your payment has been completed!</p>', 'wp-user-frontend') );
$bank_page = $this->create_page( __( 'Order Received', 'wp-user-frontend' ), __( 'Hi, we have received your order. We will validate the order and will take necessary steps to move forward.', 'wp-user-frontend') );
}
// save the settings
if ( $edit_page ) {
update_option( 'wpuf_frontend_posting', array(
'edit_page_id' => $edit_page,
'default_post_form' => $post_form
) );
}
// profile pages
$profile_options = array();
$reg_page = false;
if ( $login_page ) {
$profile_options['login_page'] = $login_page;
}
$data = apply_filters( 'wpuf_pro_page_install', $profile_options );
if ( is_array( $data ) ) {
if ( isset ( $data['profile_options'] ) ) {
$profile_options = $data['profile_options'];
}
if ( isset ( $data['reg_page'] ) ) {
$reg_page = $data['reg_page'];
}
}
if ( $login_page && $reg_page ) {
$profile_options['register_link_override'] = 'on';
}
update_option( 'wpuf_profile', $profile_options );
if ( 'on' == wpuf_get_option( 'enable_payment', 'wpuf_payment', 'on' ) ) {
// payment pages
update_option( 'wpuf_payment', array(
'subscription_page' => $subscr_page,
'payment_page' => $payment_page,
'payment_success' => $thank_page,
'bank_success' => $bank_page
) );
}
update_option( '_wpuf_page_created', '1' );
wp_redirect( admin_url( 'admin.php?page=wpuf-settings&wpuf_page_installed=1' ) );
exit;
}
/**
* Create a page with title and content
*
* @param string $page_title
* @param string $post_content
* @return false|int
*/
function create_page( $page_title, $post_content = '', $post_type = 'page' ) {
$page_id = wp_insert_post( array(
'post_title' => $page_title,
'post_type' => $post_type,
'post_status' => 'publish',
'comment_status' => 'closed',
'post_content' => $post_content
) );
if ( $page_id && ! is_wp_error( $page_id ) ) {
return $page_id;
}
return false;
}
/**
* Create a basic registration form by default
*
* @return int|boolean
*/
function create_reg_form() {
return wpuf_create_sample_form( __( 'Registration', 'wp-user-frontend' ), 'wpuf_profile' );
}
/**
* Create a post form
*
* @return void
*/
function create_form() {
return wpuf_create_sample_form( __( 'Sample Form', 'wp-user-frontend' ), 'wpuf_forms' );
}
}