|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Installation related functions and actions. |
|
4
|
|
|
* |
|
5
|
|
|
* @since 1.0.0 |
|
6
|
|
|
* @author Sébastien Dumont |
|
7
|
|
|
* @category Admin |
|
8
|
|
|
* @package Auto Load Next Post |
|
9
|
|
|
* @license GPL-2.0+ |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
if ( ! defined('ABSPATH')) { |
|
13
|
|
|
exit; |
|
14
|
|
|
} |
|
15
|
|
|
// Exit if accessed directly |
|
16
|
|
|
|
|
17
|
|
|
if ( ! class_exists('Auto_Load_Next_Post_Install')) { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class - Auto_Load_Next_Post_Install |
|
21
|
|
|
* |
|
22
|
|
|
* @since 1.0.0 |
|
23
|
|
|
*/ |
|
24
|
|
|
class Auto_Load_Next_Post_Install { |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @since 1.0.0 |
|
30
|
|
|
* @access public |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct() { |
|
33
|
|
|
register_activation_hook(AUTO_LOAD_NEXT_POST_FILE, array($this, 'install')); |
|
34
|
|
|
register_deactivation_hook(AUTO_LOAD_NEXT_POST_FILE, array($this, 'deactivate')); |
|
35
|
|
|
} // END __construct() |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Install Auto Load Next Post |
|
39
|
|
|
* |
|
40
|
|
|
* @since 1.0.0 |
|
41
|
|
|
* @access public |
|
42
|
|
|
*/ |
|
43
|
|
|
public function install() { |
|
44
|
|
|
// Add default options |
|
45
|
|
|
$this->create_options(); |
|
46
|
|
|
|
|
47
|
|
|
// Add install date |
|
48
|
|
|
$this->insert_install_date(); |
|
49
|
|
|
|
|
50
|
|
|
// Add plugin version |
|
51
|
|
|
update_option('auto_load_next_post_version', AUTO_LOAD_NEXT_POST_VERSION); |
|
52
|
|
|
} // END install() |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Insert the install date of the plugin. |
|
56
|
|
|
* |
|
57
|
|
|
* @since 1.4.4 |
|
58
|
|
|
* @access public |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
public static function insert_install_date() { |
|
62
|
|
|
$datetime_now = new DateTime(); |
|
63
|
|
|
$date_string = $datetime_now->format('Y-m-d'); |
|
64
|
|
|
|
|
65
|
|
|
add_site_option('auto_load_next_post_install_date', $date_string, '', 'no'); |
|
66
|
|
|
|
|
67
|
|
|
return $date_string; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Refresh the permalinks on deactivating the plugin. |
|
72
|
|
|
* |
|
73
|
|
|
* @since 1.0.0 |
|
74
|
|
|
* @access public |
|
75
|
|
|
*/ |
|
76
|
|
|
public function deactivate() { |
|
77
|
|
|
flush_rewrite_rules(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Default Options |
|
82
|
|
|
* |
|
83
|
|
|
* Sets up the default options defined on the settings pages. |
|
84
|
|
|
* |
|
85
|
|
|
* @since 1.0.0 |
|
86
|
|
|
* @access public |
|
87
|
|
|
*/ |
|
88
|
|
|
public function create_options() { |
|
89
|
|
|
// Include settings so that we can run through defaults |
|
90
|
|
|
include_once('class-auto-load-next-post-admin-settings.php'); |
|
91
|
|
|
|
|
92
|
|
|
$settings = Auto_Load_Next_Post_Admin_Settings::get_settings_pages(); |
|
93
|
|
|
|
|
94
|
|
|
foreach ($settings as $section) { |
|
95
|
|
|
foreach ($section->get_settings() as $value) { |
|
96
|
|
|
if (isset($value['default']) && isset($value['id'])) { |
|
97
|
|
|
$autoload = isset($value['autoload']) ? (bool) $value['autoload'] : true; |
|
98
|
|
|
add_option($value['id'], $value['default'], '', ($autoload ? 'yes' : 'no')); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} // END create_options() |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Delete all plugin options. |
|
106
|
|
|
* |
|
107
|
|
|
* @since 1.0.0 |
|
108
|
|
|
* @access public |
|
109
|
|
|
* @global $wpdb |
|
110
|
|
|
*/ |
|
111
|
|
|
public function delete_options() { |
|
112
|
|
|
global $wpdb; |
|
113
|
|
|
|
|
114
|
|
|
// Delete options |
|
115
|
|
|
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'auto_load_next_post_%';"); |
|
116
|
|
|
} // END delete_options() |
|
117
|
|
|
|
|
118
|
|
|
} // END if class. |
|
119
|
|
|
|
|
120
|
|
|
} // END if class exists. |
|
121
|
|
|
|
|
122
|
|
|
return new Auto_Load_Next_Post_Install(); |
|
123
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.