-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathclass.mesh-install.php
102 lines (81 loc) · 2.42 KB
/
class.mesh-install.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
<?php
/**
* Install class for Mesh
*
* @since 1.2.0
* @package Mesh
* @subpackage Install
*/
// Make sure we don't expose any info if called directly.
if ( ! function_exists( 'add_action' ) ) {
exit;
}
/**
* Class Mesh_Install
*/
class Mesh_Install {
/**
* Check to see if mesh has been installed before.
*/
public function __construct() {
if ( ! is_admin() ) {
return;
}
add_action( 'mesh_activate', array( $this, 'setup_activation' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_init', array( $this, 'show_welcome' ) );
}
/**
* Enqueue our notifications, but really enqueue everything
*/
public function admin_enqueue_scripts() {
wp_enqueue_script( 'admin-mesh-notifications', plugins_url( 'js/admin-mesh-notifications.js', __FILE__ ), array(), LINCHPIN_MESH_VERSION, true );
wp_localize_script( 'admin-mesh-notifications', 'mesh_notifications', array(
'dismiss_nonce' => wp_create_nonce( 'mesh_dismiss_notification_nonce' ),
) );
}
/**
* On first install show new users a welcome screen.
* Only show the message when installing an individual message.
*
* @since 1.2
*/
public function show_welcome() {
if ( is_admin() && 1 === intval( get_option( 'mesh_activation' ) ) ) {
delete_option( 'mesh_activation' );
$mesh_section_count = wp_count_posts( 'mesh_section' );
$mesh_sections = $mesh_section_count->publish + $mesh_section_count->draft + $mesh_section_count->trash + $mesh_section_count->{'auto-draft'};
// Send new users to the welcome so they learn how to use mesh.
if ( ! isset( $_GET['activate-multi'] ) && 0 === $mesh_sections ) { // WPCS: CSRF ok, input var okay.
wp_safe_redirect( admin_url( 'options-general.php?page=mesh&tab=about' ) );
exit;
}
}
}
/**
* When the option doesn't exist, it should be a new install.
*
* @return bool
*/
public function is_first_install() {
$options = get_option( 'mesh_settings' );
if ( ! empty( $options ) ) {
return false;
}
return true;
}
/**
* Sets install date. If the user doesn't have a date it sets it
* on install and activation.
*
* @since 1.2.5
*/
public function setup_activation() {
$options = get_option( 'mesh_settings' );
if ( empty( $options['first_activated_on'] ) ) {
$options['first_activated_on'] = time();
update_option( 'mesh_settings', $options );
}
}
}
$mesh_install = new Mesh_Install();