-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqsm-leaderboards.php
More file actions
186 lines (169 loc) · 4.52 KB
/
qsm-leaderboards.php
File metadata and controls
186 lines (169 loc) · 4.52 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/**
* Plugin Name: QSM - Leaderboards
* Plugin URI: https://quizandsurveymaster.com
* Description: Adds some basic leaderboards to Quiz And Survey Master
* Author: QSM Team
* Author URI: https://quizandsurveymaster.com
* Version: 1.0.4
*
* @author QSM Team
* @version 1.0.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// If the PHP version is less then our minimum requirements, end.
if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
return;
}
/**
* This class is the main class of the plugin
*
* When loaded, it loads the included plugin files and add functions to hooks or filters. The class also handles the admin menu
*
* @since 1.0.0
*/
class QSM_Leaderboards {
/**
* Version Number
*
* @var string
* @since 1.0.0
*/
public $version = '1.0.4';
/**
* Main Construct Function
*
* Call functions within class
*
* @since 1.0.0
* @uses QSM_Leaderboards::load_dependencies() Loads required filed
* @uses QSM_Leaderboards::add_hooks() Adds actions to hooks and filters
* @return void
*/
public function __construct() {
$this->load_dependencies();
$this->add_hooks();
$this->check_license();
}
/**
* Load File Dependencies
*
* @since 1.0.0
* @return void
*/
public function load_dependencies() {
include 'php/addon-settings-tab-content.php';
include 'php/quiz-settings-tab-content.php';
include 'php/leaderboard-function.php';
include 'php/shortcodes.php';
include 'php/widgets.php';
}
/**
* Add Hooks
*
* Adds functions to relavent hooks and filters
*
* @since 1.0.0
* @return void
*/
public function add_hooks() {
add_action( 'init', array( $this, 'register_fields' ) );
add_action( 'init', array( $this, 'backwards_compatibility' ) );
add_action( 'admin_init', 'qsm_addon_leaderboards_register_quiz_settings_tabs' );
add_action( 'admin_init', 'qsm_addon_leaderboards_register_addon_settings_tabs' );
add_shortcode( 'qsm_leaderboard', 'qsm_addon_leaderboards_shortcode' );
add_action( 'widgets_init', function() {
return register_widget( 'QSM_Leaderboards_Widget' );
});
}
/**
* Small fixes for using with older versions of QSM
*
* @since 1.0.0
*/
public function backwards_compatibility() {
remove_shortcode( 'mlw_quizmaster_leaderboard' );
add_shortcode( 'mlw_quizmaster_leaderboard', 'qsm_addon_leaderboards_shortcode' );
}
/**
* Sets up quiz settings for the addon
*
* @since 1.0.0
*/
public function register_fields() {
global $mlwQuizMasterNext;
$field_array = array(
'id' => 'template',
'label' => 'Leaderboard Template',
'type' => 'editor',
'variables' => array(
'%QUIZ_NAME%',
'%FIRST_PLACE_NAME%',
'%FIRST_PLACE_SCORE%',
'%SECOND_PLACE_NAME%',
'%SECOND_PLACE_SCORE%',
'%THIRD_PLACE_NAME%',
'%THIRD_PLACE_SCORE%',
'%FOURTH_PLACE_NAME%',
'%FOURTH_PLACE_SCORE%',
'%FIFTH_PLACE_NAME%',
'%FIFTH_PLACE_SCORE%',
),
'default' => 0,
);
$mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_leaderboards' );
}
/**
* Checks license
*
* Checks to see if license is active and, if so, checks for updates
*
* @since 1.0.0
* @return void
*/
public function check_license() {
if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
// Loads our custom updater.
include 'php/EDD_SL_Plugin_Updater.php';
}
// Retrieves our license key from the DB.
$leaderboard_data = get_option( 'qsm_addon_leaderboard_settings', '' );
if ( isset( $leaderboard_data['license_key'] ) ) {
$license_key = trim( $leaderboard_data['license_key'] );
} else {
$license_key = '';
}
// Sets up the updater.
$edd_updater = new EDD_SL_Plugin_Updater( 'https://quizandsurveymaster.com', __FILE__, array(
'version' => $this->version,
'license' => $license_key,
'item_name' => 'Leaderboards',
'author' => 'Frank Corso',
));
}
}
/**
* Loads the addon if QSM is installed and activated
*
* @since 1.0.0
* @return void
*/
function qsm_addon_leaderboard_load() {
// Makes sure QSM is active.
if ( class_exists( 'MLWQuizMasterNext' ) ) {
$qsm_leaderboards = new QSM_Leaderboards();
} else {
add_action( 'admin_notices', 'qsm_addon_leaderboard_missing_qsm' );
}
}
add_action( 'plugins_loaded', 'qsm_addon_leaderboard_load' );
/**
* Display notice if Quiz And Survey Master isn't installed
*
* @since 1.0.0
*/
function qsm_addon_leaderboard_missing_qsm() {
echo '<div class="error"><p>QSM - Leaderboards requires Quiz And Survey Master. Please install and activate the Quiz And Survey Master plugin.</p></div>';
}