PluginProbe
IdeaPush / 3.0
IdeaPush v3.0
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 3.0, at ideapush.php

1,187 lines 35.2 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: 3.0
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'),'Integrations' => 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
106
107
108
109
110 }
111
112
113 //run on activating the plugin
114 function idea_push_plugin_activate() {
115
116 remove_role( 'idea_push_guest' );
117
118
119 add_role( 'idea_push_guest', 'IdeaPush Guest', array('read' => true, 'level_1' => true ));
120 }
121 register_activation_hook( __FILE__, 'idea_push_plugin_activate' );
122
123
124
125
126 //add a settings link on the plugin page
127 function idea_push_add_settings_link( $links ) {
128 $settings_link = '<a href="edit.php?post_type=idea&page=idea_push_settings">' . __( 'Settings','ideapush' ) . '</a>';
129 $ideas_link = '<a href="edit.php?post_type=idea">' . __( 'All Ideas','ideapush' ) . '</a>';
130 array_unshift( $links, $settings_link );
131 array_unshift( $links, $ideas_link );
132
133
134 return $links;
135 }
136 $plugin = plugin_basename( __FILE__ );
137 add_filter( "plugin_action_links_$plugin", 'idea_push_add_settings_link' );
138
139
140
141 //create boards taxonomy
142 add_action( 'init', 'idea_push_create_taxonomy_boards', 0 );
143
144 function idea_push_create_taxonomy_boards() {
145
146 // Labels part for the GUI
147
148 $labels = array(
149 'name' => _x( 'Boards', 'taxonomy general name' ),
150 'singular_name' => _x( 'Board', 'taxonomy singular name' ),
151 'search_items' => __( 'Search Boards' ),
152 'popular_items' => __( 'Popular Boards' ),
153 'all_items' => __( 'All Boards' ),
154 'parent_item' => null,
155 'parent_item_colon' => null,
156 'edit_item' => __( 'Edit Board' ),
157 'update_item' => __( 'Update Board' ),
158 'add_new_item' => __( 'Add New Board' ),
159 'new_item_name' => __( 'New Board Name' ),
160 'separate_items_with_commas' => __( 'Separate boards with commas' ),
161 'add_or_remove_items' => __( 'Add or remove boards' ),
162 'choose_from_most_used' => __( 'Choose from the most used boards' ),
163 'menu_name' => __( 'Boards' ),
164 );
165
166 // Now register the non-hierarchical taxonomy like tag
167
168 register_taxonomy('boards','idea',array(
169 'hierarchical' => true,
170 'labels' => $labels,
171 'show_ui' => true,
172 'show_in_menu' => false,
173 'show_in_nav_menus' => false,
174 'show_admin_column' => true,
175 'update_count_callback' => '_update_post_term_count',
176 'query_var' => true,
177 'rewrite' => array( 'slug' => 'ip-board' ),
178 ));
179
180 }
181
182
183 //create tags taxonomy
184 add_action( 'init', 'idea_push_create_taxonomy_tags', 0 );
185
186 function idea_push_create_taxonomy_tags() {
187
188 // Labels part for the GUI
189
190 $labels = array(
191 'name' => _x( 'Tags', 'taxonomy general name' ),
192 'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
193 'search_items' => __( 'Search tags' ),
194 'popular_items' => __( 'Popular Tags' ),
195 'all_items' => __( 'All Tags' ),
196 'parent_item' => null,
197 'parent_item_colon' => null,
198 'edit_item' => __( 'Edit Tag' ),
199 'update_item' => __( 'Update Tag' ),
200 'add_new_item' => __( 'Add New Tag' ),
201 'new_item_name' => __( 'New Tag Name' ),
202 'separate_items_with_commas' => __( 'Separate tags with commas' ),
203 'add_or_remove_items' => __( 'Add or remove tags' ),
204 'choose_from_most_used' => __( 'Choose from the most used tags' ),
205 'menu_name' => __( 'Tags' ),
206 );
207
208 // Now register the non-hierarchical taxonomy like tag
209
210 register_taxonomy('tags','idea',array(
211 'hierarchical' => false,
212 'labels' => $labels,
213 'show_ui' => true,
214 'show_in_menu' => true,
215 'show_in_nav_menus' => false,
216 'show_admin_column' => true,
217 'update_count_callback' => '_update_post_term_count',
218 'query_var' => true,
219 'rewrite' => array( 'slug' => 'ip-tag' ),
220 // 'capabilities' => array (
221 // 'manage_terms' => 'read', //by default only admin
222 // 'edit_terms' => 'manage_tags',
223 // 'delete_terms' => 'manage_tags',
224 // 'assign_terms' => 'edit_tags'
225 // ),
226 ));
227
228 }
229
230
231
232 //create status taxonomy
233 add_action( 'init', 'idea_push_create_taxonomy_status', 0 );
234
235 function idea_push_create_taxonomy_status() {
236
237 // Labels part for the GUI
238
239 $labels = array(
240 'name' => _x( 'Status', 'taxonomy general name' ),
241 'singular_name' => _x( 'Status', 'taxonomy singular name' ),
242 'search_items' => __( 'Search Statuses' ),
243 'popular_items' => __( 'Popular Statuses' ),
244 'all_items' => __( 'All Statuses' ),
245 'parent_item' => null,
246 'parent_item_colon' => null,
247 'edit_item' => __( 'Edit Status' ),
248 'update_item' => __( 'Update Status' ),
249 'add_new_item' => __( 'Add New Status' ),
250 'new_item_name' => __( 'New Status Name' ),
251 'separate_items_with_commas' => __( 'Separate statuses with commas' ),
252 'add_or_remove_items' => __( 'Add or remove statuses' ),
253 'choose_from_most_used' => __( 'Choose from the most used statuses' ),
254 'menu_name' => __( 'Statuses' ),
255 );
256
257 // Now register the non-hierarchical taxonomy like tag
258
259 register_taxonomy('status','idea',array(
260 'hierarchical' => true,
261 'labels' => $labels,
262 'show_ui' => true,
263 'show_in_quick_edit' => false,
264 'show_in_menu' => false,
265 'show_in_nav_menus' => false,
266 'show_admin_column' => true,
267 'update_count_callback' => '_update_post_term_count',
268 'query_var' => true,
269 'rewrite' => array( 'slug' => 'ip-status' ),
270 ));
271
272 }
273
274
275
276
277 //create predefined statuses
278 add_action( 'init', 'idea_push_create_predefined_statuses', 0 );
279
280 function idea_push_create_predefined_statuses() {
281
282 if(get_term_by('name', 'Open', 'status') == false){
283 wp_insert_term(
284 'Open', // the term
285 'status', // the taxonomy
286 array(
287 'description'=> '',
288 'slug' => 'open'
289 )
290 );
291 }
292
293 if(get_term_by('name', 'Reviewed', 'status') == false){
294 wp_insert_term(
295 'Reviewed', // the term
296 'status', // the taxonomy
297 array(
298 'description'=> '',
299 'slug' => 'reviewed'
300 )
301 );
302 }
303
304 if(get_term_by('name', 'Approved', 'status') == false){
305 wp_insert_term(
306 'Approved', // the term
307 'status', // the taxonomy
308 array(
309 'description'=> '',
310 'slug' => 'approved'
311 )
312 );
313 }
314
315 if(get_term_by('name', 'Declined', 'status') == false){
316 wp_insert_term(
317 'Declined', // the term
318 'status', // the taxonomy
319 array(
320 'description'=> '',
321 'slug' => 'declined'
322 )
323 );
324 }
325
326 if(get_term_by('name', 'In Progress', 'status') == false){
327 wp_insert_term(
328 'In Progress', // the term
329 'status', // the taxonomy
330 array(
331 'description'=> '',
332 'slug' => 'in-progress'
333 )
334 );
335 }
336
337 if(get_term_by('name', 'Completed', 'status') == false){
338 wp_insert_term(
339 'Completed', // the term
340 'status', // the taxonomy
341 array(
342 'description'=> '',
343 'slug' => 'completed'
344 )
345 );
346 }
347
348
349
350
351 }
352
353
354
355
356
357
358
359
360
361
362 //lets add our settings page
363 add_action( 'admin_menu', 'idea_push_add_settings_page' );
364 add_action( 'admin_init', 'idea_push_settings_init' );
365
366 function idea_push_add_settings_page() {
367
368 global $idea_push_wp_settings_page;
369
370 $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');
371
372 }
373
374 //callback function of setting page
375 function idea_push_settings_page_content(){
376 require('inc/options/options-page-wrapper.php');
377 }
378
379 //Gets, sets and renders options
380 require('inc/options/options-output.php');
381
382 //produces the shortcode
383 require('inc/shortcode/ideaboard-shortcode.php');
384
385 //function that generates list items
386 require('inc/shortcode/idea-list-items.php');
387
388 //function that creates the idea form
389 require('inc/shortcode/create-idea-form.php');
390
391 //function that creates the idea table header
392 require('inc/shortcode/idea-table-header.php');
393
394 //function that creates ideas
395 require('inc/functions/create-idea.php');
396
397 //function that creates votes
398 require('inc/functions/create-vote.php');
399
400 //function that changes the status
401 require('inc/functions/status-change.php');
402
403 //common functions that assist other functions run
404 require('inc/functions/helper-functions.php');
405
406 //function that creates a user
407 require('inc/functions/create-user.php');
408
409 //function that updates a user
410 require('inc/functions/update-user.php');
411
412 //function puts idea stuff on the single idea page
413 require('inc/functions/single-idea.php');
414
415 //function that adds our metabox
416 require('inc/functions/create-metaboxes.php');
417
418 //function that creates user profile image
419 require('inc/functions/user-profile-image.php');
420
421
422
423 //get pro options
424 if($ideapush_is_pro=="YES"){
425 require('inc/pro-ip/idea-push-pro.php');
426 }
427
428
429
430
431 function test(){
432
433 $current = get_current_screen();
434 print_r($current);
435 }
436 add_action('admin_init','test');
437
438
439
440
441 // Load admin style and scripts
442 function idea_push_register_admin_styles($hook)
443 {
444
445 global $pagenow;
446
447 global $idea_push_wp_settings_page;
448 global $idea_push_wp_reports_page;
449
450 if('profile.php' == $pagenow || 'user-edit.php' == $pagenow){
451 //display on user profile page
452 wp_enqueue_media();
453 wp_enqueue_script( 'user-profile-script-ideapush', plugins_url( '/inc/js/userprofile.js', __FILE__ ), array( 'jquery' ),idea_push_plugin_get_version());
454 }
455
456
457 if($hook != $idea_push_wp_reports_page && $hook != $idea_push_wp_settings_page ){
458 return;
459
460 } else {
461 //css
462 wp_enqueue_style( 'wp-color-picker' );
463 wp_enqueue_style( 'custom-admin-style-ideapush', plugins_url( '/inc/css/adminstyle.css', __FILE__ ),array(),idea_push_plugin_get_version());
464 wp_enqueue_style( 'font-awesome', plugins_url( '/inc/css/font-awesome.min.css', __FILE__ ));
465
466 //js
467 wp_enqueue_script( 'custom-admin-script-ideapush', plugins_url( '/inc/js/adminscript.js', __FILE__ ), array( 'jquery','wp-color-picker' ),idea_push_plugin_get_version());
468 wp_enqueue_script('jquery-ui-dialog');
469 wp_enqueue_script('jquery-ui-accordion');
470 wp_enqueue_script('jquery-ui-tabs');
471 wp_enqueue_script('jquery-ui-datepicker');
472 wp_enqueue_script('jquery-ui-sortable');
473 wp_enqueue_script('jquery-form');
474
475
476 wp_enqueue_script('clipboard', plugins_url('/inc/js/clipboard.min.js', __FILE__ ), array( 'jquery'));
477
478 }
479
480
481
482
483
484
485
486
487 }
488 add_action( 'admin_enqueue_scripts', 'idea_push_register_admin_styles' );
489
490
491
492 // Load styles and scripts for the single idea page
493 function idea_push_register_admin_styles_single(){
494
495 global $post_type;
496
497 if('idea' != $post_type)
498 return;
499
500 //css
501
502 //js
503 wp_enqueue_script( 'custom-frontend-script-single-idea', plugins_url( '/inc/js/singleideascript.js', __FILE__ ), array( 'jquery'), idea_push_plugin_get_version());
504
505 }
506 add_action( 'admin_enqueue_scripts', 'idea_push_register_admin_styles_single' );
507
508
509
510
511
512
513
514
515
516
517
518
519
520 // Load frontend style and scripts
521 function idea_push_register_frontend_styles()
522 {
523 //get settings
524 $options = get_option('idea_push_settings');
525
526 //css
527 wp_enqueue_style( 'custom-frontend-style-ideapush', plugins_url( '/inc/css/frontendstyle.css', __FILE__ ),array(),idea_push_plugin_get_version());
528 wp_enqueue_style( 'font-awesome', plugins_url( '/inc/css/font-awesome.min.css', __FILE__ ));
529
530
531 //js
532 wp_register_script( 'custom-frontend-script-ideapush', plugins_url( '/inc/js/frontendscript.js', __FILE__ ), array( 'jquery'), idea_push_plugin_get_version());
533
534 wp_localize_script('custom-frontend-script-ideapush','get_new_ideas', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
535 wp_localize_script('custom-frontend-script-ideapush','is_person_logged_in', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
536 wp_localize_script('custom-frontend-script-ideapush','submit_vote', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
537 wp_localize_script('custom-frontend-script-ideapush','create_user', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
538 wp_localize_script('custom-frontend-script-ideapush','header_render', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
539 wp_localize_script('custom-frontend-script-ideapush','form_render', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
540 wp_localize_script('custom-frontend-script-ideapush','create_idea', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
541 wp_localize_script('custom-frontend-script-ideapush','delete_idea', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
542 wp_localize_script('custom-frontend-script-ideapush','change_status', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
543 wp_localize_script('custom-frontend-script-ideapush','update_vote_counter', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
544 wp_localize_script('custom-frontend-script-ideapush','below_title_header', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
545 wp_localize_script('custom-frontend-script-ideapush','is_person_able_to_add_tag', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
546 wp_localize_script('custom-frontend-script-ideapush','update_user_profile', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
547
548
549
550 wp_enqueue_script(array('custom-frontend-script-ideapush'));
551 wp_enqueue_script('scroll-reveal', plugins_url('/inc/js/scrollreveal.min.js', __FILE__ ), array( 'jquery'));
552 wp_enqueue_script('read-more', plugins_url('/inc/js/readmore.min.js', __FILE__ ), array( 'jquery'));
553 wp_enqueue_script('jquery-ui-dialog');
554
555
556 // if(strlen($options['idea_push_recaptcha_site_key']) > 0){
557 // wp_enqueue_script('google-recaptcha', 'https://www.google.com/recaptcha/api.js');
558 // }
559
560
561
562 }
563 add_action( 'wp_enqueue_scripts', 'idea_push_register_frontend_styles' );
564
565
566
567
568
569
570
571 //create taxonomy item
572 //this is used to create a taxonomy for the board when the user creates a board from the plugin settings
573 function idea_push_add_taxonomy_item() {
574
575 //get options
576 $options = get_option('idea_push_settings');
577
578 //get is pro
579 global $ideapush_is_pro;
580
581 //get board name from ajax call
582 $boardName = idea_push_sanitization_validation($_POST['boardName'],'boardname');
583
584 if($boardName == false){
585 wp_die();
586 }
587
588
589
590
591 //lets first check if the board already exists
592 if(get_term_by('name', $boardName, 'boards') == false){
593
594 //lets check if licenced
595 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){
596
597 $boardNameSlug = strtolower($boardName);
598 $boardNameSlug = preg_replace('/\s+/', '-', $boardNameSlug);
599
600 wp_insert_term(
601 $boardName, // the term
602 'boards', // the taxonomy
603 array(
604 'description'=> '',
605 'slug' => $boardNameSlug
606 )
607 );
608
609 //lets return the item id
610
611 $getTermId = get_term_by('name', $boardName, 'boards');
612 $termId = $getTermId->term_id;
613
614 echo $termId;
615
616
617 } else {
618 echo 'NOT-PRO';
619 }
620
621
622
623
624 } else {
625
626 echo 'TERM-EXISTS';
627
628 }
629
630 //die
631 wp_die();
632
633
634 }
635 add_action( 'wp_ajax_add_taxonomy_item', 'idea_push_add_taxonomy_item' );
636
637
638
639
640
641
642
643
644
645 //lets delete existing taxonomies and rename others where necessary
646 function idea_push_taxonomy_save_routine() {
647
648
649 //get board name from ajax call
650 $comparisonData = $_POST['comparisonData'];
651 $explodeTheData = explode("||", $comparisonData);
652
653 $boardIdArray = array();
654
655 foreach($explodeTheData as $board){
656
657 $anotherExplosion = explode("|", $board);
658 $boardId = $anotherExplosion[0];
659 $boardName = $anotherExplosion[1];
660
661 array_push($boardIdArray,$boardId);
662
663 //now lets change the name of existing taxonomies
664 $termObject = get_term($boardId,'boards');
665
666 //if the there's a match lets update the name if it has changed
667 if(!is_wp_error($termObject)){
668
669 $termName = $termObject->name;
670
671 if($boardName !== $termName){
672 //they don't match so lets update this term name with the new board name
673 wp_update_term($boardId,'boards',array('name' => $boardName));
674 }
675 }
676
677 }
678
679
680 //lets cycle through the existing terms in the taxonomy
681 $existingTerms = get_terms('boards',array( "hide_empty" => 0 ));
682
683 foreach($existingTerms as $term){
684
685 $termId = $term->term_id;
686
687 if(!in_array($termId,$boardIdArray)){
688 //if the term is not in our array delete it because it's not authorised to exist and it will cause confusion
689 wp_delete_term($termId,'boards');
690
691 }
692 }
693
694
695 //die
696 wp_die();
697
698
699 }
700 add_action( 'wp_ajax_taxonomy_save_routine', 'idea_push_taxonomy_save_routine' );
701
702
703
704
705
706
707
708
709 //add additional body class to the shortcode page for good measure
710 function idea_push_add_body_class($class) {
711
712 global $post;
713
714 if( isset($post->post_content) && has_shortcode( $post->post_content, 'ideapush' ) ) {
715 $class[] = 'idea-push';
716 }
717 return $class;
718 }
719 add_filter( 'body_class', 'idea_push_add_body_class' );
720
721
722
723 //add notification icon to menu item
724
725 add_action( 'admin_menu', 'idea_push_menu_bubble' );
726
727 function idea_push_menu_bubble() {
728 global $menu;
729
730 $count = idea_push_count_pending_ideas() + idea_push_count_ideas_review_status();
731
732
733 if ($count > 0) {
734
735 foreach ( $menu as $key => $value ) {
736
737 if ( $menu[$key][2] == 'edit.php?post_type=idea' ) {
738
739 $menu[$key][0] .= ' <span class="update-plugins"><span class="plugin-count">' . $count . '</span></span>';
740
741 return;
742 }
743 }
744 }
745 }
746
747
748 function idea_push_above_all_ideas_table() {
749
750 $screen = get_current_screen();
751
752 if ( $screen->id == 'edit-idea' ) {
753
754 echo '<style>
755
756 .idea-tasks div {
757 display: inline-block;
758 background: #fff;
759 padding: 10px;
760 border: 1px solid #e5e5e5;
761 border-radius: 6px;
762 margin-right: 10px;
763 margin-top: 10px;
764 margin-bottom: -10px;
765
766 }
767
768 .idea-tasks a {
769 text-decoration: none;
770
771 }
772
773 .pending-count, .reviewed-count {
774 display: inline-block;
775 vertical-align: top;
776 margin: 1px 0 0 5px;
777 padding: 0 5px;
778 min-width: 7px;
779 height: 17px;
780 border-radius: 11px;
781 background-color: #ca4a1f;
782 color: #fff;
783 font-size: 9px;
784 line-height: 17px;
785 text-align: center;
786 z-index: 26;
787
788 }
789
790 .column-status .open {
791 background-color: #4eb5e1;
792 color: #fff !important;
793 }
794
795 .column-status .in-progress {
796 background-color: #a7a9ac;
797 color: #fff !important;
798 }
799
800
801 .column-status .completed {
802 background-color: #414042;
803 color: #fff !important;
804 }
805
806 .column-status .reviewed {
807 background-color: #fbbf67;
808 color: #fff !important;
809 }
810
811 .column-status .approved {
812 background-color: #5eb46a;
813 color: #fff !important;
814 }
815
816 .column-status .declined {
817 background-color: #f05d55;
818 color: #fff !important;
819 }
820
821
822 .column-status a {
823
824 text-transform: uppercase;
825 padding: 3px 6px;
826 border-radius: 3px;
827 font-weight: 600;
828 font-size: smaller;
829 }
830
831 </style>';
832
833 $pendingEditPage = get_admin_url().'edit.php?post_status=pending&post_type=idea';
834 $reviewEditPage = get_admin_url().'edit.php?post_type=idea&status=reviewed';
835
836 $countPendingIdeas = idea_push_count_pending_ideas();
837 $countReviewStatus = idea_push_count_ideas_review_status();
838
839
840 echo '<div class="idea-tasks">';
841
842 if($countPendingIdeas > 0){
843 echo '<div class="pending-approval">';
844 echo '<a href="'.$pendingEditPage.'" class="pending-count-description">'.__( 'Ideas Pending Release', 'ideapush' ).'</a>';
845 echo '<span class="pending-count">'.$countPendingIdeas.'</span>';
846 echo '</div>';
847 }
848
849 if($countReviewStatus > 0){
850 echo '<div class="reviewed-status">';
851 echo '<a href="'.$reviewEditPage.'" class="reviewed-count-description">'.__( 'Ideas Needing Review', 'ideapush' ).'</a>';
852 echo '<span class="reviewed-count">'.$countReviewStatus.'</span>';
853 echo '</div>';
854 }
855
856 echo '</div>';
857
858
859 }
860
861
862 }
863 add_action( 'admin_notices', 'idea_push_above_all_ideas_table' );
864
865
866
867
868
869 add_filter( 'manage_edit-idea_columns', 'mycustomposttype_columns_definition' ) ;
870
871
872 function mycustomposttype_columns_definition( $columns ) {
873
874 $new = array();
875
876 $columns['votes'] = __( 'Votes','ideapush');
877 unset( $new['taxonomy-status'] );
878 $columns['status'] = __( 'Status','ideapush');
879
880 $customOrder = array('cb','title', 'author','taxonomy-boards' ,'status','taxonomy-tags','votes', 'comments','date');
881
882
883 foreach ($customOrder as $colname)
884 $new[$colname] = $columns[$colname];
885 return $new;
886 }
887
888
889
890
891 add_action( 'manage_idea_posts_custom_column' , 'idea_push_vote_column_content', 10, 2 );
892
893 function idea_push_vote_column_content( $column, $post_id ) {
894 switch ( $column ) {
895
896 // display a thumbnail photo
897 case 'votes' :
898 echo get_post_meta( $post_id , 'votes' , true );
899 break;
900 case 'status' :
901 $getTerms = get_the_terms( $post_id, 'status' );
902
903 foreach($getTerms as $term) {
904 $status = $term->name;
905 }
906
907 $className = strtolower($status);
908 $className = str_replace(" ","-",$className);
909
910 echo '<a class="'.$className.'" href="'.get_admin_url().'edit.php?post_type=idea&status='.$className.'">'.$status.'</a>';
911 break;
912
913 }
914 }
915
916
917 add_filter( 'manage_edit-idea_sortable_columns', 'idea_push_sortable_vote_column' );
918
919 function idea_push_sortable_vote_column( $columns ) {
920 $columns['votes'] = 'votes';
921 return $columns;
922 }
923
924
925 add_action( 'pre_get_posts', 'idea_push_custom_orderby' );
926
927 function idea_push_custom_orderby( $query ) {
928 if ( ! is_admin() )
929 return;
930
931 $orderby = $query->get( 'orderby');
932
933 if ( 'votes' == $orderby ) {
934 $query->set( 'meta_key', 'votes' );
935 $query->set( 'orderby', 'meta_value_num' );
936 }
937
938 }
939
940
941
942
943 add_filter( 'template_include', 'idea_push_ip_tag_template', 99 );
944
945 function idea_push_ip_tag_template( $template ) {
946
947
948
949 if ( is_tax( 'tags' )) {
950 $template = dirname( __FILE__ ) . '/inc/templates/ip-tag.php';
951 return $template;
952 } else {
953 return $template;
954 }
955
956 }
957
958
959 function idea_push_languages() {
960 load_plugin_textdomain( 'ideapush', false, 'ideapush/inc/languages' );
961 }
962 add_action('init', 'idea_push_languages');
963
964
965
966
967
968
969 add_action( 'pre_get_posts', function ( $query ) {
970
971 //get options
972 $options = get_option('idea_push_settings');
973
974 //get board configuration
975 $boardConfiguration = $options['idea_push_board_configuration'];
976
977 //split board configuration
978 $splitBoardConfiguration = explode('||',$boardConfiguration);
979
980 $boardsToHide = array();
981
982 //cycle through boards
983 foreach($splitBoardConfiguration as $boardConfig){
984
985 if(!empty($boardConfig)){
986
987 $furtherSplitBoardConfiguration = explode('|',$boardConfig);
988
989 if($furtherSplitBoardConfiguration[13] == 'Yes'){
990
991 $term = get_term($furtherSplitBoardConfiguration[0], 'boards' );
992 $slug = $term->slug;
993
994 array_push($boardsToHide,$slug);
995 }
996 }
997
998 }
999
1000
1001 global $wp_the_query;
1002 if($query === $wp_the_query && $query->is_search() && !is_admin()) {
1003 $tax_query = array(
1004 array(
1005 'taxonomy' => 'boards',
1006 'field' => 'slug',
1007 'terms' => $boardsToHide,
1008 'operator' => 'NOT IN',
1009 )
1010 );
1011 $query->set( 'tax_query', $tax_query );
1012 }
1013
1014
1015 });
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029 //add custom css to the frontend
1030 function idea_push_custom_css() {
1031
1032 //get options
1033 $options = get_option('idea_push_settings');
1034
1035
1036 if(isset($options['idea_push_custom_css']) && strlen($options['idea_push_custom_css'])>0){
1037
1038 wp_enqueue_style( 'custom-frontend-style', plugins_url( '/inc/css/frontendstyle.css', __FILE__ ) );
1039 wp_add_inline_style( 'custom-frontend-style', $options['idea_push_custom_css'] );
1040
1041 }
1042
1043 }
1044 add_action( 'wp_enqueue_scripts', 'idea_push_custom_css', 999 );
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062 //do pro updates
1063 //initialise the update check
1064 if($ideapush_is_pro == 'YES'){
1065
1066 require 'inc/pro-ip/plugin-update-checker/plugin-update-checker.php';
1067 $updateChecker = Puc_v4_Factory::buildUpdateChecker(
1068 'https://northernbeacheswebsites.com.au/?update_action=get_metadata&update_slug=ideapush', //Metadata URL.
1069 __FILE__, //Full path to the main plugin file.
1070 'ideapush' //Plugin slug. Usually it's the same as the name of the directory.
1071 );
1072
1073
1074 //add queries to the update call
1075 $updateChecker->addQueryArgFilter('filter_update_checks_ideapush');
1076 function filter_update_checks_ideapush($queryArgs) {
1077
1078
1079 $pluginSettings = get_option('idea_push_settings');
1080
1081 if(isset($pluginSettings['idea_push_purchase_email']) && isset($pluginSettings['idea_push_order_id'])){
1082
1083 $purchaseEmailAddress = $pluginSettings['idea_push_purchase_email'];
1084 $orderId = $pluginSettings['idea_push_order_id'];
1085 $siteUrl = get_site_url();
1086
1087 if (!empty($purchaseEmailAddress) && !empty($orderId)) {
1088 $queryArgs['purchaseEmailAddress'] = $purchaseEmailAddress;
1089 $queryArgs['orderId'] = $orderId;
1090 $queryArgs['siteUrl'] = $siteUrl;
1091 $queryArgs['productId'] = '9719';
1092 }
1093
1094 }
1095
1096 return $queryArgs;
1097 }
1098
1099
1100
1101 // define the puc_request_info_result-<slug> callback
1102 function filter_puc_request_info_result_slug_ideapush( $plugininfo, $result ) {
1103 //get the message from the server and set as transient
1104 set_transient('ideapush-update',$plugininfo->{'message'},YEAR_IN_SECONDS * 1);
1105
1106 return $plugininfo;
1107 };
1108 add_filter( "puc_request_info_result-ideapush", 'filter_puc_request_info_result_slug_ideapush', 10, 2 );
1109
1110
1111
1112
1113
1114
1115 $path = plugin_basename( __FILE__ );
1116
1117 add_action("after_plugin_row_{$path}", function( $plugin_file, $plugin_data, $status ) {
1118
1119 //get plugin settings
1120 $pluginSettings = get_option('idea_push_settings');
1121
1122
1123 if (!empty($pluginSettings['idea_push_purchase_email']) && !empty($pluginSettings['idea_push_order_id'])) {
1124
1125
1126
1127 //get transient
1128 $message = get_transient('ideapush-update');
1129
1130 if($message !== 'Yes'){
1131
1132 $purchaseLink = 'https://northernbeacheswebsites.com.au/ideapush-pro/';
1133
1134 if($message == 'Incorrect Details'){
1135 $displayMessage = 'The Order ID and Purchase ID you entered is not correct. Please double check the details you entered to receive product updates.';
1136 } elseif ($message == 'Licence Expired'){
1137 $displayMessage = 'Your licence has expired. Please <a href="'.$purchaseLink.'" target="_blank">purchase a new licence</a> to receive further updates for this plugin.';
1138 } elseif ($message == 'Website Mismatch') {
1139 $displayMessage = 'This plugin has already been registered on another website using your details. Under the licence terms this plugin can only be used on one website. Please <a href="'.$purchaseLink.'" target="_blank">click here</a> to purchase an additional licence.';
1140 } else {
1141 $displayMessage = '';
1142 }
1143
1144 echo '<tr class="plugin-update-tr active"><td colspan="3" class="plugin-update colspanchange"><div class="update-message notice inline notice-error notice-alt"><p class="installer-q-icon">'.$displayMessage.'</p></div></td></tr>';
1145
1146 }
1147
1148 } else {
1149
1150 echo '<tr class="plugin-update-tr active"><td colspan="3" class="plugin-update colspanchange"><div class="update-message notice inline notice-error notice-alt"><p class="installer-q-icon">Please enter your Order ID and Purchase ID in the plugin settings to receive automatics updates.</p></div></td></tr>';
1151
1152 }
1153
1154
1155 }, 10, 3 );
1156
1157
1158 }
1159 /**
1160 *
1161 *
1162 *
1163 * Add custom links to plugin on plugins page
1164 */
1165 function idea_push_plugin_links( $links, $file ) {
1166 if ( strpos( $file, 'ideapush.php' ) !== false ) {
1167 $new_links = array(
1168 '<a href="https://northernbeacheswebsites.com.au/product/donate-to-northern-beaches-websites/" target="_blank">' . __('Donate') . '</a>',
1169 '<a href="https://wordpress.org/support/plugin/ideapush" target="_blank">' . __('Support Forum') . '</a>',
1170 );
1171 $links = array_merge( $links, $new_links );
1172 }
1173 return $links;
1174 }
1175 add_filter( 'plugin_row_meta', 'idea_push_plugin_links', 10, 2 );
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187 ?>