This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wptroopid_LifeCycle.php
205 lines (172 loc) · 6.62 KB
/
wptroopid_LifeCycle.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/*
"WordPress Plugin Template" Copyright (C) 2014 Michael Simpson (email : [email protected])
This file is part of WordPress Plugin Template for WordPress.
WordPress Plugin Template is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
WordPress Plugin Template is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Contact Form to Database Extension.
If not, see http://www.gnu.org/licenses/gpl-3.0.html
*/
include_once('wptroopid_InstallIndicator.php');
class troopid_LifeCycle extends troopid_InstallIndicator {
public function install() {
// Initialize Plugin Options
$this->initOptions();
// Initialize DB Tables used by the plugin
$this->installDatabaseTables();
// Other Plugin initialization - for the plugin writer to override as needed
$this->otherInstall();
// Record the installed version
$this->saveInstalledVersion();
// To avoid running install() more then once
$this->markAsInstalled();
}
public function uninstall() {
$this->otherUninstall();
$this->unInstallDatabaseTables();
$this->deleteSavedOptions();
$this->markAsUnInstalled();
}
/**
* Perform any version-upgrade activities prior to activation (e.g. database changes)
* @return void
*/
public function upgrade() {
}
/**
* See: http://plugin.michael-simpson.com/?page_id=105
* @return void
*/
public function activate() {
//test for redirect URI already set, if not, set it to the default
if(strlen($this->getOption('redirect_uri'))<4){
$this->updateOption('redirect_uri',plugin_dir_url(__FILE__).'wptroopid_redir.php');
}
//Set default scope to military.
$this->updateOption('scope','military');
//Set default response type to token
$this->updateOption('response_type','token');
}
/**
* See: http://plugin.michael-simpson.com/?page_id=105
* @return void
*/
public function deactivate() {
}
/**
* See: http://plugin.michael-simpson.com/?page_id=31
* @return void
*/
protected function initOptions() {
}
public function addActionsAndFilters() {
}
/**
* See: http://plugin.michael-simpson.com/?page_id=101
* Called by install() to create any database tables if needed.
* Best Practice:
* (1) Prefix all table names with $wpdb->prefix
* (2) make table names lower case only
* @return void
*/
protected function installDatabaseTables() {
}
/**
* See: http://plugin.michael-simpson.com/?page_id=101
* Drop plugin-created tables on uninstall.
* @return void
*/
protected function unInstallDatabaseTables() {
}
/**
* Override to add any additional actions to be done at install time
* See: http://plugin.michael-simpson.com/?page_id=33
* @return void
*/
protected function otherInstall() {
}
/**
* Override to add any additional actions to be done at uninstall time
* See: http://plugin.michael-simpson.com/?page_id=33
* @return void
*/
protected function otherUninstall() {
}
/**
* Puts the configuration page in the Plugins menu by default.
* Override to put it elsewhere or create a set of submenus
* Override with an empty implementation if you don't want a configuration page
* @return void
*/
public function addSettingsSubMenuPage() {
//$this->addSettingsSubMenuPageToPluginsMenu();
$this->addSettingsSubMenuPageToSettingsMenu();
}
protected function requireExtraPluginFiles() {
require_once(ABSPATH . 'wp-includes/pluggable.php');
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
}
/**
* @return string Slug name for the URL to the Setting page
* (i.e. the page for setting options)
*/
protected function getSettingsSlug() {
return get_class($this) . 'Settings';
}
protected function addSettingsSubMenuPageToPluginsMenu() {
$this->requireExtraPluginFiles();
$displayName = $this->getPluginDisplayName();
add_submenu_page('plugins.php',
$displayName,
$displayName,
'manage_options',
$this->getSettingsSlug(),
array(&$this, 'settingsPage'));
}
protected function addSettingsSubMenuPageToSettingsMenu() {
$this->requireExtraPluginFiles();
$displayName = $this->getPluginDisplayName();
add_options_page($displayName,
$displayName,
'manage_options',
$this->getSettingsSlug(),
array(&$this, 'settingsPage'));
}
/**
* @param $name string name of a database table
* @return string input prefixed with the WordPress DB table prefix
* plus the prefix for this plugin (lower-cased) to avoid table name collisions.
* The plugin prefix is lower-cases as a best practice that all DB table names are lower case to
* avoid issues on some platforms
*/
protected function prefixTableName($name) {
global $wpdb;
return $wpdb->prefix . strtolower($this->prefix($name));
}
/**
* Convenience function for creating AJAX URLs.
*
* @param $actionName string the name of the ajax action registered in a call like
* add_action('wp_ajax_actionName', array(&$this, 'functionName'));
* and/or
* add_action('wp_ajax_nopriv_actionName', array(&$this, 'functionName'));
*
* If have an additional parameters to add to the Ajax call, e.g. an "id" parameter,
* you could call this function and append to the returned string like:
* $url = $this->getAjaxUrl('myaction&id=') . urlencode($id);
* or more complex:
* $url = sprintf($this->getAjaxUrl('myaction&id=%s&var2=%s&var3=%s'), urlencode($id), urlencode($var2), urlencode($var3));
*
* @return string URL that can be used in a web page to make an Ajax call to $this->functionName
*/
public function getAjaxUrl($actionName) {
return admin_url('admin-ajax.php') . '?action=' . $actionName;
}
}