-
Notifications
You must be signed in to change notification settings - Fork 27
/
functions.php
136 lines (110 loc) · 4.52 KB
/
functions.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
<?php
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'MYPLUGIN_admin_enqueue_script' ) ) {
function MYPLUGIN_admin_enqueue_script() {
wp_enqueue_style( 'buddyboss-addon-admin-css', plugin_dir_url( __FILE__ ) . 'style.css' );
}
add_action( 'admin_enqueue_scripts', 'MYPLUGIN_admin_enqueue_script' );
}
if ( ! function_exists( 'MYPLUGIN_get_settings_sections' ) ) {
function MYPLUGIN_get_settings_sections() {
$settings = array(
'MYPLUGIN_settings_section' => array(
'page' => 'addon',
'title' => __( 'Add-on Settings', 'buddyboss-platform-addon' ),
),
);
return (array) apply_filters( 'MYPLUGIN_get_settings_sections', $settings );
}
}
if ( ! function_exists( 'MYPLUGIN_get_settings_fields_for_section' ) ) {
function MYPLUGIN_get_settings_fields_for_section( $section_id = '' ) {
// Bail if section is empty
if ( empty( $section_id ) ) {
return false;
}
$fields = MYPLUGIN_get_settings_fields();
$retval = isset( $fields[ $section_id ] ) ? $fields[ $section_id ] : false;
return (array) apply_filters( 'MYPLUGIN_get_settings_fields_for_section', $retval, $section_id );
}
}
if ( ! function_exists( 'MYPLUGIN_get_settings_fields' ) ) {
function MYPLUGIN_get_settings_fields() {
$fields = array();
$fields['MYPLUGIN_settings_section'] = array(
'MYPLUGIN_field' => array(
'title' => __( 'Add-on Field', 'buddyboss-platform-addon' ),
'callback' => 'MYPLUGIN_settings_callback_field',
'sanitize_callback' => 'absint',
'args' => array(),
),
);
return (array) apply_filters( 'MYPLUGIN_get_settings_fields', $fields );
}
}
if ( ! function_exists( 'MYPLUGIN_settings_callback_field' ) ) {
function MYPLUGIN_settings_callback_field() {
?>
<input name="MYPLUGIN_field"
id="MYPLUGIN_field"
type="checkbox"
value="1"
<?php checked( MYPLUGIN_is_addon_field_enabled() ); ?>
/>
<label for="MYPLUGIN_field">
<?php _e( 'Enable this option', 'buddyboss-platform-addon' ); ?>
</label>
<?php
}
}
if ( ! function_exists( 'MYPLUGIN_is_addon_field_enabled' ) ) {
function MYPLUGIN_is_addon_field_enabled( $default = 1 ) {
return (bool) apply_filters( 'MYPLUGIN_is_addon_field_enabled', (bool) get_option( 'MYPLUGIN_field', $default ) );
}
}
/***************************** Add section in current settings ***************************************/
/**
* Register fields for settings hooks
* bp_admin_setting_general_register_fields
* bp_admin_setting_xprofile_register_fields
* bp_admin_setting_groups_register_fields
* bp_admin_setting_forums_register_fields
* bp_admin_setting_activity_register_fields
* bp_admin_setting_media_register_fields
* bp_admin_setting_friends_register_fields
* bp_admin_setting_invites_register_fields
* bp_admin_setting_search_register_fields
*/
if ( ! function_exists( 'MYPLUGIN_bp_admin_setting_general_register_fields' ) ) {
function MYPLUGIN_bp_admin_setting_general_register_fields( $setting ) {
// Main General Settings Section
$setting->add_section( 'MYPLUGIN_addon', __( 'Add-on Settings', 'buddyboss-platform-addon' ) );
$args = array();
$setting->add_field( 'bp-enable-my-addon', __( 'My Field', 'buddyboss-platform-addon' ), 'MYPLUGIN_admin_general_setting_callback_my_addon', 'intval', $args );
}
add_action( 'bp_admin_setting_general_register_fields', 'MYPLUGIN_bp_admin_setting_general_register_fields' );
}
if ( ! function_exists( 'MYPLUGIN_admin_general_setting_callback_my_addon' ) ) {
function MYPLUGIN_admin_general_setting_callback_my_addon() {
?>
<input id="bp-enable-my-addon" name="bp-enable-my-addon" type="checkbox"
value="1" <?php checked( MYPLUGIN_enable_my_addon() ); ?> />
<label for="bp-enable-my-addon"><?php _e( 'Enable my option', 'buddyboss-platform-addon' ); ?></label>
<?php
}
}
if ( ! function_exists( 'MYPLUGIN_enable_my_addon' ) ) {
function MYPLUGIN_enable_my_addon( $default = false ) {
return (bool) apply_filters( 'MYPLUGIN_enable_my_addon', (bool) bp_get_option( 'bp-enable-my-addon', $default ) );
}
}
/**************************************** MY PLUGIN INTEGRATION ************************************/
/**
* Set up the my plugin integration.
*/
function MYPLUGIN_register_integration() {
require_once dirname( __FILE__ ) . '/integration/buddyboss-integration.php';
buddypress()->integrations['addon'] = new MYPLUGIN_BuddyBoss_Integration();
}
add_action( 'bp_setup_integrations', 'MYPLUGIN_register_integration' );