This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuddyboss-photo-categorization.php
265 lines (242 loc) · 7.56 KB
/
buddyboss-photo-categorization.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/**
* Plugin Name: BuddyBoss - Photo Categorization
* Plugin URI: https://github.com/alexangc/buddyboss-photo-categorization
* Description: Plugin allowing users to categorize uploaded pictures, based on given presets.
* Author: Alexis Miranda
* Author URI: https://github.com/alexangc/
* Version: 0.1.0
* Text Domain: buddyboss-photo-categorization
* Domain Path: /languages/
* License: GPLv3 or later (LICENCE)
*/
/**
* This file should always remain compatible with the minimum version of
* PHP supported by WordPress.
*/
// Exit if accessed directly
defined('ABSPATH') || exit();
if (!class_exists('PHOTOCAT_BB_Platform_Addon')) {
/**
* @class PHOTOCAT_BB_Platform_Addon
* @version 0.1.0
*/
final class PHOTOCAT_BB_Platform_Addon
{
/**
* @var PHOTOCAT_BB_Platform_Addon The single instance of the class
* @since 0.1.0
*/
protected static $_instance = null;
/**
* Main PHOTOCAT_BB_Platform_Addon Instance
*
* Ensures only one instance of PHOTOCAT_BB_Platform_Addon is loaded or can be loaded.
*
* @since 0.1.0
* @static
* @see PHOTOCAT_BB_Platform_Addon()
* @return PHOTOCAT_BB_Platform_Addon - Main instance
*/
public static function instance()
{
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Cloning is forbidden.
* @since 0.1.0
*/
public function __clone()
{
_doing_it_wrong(
__FUNCTION__,
__('Cheatin’ huh?', 'buddyboss-photo-categorization'),
'0.1.0'
);
}
/**
* Unserializing instances of this class is forbidden.
* @since 0.1.0
*/
public function __wakeup()
{
_doing_it_wrong(
__FUNCTION__,
__('Cheatin’ huh?', 'buddyboss-photo-categorization'),
'0.1.0'
);
}
/**
* PHOTOCAT_BB_Platform_Addon Constructor.
*/
public function __construct()
{
$this->define_constants();
$this->includes();
// Set up localisation.
$this->load_plugin_textdomain();
}
/**
* Define WCE Constants
*/
private function define_constants()
{
$this->define('PHOTOCAT_BB_ADDON_PLUGIN_FILE', __FILE__);
$this->define(
'PHOTOCAT_BB_ADDON_PLUGIN_BASENAME',
plugin_basename(__FILE__)
);
$this->define(
'PHOTOCAT_BB_ADDON_PLUGIN_PATH',
plugin_dir_path(__FILE__)
);
$this->define(
'PHOTOCAT_BB_ADDON_PLUGIN_URL',
plugin_dir_url(__FILE__)
);
}
/**
* Define constant if not already set
* @param string $name
* @param string|bool $value
*/
private function define($name, $value)
{
if (!defined($name)) {
define($name, $value);
}
}
/**
* Include required core files used in admin and on the frontend.
*/
public function includes()
{
include_once 'includes/components.php';
}
/**
* Get the plugin url.
* @return string
*/
public function plugin_url()
{
return untrailingslashit(plugins_url('/', __FILE__));
}
/**
* Get the plugin path.
* @return string
*/
public function plugin_path()
{
return untrailingslashit(plugin_dir_path(__FILE__));
}
/**
* Load Localisation files.
*
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
*/
public function load_plugin_textdomain()
{
$locale =
is_admin() && function_exists('get_user_locale')
? get_user_locale()
: get_locale();
$locale = apply_filters(
'plugin_locale',
$locale,
'buddyboss-photo-categorization'
);
unload_textdomain('buddyboss-photo-categorization');
load_textdomain(
'buddyboss-photo-categorization',
WP_LANG_DIR .
'/' .
plugin_basename(dirname(__FILE__)) .
'/' .
plugin_basename(dirname(__FILE__)) .
'-' .
$locale .
'.mo'
);
load_plugin_textdomain(
'buddyboss-photo-categorization',
false,
plugin_basename(dirname(__FILE__)) . '/languages'
);
}
}
/**
* Returns the main instance of PHOTOCAT_BB_Platform_Addon to prevent the need to use globals.
*
* @since 0.1.0
* @return PHOTOCAT_BB_Platform_Addon
*/
function PHOTOCAT_BB_Platform_Addon()
{
return PHOTOCAT_BB_Platform_Addon::instance();
}
function PHOTOCAT_BB_Platform_install_bb_platform_notice()
{
echo '<div class="error fade"><p>';
_e(
'<strong>BuddyBoss - Photo Categorization</strong></a> requires the BuddyBoss Platform plugin to work. Please <a href="https://buddyboss.com/platform/" target="_blank">install BuddyBoss Platform</a> first.',
'buddyboss-photo-categorization'
);
echo '</p></div>';
}
function PHOTOCAT_BB_Platform_update_bb_platform_notice()
{
echo '<div class="error fade"><p>';
_e(
'<strong>BuddyBoss - Photo Categorization</strong></a> requires BuddyBoss Platform plugin version 1.2.6 or higher to work. Please update BuddyBoss Platform.',
'buddyboss-photo-categorization'
);
echo '</p></div>';
}
function PHOTOCAT_BB_Platform_is_active()
{
if (
defined('BP_PLATFORM_VERSION') &&
version_compare(BP_PLATFORM_VERSION, '1.2.6', '>=')
) {
return true;
}
return false;
}
function PHOTOCAT_BB_Platform_init()
{
if (!defined('BP_PLATFORM_VERSION')) {
add_action(
'admin_notices',
'PHOTOCAT_BB_Platform_install_bb_platform_notice'
);
add_action(
'network_admin_notices',
'PHOTOCAT_BB_Platform_install_bb_platform_notice'
);
return;
}
if (version_compare(BP_PLATFORM_VERSION, '1.2.6', '<')) {
add_action(
'admin_notices',
'PHOTOCAT_BB_Platform_update_bb_platform_notice'
);
add_action(
'network_admin_notices',
'PHOTOCAT_BB_Platform_update_bb_platform_notice'
);
return;
}
PHOTOCAT_BB_Platform_Addon();
}
function PHOTOCAT_plugin_activate()
{
add_option('Activated_Plugin', 'buddyboss-photo-categorization');
require_once dirname(__FILE__) . '/includes/database.php';
PHOTOCAT_create_tables();
}
register_activation_hook(__FILE__, 'PHOTOCAT_plugin_activate');
add_action('plugins_loaded', 'PHOTOCAT_BB_Platform_init', 9);
}