This repository has been archived by the owner on Nov 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprofil-de-groupes.php
156 lines (133 loc) · 3.19 KB
/
profil-de-groupes.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
<?php
/**
* Plugin Name: Profil de Groupes
* Plugin URI: https://github.com/imath/profil-de-groupes/
* Description: Un profil pour les groupes BuddyPress.
* Version: 1.2.0
* Requires at least: 4.8
* Requires PHP: 5.6
* Requires Plugins: buddypress
* Tested up to: 6.1
* License: GPLv2 or later
* Author: imath
* Author URI: https://imathi.eu/
* Text Domain: profil-de-groupes
* Domain Path: /languages/
* GitHub Plugin URI: https://github.com/imath/profil-de-groupes/
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Profil_De_Groupes' ) ) :
/**
* Main Plugin Class
*
* @since 1.0.0
*/
final class Profil_De_Groupes {
/**
* Plugin's main instance
*
* @var object
*/
protected static $instance;
/**
* Initialize the plugin
*
* @since 1.0.0
*/
private function __construct() {
$this->globals();
$this->inc();
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function start() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Setups plugin's globals
*
* @since 1.0.0
*/
private function globals() {
// Version
$this->version = '1.2.0';
// Domain
$this->domain = 'profil-de-groupes';
// Base name
$this->file = __FILE__;
$this->basename = plugin_basename( $this->file );
// Path and URL
$this->dir = plugin_dir_path( $this->file );
$this->url = plugin_dir_url ( $this->file );
$this->lang_dir = trailingslashit( $this->dir . 'languages' );
$this->inc_dir = trailingslashit( $this->dir . 'inc' );
$this->tpl_dir = trailingslashit( $this->dir . 'templates' );
// The Fields group ID for Groups profile fields.
$this->fields_group = (int) bp_get_option( '_profil_de_groupes_id', 0 );
}
/**
* Includes plugin's needed files
*
* @since 1.0.0
*/
private function inc() {
if ( ! bp_is_active( 'groups' ) || ! bp_is_active( 'xprofile' ) ) {
return;
}
/**
* The BuddyPress Class autoload doesn't load the group extension
* when no groups were created yet. We need to make sure to avoid
* a fatal to happen by instanciating a dummy Group Extension.
*/
if ( ! class_exists( 'BP_Group_Extension' ) ) {
$dummy_group_extension = new BP_Group_Extension;
}
spl_autoload_register( array( $this, 'autoload' ) );
require $this->inc_dir . 'functions.php';
require $this->inc_dir . 'templates.php';
if ( is_admin() ) {
require $this->inc_dir . 'admin.php';
}
}
/**
* Class Autoload function
*
* @since 1.0.0
*
* @param string $class The class name.
*/
public function autoload( $class ) {
if ( 0 !== strpos( $class, get_class() ) ) {
return;
}
$path = sprintf( '%1$sclasses/class-%2$s.php',
$this->inc_dir,
str_replace( '_', '-', strtolower( $class ) )
);
// Sanity check.
if ( ! file_exists( $path ) ) {
return;
}
require $path;
}
}
endif;
/**
* Boot the plugin.
*
* @since 1.0.0
*/
function profil_de_groupes() {
return Profil_De_Groupes::start();
}
add_action( 'bp_include', 'profil_de_groupes', 9 );