PluginProbe
HD Quiz / trunk
HD Quiz vtrunk
2.2.2 2.2.1 2.2.0 2.1.1 trunk 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.8.1 1.8.12 1.8.15 1.8.2 1.8.4 1.8.5 1.8.6 1.8.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 All 29 releases
hd-quiz / index.php

index.php in HD Quiz trunk, at index.php

219 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: HD Quiz
4 * Description: Add fun and interactive quizzes to your site.
5 * Plugin URI: https://harmonicdesign.ca/hd-quiz/
6 * Author: Harmonic Design
7 * Author URI: https://harmonicdesign.ca
8 * Version: 2.2.2
9 * License: GPL-2.0+
10 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11 * Text Domain: hd-quiz
12 * Domain Path: /languages
13 */
14
15 // Future updates
16 // * Default quiz settings (accessed from settings page)
17 // * Load quiz via ajax (good to bypass pagecache issues)
18 // * New question types
19 // * Filter to add new quiz types
20 // * More translations
21
22 if (!defined('ABSPATH')) {
23 die('Invalid request.');
24 }
25 if (!defined('HDQ_PLUGIN_VERSION')) {
26 define('HDQ_PLUGIN_VERSION', '2.2.2');
27 }
28
29 // Settings that a power user might want to change,
30 // but that I don't want to have a dedicated setting for
31 function hdq_admin_init()
32 {
33 if (!defined('HDQ_MAX_ANSWERS')) {
34 define('HDQ_MAX_ANSWERS', 10);
35 }
36 if (!defined('HDQ_REDIRECT')) {
37 define('HDQ_REDIRECT', true);
38 }
39 if (!defined('HDQ_FORCE_ORDER')) {
40 define('HDQ_FORCE_ORDER', false);
41 }
42 if (!defined('HDQ_PER_PAGE')) {
43 define('HDQ_PER_PAGE', 50);
44 }
45 if (!defined('HDQ_DISABLE_PREV_BUTTON')) {
46 define('HDQ_DISABLE_PREV_BUTTON', false);
47 }
48 if (!defined('HDQ_ENABLE_WP_PAGINATION')) {
49 define('HDQ_ENABLE_WP_PAGINATION', false);
50 }
51 }
52 add_action("init", "hdq_admin_init", 10);
53
54 // custom quiz image sizes
55 add_image_size('hd_qu_size2', 400, 400, true); // image-as-answer
56
57 // load in translations
58 function hdq_load_translations()
59 {
60 load_plugin_textdomain('hd-quiz', false, plugin_basename(dirname(__FILE__)) . '/languages/');
61 }
62 add_action('init', 'hdq_load_translations');
63
64 /* Include the basic required files
65 ------------------------------------------------------- */
66 require dirname(__FILE__) . '/hdfields/HDFields.php';
67 require dirname(__FILE__) . '/includes/actions-ajax.php';
68 require dirname(__FILE__) . '/classes/settings.php';
69 require dirname(__FILE__) . '/classes/dashboard.php';
70 require dirname(__FILE__) . '/classes/quiz.php';
71 require dirname(__FILE__) . '/classes/question.php';
72 require dirname(__FILE__) . '/includes/functions.php';
73 require dirname(__FILE__) . '/includes/admin-pages.php';
74 require dirname(__FILE__) . '/includes/quiz-taxonomy.php';
75 require dirname(__FILE__) . '/includes/question-cpt.php';
76 require dirname(__FILE__) . '/includes/custom-fields.php';
77
78
79 /* Function to check if HD Quiz is active
80 ------------------------------------------------------- */
81 function hdq_exists()
82 {
83 return;
84 }
85
86 /* Disable Canonical redirection for paginated quizzes
87 ------------------------------------------------------- */
88 function hdq_disable_redirect_canonical($redirect_url)
89 {
90 global $post;
91 if (!isset($post->post_content)) {
92 return;
93 }
94 if (has_shortcode($post->post_content, 'hdquiz')) {
95 return false;
96 }
97 if (has_shortcode($post->post_content, 'HDquiz')) {
98 return false;
99 }
100 if (has_block("hdq/quiz-block")) {
101 return false;
102 }
103 return $redirect_url;
104 }
105 add_filter('redirect_canonical', 'hdq_disable_redirect_canonical');
106
107 /* Create HD Quiz Settings page
108 ------------------------------------------------------- */
109 function hdq_create_settings_page()
110 {
111 if (hdq_user_permission()) {
112 add_action('admin_menu', 'hdq_register_quizzes_page');
113 }
114 }
115 add_action('init', 'hdq_create_settings_page');
116
117 function hdq_register_quizzes_page()
118 {
119 $addon_text = "";
120 $new_addon = get_transient("hdq_new_addon");
121 if ($new_addon === false) {
122 hdq_check_for_updates();
123 } else {
124 $new_addon["isNew"] = sanitize_text_field($new_addon["isNew"]);
125 if ($new_addon["isNew"] === "yes") {
126 $addon_text = ' <span class="awaiting-mod">NEW</span>';
127 }
128 }
129
130 add_menu_page('HD Quiz', 'HD Quiz', 'publish_posts', 'hdq_quizzes', 'hdq_main_page', 'dashicons-clipboard', 5);
131
132 add_submenu_page("hdq_quizzes", "HD Quiz Addons", __("Addons", "hd-quiz") . $addon_text, "delete_others_posts", "hdq_addons", "hdq_addons_page");
133 add_submenu_page("hdq_quizzes", "HD Quiz Tools", __("Tools", "hd-quiz"), "manage_options", "hdq_tools", "hdq_tools_page");
134 add_submenu_page("hdq_quizzes", "HD Quiz Settings", __("Settings", "hd-quiz"), "manage_options", 'hdq_options', 'hdq_about_settings_page');
135
136 // tools, hidden pages
137 add_submenu_page("", "CSV Importer", "CSV Importer", "manage_options", "hdq_importer", "hdq_tools_csv_importer");
138 }
139
140 /* Set custom plugin links on WP plugins page
141 ------------------------------------------------------- */
142 function hdq_plugin_links($actions, $plugin_file, $plugin_data, $context)
143 {
144 $new = array(
145 'settings' => sprintf(
146 '<a href="%s">%s</a>',
147 esc_url(admin_url('admin.php?page=hdq_options')),
148 esc_html__('Settings', 'hd-quiz')
149 ),
150 'help' => sprintf(
151 '<a href="%s">%s</a>',
152 'https://hdplugins.com/forum/hd-quiz-support/',
153 esc_html__('Help', 'hd-quiz')
154 )
155 );
156 return array_merge($new, $actions);
157 }
158 add_filter("plugin_action_links_" . plugin_basename(__FILE__), 'hdq_plugin_links', 10, 4);
159
160 /* Add shortcode
161 ------------------------------------------------------- */
162 function hdq_add_shortcode($atts)
163 {
164 // Attributes
165 extract(
166 shortcode_atts(
167 array(
168 'quiz' => '',
169 ),
170 $atts
171 )
172 );
173
174 // Code
175 ob_start();
176 include plugin_dir_path(__FILE__) . './includes/template.php';
177 return ob_get_clean();
178 }
179 add_shortcode('HDquiz', 'hdq_add_shortcode');
180
181 function hdq_check_for_updates()
182 {
183 $remote = wp_remote_get("https://hdplugins.com/plugins/hd-quiz/addons_updated.txt");
184 $local = intval(get_option("hdq_new_addon"));
185 if (is_array($remote)) {
186 $remote = intval($remote["body"]);
187 update_option("hdq_new_addon", $remote);
188
189 $transient = array(
190 "date" => $remote,
191 "isNew" => ""
192 );
193
194 if ($remote > $local) {
195 $transient["isNew"] = "yes";
196 }
197
198 set_transient("hdq_new_addon", $transient, WEEK_IN_SECONDS); // only check every week
199
200 } else {
201 update_option("hdq_new_addon", "");
202 set_transient("hdq_new_addon", array("date" => 0, "isNew" => ""), DAY_IN_SECONDS); // unable to connect. try again tomorrow
203 }
204 }
205
206 /* Clear all schedules on plugin deactivation
207 ------------------------------------------------------- */
208 function hdq_deactivation()
209 {
210 wp_clear_scheduled_hook('hdq_check_for_updates');
211 }
212 register_deactivation_hook(__FILE__, 'hdq_deactivation');
213
214 function create_block_hd_quiz_block_block_init()
215 {
216 register_block_type(__DIR__ . '/assets/block');
217 }
218 add_action('init', 'create_block_hd_quiz_block_block_init');
219