forked from ubc/open-badges-issuer-addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
badgeos-open-badges.php
executable file
·153 lines (131 loc) · 4.72 KB
/
badgeos-open-badges.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
<?php
/**
* @wordpress-plugin
* Plugin Name: BadgeOS Open Badges Issuer Add-On (UBC fork)
* Description: This is a BadgeOS add-on which allows you to host Mozilla Open Badges compatible assertions and allow users to push awarded badges directly to their Mozilla Backpack
* Version: 1.1.1
* Author: mhawksey, CTLT, Devindra Payment
* Text Domain: bosobi
* License: GNU AGPLv3
* License URI: http://www.gnu.org/licenses/agpl-3.0.html
* Domain Path: /languages
* GitHub Plugin URI: https://github.com/mhawksey/open-badges-issuer-addon
*/
class BadgeOS_Open_Badges_Issuer_AddOn {
public static $basename = '';
public static $directory_path = '';
public static $directory_url = '';
public static $dependencies = array(
'BadgeOS' => 'http://wordpress.org/plugins/badgeos/',
'JSON_API' => 'http://wordpress.org/plugins/json-api/'
);
public static function init() {
self::$basename = plugin_basename( __FILE__ );
self::$directory_path = plugin_dir_path( __FILE__ );
self::$directory_url = plugins_url( dirname( self::$basename ) );
register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) );
add_action( 'admin_notices', array( __CLASS__, 'check_requirements' ) );
add_action( 'plugins_loaded', array( __CLASS__, 'load' ), 11 );
/*
* Fixes by mhawksey, imported by [email protected]
* See https://github.com/mhawksey/open-badges-issuer-addon/issues/3#issuecomment-112331043
*
* cyclingzealot changed the function name from set_public_badge_submission
* to get_public_badge_submission
*/
add_filter('badgeos_public_submissions', array('BadgeOS_Open_Badges_Issuer_AddOn', 'get_public_badge_submission'), 999, 1);
}
/**
* Set if badge submission evidence is public
*
* cyclingzealot changed the function name from set_public_badge_submission
* to get_public_badge_submission
*
* @since 1.0.0
* @param boolean $public submission display
* @author mhawksey, cyclingzealot - [email protected]
* @return boolen submission display
*/
public static function get_public_badge_submission($public){
return get_option('badgeos_obi_issuer_public_evidence');
}
/**
* Load the plugin, if we meet requirements.
* @filter plugins_loaded
*/
public static function load() {
if ( self::meets_requirements() ) {
load_plugin_textdomain( 'bosobi', false, dirname( self::$basename ) . '/languages' );
require_once( sprintf( "%s/includes/class-bosobi-json.php", self::$directory_path ) );
require_once( sprintf( "%s/includes/class-bosobi-settings.php", self::$directory_path ) );
require_once( sprintf( "%s/includes/class-bosobi-logging.php", self::$directory_path ) );
if ( ! is_admin() ) {
require_once( sprintf( "%s/public/class-bosobi-shortcodes.php", self::$directory_path ) );
}
}
}
/**
* Activation hook for the plugin.
*
* @since 1.0.0
*/
public static function activate() {
// If BadgeOS is available, run our activation functions
if ( self::meets_requirements() ) {
$json_api_controllers = explode( ",", get_option( 'json_api_controllers' ) );
if ( ! in_array( 'badge', $json_api_controllers ) ) {
$json_api_controllers[] = 'badge';
JSON_API::save_option( 'json_api_controllers', implode( ',', $json_api_controllers ) );
}
}
}
/**
* Generate a custom error message and deactivates the plugin if we don't meet requirements
* @filter admin_notices
*/
public static function check_requirements() {
if ( ! self::meets_requirements() ) {
?>
<div id="message" class="error">
<?php
foreach ( self::$dependencies as $class => $url ) {
if ( ! class_exists( $class ) ) {
$dependency = sprintf('<a href="%s">%s</a>', $url, $class);
?>
<p>
<?php printf( __( 'Open Badges Issuer requires %s and has been <a href="%s">deactivated</a>. Please install and activate %s and then reactivate this plugin.', 'bosobi' ), $dependency, admin_url( 'plugins.php' ), $dependency ); ?>
</p>
<?php
}
}
?>
</div>
<?php
// Deactivate our plugin
deactivate_plugins( plugin_basename( __FILE__ ) );
}
}
/**
* Checks if the required plugin is installed.
*/
public static function meets_requirements() {
$return = true;
foreach ( self::$dependencies as $class => $url ) {
if ( ! class_exists( $class ) ) {
$return = false;
break;
}
}
return $return;
}
/**
* Checks if this plugin has been network activated.
*/
public static function is_network_activated() {
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
return is_plugin_active_for_network( self::$basename );
}
}
BadgeOS_Open_Badges_Issuer_AddOn::init();