forked from GeoDirectory/buddypress-compliments
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbp-compliments.php
205 lines (180 loc) · 6.49 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
<?php
/**
* This is the main BuddyPress Compliments plugin file, here we declare and call the important stuff
*
* @package BuddyPress_Compliments
* @copyright 2016 AyeCode Ltd
* @license GPL-2.0+
*
* @wordpress-plugin
* Plugin Name: BuddyPress Compliments
* Plugin URI: http://wpgeodirectory.com/
* Description: Compliments module for BuddyPress.
* Version: 1.0.6
* Author: GeoDirectory
* Author URI: http://wpgeodirectory.com
* Text Domain: bp-compliments
* Domain Path: /languages
* Requires at least: 3.1
* Tested up to: 4.4
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
// Define the plugin version.
define( 'BP_COMPLIMENTS_VER', '1.0.6' );
/**
* BuddyPress compliments text domain.
*/
define( 'BP_COMP_TEXTDOMAIN', 'bp-compliments' );
/**
* BuddyPress compliments names.
*/
define( 'BP_COMP_SINGULAR_NAME', trim(esc_attr( get_option('bp_compliment_singular_name', __( 'Compliment', 'bp-compliments' )))) );
define( 'BP_COMP_PLURAL_NAME', trim(esc_attr( get_option('bp_compliment_plural_name', __( 'Compliments', 'bp-compliments' )))) );
define( 'BP_COMPLIMENTS_SLUG', strtolower(trim(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;
//define the plugin path.
define( 'BP_COMPLIMENTS_DIR', dirname( __FILE__ ) );
//define the plugin url.
define( 'BP_COMPLIMENTS_URL', plugin_dir_url( __FILE__ ) );
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 );
////define the plugin table.
define( 'BP_COMPLIMENTS_TABLE', $table_prefix . 'bp_compliments' );
// only supported in BP 1.5+
if ( version_compare( BP_VERSION, '1.3', '>' ) ) {
require( constant( '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' );
/**
* 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() ) {
register_activation_hook( __FILE__, 'bp_compliments_activate' );
register_deactivation_hook( __FILE__, 'bp_compliments_deactivate' );
add_filter( 'geodir_plugins_uninstall_settings', 'bp_compliments_uninstall_settings', 10, 1 );
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' );
wp_redirect( admin_url( 'admin.php?page=bp-compliment-settings' ) );
}
}
/**
* Custom text domain loader.
*
* @since 0.0.1
* @package BuddyPress_Compliments
*/
function bp_compliments_localization() {
/**
* Filters the value of plugin locale.
*
* @since 0.0.1
* @package BuddyPress_Compliments
*/
$locale = apply_filters('plugin_locale', get_locale(), 'bp-compliments');
load_textdomain('bp-compliments', WP_LANG_DIR . '/' . 'bp-compliments' . '/' . 'bp-compliments' . '-' . $locale . '.mo');
load_plugin_textdomain('bp-compliments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages');
}
add_action( 'plugins_loaded', 'bp_compliments_localization' );
add_action( 'admin_notices', 'bp_compliments_required_plugins_nag' );
function bp_compliments_required_plugins_nag() {
// Check for BuddyPress
$class = "update-nag";
$url = 'https://wordpress.org/plugins/buddypress/';
$message = sprintf( wp_kses( __( 'BuddyPress Compliments requires <a target="_blank" href="%s">BuddyPress</a> plugin.', 'bp-compliments' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) );
if(!class_exists('BuddyPress')){
echo"<div class=\"$class\"> <p>$message</p></div>";
}
}
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>';
}
/**
* Add the plugin to uninstall settings.
*
* @since 1.0.7
*
* @return array $settings the settings array.
* @return array The modified settings.
*/
function bp_compliments_uninstall_settings($settings) {
$settings[] = plugin_basename(dirname(__FILE__));
return $settings;
}