-
Notifications
You must be signed in to change notification settings - Fork 6
/
bp-compliments.php
255 lines (225 loc) · 7.16 KB
/
bp-compliments.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
<?php
/**
* BuddyPress Compliments
*
* @package BuddyPress_Compliments
* @author AyeCode Ltd
* @copyright 2016 AyeCode Ltd
* @license GPLv3
*
* @wordpress-plugin
* Plugin Name: BuddyPress Compliments
* Plugin URI: https://wordpress.org/plugins/buddypress-compliments/
* Description: BuddyPress Compliments plugin adds a smart way for BuddyPress members to interact with each other via compliments.
* Version: 1.1.1
* Requires at least: 4.5
* Tested up to: 6.0
* Requires PHP: 5.6
* Author: AyeCode Ltd
* Author URI: https://ayecode.io
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: bp-compliments
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! defined( 'BP_COMPLIMENTS_VER' ) ) {
/**
* Plugin version.
*/
define( 'BP_COMPLIMENTS_VER', '1.1.1' );
}
if ( ! defined( 'BP_COMP_TEXTDOMAIN' ) ) {
/**
* Plugin textdomain.
*/
define( 'BP_COMP_TEXTDOMAIN', 'bp-compliments' );
}
if ( ! defined( 'BP_COMP_SINGULAR_NAME' ) ) {
/**
* Compliments singular name.
*/
define( 'BP_COMP_SINGULAR_NAME', trim( esc_attr( get_option( 'bp_compliment_singular_name', __( 'Compliment', 'bp-compliments' ) ) ) ) );
}
if ( ! defined( 'BP_COMP_PLURAL_NAME' ) ) {
/**
* Compliments plural name.
*/
define( 'BP_COMP_PLURAL_NAME', trim( esc_attr( get_option( 'bp_compliment_plural_name', __( 'Compliments', 'bp-compliments' ) ) ) ) );
}
if ( ! defined( 'BP_COMPLIMENTS_SLUG' ) ) {
/**
* Compliments slug.
*/
define( 'BP_COMPLIMENTS_SLUG', trim( strtolower( esc_attr( get_option('bp_compliment_slug', __( 'compliments', 'bp-compliments' ) ) ) ) ) );
}
/**
* Only load the plugin code if BuddyPress is activated.
*
* @since 0.0.1
* @package BuddyPress_Compliments
*
* @global object $bp BuddyPress instance.
* @global object $wpdb WordPress db object.
*/
function bp_compliments_init() {
global $wpdb, $bp;
if ( !$table_prefix = $bp->table_prefix )
/**
* Filters the value of BuddyPress table prefix.
*
* @since 0.0.1
* @package BuddyPress_Compliments
*
* @param string $wpdb->base_prefix WordPress table prefix.
*/
$table_prefix = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );
if ( ! defined( 'BP_COMPLIMENTS_DIR' ) ) {
/**
* Compliments plugin directory.
*/
define( 'BP_COMPLIMENTS_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'BP_COMPLIMENTS_URL' ) ) {
/**
* Compliments plugin url.
*/
define( 'BP_COMPLIMENTS_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) . '/' );
}
if ( ! defined( 'BP_COMPLIMENTS_TABLE' ) ) {
/**
* Compliments database table.
*/
define( 'BP_COMPLIMENTS_TABLE', $table_prefix . 'bp_compliments' );
}
if ( file_exists( BP_COMPLIMENTS_DIR . 'vendor/autoload.php' ) ) {
require_once( BP_COMPLIMENTS_DIR . 'vendor/autoload.php' );
}
// Only supported in BP 1.5+
if ( version_compare( BP_VERSION, '1.3', '>' ) ) {
require( BP_COMPLIMENTS_DIR . 'bp-compliments-core.php' );
// Show admin notice for users on BP 1.2.x
} else {
add_action( 'admin_notices', 'bp_compliments_older_version_notice' );
return;
}
}
add_action( 'bp_include', 'bp_compliments_init' );
add_action( 'init', 'bp_compliments_plugin_init' );
/**
* Hook into actions and filters on site init.
*/
function bp_compliments_plugin_init() {
add_action( 'tgmpa_register', 'bp_compliments_require_plugins' );
}
/**
* Add required plugin check.
*/
function bp_compliments_require_plugins(){
$plugins = array( /* The array to install plugins */ );
$plugins = array(
array(
'name' => 'BuddyPress',
'slug' => 'buddypress',
'required' => true, // this plugin is recommended
'version' => '1.5'
)
);
$config = array(); /* The array to configure TGM Plugin Activation */
tgmpa( $plugins, $config );
}
/**
* Creates Custom table for BuddyPress compliments.
*
* @since 0.0.1
* @package BuddyPress_Compliments
*
* @global object $bp BuddyPress instance.
* @global object $wpdb WordPress db object.
*/
function bp_compliments_activate() {
global $bp, $wpdb;
$version = get_option( 'bp_compliments_version');
if (!$version) {
$charset_collate = !empty( $wpdb->charset ) ? "DEFAULT CHARACTER SET $wpdb->charset" : '';
if ( !$table_prefix = $bp->table_prefix )
/**
* Filters the value of BuddyPress table prefix.
*
* @since 0.0.1
* @package BuddyPress_Compliments
*
* @param string $wpdb->base_prefix WordPress table prefix.
*/
$table_prefix = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );
$sql = "CREATE TABLE {$table_prefix}bp_compliments (
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
term_id int(10) NOT NULL,
post_id int(10) NULL DEFAULT NULL,
receiver_id bigint(20) NOT NULL,
sender_id bigint(20) NOT NULL,
message varchar(1000) NULL DEFAULT NULL,
created_at datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
KEY compliments (receiver_id, sender_id)
) {$charset_collate};";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
update_option( 'bp_compliments_version', BP_COMPLIMENTS_VER );
}
add_option( 'bp_compliments_activation_redirect', 1 );
}
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
register_activation_hook( __FILE__, 'bp_compliments_activate' );
register_deactivation_hook( __FILE__, 'bp_compliments_deactivate' );
add_action( 'admin_init', 'bp_compliments_activation_redirect' );
}
/**
* Plugin deactivation hook.
*
* @since 1.0.7
*/
function bp_compliments_deactivate() {
// Plugin deactivation stuff.
}
/**
* Redirects user to BuddyPress Compliments settings page after plugin activation.
*
* @since 1.0.7
*/
function bp_compliments_activation_redirect() {
if ( get_option( 'bp_compliments_activation_redirect', false ) ) {
delete_option( 'bp_compliments_activation_redirect' );
if(class_exists('BuddyPress')){
wp_redirect( admin_url( 'admin.php?page=bp-compliment-settings' ) );
exit;
}
}
}
/**
* Custom text domain loader.
*
* @since 0.0.1
* @package BuddyPress_Compliments
*/
function bp_compliments_localization() {
global $wp_version;
$locale = $wp_version >= 4.7 ? get_user_locale() : get_locale();
/**
* Filter the plugin locale.
*
* @since 1.0.0
* @package BuddyPress_Compliments
*/
$locale = apply_filters( 'plugin_locale', $locale, 'bp-compliments' );
unload_textdomain( 'bp-compliments' );
load_textdomain( 'bp-compliments', WP_LANG_DIR . '/bp-compliments/bp-compliments-' . $locale . '.mo' );
load_plugin_textdomain( 'bp-compliments', false, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'bp_compliments_localization' );
function bp_compliments_older_version_notice() {
$older_version_notice = __( "Hey! BP Compliments requires BuddyPress 1.5 or higher.", 'bp-compliments' );
echo '<div class="error"><p>' . $older_version_notice . '</p></div>';
}