-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbwl-poll-manager-lite.php
319 lines (226 loc) · 11.6 KB
/
bwl-poll-manager-lite.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
/*
Plugin Name: BWL Poll Manager Lite
Plugin URI: https://wordpress.org/plugins/bwl-poll-manager-lite
Description: Poll Manager Lite provides a great option to add a custom voting system anywhere on the site. Easy drag and drop features allow you to create polls within a few minutes, and you can also sort poll options using drag-drop features.
Author: Md Mahbub Alam Khan
Version: 1.0.6
WP Requires at least: 5.4+
Author URI: http://www.bluewindlab.net
text-domain: bwl-poll
License: GPL2+
License URI: https://www.gnu.org/licenses/gpl-2.0.txt
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
if (!class_exists('BWL_Poll_Manager')) {
register_activation_hook(__FILE__, array('BWL_Poll_Manager', 'bpm_create_custom_table'));
class BWL_Poll_Manager
{
function __construct()
{
/*--- PLUGIN COMMON CONSTANTS ---*/
define("BWL_PM_PLUGIN_TITLE", 'BWL Poll Manager Lite');
define("BWL_PM_PLUGIN_DIR", plugins_url() . '/bwl-poll-manager-lite/');
define("BWL_PM_PLUGIN_VERSION", '1.0.6');
$this->register_post_type();
$this->taxonomies();
// Call Immediatly Initialized.
$this->included_files();
$this->enqueue_plugin_scripts();
// Upgrade data table
//Since: Version 1.0.4
$this->bpm_upgrade_db_table();
$this->bpm_flash_rules(); // Added in version 1.0.4
// Edit plugin metalinks
add_filter('plugin_row_meta', array($this, 'bpm_metalinks'), null, 2);
}
public function bpm_metalinks($links, $file)
{
if (empty(get_option('bpm_lite_install_date'))) {
add_option('bpm_lite_install_date', date('Y-m-d H:i:s'));
}
if (strpos($file, 'bwl-poll-manager-lite.php') !== false && is_plugin_active($file)) {
$new_links = array(
'<a href="' . esc_url('https://xenioushk.github.io/docs-wp-plugins/bpm/index.html') . '" target="_blank">' . __('Documentation', 'bwl-poll') . '</a>',
'<a href="' . esc_url('https://1.envato.market/bpm-wp') . '" target="_blank" style="color:green; font-weight: bold;">' . __('Get Pro Version', 'bwl-poll') . '</a>'
);
$links = array_merge($links, $new_links);
}
return $links;
}
function bpm_flash_rules()
{
$bpm_data = get_option('bwl_poll_options');
$bpm_flash_rules_status = get_option('bpm_flash_rules_status');
if ($bpm_flash_rules_status != 1) {
flush_rewrite_rules();
update_option('bpm_flash_rules_status', 1);
}
// Matching Old Slug & New Slug Value.
// First we get data from plugin option panel.
$bpm_custom_slug = "bwl-poll";
if (isset($bpm_data['bpm_custom_slug']) && $bpm_data['bpm_custom_slug'] != "") {
$bpm_custom_slug = trim($bpm_data['bpm_custom_slug']);
}
//
$bpm_old_custom_slug = get_option('bpm_old_custom_slug');
if ($bpm_old_custom_slug == "") {
update_option('bpm_old_custom_slug', $bpm_custom_slug);
}
if ($bpm_custom_slug != $bpm_old_custom_slug) {
flush_rewrite_rules();
update_option('bpm_old_custom_slug', $bpm_custom_slug);
}
}
function included_files()
{
include_once dirname(__FILE__) . '/includes/bpm-filters.php';
include_once dirname(__FILE__) . '/includes/bpm-helper-functions.php';
include_once dirname(__FILE__) . '/shortcode/bpm-shortcodes.php';
include_once dirname(__FILE__) . '/includes/bpm-vote-counter.php';
include_once dirname(__FILE__) . '/includes/bpm-custom-google-font.php';
include_once dirname(__FILE__) . '/includes/bpm-single-page.php';
if (!is_admin()) {
include_once dirname(__FILE__) . '/includes/bpm-custom-theme.php'; // Intriduced in version 1.0.3
}
if (is_admin()) {
include_once dirname(__FILE__) . '/includes/bpm-cmb-framework/bpm_cmb_fields.php';
include_once dirname(__FILE__) . '/includes/bpm-custom-column.php';
include_once dirname(__FILE__) . '/tinymce/bpm_tiny_mce_config.php';
include_once dirname(__FILE__) . '/includes/bpm-quick-edit.php';
include_once dirname(__FILE__) . '/option-panel/bpm-admin-settings.php';
}
}
//@Upgrade Database Tabel.
//@Introduced in version: 1.1.0
function bpm_upgrade_db_table()
{
global $wpdb;
$bpm_voting_data_table = $wpdb->prefix . "bpm_vote_data";
if ($wpdb->get_var("SHOW TABLES LIKE '$bpm_voting_data_table'") != $bpm_voting_data_table) {
$this->bpm_create_custom_table();
}
}
//@Custom Table For Count Votes.
//@Introduced in version: 1.0.4
public static function bpm_create_custom_table()
{
global $wpdb;
$bpm_voting_data_table = $wpdb->prefix . "bpm_vote_data"; // for deatils. each day info.
$sql = "CREATE TABLE $bpm_voting_data_table (
ID int(11) NOT NULL AUTO_INCREMENT,
postid bigint(20) NOT NULL,
opt_id bigint(20) NOT NULL,
vote int(20) DEFAULT 1,
voted_ip varchar(36) NOT NULL,
user_id int(20) DEFAULT 0,
vote_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (ID)
)";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
function enqueue_plugin_scripts()
{
$bwl_pm_data = get_option('bwl_poll_options');
if (!is_admin()) {
bpm_enqueue_google_fonts();
if (!isset($pvm_data['bpm_fontawesome_status']) || $pvm_data['bpm_fontawesome_status'] == 1) {
wp_enqueue_style('bpm-font-awesome', plugins_url('css/font-awesome.min.css', __FILE__));
}
// Register Styles.
wp_register_style('bpm-tooltipster', plugins_url('css/tooltipster.css', __FILE__));
wp_register_style('bpm-jquery-remodal-style', plugins_url('css/jquery.remodal.css', __FILE__));
wp_register_style('bpm-jquery-toast-style', plugins_url('css/jquery.toast.min.css', __FILE__));
wp_register_style('bpm-custom-styles', plugins_url('css/custom-styles.css', __FILE__));
wp_register_style('bpm-rtl-support', plugins_url('css/rtl-support.css', __FILE__));
wp_enqueue_style('bpm-custom-styles');
wp_enqueue_style('bpm-rtl-support');
// Register Scripts.
wp_register_script('bpm-custom-script', plugins_url('js/custom-scripts.js', __FILE__), array('jquery'), '', FALSE);
}
if (is_admin()) {
// shortcode
wp_enqueue_style('bwl-poll-shortcode-editor-style', plugins_url('tinymce/css/bpm-editor.css', __FILE__));
wp_register_script('bpm-admin-custom-scripts', plugins_url('js/bpm-admin-custom-scripts.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable'), '', TRUE);
wp_enqueue_script('bpm-admin-custom-scripts');
}
}
/*--- Define Custom Post Type ---*/
public function register_post_type()
{
/*
* Custom Slug Section.
*/
$bpm_options = get_option('bwl_poll_options');
$bpm_custom_slug = "bwl-poll";
if (isset($bpm_options['bpm_custom_slug']) && $bpm_options['bpm_custom_slug'] != "") {
$bpm_custom_slug = trim($bpm_options['bpm_custom_slug']);
}
$labels = array(
'name' => esc_html__('All Polls', 'bwl-poll'),
'singular_name' => esc_html__('Poll', 'bwl-poll'),
'add_new' => esc_html__('Add New Poll', 'bwl-poll'),
'add_new_item' => esc_html__('Add New Poll', 'bwl-poll'),
'edit_item' => esc_html__('Edit Poll', 'bwl-poll'),
'new_item' => esc_html__('New Poll', 'bwl-poll'),
'all_items' => esc_html__('All Poll', 'bwl-poll'),
'view_item' => esc_html__('View Polls', 'bwl-poll'),
'search_items' => esc_html__('Search Polls', 'bwl-poll'),
'not_found' => esc_html__('No Poll found', 'bwl-poll'),
'not_found_in_trash' => esc_html__('No Poll found in Trash', 'bwl-poll'),
'parent_item_colon' => '',
'menu_name' => esc_html__('BWL Poll Lite', 'bwl-poll')
);
$args = array(
'labels' => $labels,
'query_var' => 'bwl_polls',
'show_in_nav_menus' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'rewrite' => array(
'slug' => $bpm_custom_slug
),
'publicly_queryable' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'show_in_admin_bar' => true,
'supports' => array('title'),
'menu_icon' => BWL_PM_PLUGIN_DIR . 'images/bwl_poll_menu_icon.png'
);
register_post_type('bwl_poll', $args); // text domian limitations :D
}
public function taxonomies()
{
/*
* Custom Slug Section.
*/
$bpm_options = get_option('bpm_options');
$bpm_custom_slug = "bwl-poll";
if (isset($bpm_options['bpm_custom_slug']) && $bpm_options['bpm_custom_slug'] != "") {
$bpm_custom_slug = trim($bpm_options['bpm_custom_slug']);
}
$taxonomies = array();
$this->register_all_taxonomies($taxonomies);
}
function register_all_taxonomies($taxonomies)
{
foreach ($taxonomies as $name => $arr) {
register_taxonomy($name, array('bwl_poll'), $arr);
}
}
}
/*--- Initialization ---*/
function init_bwl_poll_manager()
{
new BWL_Poll_Manager();
}
add_action('init', 'init_bwl_poll_manager');
/*--- TRANSLATION FILE ---*/
load_plugin_textdomain('bwl-poll', FALSE, dirname(plugin_basename(__FILE__)) . '/lang/');
}