PluginProbe
IdeaPush / 1.11
IdeaPush v1.11
trunk 1.11 1.13 1.14 1.15 1.16 1.2 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.3 1.4 1.5 1.6 1.7 2.0 2.2 2.4 3.0 3.10 3.11 All 78 releases
ideapush / ideapush.php

ideapush.php in IdeaPush 1.11, at ideapush.php

982 lines 28.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: IdeaPush - Feature Request Manager
4 * Plugin URI: https://www.northernbeacheswebsites.com.au
5 * Description: IdeaPush is a feature request management system for WordPress
6 * Version: 1.11
7 * Author: Martin Gibson
8 * Text Domain: ideapush
9 * Support: https://www.northernbeacheswebsites.com.au/contact
10 * Licence: GPL2
11 */
12
13 // Assign global variables
14 global $ideapush_is_pro;
15 $ideapush_is_pro = "NO";
16
17
18 //the first YES/NO in the array is if the feature is pro, the second YES/NO in the array is if a save settings button is necessary
19 global $ideapush_pro_features;
20 $ideapush_pro_features = array('Boards' => array('NO','YES'),'Notifications' => array('NO','YES'), 'Statuses' => array('NO','YES'), 'Design' => array('NO','YES'), 'Idea Form' => array('NO','YES'), 'IdeaPush Support' => array('NO','NO'),'IdeaPush Pro' => array('YES','YES'));
21
22 //get plugin version number
23 function idea_push_plugin_get_version() {
24 if ( ! function_exists( 'get_plugins' ) )
25 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
26 $plugin_folder = get_plugins( '/' . plugin_basename( dirname( __FILE__ ) ) );
27 $plugin_file = basename( ( __FILE__ ) );
28 return $plugin_folder[$plugin_file]['Version'];
29 }
30
31
32 function idea_push_create_custom_post_type() {
33
34 //SVG of the icon
35 $menu_icon_svg = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIyLjAuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMiIgYmFzZVByb2ZpbGU9InRpbnkiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIgoJIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMjAgMjAiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8cGF0aCBmaWxsPSIjNzhDMTQ4IiBkPSJNMTAsMEM0LjUsMCwwLDQuNSwwLDEwczQuNSwxMCwxMCwxMHMxMC00LjUsMTAtMTBTMTUuNSwwLDEwLDB6IE04LjEsMTIuMWwtMS42LDEuNQoJYy0wLjIsMC4yLTAuNCwwLjMtMC43LDAuM2MtMC4zLDAtMC41LTAuMS0wLjctMC4zbC0xLjYtMS41Yy0wLjItMC4yLTAuMi0wLjYsMC0wLjljMC4yLTAuMiwwLjYtMC4yLDAuOSwwbDEuNCwxLjRsMS40LTEuNAoJQzcuMywxMS4xLDcuNSwxMSw3LjYsMTFzMC4zLDAuMSwwLjQsMC4yQzguMywxMS40LDguMywxMS44LDguMSwxMi4xeiBNOC4xLDlDNy45LDkuMSw3LjgsOS4yLDcuNiw5LjJTNy4zLDkuMSw3LjIsOUw1LjgsNy42TDQuNCw5CglDNC4yLDkuMiwzLjgsOS4yLDMuNiw5Yy0wLjItMC4yLTAuMi0wLjYsMC0wLjlsMS42LTEuNWMwLjItMC4yLDAuNC0wLjMsMC43LTAuM2MwLjMsMCwwLjUsMC4xLDAuNywwLjNsMS42LDEuNQoJQzguMyw4LjQsOC4zLDguOCw4LjEsOXogTTE1LjIsMTRoLTQuNmMtMC44LDAtMS40LTAuNi0xLjQtMS40YzAtMC44LDAuNi0xLjQsMS40LTEuNGg0LjZjMC44LDAsMS40LDAuNiwxLjQsMS40CglDMTYuNiwxMy4zLDE2LDE0LDE1LjIsMTR6IE0xNS4yLDkuMmgtNC42Yy0wLjgsMC0xLjQtMC42LTEuNC0xLjRjMC0wLjgsMC42LTEuNCwxLjQtMS40aDQuNmMwLjgsMCwxLjQsMC42LDEuNCwxLjQKCUMxNi42LDguNSwxNiw5LjIsMTUuMiw5LjJ6Ii8+Cjwvc3ZnPgo=';
36
37 // Set UI labels for Custom Post Type
38 $labels = array(
39 'name' => _x( 'Ideas', 'Post Type General Name', 'ideapush' ),
40 'singular_name' => _x( 'Idea', 'Post Type Singular Name', 'ideapush' ),
41 'menu_name' => __( 'IdeaPush', 'ideapush' ),
42 'parent_item_colon' => __( 'Parent Idea', 'ideapush' ),
43 'all_items' => __( 'All Ideas', 'ideapush' ),
44 'view_item' => __( 'View Idea', 'ideapush' ),
45 'add_new_item' => __( 'Add New Idea', 'ideapush' ),
46 'add_new' => __( 'Add New', 'ideapush' ),
47 'edit_item' => __( 'Edit Idea', 'ideapush' ),
48 'update_item' => __( 'Update Idea', 'ideapush' ),
49 'search_items' => __( 'Search Idea', 'ideapush' ),
50 'not_found' => __( 'Not Found', 'ideapush' ),
51 'not_found_in_trash' => __( 'Not found in Trash', 'ideapush' ),
52 );
53
54 // Set other options for Custom Post Type
55 $args = array(
56 'label' => __( 'ideas', 'ideapush' ),
57 'description' => __( 'IdeaPush ideas', 'ideapush' ),
58 'labels' => $labels,
59 // Features this CPT supports in Post Editor
60 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields',),
61 // 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'comments', 'revisions',),
62
63 // You can associate this CPT with a taxonomy or custom taxonomy.
64 'taxonomies' => array( 'idea-boards' ),
65 /* A hierarchical CPT is like Pages and can have
66 * Parent and child items. A non-hierarchical CPT
67 * is like Posts.
68 */
69 'hierarchical' => false,
70 'public' => true,
71 'show_ui' => true,
72 'show_in_menu' => true,
73 'show_in_nav_menus' => true,
74 'show_in_admin_bar' => true,
75 'menu_position' => 5,
76 'menu_icon' => $menu_icon_svg,
77 'can_export' => true,
78 'has_archive' => true,
79 'exclude_from_search' => false,
80 'publicly_queryable' => true,
81 'capability_type' => 'page',
82 );
83
84 // Registering your Custom Post Type
85 register_post_type( 'idea', $args );
86
87 }
88
89 /* Hook into the 'init' action so that the function
90 * Containing our post type registration is not
91 * unnecessarily executed.
92 */
93
94 add_action( 'init', 'idea_push_create_custom_post_type', 0 );
95
96
97 //when activating or deactivating the plugin lets fluch the rewrite rules because otherwise the single post pages may produce an error
98 register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
99 register_activation_hook( __FILE__, 'idea_push_flush_rewrites' );
100 function idea_push_flush_rewrites() {
101 // call your CPT registration function here (it should also be hooked into 'init')
102 idea_push_create_custom_post_type();
103 flush_rewrite_rules();
104
105 //lets also create a new user role for guests
106 add_role( 'idea_push_guest', 'IdeaPush Guest', array( 'read' => true, 'level_0' => true ) );
107
108 }
109
110
111
112 //create boards taxonomy
113 add_action( 'init', 'idea_push_create_taxonomy_boards', 0 );
114
115 function idea_push_create_taxonomy_boards() {
116
117 // Labels part for the GUI
118
119 $labels = array(
120 'name' => _x( 'Boards', 'taxonomy general name' ),
121 'singular_name' => _x( 'Board', 'taxonomy singular name' ),
122 'search_items' => __( 'Search Boards' ),
123 'popular_items' => __( 'Popular Boards' ),
124 'all_items' => __( 'All Boards' ),
125 'parent_item' => null,
126 'parent_item_colon' => null,
127 'edit_item' => __( 'Edit Board' ),
128 'update_item' => __( 'Update Board' ),
129 'add_new_item' => __( 'Add New Board' ),
130 'new_item_name' => __( 'New Board Name' ),
131 'separate_items_with_commas' => __( 'Separate boards with commas' ),
132 'add_or_remove_items' => __( 'Add or remove boards' ),
133 'choose_from_most_used' => __( 'Choose from the most used boards' ),
134 'menu_name' => __( 'Boards' ),
135 );
136
137 // Now register the non-hierarchical taxonomy like tag
138
139 register_taxonomy('boards','idea',array(
140 'hierarchical' => true,
141 'labels' => $labels,
142 'show_ui' => true,
143 'show_in_menu' => false,
144 'show_in_nav_menus' => false,
145 'show_admin_column' => true,
146 'update_count_callback' => '_update_post_term_count',
147 'query_var' => true,
148 'rewrite' => array( 'slug' => 'ip-board' ),
149 ));
150
151 }
152
153
154 //create tags taxonomy
155 add_action( 'init', 'idea_push_create_taxonomy_tags', 0 );
156
157 function idea_push_create_taxonomy_tags() {
158
159 // Labels part for the GUI
160
161 $labels = array(
162 'name' => _x( 'Tags', 'taxonomy general name' ),
163 'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
164 'search_items' => __( 'Search tags' ),
165 'popular_items' => __( 'Popular Tags' ),
166 'all_items' => __( 'All Tags' ),
167 'parent_item' => null,
168 'parent_item_colon' => null,
169 'edit_item' => __( 'Edit Tag' ),
170 'update_item' => __( 'Update Tag' ),
171 'add_new_item' => __( 'Add New Tag' ),
172 'new_item_name' => __( 'New Tag Name' ),
173 'separate_items_with_commas' => __( 'Separate tags with commas' ),
174 'add_or_remove_items' => __( 'Add or remove tags' ),
175 'choose_from_most_used' => __( 'Choose from the most used tags' ),
176 'menu_name' => __( 'Tags' ),
177 );
178
179 // Now register the non-hierarchical taxonomy like tag
180
181 register_taxonomy('tags','idea',array(
182 'hierarchical' => false,
183 'labels' => $labels,
184 'show_ui' => true,
185 'show_in_menu' => true,
186 'show_in_nav_menus' => false,
187 'show_admin_column' => true,
188 'update_count_callback' => '_update_post_term_count',
189 'query_var' => true,
190 'rewrite' => array( 'slug' => 'ip-tag' ),
191 ));
192
193 }
194
195
196
197 //create status taxonomy
198 add_action( 'init', 'idea_push_create_taxonomy_status', 0 );
199
200 function idea_push_create_taxonomy_status() {
201
202 // Labels part for the GUI
203
204 $labels = array(
205 'name' => _x( 'Status', 'taxonomy general name' ),
206 'singular_name' => _x( 'Status', 'taxonomy singular name' ),
207 'search_items' => __( 'Search Statuses' ),
208 'popular_items' => __( 'Popular Statuses' ),
209 'all_items' => __( 'All Statuses' ),
210 'parent_item' => null,
211 'parent_item_colon' => null,
212 'edit_item' => __( 'Edit Status' ),
213 'update_item' => __( 'Update Status' ),
214 'add_new_item' => __( 'Add New Status' ),
215 'new_item_name' => __( 'New Status Name' ),
216 'separate_items_with_commas' => __( 'Separate statuses with commas' ),
217 'add_or_remove_items' => __( 'Add or remove statuses' ),
218 'choose_from_most_used' => __( 'Choose from the most used statuses' ),
219 'menu_name' => __( 'Statuses' ),
220 );
221
222 // Now register the non-hierarchical taxonomy like tag
223
224 register_taxonomy('status','idea',array(
225 'hierarchical' => true,
226 'labels' => $labels,
227 'show_ui' => true,
228 'show_in_quick_edit' => false,
229 'show_in_menu' => false,
230 'show_in_nav_menus' => false,
231 'show_admin_column' => true,
232 'update_count_callback' => '_update_post_term_count',
233 'query_var' => true,
234 'rewrite' => array( 'slug' => 'ip-status' ),
235 ));
236
237 }
238
239
240
241
242 //create predefined statuses
243 add_action( 'init', 'idea_push_create_predefined_statuses', 0 );
244
245 function idea_push_create_predefined_statuses() {
246
247 if(get_term_by('name', 'Open', 'status') == false){
248 wp_insert_term(
249 'Open', // the term
250 'status', // the taxonomy
251 array(
252 'description'=> '',
253 'slug' => 'open'
254 )
255 );
256 }
257
258 if(get_term_by('name', 'Reviewed', 'status') == false){
259 wp_insert_term(
260 'Reviewed', // the term
261 'status', // the taxonomy
262 array(
263 'description'=> '',
264 'slug' => 'reviewed'
265 )
266 );
267 }
268
269 if(get_term_by('name', 'Approved', 'status') == false){
270 wp_insert_term(
271 'Approved', // the term
272 'status', // the taxonomy
273 array(
274 'description'=> '',
275 'slug' => 'approved'
276 )
277 );
278 }
279
280 if(get_term_by('name', 'Declined', 'status') == false){
281 wp_insert_term(
282 'Declined', // the term
283 'status', // the taxonomy
284 array(
285 'description'=> '',
286 'slug' => 'declined'
287 )
288 );
289 }
290
291 if(get_term_by('name', 'In Progress', 'status') == false){
292 wp_insert_term(
293 'In Progress', // the term
294 'status', // the taxonomy
295 array(
296 'description'=> '',
297 'slug' => 'in-progress'
298 )
299 );
300 }
301
302 if(get_term_by('name', 'Completed', 'status') == false){
303 wp_insert_term(
304 'Completed', // the term
305 'status', // the taxonomy
306 array(
307 'description'=> '',
308 'slug' => 'completed'
309 )
310 );
311 }
312
313
314
315
316 }
317
318
319
320
321
322
323
324
325
326
327 //lets add our settings page
328 add_action( 'admin_menu', 'idea_push_add_settings_page' );
329 add_action( 'admin_init', 'idea_push_settings_init' );
330
331 function idea_push_add_settings_page() {
332
333 global $idea_push_wp_settings_page;
334
335 $idea_push_wp_settings_page = add_submenu_page('edit.php?post_type=idea', __('Settings','ideapush'), __('Settings','ideapush'), 'manage_options', 'idea_push_settings', 'idea_push_settings_page_content');
336
337 }
338
339 //callback function of setting page
340 function idea_push_settings_page_content(){
341 require('inc/options/options-page-wrapper.php');
342 }
343
344 //Gets, sets and renders options
345 require('inc/options/options-output.php');
346
347 //produces the shortcode
348 require('inc/shortcode/ideaboard-shortcode.php');
349
350 //function that generates list items
351 require('inc/shortcode/idea-list-items.php');
352
353 //function that creates the idea form
354 require('inc/shortcode/create-idea-form.php');
355
356 //function that creates the idea table header
357 require('inc/shortcode/idea-table-header.php');
358
359 //function that creates ideas
360 require('inc/functions/create-idea.php');
361
362 //function that creates votes
363 require('inc/functions/create-vote.php');
364
365 //function that changes the status
366 require('inc/functions/status-change.php');
367
368 //common functions that assist other functions run
369 require('inc/functions/helper-functions.php');
370
371 //function that creates a user
372 require('inc/functions/create-user.php');
373
374 //function puts idea stuff on the single idea page
375 require('inc/functions/single-idea.php');
376
377 //function that adds our metabox
378 require('inc/functions/create-metaboxes.php');
379
380
381
382 //get pro options
383 if($ideapush_is_pro=="YES"){
384 require('inc/pro-ip/idea-push-pro.php');
385 }
386
387
388
389
390
391
392
393 // Load admin style and scripts
394 function idea_push_register_admin_styles($hook)
395 {
396
397 global $idea_push_wp_settings_page;
398 if($hook != $idea_push_wp_settings_page)
399 return;
400
401 //css
402 wp_enqueue_style( 'wp-color-picker' );
403 wp_enqueue_style( 'custom-admin-style-ideapush', plugins_url( '/inc/css/adminstyle.css', __FILE__ ));
404 wp_enqueue_style( 'font-awesome', plugins_url( '/inc/css/font-awesome.min.css', __FILE__ ));
405
406 //js
407 wp_enqueue_script( 'custom-admin-script-ideapush', plugins_url( '/inc/js/adminscript.js', __FILE__ ), array( 'jquery','wp-color-picker' ));
408 wp_enqueue_script('jquery-ui-dialog');
409 wp_enqueue_script('jquery-ui-accordion');
410 wp_enqueue_script('jquery-ui-tabs');
411 wp_enqueue_script('jquery-form');
412
413
414 wp_enqueue_script('clipboard', plugins_url('/inc/js/clipboard.min.js', __FILE__ ), array( 'jquery'));
415
416 }
417 add_action( 'admin_enqueue_scripts', 'idea_push_register_admin_styles' );
418
419
420
421 // Load styles and scripts for the single idea page
422 function idea_push_register_admin_styles_single()
423 {
424
425 global $post_type;
426
427 if('idea' != $post_type)
428 return;
429
430 //css
431
432 //js
433 wp_enqueue_script( 'custom-frontend-script-single-idea', plugins_url( '/inc/js/singleideascript.js', __FILE__ ), array( 'jquery'), '1.0.0');
434
435 }
436 add_action( 'admin_enqueue_scripts', 'idea_push_register_admin_styles_single' );
437
438
439
440
441
442
443
444
445
446
447
448
449
450 // Load frontend style and scripts
451 function idea_push_register_frontend_styles()
452 {
453 //get settings
454 $options = get_option('idea_push_settings');
455
456 //css
457 wp_enqueue_style( 'tags-input', plugins_url( '/inc/css/jquery.tagsinput.min.css', __FILE__ ));
458 wp_enqueue_style( 'custom-frontend-style-ideapush', plugins_url( '/inc/css/frontendstyle.css', __FILE__ ),array(),'1.0.2');
459 wp_enqueue_style( 'font-awesome', plugins_url( '/inc/css/font-awesome.min.css', __FILE__ ));
460
461
462 //js
463 wp_register_script( 'custom-frontend-script-ideapush', plugins_url( '/inc/js/frontendscript.js', __FILE__ ), array( 'jquery'), '1.0.2');
464
465 wp_localize_script('custom-frontend-script-ideapush','get_new_ideas', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
466 wp_localize_script('custom-frontend-script-ideapush','is_person_logged_in', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
467 wp_localize_script('custom-frontend-script-ideapush','submit_vote', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
468 wp_localize_script('custom-frontend-script-ideapush','create_user', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
469 wp_localize_script('custom-frontend-script-ideapush','header_render', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
470 wp_localize_script('custom-frontend-script-ideapush','form_render', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
471 wp_localize_script('custom-frontend-script-ideapush','create_idea', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
472 wp_localize_script('custom-frontend-script-ideapush','delete_idea', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
473 wp_localize_script('custom-frontend-script-ideapush','change_status', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
474 wp_localize_script('custom-frontend-script-ideapush','update_vote_counter', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
475 wp_localize_script('custom-frontend-script-ideapush','below_title_header', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
476
477
478
479 wp_enqueue_script(array('custom-frontend-script-ideapush'));
480 wp_enqueue_script('scroll-reveal', plugins_url('/inc/js/scrollreveal.min.js', __FILE__ ), array( 'jquery'));
481 wp_enqueue_script('read-more', plugins_url('/inc/js/readmore.min.js', __FILE__ ), array( 'jquery'));
482 wp_enqueue_script('tags-input-ideapush', plugins_url('/inc/js/jquery.tagsinput.min.js', __FILE__ ), array( 'jquery'));
483 wp_enqueue_script('jquery-ui-dialog');
484
485
486 if(strlen($options['idea_push_recaptcha_site_key']) > 0){
487 wp_enqueue_script('google-recaptcha', 'https://www.google.com/recaptcha/api.js');
488 }
489
490
491
492 }
493 add_action( 'wp_enqueue_scripts', 'idea_push_register_frontend_styles' );
494
495
496
497
498
499
500
501
502
503 //create taxonomy item
504 //this is used to create a taxonomy for the board when the user creates a board from the plugin settings
505 function idea_push_add_taxonomy_item() {
506
507 //get options
508 $options = get_option('idea_push_settings');
509
510 //get is pro
511 global $ideapush_is_pro;
512
513 //get board name from ajax call
514 $boardName = idea_push_sanitization_validation($_POST['boardName'],'boardname');
515
516 if($boardName == false){
517 wp_die();
518 }
519
520
521
522
523 //lets first check if the board already exists
524 if(get_term_by('name', $boardName, 'boards') == false){
525
526 //lets check if licenced
527 if(($ideapush_is_pro == 'YES' && strlen($options['idea_push_purchase_email'])>0 && strlen($options['idea_push_order_id'])>0) || wp_count_terms('boards',array( "hide_empty" => 0 )) == 0){
528
529 $boardNameSlug = strtolower($boardName);
530 $boardNameSlug = preg_replace('/\s+/', '-', $boardNameSlug);
531
532 wp_insert_term(
533 $boardName, // the term
534 'boards', // the taxonomy
535 array(
536 'description'=> '',
537 'slug' => $boardNameSlug
538 )
539 );
540
541 //lets return the item id
542
543 $getTermId = get_term_by('name', $boardName, 'boards');
544 $termId = $getTermId->term_id;
545
546 echo $termId;
547
548
549 } else {
550 echo 'NOT-PRO';
551 }
552
553
554
555
556 } else {
557
558 echo 'TERM-EXISTS';
559
560
561 }
562
563 //die
564 wp_die();
565
566
567 }
568 add_action( 'wp_ajax_add_taxonomy_item', 'idea_push_add_taxonomy_item' );
569
570
571
572
573
574
575
576
577
578 //lets delete existing taxonomies and rename others where necessary
579 function idea_push_taxonomy_save_routine() {
580
581
582 //get board name from ajax call
583 $comparisonData = $_POST['comparisonData'];
584 $explodeTheData = explode("||", $comparisonData);
585
586 $boardIdArray = array();
587
588 foreach($explodeTheData as $board){
589
590 $anotherExplosion = explode("|", $board);
591 $boardId = $anotherExplosion[0];
592 $boardName = $anotherExplosion[1];
593
594 array_push($boardIdArray,$boardId);
595
596 //now lets change the name of existing taxonomies
597 $termObject = get_term($boardId,'boards');
598
599 //if the there's a match lets update the name if it has changed
600 if(!is_wp_error($termObject)){
601
602 $termName = $termObject->name;
603
604 if($boardName !== $termName){
605 //they don't match so lets update this term name with the new board name
606 wp_update_term($boardId,'boards',array('name' => $boardName));
607 }
608 }
609
610 }
611
612
613 //lets cycle through the existing terms in the taxonomy
614 $existingTerms = get_terms('boards',array( "hide_empty" => 0 ));
615
616 foreach($existingTerms as $term){
617
618 $termId = $term->term_id;
619
620 if(!in_array($termId,$boardIdArray)){
621 //if the term is not in our array delete it because it's not authorised to exist and it will cause confusion
622 wp_delete_term($termId,'boards');
623
624 }
625 }
626
627
628 //die
629 wp_die();
630
631
632 }
633 add_action( 'wp_ajax_taxonomy_save_routine', 'idea_push_taxonomy_save_routine' );
634
635
636
637
638
639
640
641
642 //add additional body class to the shortcode page for good measure
643 function idea_push_add_body_class($class) {
644
645 global $post;
646
647 if( isset($post->post_content) && has_shortcode( $post->post_content, 'ideapush' ) ) {
648 $class[] = 'idea-push';
649 }
650 return $class;
651 }
652 add_filter( 'body_class', 'idea_push_add_body_class' );
653
654
655
656 //add notification icon to menu item
657
658 add_action( 'admin_menu', 'idea_push_menu_bubble' );
659
660 function idea_push_menu_bubble() {
661 global $menu;
662
663 $count = idea_push_count_pending_ideas() + idea_push_count_ideas_review_status();
664
665
666 if ($count > 0) {
667
668 foreach ( $menu as $key => $value ) {
669
670 if ( $menu[$key][2] == 'edit.php?post_type=idea' ) {
671
672 $menu[$key][0] .= ' <span class="update-plugins"><span class="plugin-count">' . $count . '</span></span>';
673
674 return;
675 }
676 }
677 }
678 }
679
680
681 function idea_push_above_all_ideas_table() {
682
683 $screen = get_current_screen();
684
685 if ( $screen->id == 'edit-idea' ) {
686
687 echo '<style>
688
689 .idea-tasks div {
690 display: inline-block;
691 background: #fff;
692 padding: 10px;
693 border: 1px solid #e5e5e5;
694 border-radius: 6px;
695 margin-right: 10px;
696 margin-top: 10px;
697 margin-bottom: -10px;
698
699 }
700
701 .idea-tasks a {
702 text-decoration: none;
703
704 }
705
706 .pending-count, .reviewed-count {
707 display: inline-block;
708 vertical-align: top;
709 margin: 1px 0 0 5px;
710 padding: 0 5px;
711 min-width: 7px;
712 height: 17px;
713 border-radius: 11px;
714 background-color: #ca4a1f;
715 color: #fff;
716 font-size: 9px;
717 line-height: 17px;
718 text-align: center;
719 z-index: 26;
720
721 }
722
723 .column-status .open {
724 background-color: #4eb5e1;
725 color: #fff !important;
726 }
727
728 .column-status .in-progress {
729 background-color: #a7a9ac;
730 color: #fff !important;
731 }
732
733
734 .column-status .completed {
735 background-color: #414042;
736 color: #fff !important;
737 }
738
739 .column-status .reviewed {
740 background-color: #fbbf67;
741 color: #fff !important;
742 }
743
744 .column-status .approved {
745 background-color: #5eb46a;
746 color: #fff !important;
747 }
748
749 .column-status .declined {
750 background-color: #f05d55;
751 color: #fff !important;
752 }
753
754
755 .column-status a {
756
757 text-transform: uppercase;
758 padding: 3px 6px;
759 border-radius: 3px;
760 font-weight: 600;
761 font-size: smaller;
762 }
763
764 </style>';
765
766 $pendingEditPage = get_admin_url().'edit.php?post_status=pending&post_type=idea';
767 $reviewEditPage = get_admin_url().'edit.php?post_type=idea&status=reviewed';
768
769 $countPendingIdeas = idea_push_count_pending_ideas();
770 $countReviewStatus = idea_push_count_ideas_review_status();
771
772
773 echo '<div class="idea-tasks">';
774
775 if($countPendingIdeas > 0){
776 echo '<div class="pending-approval">';
777 echo '<a href="'.$pendingEditPage.'" class="pending-count-description">'.__( 'Ideas Pending Release', 'ideapush' ).'</a>';
778 echo '<span class="pending-count">'.$countPendingIdeas.'</span>';
779 echo '</div>';
780 }
781
782 if($countReviewStatus > 0){
783 echo '<div class="reviewed-status">';
784 echo '<a href="'.$reviewEditPage.'" class="reviewed-count-description">'.__( 'Ideas Needing Review', 'ideapush' ).'</a>';
785 echo '<span class="reviewed-count">'.$countReviewStatus.'</span>';
786 echo '</div>';
787 }
788
789 echo '</div>';
790
791
792 }
793
794
795 }
796 add_action( 'admin_notices', 'idea_push_above_all_ideas_table' );
797
798
799
800
801
802 add_filter( 'manage_edit-idea_columns', 'mycustomposttype_columns_definition' ) ;
803
804
805 function mycustomposttype_columns_definition( $columns ) {
806
807 $columns['votes'] = __( 'Votes' );
808 unset( $new['taxonomy-status'] );
809 $columns['status'] = __( 'Status' );
810
811 $customOrder = array('cb','title', 'author','taxonomy-boards' ,'status','taxonomy-tags','votes', 'comments','date');
812
813
814 foreach ($customOrder as $colname)
815 $new[$colname] = $columns[$colname];
816 return $new;
817 }
818
819
820
821
822 add_action( 'manage_idea_posts_custom_column' , 'idea_push_vote_column_content', 10, 2 );
823
824 function idea_push_vote_column_content( $column, $post_id ) {
825 switch ( $column ) {
826
827 // display a thumbnail photo
828 case 'votes' :
829 echo get_post_meta( $post_id , 'votes' , true );
830 break;
831 case 'status' :
832 $getTerms = get_the_terms( $post_id, 'status' );
833
834 foreach($getTerms as $term) {
835 $status = $term->name;
836 }
837
838 $className = strtolower($status);
839 $className = str_replace(" ","-",$className);
840
841 echo '<a class="'.$className.'" href="'.get_admin_url().'edit.php?post_type=idea&status='.$className.'">'.$status.'</a>';
842 break;
843
844 }
845 }
846
847
848 add_filter( 'manage_edit-idea_sortable_columns', 'idea_push_sortable_vote_column' );
849
850 function idea_push_sortable_vote_column( $columns ) {
851 $columns['votes'] = 'votes';
852 return $columns;
853 }
854
855
856 add_action( 'pre_get_posts', 'idea_push_custom_orderby' );
857
858 function idea_push_custom_orderby( $query ) {
859 if ( ! is_admin() )
860 return;
861
862 $orderby = $query->get( 'orderby');
863
864 if ( 'votes' == $orderby ) {
865 $query->set( 'meta_key', 'votes' );
866 $query->set( 'orderby', 'meta_value_num' );
867 }
868
869 }
870
871
872
873
874 add_filter( 'template_include', 'idea_push_ip_tag_template', 99 );
875
876 function idea_push_ip_tag_template( $template ) {
877
878
879
880 if ( is_tax( 'tags' )) {
881 $template = dirname( __FILE__ ) . '/inc/templates/ip-tag.php';
882 return $template;
883 } else {
884 return $template;
885 }
886
887 }
888
889
890 function idea_push_languages() {
891 load_plugin_textdomain( 'ideapush', false, 'ideapush/inc/languages' );
892 }
893 add_action('init', 'idea_push_languages');
894
895
896
897
898
899
900 add_action( 'pre_get_posts', function ( $query ) {
901
902 //get options
903 $options = get_option('idea_push_settings');
904
905 //get board configuration
906 $boardConfiguration = $options['idea_push_board_configuration'];
907
908 //split board configuration
909 $splitBoardConfiguration = explode('||',$boardConfiguration);
910
911 $boardsToHide = array();
912
913 //cycle through boards
914 foreach($splitBoardConfiguration as $boardConfig){
915
916 if(!empty($boardConfig)){
917
918 $furtherSplitBoardConfiguration = explode('|',$boardConfig);
919
920 if($furtherSplitBoardConfiguration[13] == 'Yes'){
921
922 $term = get_term($furtherSplitBoardConfiguration[0], 'boards' );
923 $slug = $term->slug;
924
925 array_push($boardsToHide,$slug);
926 }
927 }
928
929 }
930
931
932 global $wp_the_query;
933 if($query === $wp_the_query && $query->is_search() && !is_admin()) {
934 $tax_query = array(
935 array(
936 'taxonomy' => 'boards',
937 'field' => 'slug',
938 'terms' => $boardsToHide,
939 'operator' => 'NOT IN',
940 )
941 );
942 $query->set( 'tax_query', $tax_query );
943 }
944
945
946 });
947
948
949
950
951
952
953
954
955
956
957
958
959
960 //add custom css to the frontend
961 function idea_push_custom_css() {
962
963 //get options
964 $options = get_option('idea_push_settings');
965
966
967 if(isset($options['idea_push_custom_css']) && strlen($options['idea_push_custom_css'])>0){
968
969 wp_enqueue_style( 'custom-frontend-style', plugins_url( '/inc/css/frontendstyle.css', __FILE__ ) );
970 wp_add_inline_style( 'custom-frontend-style', $options['idea_push_custom_css'] );
971
972 }
973
974 }
975 add_action( 'wp_enqueue_scripts', 'idea_push_custom_css', 999 );
976
977
978
979
980
981
982 ?>