-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbbolt-client.class.php
100 lines (80 loc) · 2.86 KB
/
bbbolt-client.class.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
<?php
/**
* The bbBolt Client.
*
* This class houses the custom settings for each client, like name & url. It then creates
* an instance of the bbBolt_Client_UI to ensure the relevant UI elements are in place.
*
* Most of the work is done in the bbBolt_Client_UI singleton class.
*
* Called by @see register_bbbolt_client()
*
* Version: beta-1
**/
if( ! class_exists( 'bbBolt_Client_UI' ) )
require_once( 'bbbolt-client-ui.class.php' );
if( ! class_exists( 'bbBolt_Client' ) ) :
class bbBolt_Client {
private $name;
private $internal_name;
private $bbbolt_url;
public function __construct( $name, $args = array() ){
$defaults = array(
'labels' => array( 'name' => ucfirst( $name ), 'singular_name' => ucfirst( $name ) )
);
$args = wp_parse_args($args, $defaults);
$this->name = sanitize_key( $name );
$this->labels = (object)$args['labels'];
$this->site_url = $args['site_url'];
$this->bbbolt_url = $args['site_url'] . '?bbbolt';
bbBolt_Client_UI::singleton();
}
/**
* Get the public label for this client
*/
public function get_name() {
return $this->labels->name;
}
/**
* Get different URLs on the bbBolt Server
*
* @param $page, optional, default home, a specific page on the bbBolt Server to load
*/
public function get_url( $page = 'home' ) {
return add_query_arg( 'bbbolt', $page, $this->site_url );
}
/**
* Returns the URL to the location of this file's parent folder.
*
* Useful for enqueuing scripts, styles & images without hardcoding the URL.
* Allows the bbbolt directory to be located anywhere in a plugin.
*/
public function get_dir_url() {
$path_after_plugin_dir = explode( 'plugins', dirname( __FILE__ ) );
return plugins_url() . $path_after_plugin_dir[1];
}
}
endif;
if( ! function_exists( 'register_bbbolt_client' ) ) :
/**
* Register a bbBolt client. Do not use before init.
*
* A function for creating or modifying a bbbolt client pointing to our
* remote WordPress site that is running the bbPress forums & acting as a
* bbBolt Server.
*
* The function will accept an array (second optional parameter),
* along with a string for the URL of the site running bbPress.
*
* @param $name (string)(required) the name of your plugin.
* @param $args (array) - an array of named arguments including:
* 'site_url' (required) - the URL of your remote bbBolt Server
* 'labels' (optional)(array) - associative array of labels for the client, currently only support 'name' & 'singular_name'
**/
function register_bbbolt_client( $name, $args = array() ){
global $bbbolt_clients;
// If you are using a custom bbBolt Server Class, hook into this filter & return your new class when $name is == your client
$bbbolt_client_class = apply_filters( 'bbBolt_Client_Class', 'bbBolt_Client', $name );
$bbbolt_clients[] = new $bbbolt_client_class( $name, $args );
}
endif;