-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
164 lines (114 loc) · 4.94 KB
/
Plugin.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
154
155
156
157
158
159
160
161
162
163
164
<?php
/*
*
* Plugin Name: QBank
*
*/
namespace QBank;
define( 'QBANK_URL', plugin_dir_url( __FILE__ ) );
define( 'QBANK_PATH', plugin_dir_path( __FILE__ ) );
define( 'QBANK_VERSION', '1.1.0' );
class Plugin {
public function __construct() {
require_once( QBANK_PATH . '/inc/post_types.php' );
require_once( QBANK_PATH . '/inc/acf_fields.php' );
require_once( QBANK_PATH . '/functions.php' );
add_action( 'elementor/widgets/register', [$this, 'register_new_widgets'] );
add_action('wp_enqueue_scripts', function() {
wp_enqueue_style(
'qbank-main-style',
QBANK_URL . 'style/main.css',
[],
time(),
'all'
);
});
}
/**
* Register new Elementor widgets.
*
* @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager.
* @return void
*/
function register_new_widgets( $widgets_manager ) {
require_once( QBANK_PATH . '/widgets/question-answers.php' );
$widgets_manager->register( new \QBank\QuestionAnswers_Widget() );
require_once( QBANK_PATH . '/widgets/answer-button.php' );
$widgets_manager->register( new \QBank\AnswerButton_Widget() );
require_once( QBANK_PATH . '/widgets/question-content.php' );
$widgets_manager->register( new \QBank\QuestionContent_Widget() );
require_once( QBANK_PATH . '/widgets/question-lesson.php' );
$widgets_manager->register( new \QBank\QuestionLesson_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-start-button.php' );
$widgets_manager->register( new \QBank\QuizStartButton_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-restart-button.php' );
$widgets_manager->register( new \QBank\QuizRestartButton_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-review-button.php' );
$widgets_manager->register( new \QBank\QuizReviewButton_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-question.php' );
$widgets_manager->register( new \QBank\QuizQuestion_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-title.php' );
$widgets_manager->register( new \QBank\QuizTitle_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-description.php' );
$widgets_manager->register( new \QBank\QuizDescription_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-next-button.php' );
$widgets_manager->register( new \QBank\QuizNextButton_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-previous-button.php' );
$widgets_manager->register( new \QBank\QuizPreviousButton_Widget() );
require_once( QBANK_PATH . '/widgets/quiz.php' );
$widgets_manager->register( new \QBank\Quiz_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-score.php' );
$widgets_manager->register( new \QBank\QuizScore_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-score-incorrect.php' );
$widgets_manager->register( new \QBank\QuizScoreIncorrect_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-score-percent.php' );
$widgets_manager->register( new \QBank\QuizScorePercent_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-score-answers.php' );
$widgets_manager->register( new \QBank\QuizScoreAnswers_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-question-number.php' );
$widgets_manager->register( new \QBank\QuizQuestionNumber_Widget() );
require_once( QBANK_PATH . '/widgets/student-score-percent.php' );
$widgets_manager->register( new \QBank\StudentScorePercent_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-score-total.php' );
$widgets_manager->register( new \QBank\QuizScoreTotal_Widget() );
require_once( QBANK_PATH . '/widgets/quiz-question-count.php' );
$widgets_manager->register( new \QBank\QuizQuestionCount_Widget() );
}
public static function activate() {
// Check if Elementor is active
if (!class_exists('Elementor\Plugin')) {
return;
}
self::import_templates();
}
public static function import_templates() {
error_log('running import templates...');
// Create an instance of Elementor TemplateLibrary Manager
$template_manager = new \Elementor\TemplateLibrary\Manager();
// Define the path to your templates directory
$templates_dir = QBANK_PATH . '/templates/';
// Get a list of template files in the directory
$template_files = glob($templates_dir . '*.json');
// Check if the manager exists
if (method_exists($template_manager, 'instance')) {
// Import each template
foreach ($template_files as $template_file) {
$template_data = file_get_contents($template_file);
if ($template_data) {
// Import the template into Elementor
$import_result = $template_manager->instance()->import_template([
'source' => 'local',
'data' => $template_data,
]);
// Check $import_result for success or error handling
error_log(print_r($import_result, 1));
}
}
} else {
error_log('Instance method does not exist in template manager.');
}
}
}
new Plugin();
// Register activation hook.
register_activation_hook(__FILE__, ['\QBank\Plugin', 'activate']);