class.BadgeOS_Shortcode.php
1.74 KB
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
<?php
/**
* BadgeOS Shortcode
*
* @package BadgeOS
* @subpackage Classes
* @author LearningTimes, LLC
* @license http://www.gnu.org/licenses/agpl.txt GNU AGPL v3.0
* @link https://credly.com
*/
class BadgeOS_Shortcode {
public $name = '';
public $description = '';
public $slug = '';
public $output_callback = '';
public $attributes = array();
public function __construct( $_args = array() ) {
// Setup this shortcode's properties
$this->_set_properties( $_args );
// Register this shortcode with WP and BadgeOS
add_shortcode( $this->slug, $this->output_callback );
add_filter( 'badgeos_shortcodes', array( $this, 'register_shortcode' ) );
}
private function _set_properties( $_args = array() ) {
$defaults = array(
'name' => '',
'description' => '',
'slug' => '',
'output_callback' => '',
'attributes' => array(),
);
$args = wp_parse_args( $_args, $defaults );
$this->name = $args['name'];
$this->description = $args['description'];
$this->slug = $args['slug'];
$this->output_callback = $args['output_callback'];
$this->attributes = $this->_set_attribute_defaults( $args['attributes'] );
}
private function _set_attribute_defaults( $attributes = array() ) {
foreach ( $attributes as $attribute => $details ) {
$attr_defaults = array(
'name' => '',
'type' => '',
'description' => '',
'values' => '',
'default' => '',
);
$attributes[ $attribute ] = wp_parse_args( $details, $attr_defaults );
}
return $attributes;
}
public function register_shortcode( $shortcodes = array() ) {
$shortcodes[ $this->slug ] = $this;
return $shortcodes;
}
}