-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbadgeos-activity-progress.php
118 lines (98 loc) · 3.42 KB
/
badgeos-activity-progress.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
<?php
/**
* Plugin Name: BadgeOS Activity Progress
* Plugin URI: https://wordpress.org/plugins/activity-progress-add-on-for-badgeos/
* Description: Adds a shortcode to show a progress bar for the users current activity points.
* Author: konnektiv
* Version: 1.0.0
* Author URI: https://konnektiv.de/
* License: GNU AGPL
* Text Domain: badgeos-activity-progress
*/
/*
* Copyright © 2016 Konnektiv, Christoph Herbst
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
* Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>;.
*/
class BadgeOS_Activity_Progress {
function __construct() {
// Define plugin constants
$this->basename = plugin_basename( __FILE__ );
$this->directory_path = plugin_dir_path( __FILE__ );
$this->directory_url = plugins_url( 'badgeos-activity-progress/' );
// Load translations
load_plugin_textdomain( 'badgeos-activity-progress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
// Run our activation
register_activation_hook( __FILE__, array( $this, 'activate' ) );
// If BadgeOS is unavailable, deactivate our plugin
add_action( 'admin_notices', array( $this, 'maybe_disable_plugin' ) );
add_action( 'plugins_loaded', array( $this, 'includes' ) );
add_action( 'wp_print_scripts', array( $this, 'enqueue_scripts' ) );
}
/**
* Files to include for BadgeOS integration.
*
* @since 1.0.0
*/
public function includes() {
if ( $this->meets_requirements() ) {
require_once $this->directory_path . '/includes/activity-progress-shortcode-class.php';
}
}
/**
* Enqueue custom scripts and styles
*
* @since 1.0.0
*/
public function enqueue_scripts() {
}
/**
* Activation hook for the plugin.
*
* @since 1.0.0
*/
public function activate() {
// If BadgeOS is available, run our activation functions
if ( $this->meets_requirements() ) {
}
}
/**
* Check if BadgeOS is available
*
* @since 1.0.0
* @return bool True if BadgeOS is available, false otherwise
*/
public static function meets_requirements() {
if ( class_exists( 'BadgeOS' ) && version_compare( BadgeOS::$version, '1.4.0', '>=' ) ) {
return true;
} else {
return false;
}
}
/**
* Generate a custom error message and deactivates the plugin if we don't meet requirements
*
* @since 1.0.0
*/
public function maybe_disable_plugin() {
if ( ! $this->meets_requirements() ) {
// Display our error
echo '<div id="message" class="error">';
echo '<p>' . sprintf( __( 'BadgeOS Activity Progress Add-On requires BadgeOS 1.4.0 or greater and has been <a href="%s">deactivated</a>. Please install and activate BadgeOS and then reactivate this plugin.', 'badgeos-activity-progress' ), admin_url( 'plugins.php' ) ) . '</p>';
echo '</div>';
// Deactivate our plugin
deactivate_plugins( $this->basename );
}
}
}
new BadgeOS_Activity_Progress();