| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: IdeaPush |
| 4 |
* Plugin URI: https://www.northernbeacheswebsites.com.au |
| 5 |
* Description: IdeaPush is a feature request management system for WordPress |
| 6 |
* Version: 1.4 |
| 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_menu' => false, |
| 229 |
'show_in_nav_menus' => false, |
| 230 |
'show_admin_column' => true, |
| 231 |
'update_count_callback' => '_update_post_term_count', |
| 232 |
'query_var' => true, |
| 233 |
'rewrite' => array( 'slug' => 'ip-status' ), |
| 234 |
)); |
| 235 |
|
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
//create predefined statuses |
| 242 |
add_action( 'init', 'idea_push_create_predefined_statuses', 0 ); |
| 243 |
|
| 244 |
function idea_push_create_predefined_statuses() { |
| 245 |
|
| 246 |
if(get_term_by('name', 'Open', 'status') == false){ |
| 247 |
wp_insert_term( |
| 248 |
'Open', // the term |
| 249 |
'status', // the taxonomy |
| 250 |
array( |
| 251 |
'description'=> '', |
| 252 |
'slug' => 'open' |
| 253 |
) |
| 254 |
); |
| 255 |
} |
| 256 |
|
| 257 |
if(get_term_by('name', 'Reviewed', 'status') == false){ |
| 258 |
wp_insert_term( |
| 259 |
'Reviewed', // the term |
| 260 |
'status', // the taxonomy |
| 261 |
array( |
| 262 |
'description'=> '', |
| 263 |
'slug' => 'reviewed' |
| 264 |
) |
| 265 |
); |
| 266 |
} |
| 267 |
|
| 268 |
if(get_term_by('name', 'Approved', 'status') == false){ |
| 269 |
wp_insert_term( |
| 270 |
'Approved', // the term |
| 271 |
'status', // the taxonomy |
| 272 |
array( |
| 273 |
'description'=> '', |
| 274 |
'slug' => 'approved' |
| 275 |
) |
| 276 |
); |
| 277 |
} |
| 278 |
|
| 279 |
if(get_term_by('name', 'Declined', 'status') == false){ |
| 280 |
wp_insert_term( |
| 281 |
'Declined', // the term |
| 282 |
'status', // the taxonomy |
| 283 |
array( |
| 284 |
'description'=> '', |
| 285 |
'slug' => 'declined' |
| 286 |
) |
| 287 |
); |
| 288 |
} |
| 289 |
|
| 290 |
if(get_term_by('name', 'In Progress', 'status') == false){ |
| 291 |
wp_insert_term( |
| 292 |
'In Progress', // the term |
| 293 |
'status', // the taxonomy |
| 294 |
array( |
| 295 |
'description'=> '', |
| 296 |
'slug' => 'in-progress' |
| 297 |
) |
| 298 |
); |
| 299 |
} |
| 300 |
|
| 301 |
if(get_term_by('name', 'Completed', 'status') == false){ |
| 302 |
wp_insert_term( |
| 303 |
'Completed', // the term |
| 304 |
'status', // the taxonomy |
| 305 |
array( |
| 306 |
'description'=> '', |
| 307 |
'slug' => 'completed' |
| 308 |
) |
| 309 |
); |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
//lets add our settings page |
| 327 |
add_action( 'admin_menu', 'idea_push_add_settings_page' ); |
| 328 |
add_action( 'admin_init', 'idea_push_settings_init' ); |
| 329 |
|
| 330 |
function idea_push_add_settings_page() { |
| 331 |
|
| 332 |
global $idea_push_wp_settings_page; |
| 333 |
|
| 334 |
$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'); |
| 335 |
|
| 336 |
} |
| 337 |
|
| 338 |
//callback function of setting page |
| 339 |
function idea_push_settings_page_content(){ |
| 340 |
require('inc/options/options-page-wrapper.php'); |
| 341 |
} |
| 342 |
|
| 343 |
//Gets, sets and renders options |
| 344 |
require('inc/options/options-output.php'); |
| 345 |
|
| 346 |
//produces the shortcode |
| 347 |
require('inc/shortcode/ideaboard-shortcode.php'); |
| 348 |
|
| 349 |
//function that generates list items |
| 350 |
require('inc/shortcode/idea-list-items.php'); |
| 351 |
|
| 352 |
//function that creates the idea form |
| 353 |
require('inc/shortcode/create-idea-form.php'); |
| 354 |
|
| 355 |
//function that creates the idea table header |
| 356 |
require('inc/shortcode/idea-table-header.php'); |
| 357 |
|
| 358 |
//function that creates ideas |
| 359 |
require('inc/functions/create-idea.php'); |
| 360 |
|
| 361 |
//function that creates votes |
| 362 |
require('inc/functions/create-vote.php'); |
| 363 |
|
| 364 |
//function that changes the status |
| 365 |
require('inc/functions/status-change.php'); |
| 366 |
|
| 367 |
//common functions that assist other functions run |
| 368 |
require('inc/functions/helper-functions.php'); |
| 369 |
|
| 370 |
//function that creates a user |
| 371 |
require('inc/functions/create-user.php'); |
| 372 |
|
| 373 |
//function puts idea stuff on the single idea page |
| 374 |
require('inc/functions/single-idea.php'); |
| 375 |
|
| 376 |
//function that adds our metabox |
| 377 |
require('inc/functions/create-metaboxes.php'); |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
//get pro options |
| 382 |
if($ideapush_is_pro=="YES"){ |
| 383 |
require('inc/pro-ip/idea-push-pro.php'); |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
// Load admin style and scripts |
| 393 |
function idea_push_register_admin_styles($hook) |
| 394 |
{ |
| 395 |
|
| 396 |
global $idea_push_wp_settings_page; |
| 397 |
if($hook != $idea_push_wp_settings_page) |
| 398 |
return; |
| 399 |
|
| 400 |
//css |
| 401 |
wp_enqueue_style( 'wp-color-picker' ); |
| 402 |
wp_enqueue_style( 'custom-admin-style-ideapush', plugins_url( '/inc/css/adminstyle.css', __FILE__ )); |
| 403 |
wp_enqueue_style( 'font-awesome', plugins_url( '/inc/css/font-awesome.min.css', __FILE__ )); |
| 404 |
|
| 405 |
//js |
| 406 |
wp_enqueue_script( 'custom-admin-script-ideapush', plugins_url( '/inc/js/adminscript.js', __FILE__ ), array( 'jquery','wp-color-picker' )); |
| 407 |
wp_enqueue_script('jquery-ui-dialog'); |
| 408 |
wp_enqueue_script('jquery-ui-accordion'); |
| 409 |
wp_enqueue_script('jquery-ui-tabs'); |
| 410 |
wp_enqueue_script('jquery-form'); |
| 411 |
|
| 412 |
|
| 413 |
wp_enqueue_script('clipboard', plugins_url('/inc/js/clipboard.min.js', __FILE__ ), array( 'jquery')); |
| 414 |
|
| 415 |
} |
| 416 |
add_action( 'admin_enqueue_scripts', 'idea_push_register_admin_styles' ); |
| 417 |
|
| 418 |
|
| 419 |
// Load frontend style and scripts |
| 420 |
function idea_push_register_frontend_styles() |
| 421 |
{ |
| 422 |
//get settings |
| 423 |
$options = get_option('idea_push_settings'); |
| 424 |
|
| 425 |
//css |
| 426 |
wp_enqueue_style( 'tags-input', plugins_url( '/inc/css/jquery.tagsinput.min.css', __FILE__ )); |
| 427 |
wp_enqueue_style( 'custom-frontend-style-ideapush', plugins_url( '/inc/css/frontendstyle.css', __FILE__ )); |
| 428 |
wp_enqueue_style( 'font-awesome', plugins_url( '/inc/css/font-awesome.min.css', __FILE__ )); |
| 429 |
|
| 430 |
|
| 431 |
//js |
| 432 |
wp_register_script( 'custom-frontend-script-ideapush', plugins_url( '/inc/js/frontendscript.js', __FILE__ ), array( 'jquery'), '1.0.0'); |
| 433 |
|
| 434 |
wp_localize_script('custom-frontend-script-ideapush','get_new_ideas', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 435 |
wp_localize_script('custom-frontend-script-ideapush','is_person_logged_in', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 436 |
wp_localize_script('custom-frontend-script-ideapush','submit_vote', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 437 |
wp_localize_script('custom-frontend-script-ideapush','create_user', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 438 |
wp_localize_script('custom-frontend-script-ideapush','header_render', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 439 |
wp_localize_script('custom-frontend-script-ideapush','form_render', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 440 |
wp_localize_script('custom-frontend-script-ideapush','create_idea', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 441 |
wp_localize_script('custom-frontend-script-ideapush','delete_idea', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 442 |
wp_localize_script('custom-frontend-script-ideapush','change_status', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 443 |
wp_localize_script('custom-frontend-script-ideapush','update_vote_counter', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 444 |
wp_localize_script('custom-frontend-script-ideapush','below_title_header', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
wp_enqueue_script(array('custom-frontend-script-ideapush')); |
| 449 |
wp_enqueue_script('scroll-reveal', plugins_url('/inc/js/scrollreveal.min.js', __FILE__ ), array( 'jquery')); |
| 450 |
wp_enqueue_script('tags-input-ideapush', plugins_url('/inc/js/jquery.tagsinput.min.js', __FILE__ ), array( 'jquery')); |
| 451 |
wp_enqueue_script('jquery-ui-dialog'); |
| 452 |
|
| 453 |
|
| 454 |
if(strlen($options['idea_push_recaptcha_site_key']) > 0){ |
| 455 |
wp_enqueue_script('google-recaptcha', 'https://www.google.com/recaptcha/api.js'); |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
} |
| 461 |
add_action( 'wp_enqueue_scripts', 'idea_push_register_frontend_styles' ); |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
//create taxonomy item |
| 472 |
//this is used to create a taxonomy for the board when the user creates a board from the plugin settings |
| 473 |
function idea_push_add_taxonomy_item() { |
| 474 |
|
| 475 |
//get options |
| 476 |
$options = get_option('idea_push_settings'); |
| 477 |
|
| 478 |
//get is pro |
| 479 |
global $ideapush_is_pro; |
| 480 |
|
| 481 |
//get board name from ajax call |
| 482 |
$boardName = idea_push_sanitization_validation($_POST['boardName'],'boardname'); |
| 483 |
|
| 484 |
if($boardName == false){ |
| 485 |
wp_die(); |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
//lets first check if the board already exists |
| 492 |
if(get_term_by('name', $boardName, 'boards') == false){ |
| 493 |
|
| 494 |
//lets check if licenced |
| 495 |
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){ |
| 496 |
|
| 497 |
$boardNameSlug = strtolower($boardName); |
| 498 |
$boardNameSlug = preg_replace('/\s+/', '-', $boardNameSlug); |
| 499 |
|
| 500 |
wp_insert_term( |
| 501 |
$boardName, // the term |
| 502 |
'boards', // the taxonomy |
| 503 |
array( |
| 504 |
'description'=> '', |
| 505 |
'slug' => $boardNameSlug |
| 506 |
) |
| 507 |
); |
| 508 |
|
| 509 |
//lets return the item id |
| 510 |
|
| 511 |
$getTermId = get_term_by('name', $boardName, 'boards'); |
| 512 |
$termId = $getTermId->term_id; |
| 513 |
|
| 514 |
echo $termId; |
| 515 |
|
| 516 |
|
| 517 |
} else { |
| 518 |
echo 'NOT-PRO'; |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
} else { |
| 525 |
|
| 526 |
echo 'TERM-EXISTS'; |
| 527 |
|
| 528 |
|
| 529 |
} |
| 530 |
|
| 531 |
//die |
| 532 |
wp_die(); |
| 533 |
|
| 534 |
|
| 535 |
} |
| 536 |
add_action( 'wp_ajax_add_taxonomy_item', 'idea_push_add_taxonomy_item' ); |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
//lets delete existing taxonomies and rename others where necessary |
| 547 |
function idea_push_taxonomy_save_routine() { |
| 548 |
|
| 549 |
|
| 550 |
//get board name from ajax call |
| 551 |
$comparisonData = $_POST['comparisonData']; |
| 552 |
$explodeTheData = explode("||", $comparisonData); |
| 553 |
|
| 554 |
$boardIdArray = array(); |
| 555 |
|
| 556 |
foreach($explodeTheData as $board){ |
| 557 |
|
| 558 |
$anotherExplosion = explode("|", $board); |
| 559 |
$boardId = $anotherExplosion[0]; |
| 560 |
$boardName = $anotherExplosion[1]; |
| 561 |
|
| 562 |
array_push($boardIdArray,$boardId); |
| 563 |
|
| 564 |
//now lets change the name of existing taxonomies |
| 565 |
$termObject = get_term($boardId,'boards'); |
| 566 |
|
| 567 |
//if the there's a match lets update the name if it has changed |
| 568 |
if(!is_wp_error($termObject)){ |
| 569 |
|
| 570 |
$termName = $termObject->name; |
| 571 |
|
| 572 |
if($boardName !== $termName){ |
| 573 |
//they don't match so lets update this term name with the new board name |
| 574 |
wp_update_term($boardId,'boards',array('name' => $boardName)); |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
//lets cycle through the existing terms in the taxonomy |
| 582 |
$existingTerms = get_terms('boards',array( "hide_empty" => 0 )); |
| 583 |
|
| 584 |
foreach($existingTerms as $term){ |
| 585 |
|
| 586 |
$termId = $term->term_id; |
| 587 |
|
| 588 |
if(!in_array($termId,$boardIdArray)){ |
| 589 |
//if the term is not in our array delete it because it's not authorised to exist and it will cause confusion |
| 590 |
wp_delete_term($termId,'boards'); |
| 591 |
|
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
//die |
| 597 |
wp_die(); |
| 598 |
|
| 599 |
|
| 600 |
} |
| 601 |
add_action( 'wp_ajax_taxonomy_save_routine', 'idea_push_taxonomy_save_routine' ); |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
//add additional body class to the shortcode page for good measure |
| 611 |
function idea_push_add_body_class($class) { |
| 612 |
|
| 613 |
global $post; |
| 614 |
|
| 615 |
if( isset($post->post_content) && has_shortcode( $post->post_content, 'ideapush' ) ) { |
| 616 |
$class[] = 'idea-push'; |
| 617 |
} |
| 618 |
return $class; |
| 619 |
} |
| 620 |
add_filter( 'body_class', 'idea_push_add_body_class' ); |
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
?> |