| 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: 8.66 |
| 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 |
|
| 16 |
if(file_exists(dirname( __FILE__ ).'/inc/pro-ip')){ |
| 17 |
$ideapush_is_pro = "YES"; |
| 18 |
} else { |
| 19 |
$ideapush_is_pro = "NO"; |
| 20 |
} |
| 21 |
|
| 22 |
//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 |
| 23 |
global $ideapush_pro_features; |
| 24 |
$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'), 'Tag Page' => array('NO','YES'), 'IdeaPush Support' => array('NO','NO'),'IdeaPush Pro' => array('YES','YES'),'Integrations' => array('YES','YES')); |
| 25 |
|
| 26 |
//get plugin version number |
| 27 |
function idea_push_plugin_get_version() { |
| 28 |
if ( ! function_exists( 'get_plugins' ) ) |
| 29 |
require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 30 |
$plugin_folder = get_plugins( '/' . plugin_basename( dirname( __FILE__ ) ) ); |
| 31 |
$plugin_file = basename( ( __FILE__ ) ); |
| 32 |
return $plugin_folder[$plugin_file]['Version']; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
function idea_push_create_custom_post_type() { |
| 37 |
|
| 38 |
//SVG of the icon |
| 39 |
$menu_icon_svg = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIyLjAuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMiIgYmFzZVByb2ZpbGU9InRpbnkiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIgoJIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMjAgMjAiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8cGF0aCBmaWxsPSIjNzhDMTQ4IiBkPSJNMTAsMEM0LjUsMCwwLDQuNSwwLDEwczQuNSwxMCwxMCwxMHMxMC00LjUsMTAtMTBTMTUuNSwwLDEwLDB6IE04LjEsMTIuMWwtMS42LDEuNQoJYy0wLjIsMC4yLTAuNCwwLjMtMC43LDAuM2MtMC4zLDAtMC41LTAuMS0wLjctMC4zbC0xLjYtMS41Yy0wLjItMC4yLTAuMi0wLjYsMC0wLjljMC4yLTAuMiwwLjYtMC4yLDAuOSwwbDEuNCwxLjRsMS40LTEuNAoJQzcuMywxMS4xLDcuNSwxMSw3LjYsMTFzMC4zLDAuMSwwLjQsMC4yQzguMywxMS40LDguMywxMS44LDguMSwxMi4xeiBNOC4xLDlDNy45LDkuMSw3LjgsOS4yLDcuNiw5LjJTNy4zLDkuMSw3LjIsOUw1LjgsNy42TDQuNCw5CglDNC4yLDkuMiwzLjgsOS4yLDMuNiw5Yy0wLjItMC4yLTAuMi0wLjYsMC0wLjlsMS42LTEuNWMwLjItMC4yLDAuNC0wLjMsMC43LTAuM2MwLjMsMCwwLjUsMC4xLDAuNywwLjNsMS42LDEuNQoJQzguMyw4LjQsOC4zLDguOCw4LjEsOXogTTE1LjIsMTRoLTQuNmMtMC44LDAtMS40LTAuNi0xLjQtMS40YzAtMC44LDAuNi0xLjQsMS40LTEuNGg0LjZjMC44LDAsMS40LDAuNiwxLjQsMS40CglDMTYuNiwxMy4zLDE2LDE0LDE1LjIsMTR6IE0xNS4yLDkuMmgtNC42Yy0wLjgsMC0xLjQtMC42LTEuNC0xLjRjMC0wLjgsMC42LTEuNCwxLjQtMS40aDQuNmMwLjgsMCwxLjQsMC42LDEuNCwxLjQKCUMxNi42LDguNSwxNiw5LjIsMTUuMiw5LjJ6Ii8+Cjwvc3ZnPgo='; |
| 40 |
|
| 41 |
// Set UI labels for Custom Post Type |
| 42 |
$labels = array( |
| 43 |
'name' => _x( 'Ideas', 'Post Type General Name', 'ideapush' ), |
| 44 |
'singular_name' => _x( 'Idea', 'Post Type Singular Name', 'ideapush' ), |
| 45 |
'menu_name' => __( 'IdeaPush', 'ideapush' ), |
| 46 |
'parent_item_colon' => __( 'Parent Idea', 'ideapush' ), |
| 47 |
'all_items' => __( 'All Ideas', 'ideapush' ), |
| 48 |
'view_item' => __( 'View Idea', 'ideapush' ), |
| 49 |
'add_new_item' => __( 'Add New Idea', 'ideapush' ), |
| 50 |
'add_new' => __( 'Add New', 'ideapush' ), |
| 51 |
'edit_item' => __( 'Edit Idea', 'ideapush' ), |
| 52 |
'update_item' => __( 'Update Idea', 'ideapush' ), |
| 53 |
'search_items' => __( 'Search Idea', 'ideapush' ), |
| 54 |
'not_found' => __( 'Not Found', 'ideapush' ), |
| 55 |
'not_found_in_trash' => __( 'Not found in Trash', 'ideapush' ), |
| 56 |
); |
| 57 |
|
| 58 |
// Set other options for Custom Post Type |
| 59 |
$args = array( |
| 60 |
'label' => __( 'ideas', 'ideapush' ), |
| 61 |
'description' => __( 'IdeaPush ideas', 'ideapush' ), |
| 62 |
'labels' => $labels, |
| 63 |
// Features this CPT supports in Post Editor |
| 64 |
// 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields',), |
| 65 |
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'comments', 'revisions','excerpt'), |
| 66 |
|
| 67 |
// You can associate this CPT with a taxonomy or custom taxonomy. |
| 68 |
'taxonomies' => array( 'idea-boards' ), |
| 69 |
/* A hierarchical CPT is like Pages and can have |
| 70 |
* Parent and child items. A non-hierarchical CPT |
| 71 |
* is like Posts. |
| 72 |
*/ |
| 73 |
'hierarchical' => false, |
| 74 |
'public' => true, |
| 75 |
'show_ui' => true, |
| 76 |
'show_in_menu' => true, |
| 77 |
'show_in_nav_menus' => true, |
| 78 |
'show_in_admin_bar' => true, |
| 79 |
'menu_position' => 5, |
| 80 |
'menu_icon' => $menu_icon_svg, |
| 81 |
'can_export' => true, |
| 82 |
'has_archive' => false, |
| 83 |
'exclude_from_search' => false, |
| 84 |
'publicly_queryable' => apply_filters( 'ideapush_display_single_ideas', true ), |
| 85 |
'capability_type' => array('ip_idea','ip_ideas'), |
| 86 |
'map_meta_cap' => true, |
| 87 |
'show_in_rest' => true, |
| 88 |
); |
| 89 |
|
| 90 |
// Registering your Custom Post Type |
| 91 |
register_post_type( 'idea', $args ); |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
/* Hook into the 'init' action so that the function |
| 96 |
* Containing our post type registration is not |
| 97 |
* unnecessarily executed. |
| 98 |
*/ |
| 99 |
|
| 100 |
add_action( 'init', 'idea_push_create_custom_post_type', 0 ); |
| 101 |
|
| 102 |
|
| 103 |
//when activating or deactivating the plugin lets fluch the rewrite rules because otherwise the single post pages may produce an error |
| 104 |
|
| 105 |
register_activation_hook( __FILE__, 'idea_push_flush_rewrites' ); |
| 106 |
function idea_push_flush_rewrites() { |
| 107 |
// call your CPT registration function here (it should also be hooked into 'init') |
| 108 |
idea_push_create_custom_post_type(); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
//run on activating the plugin |
| 120 |
function idea_push_plugin_activate() { |
| 121 |
|
| 122 |
// remove_role( 'idea_push_guest' ); |
| 123 |
add_role( 'idea_push_guest', 'IdeaPush Guest', array('read' => true, 'level_1' => true )); |
| 124 |
add_role( 'idea_push_manager', 'IdeaPush Manager', array('read' => true, 'level_1' => true,'manage_idea_push_settings' => true )); |
| 125 |
} |
| 126 |
register_activation_hook( __FILE__, 'idea_push_plugin_activate' ); |
| 127 |
|
| 128 |
|
| 129 |
//adds new role to wordpress |
| 130 |
//this is poorly implemented but I don't know a nicer way to do it because adding the role upon updating was not working |
| 131 |
function idea_push_check_if_manager_role_exists(){ |
| 132 |
if(get_role("idea_push_manager") == null){ |
| 133 |
add_role( 'idea_push_manager', 'IdeaPush Manager', array('read' => true, 'level_1' => true,'manage_idea_push_settings' => true )); |
| 134 |
} |
| 135 |
} |
| 136 |
add_action( 'admin_init', 'idea_push_check_if_manager_role_exists' ); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
//add role capabilities for custom post type |
| 142 |
add_action('admin_init','idea_push_role_capabilities',999); |
| 143 |
function idea_push_role_capabilities() { |
| 144 |
|
| 145 |
// Add the roles you'd like to administer the custom post types |
| 146 |
$roles = array('idea_push_manager','editor','administrator'); |
| 147 |
$capability_normal = 'ip_idea'; |
| 148 |
$capability_plural = 'ip_ideas'; |
| 149 |
|
| 150 |
// Loop through each role and assign capabilities |
| 151 |
foreach($roles as $the_role) { |
| 152 |
|
| 153 |
$role = get_role($the_role); |
| 154 |
|
| 155 |
if($role){ |
| 156 |
$role->add_cap( 'read' ); |
| 157 |
$role->add_cap( 'manage_tags' ); |
| 158 |
$role->add_cap( 'edit_tags' ); |
| 159 |
$role->add_cap( 'read_'.$capability_normal); |
| 160 |
$role->add_cap( 'delete_'.$capability_normal ); |
| 161 |
$role->add_cap( 'read_private_'.$capability_plural ); |
| 162 |
$role->add_cap( 'edit_'.$capability_normal ); |
| 163 |
$role->add_cap( 'edit_'.$capability_plural ); |
| 164 |
$role->add_cap( 'edit_others_'.$capability_plural ); |
| 165 |
$role->add_cap( 'edit_published_'.$capability_plural ); |
| 166 |
$role->add_cap( 'edit_private_'.$capability_plural ); |
| 167 |
$role->add_cap( 'publish_'.$capability_plural ); |
| 168 |
$role->add_cap( 'delete_others_'.$capability_plural ); |
| 169 |
$role->add_cap( 'delete_private_'.$capability_plural ); |
| 170 |
$role->add_cap( 'delete_published_'.$capability_plural ); |
| 171 |
$role->add_cap( 'delete_'.$capability_plural ); |
| 172 |
$role->add_cap( 'manage_idea_push_settings'); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
//run on deactivating the plugin |
| 184 |
function idea_push_plugin_deactivate(){ |
| 185 |
remove_role( 'idea_push_guest' ); |
| 186 |
remove_role( 'idea_push_manager' ); |
| 187 |
} |
| 188 |
register_deactivation_hook( __FILE__, 'idea_push_plugin_deactivate' ); |
| 189 |
|
| 190 |
|
| 191 |
//enable idea push managers to save the settings |
| 192 |
function idea_push_manager_save_settings(){ |
| 193 |
return 'manage_idea_push_settings'; |
| 194 |
} |
| 195 |
add_filter( 'option_page_capability_ip_notifications', 'idea_push_manager_save_settings'); |
| 196 |
add_filter( 'option_page_capability_ip_statuses', 'idea_push_manager_save_settings'); |
| 197 |
add_filter( 'option_page_capability_ip_design', 'idea_push_manager_save_settings'); |
| 198 |
add_filter( 'option_page_capability_ip_idea_form', 'idea_push_manager_save_settings'); |
| 199 |
add_filter( 'option_page_capability_ip_boards', 'idea_push_manager_save_settings'); |
| 200 |
add_filter( 'option_page_capability_ip_licence', 'idea_push_manager_save_settings'); |
| 201 |
add_filter( 'option_page_capability_ip_ideapush_support', 'idea_push_manager_save_settings'); |
| 202 |
add_filter( 'option_page_capability_ip_ideapush_pro', 'idea_push_manager_save_settings'); |
| 203 |
add_filter( 'option_page_capability_ip_integrations', 'idea_push_manager_save_settings'); |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
//add a settings link on the plugin page |
| 208 |
function idea_push_add_settings_link( $links ) { |
| 209 |
$settings_link = '<a href="edit.php?post_type=idea&page=idea_push_settings">' . __( 'Settings','ideapush' ) . '</a>'; |
| 210 |
$ideas_link = '<a href="edit.php?post_type=idea">' . __( 'All Ideas','ideapush' ) . '</a>'; |
| 211 |
array_unshift( $links, $settings_link ); |
| 212 |
array_unshift( $links, $ideas_link ); |
| 213 |
|
| 214 |
|
| 215 |
return $links; |
| 216 |
} |
| 217 |
$plugin = plugin_basename( __FILE__ ); |
| 218 |
add_filter( "plugin_action_links_$plugin", 'idea_push_add_settings_link' ); |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
//create boards taxonomy |
| 223 |
add_action( 'init', 'idea_push_create_taxonomy_boards', 0 ); |
| 224 |
|
| 225 |
function idea_push_create_taxonomy_boards() { |
| 226 |
|
| 227 |
// Labels part for the GUI |
| 228 |
|
| 229 |
$labels = array( |
| 230 |
'name' => _x( 'Boards', 'taxonomy general name' ), |
| 231 |
'singular_name' => _x( 'Board', 'taxonomy singular name' ), |
| 232 |
'search_items' => __( 'Search Boards' ), |
| 233 |
'popular_items' => __( 'Popular Boards' ), |
| 234 |
'all_items' => __( 'All Boards' ), |
| 235 |
'parent_item' => null, |
| 236 |
'parent_item_colon' => null, |
| 237 |
'edit_item' => __( 'Edit Board' ), |
| 238 |
'update_item' => __( 'Update Board' ), |
| 239 |
'add_new_item' => __( 'Add New Board' ), |
| 240 |
'new_item_name' => __( 'New Board Name' ), |
| 241 |
'separate_items_with_commas' => __( 'Separate boards with commas' ), |
| 242 |
'add_or_remove_items' => __( 'Add or remove boards' ), |
| 243 |
'choose_from_most_used' => __( 'Choose from the most used boards' ), |
| 244 |
'menu_name' => __( 'Boards' ), |
| 245 |
); |
| 246 |
|
| 247 |
// Now register the non-hierarchical taxonomy like tag |
| 248 |
|
| 249 |
register_taxonomy('boards','idea',array( |
| 250 |
'hierarchical' => true, |
| 251 |
'labels' => $labels, |
| 252 |
'show_ui' => true, |
| 253 |
'show_in_menu' => false, |
| 254 |
'show_in_nav_menus' => false, |
| 255 |
'show_admin_column' => true, |
| 256 |
'update_count_callback' => '_update_post_term_count', |
| 257 |
'query_var' => true, |
| 258 |
'rewrite' => array( 'slug' => 'ip-board' ), |
| 259 |
'meta_box_cb' => 'idea_push_taxonomy_radio_meta_box', |
| 260 |
'capabilities' => array ( |
| 261 |
'manage_terms' => 'read', //by default only admin |
| 262 |
'edit_terms' => 'manage_tags', |
| 263 |
'delete_terms' => 'manage_tags', |
| 264 |
'assign_terms' => 'edit_tags' |
| 265 |
), |
| 266 |
)); |
| 267 |
|
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
//create tags taxonomy |
| 272 |
add_action( 'init', 'idea_push_create_taxonomy_tags', 0 ); |
| 273 |
|
| 274 |
function idea_push_create_taxonomy_tags() { |
| 275 |
|
| 276 |
// Labels part for the GUI |
| 277 |
|
| 278 |
$labels = array( |
| 279 |
'name' => _x( 'Tags', 'taxonomy general name' ), |
| 280 |
'singular_name' => _x( 'Tag', 'taxonomy singular name' ), |
| 281 |
'search_items' => __( 'Search tags' ), |
| 282 |
'popular_items' => __( 'Popular Tags' ), |
| 283 |
'all_items' => __( 'All Tags' ), |
| 284 |
'parent_item' => null, |
| 285 |
'parent_item_colon' => null, |
| 286 |
'edit_item' => __( 'Edit Tag' ), |
| 287 |
'update_item' => __( 'Update Tag' ), |
| 288 |
'add_new_item' => __( 'Add New Tag' ), |
| 289 |
'new_item_name' => __( 'New Tag Name' ), |
| 290 |
'separate_items_with_commas' => __( 'Separate tags with commas' ), |
| 291 |
'add_or_remove_items' => __( 'Add or remove tags' ), |
| 292 |
'choose_from_most_used' => __( 'Choose from the most used tags' ), |
| 293 |
'menu_name' => __( 'Tags' ), |
| 294 |
); |
| 295 |
|
| 296 |
// Now register the non-hierarchical taxonomy like tag |
| 297 |
|
| 298 |
register_taxonomy('tags','idea',array( |
| 299 |
'hierarchical' => false, |
| 300 |
'labels' => $labels, |
| 301 |
'show_ui' => true, |
| 302 |
'show_in_menu' => true, |
| 303 |
'show_in_nav_menus' => false, |
| 304 |
'show_admin_column' => true, |
| 305 |
'update_count_callback' => '_update_post_term_count', |
| 306 |
'query_var' => true, |
| 307 |
'rewrite' => array( 'slug' => 'ip-tag' ), |
| 308 |
'capabilities' => array ( |
| 309 |
'manage_terms' => 'read', //by default only admin |
| 310 |
'edit_terms' => 'manage_tags', |
| 311 |
'delete_terms' => 'manage_tags', |
| 312 |
'assign_terms' => 'edit_tags' |
| 313 |
), |
| 314 |
)); |
| 315 |
|
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
//create status taxonomy |
| 321 |
add_action( 'init', 'idea_push_create_taxonomy_status', 0 ); |
| 322 |
|
| 323 |
function idea_push_create_taxonomy_status() { |
| 324 |
|
| 325 |
// Labels part for the GUI |
| 326 |
|
| 327 |
$labels = array( |
| 328 |
'name' => _x( 'Status', 'taxonomy general name' ), |
| 329 |
'singular_name' => _x( 'Status', 'taxonomy singular name' ), |
| 330 |
'search_items' => __( 'Search Statuses' ), |
| 331 |
'popular_items' => __( 'Popular Statuses' ), |
| 332 |
'all_items' => __( 'All Statuses' ), |
| 333 |
'parent_item' => null, |
| 334 |
'parent_item_colon' => null, |
| 335 |
'edit_item' => __( 'Edit Status' ), |
| 336 |
'update_item' => __( 'Update Status' ), |
| 337 |
'add_new_item' => __( 'Add New Status' ), |
| 338 |
'new_item_name' => __( 'New Status Name' ), |
| 339 |
'separate_items_with_commas' => __( 'Separate statuses with commas' ), |
| 340 |
'add_or_remove_items' => __( 'Add or remove statuses' ), |
| 341 |
'choose_from_most_used' => __( 'Choose from the most used statuses' ), |
| 342 |
'menu_name' => __( 'Statuses' ), |
| 343 |
); |
| 344 |
|
| 345 |
// Now register the non-hierarchical taxonomy like tag |
| 346 |
|
| 347 |
register_taxonomy('status','idea',array( |
| 348 |
'hierarchical' => true, |
| 349 |
'labels' => $labels, |
| 350 |
'show_ui' => true, |
| 351 |
'show_in_quick_edit' => true, |
| 352 |
'show_in_menu' => true, |
| 353 |
'show_in_nav_menus' => false, |
| 354 |
'show_admin_column' => true, |
| 355 |
'update_count_callback' => '_update_post_term_count', |
| 356 |
'query_var' => true, |
| 357 |
'rewrite' => array( 'slug' => 'ip-status' ), |
| 358 |
'meta_box_cb' => 'idea_push_taxonomy_radio_meta_box_status', |
| 359 |
'capabilities' => array ( |
| 360 |
'manage_terms' => 'read', //by default only admin |
| 361 |
'edit_terms' => 'manage_tags', |
| 362 |
'delete_terms' => 'manage_tags', |
| 363 |
'assign_terms' => 'edit_tags' |
| 364 |
), |
| 365 |
)); |
| 366 |
|
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
//create predefined statuses |
| 384 |
add_action( 'init', 'idea_push_create_predefined_statuses', 0 ); |
| 385 |
|
| 386 |
function idea_push_create_predefined_statuses() { |
| 387 |
|
| 388 |
if(get_term_by('name', 'Open', 'status') == false){ |
| 389 |
wp_insert_term( |
| 390 |
'Open', // the term |
| 391 |
'status', // the taxonomy |
| 392 |
array( |
| 393 |
'description'=> '', |
| 394 |
'slug' => 'open' |
| 395 |
) |
| 396 |
); |
| 397 |
} |
| 398 |
|
| 399 |
if(get_term_by('name', 'Reviewed', 'status') == false){ |
| 400 |
wp_insert_term( |
| 401 |
'Reviewed', // the term |
| 402 |
'status', // the taxonomy |
| 403 |
array( |
| 404 |
'description'=> '', |
| 405 |
'slug' => 'reviewed' |
| 406 |
) |
| 407 |
); |
| 408 |
} |
| 409 |
|
| 410 |
if(get_term_by('name', 'Approved', 'status') == false){ |
| 411 |
wp_insert_term( |
| 412 |
'Approved', // the term |
| 413 |
'status', // the taxonomy |
| 414 |
array( |
| 415 |
'description'=> '', |
| 416 |
'slug' => 'approved' |
| 417 |
) |
| 418 |
); |
| 419 |
} |
| 420 |
|
| 421 |
if(get_term_by('name', 'Declined', 'status') == false){ |
| 422 |
wp_insert_term( |
| 423 |
'Declined', // the term |
| 424 |
'status', // the taxonomy |
| 425 |
array( |
| 426 |
'description'=> '', |
| 427 |
'slug' => 'declined' |
| 428 |
) |
| 429 |
); |
| 430 |
} |
| 431 |
|
| 432 |
if(get_term_by('name', 'In Progress', 'status') == false){ |
| 433 |
wp_insert_term( |
| 434 |
'In Progress', // the term |
| 435 |
'status', // the taxonomy |
| 436 |
array( |
| 437 |
'description'=> '', |
| 438 |
'slug' => 'in-progress' |
| 439 |
) |
| 440 |
); |
| 441 |
} |
| 442 |
|
| 443 |
if(get_term_by('name', 'Completed', 'status') == false){ |
| 444 |
wp_insert_term( |
| 445 |
'Completed', // the term |
| 446 |
'status', // the taxonomy |
| 447 |
array( |
| 448 |
'description'=> '', |
| 449 |
'slug' => 'completed' |
| 450 |
) |
| 451 |
); |
| 452 |
} |
| 453 |
|
| 454 |
if(get_term_by('name', 'Duplicate', 'status') == false){ |
| 455 |
wp_insert_term( |
| 456 |
'Duplicate', // the term |
| 457 |
'status', // the taxonomy |
| 458 |
array( |
| 459 |
'description'=> '', |
| 460 |
'slug' => 'duplicate' |
| 461 |
) |
| 462 |
); |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
//lets add our settings page |
| 480 |
add_action( 'admin_menu', 'idea_push_add_settings_page' ); |
| 481 |
add_action( 'admin_init', 'idea_push_settings_init' ); |
| 482 |
|
| 483 |
function idea_push_add_settings_page() { |
| 484 |
|
| 485 |
global $idea_push_wp_settings_page; |
| 486 |
|
| 487 |
$idea_push_wp_settings_page = add_submenu_page('edit.php?post_type=idea', __('Settings','ideapush'), __('Settings','ideapush'),'manage_idea_push_settings', 'idea_push_settings', 'idea_push_settings_page_content'); |
| 488 |
|
| 489 |
} |
| 490 |
|
| 491 |
//callback function of setting page |
| 492 |
function idea_push_settings_page_content(){ |
| 493 |
require('inc/options/options-page-wrapper.php'); |
| 494 |
} |
| 495 |
|
| 496 |
//Gets, sets and renders options |
| 497 |
require('inc/options/options-output.php'); |
| 498 |
|
| 499 |
//Renders the board |
| 500 |
require('inc/options/options-board-render.php'); |
| 501 |
|
| 502 |
//produces the shortcode |
| 503 |
require('inc/shortcode/ideaboard-shortcode.php'); |
| 504 |
|
| 505 |
//function that generates list items |
| 506 |
require('inc/shortcode/idea-list-items.php'); |
| 507 |
|
| 508 |
//function that creates the idea form |
| 509 |
require('inc/shortcode/create-idea-form.php'); |
| 510 |
|
| 511 |
//function that creates the idea table header |
| 512 |
require('inc/shortcode/idea-table-header.php'); |
| 513 |
|
| 514 |
//function that creates ideas |
| 515 |
require('inc/functions/create-idea.php'); |
| 516 |
|
| 517 |
//function that creates votes |
| 518 |
require('inc/functions/create-vote.php'); |
| 519 |
|
| 520 |
//function that changes the status |
| 521 |
require('inc/functions/status-change.php'); |
| 522 |
|
| 523 |
//common functions that assist other functions run |
| 524 |
require('inc/functions/helper-functions.php'); |
| 525 |
|
| 526 |
//function that creates a user |
| 527 |
require('inc/functions/create-user.php'); |
| 528 |
|
| 529 |
//function that updates a user |
| 530 |
require('inc/functions/update-user.php'); |
| 531 |
|
| 532 |
//function puts idea stuff on the single idea page |
| 533 |
require('inc/functions/single-idea.php'); |
| 534 |
|
| 535 |
//function that adds our metabox |
| 536 |
require('inc/functions/create-metaboxes.php'); |
| 537 |
|
| 538 |
//function that creates user profile image and votes remaining |
| 539 |
require('inc/functions/user-profile-meta.php'); |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
//get pro options |
| 544 |
if($ideapush_is_pro=="YES"){ |
| 545 |
require('inc/pro-ip/idea-push-pro.php'); |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
// Load admin style and scripts |
| 552 |
function idea_push_register_admin_styles($hook) |
| 553 |
{ |
| 554 |
|
| 555 |
global $pagenow; |
| 556 |
|
| 557 |
global $idea_push_wp_settings_page; |
| 558 |
global $idea_push_wp_reports_page; |
| 559 |
|
| 560 |
if('profile.php' == $pagenow || 'user-edit.php' == $pagenow){ |
| 561 |
//display on user profile page |
| 562 |
wp_enqueue_media(); |
| 563 |
wp_enqueue_script( 'user-profile-script-ideapush', plugins_url( '/inc/js/userprofile.js', __FILE__ ), array( 'jquery' ),idea_push_plugin_get_version()); |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
if($hook != $idea_push_wp_reports_page && $hook != $idea_push_wp_settings_page ){ |
| 568 |
return; |
| 569 |
|
| 570 |
} else { |
| 571 |
//css |
| 572 |
wp_enqueue_style( 'wp-color-picker' ); |
| 573 |
wp_enqueue_style( 'custom-admin-style-ideapush', plugins_url( '/inc/css/adminstyle.css', __FILE__ ),array(),idea_push_plugin_get_version()); |
| 574 |
wp_enqueue_style( 'font-awesome', plugins_url( '/inc/css/font-awesome.min.css', __FILE__ )); |
| 575 |
wp_enqueue_style('tippy', plugins_url('/inc/css/tippy.css', __FILE__ )); |
| 576 |
|
| 577 |
//js |
| 578 |
wp_enqueue_script( 'custom-admin-script-ideapush', plugins_url( '/inc/js/adminscript.js', __FILE__ ), array( 'jquery','wp-color-picker' ),idea_push_plugin_get_version()); |
| 579 |
wp_enqueue_script('jquery-ui-dialog'); |
| 580 |
wp_enqueue_script('jquery-ui-accordion'); |
| 581 |
wp_enqueue_script('jquery-ui-tabs'); |
| 582 |
wp_enqueue_script('jquery-ui-datepicker'); |
| 583 |
wp_enqueue_script('jquery-ui-sortable'); |
| 584 |
wp_enqueue_script('jquery-form'); |
| 585 |
|
| 586 |
wp_enqueue_script('alertify', plugins_url('/inc/js/alertify.js', __FILE__ ), array( 'jquery'),null,true); |
| 587 |
wp_enqueue_script('clipboard', plugins_url('/inc/js/clipboard.min.js', __FILE__ ), array( 'jquery'),'2.0.4'); |
| 588 |
wp_enqueue_script('tippy', plugins_url('/inc/js/tippy.min.js', __FILE__ ), array( 'jquery'),'1.0'); |
| 589 |
|
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
} |
| 600 |
add_action( 'admin_enqueue_scripts', 'idea_push_register_admin_styles' ); |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
// Load styles and scripts for the single idea page |
| 605 |
function idea_push_register_admin_styles_single(){ |
| 606 |
|
| 607 |
global $post_type; |
| 608 |
|
| 609 |
if('idea' != $post_type) |
| 610 |
return; |
| 611 |
|
| 612 |
//css |
| 613 |
|
| 614 |
//js |
| 615 |
wp_enqueue_script( 'custom-frontend-script-single-idea', plugins_url( '/inc/js/singleideascript.js', __FILE__ ), array( 'jquery'), idea_push_plugin_get_version()); |
| 616 |
|
| 617 |
} |
| 618 |
add_action( 'admin_enqueue_scripts', 'idea_push_register_admin_styles_single' ); |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
// Load frontend style and scripts |
| 633 |
function idea_push_register_frontend_styles() |
| 634 |
{ |
| 635 |
//get settings |
| 636 |
$options = get_option('idea_push_settings'); |
| 637 |
|
| 638 |
//css |
| 639 |
wp_register_style( 'custom-frontend-style-ideapush', plugins_url( '/inc/css/frontendstyle.css', __FILE__ ),array(),idea_push_plugin_get_version()); |
| 640 |
wp_register_style( 'ideapush-font', plugins_url( '/inc/css/ideapush-font.css', __FILE__ )); |
| 641 |
|
| 642 |
|
| 643 |
//js |
| 644 |
wp_register_script( 'custom-frontend-script-ideapush', plugins_url( '/inc/js/frontendscript.js', __FILE__ ), array( 'jquery'), idea_push_plugin_get_version()); |
| 645 |
|
| 646 |
wp_localize_script('custom-frontend-script-ideapush','get_new_ideas', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 647 |
wp_localize_script('custom-frontend-script-ideapush','submit_vote', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 648 |
wp_localize_script('custom-frontend-script-ideapush','create_user', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 649 |
wp_localize_script('custom-frontend-script-ideapush','header_render', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 650 |
wp_localize_script('custom-frontend-script-ideapush','form_render', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 651 |
wp_localize_script('custom-frontend-script-ideapush','create_idea', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 652 |
wp_localize_script('custom-frontend-script-ideapush','delete_idea', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 653 |
wp_localize_script('custom-frontend-script-ideapush','change_status', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 654 |
wp_localize_script('custom-frontend-script-ideapush','update_vote_counter', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 655 |
wp_localize_script('custom-frontend-script-ideapush','below_title_header', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 656 |
wp_localize_script('custom-frontend-script-ideapush','is_person_able_to_add_tag', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 657 |
wp_localize_script('custom-frontend-script-ideapush','update_user_profile', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); |
| 658 |
|
| 659 |
|
| 660 |
wp_register_script('alertify', plugins_url('/inc/js/alertify.js', __FILE__ ), array( 'jquery'),null,true); |
| 661 |
wp_register_script('scroll-reveal', plugins_url('/inc/js/scrollreveal.min.js', __FILE__ ), array( 'jquery')); |
| 662 |
wp_register_script('read-more', plugins_url('/inc/js/readmore.min.js', __FILE__ ), array( 'jquery')); |
| 663 |
// wp_register_script('jquery-ui-dialog'); |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
} |
| 668 |
add_action( 'wp_enqueue_scripts', 'idea_push_register_frontend_styles' ); |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
//create taxonomy item |
| 677 |
//this is used to create a taxonomy for the board when the user creates a board from the plugin settings |
| 678 |
function idea_push_add_taxonomy_item() { |
| 679 |
|
| 680 |
//add better protection of this function |
| 681 |
//check if user is admin or manager |
| 682 |
$nonce = $_POST['nonce']; |
| 683 |
|
| 684 |
if( wp_verify_nonce( $nonce, 'ideapush_create_board' ) ){ |
| 685 |
|
| 686 |
if(current_user_can('administrator') || current_user_can('idea_push_manager')){ |
| 687 |
|
| 688 |
|
| 689 |
//get options |
| 690 |
$options = get_option('idea_push_settings'); |
| 691 |
|
| 692 |
//get is pro |
| 693 |
global $ideapush_is_pro; |
| 694 |
|
| 695 |
//get board name from ajax call |
| 696 |
$boardName = idea_push_sanitization_validation($_POST['boardName'],'boardname'); |
| 697 |
|
| 698 |
if($boardName == false){ |
| 699 |
wp_die(); |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
//lets first check if the board already exists |
| 706 |
if(get_term_by('name', $boardName, 'boards') == false){ |
| 707 |
|
| 708 |
//lets check if licenced |
| 709 |
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){ |
| 710 |
|
| 711 |
idea_push_create_taxonomy_boards(); |
| 712 |
|
| 713 |
$boardNameSlug = strtolower($boardName); |
| 714 |
$boardNameSlug = preg_replace('/\s+/', '-', $boardNameSlug); |
| 715 |
|
| 716 |
wp_insert_term( |
| 717 |
$boardName, // the term |
| 718 |
'boards', // the taxonomy |
| 719 |
array( |
| 720 |
'description'=> '', |
| 721 |
'slug' => $boardNameSlug |
| 722 |
) |
| 723 |
); |
| 724 |
|
| 725 |
//lets return the item id |
| 726 |
|
| 727 |
$getTermId = get_term_by('name', $boardName, 'boards'); |
| 728 |
$termId = $getTermId->term_id; |
| 729 |
|
| 730 |
//return board html |
| 731 |
echo idea_push_render_board('',$termId,$boardName); |
| 732 |
|
| 733 |
|
| 734 |
} else { |
| 735 |
echo 'NOT-PRO'; |
| 736 |
} |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
} else { |
| 742 |
|
| 743 |
echo 'TERM-EXISTS'; |
| 744 |
|
| 745 |
} |
| 746 |
|
| 747 |
} //end manager/admin check |
| 748 |
} //end nonce check |
| 749 |
|
| 750 |
//die |
| 751 |
wp_die(); |
| 752 |
|
| 753 |
|
| 754 |
} |
| 755 |
add_action( 'wp_ajax_add_taxonomy_item', 'idea_push_add_taxonomy_item' ); |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
//lets delete existing taxonomies and rename others where necessary |
| 766 |
function idea_push_taxonomy_save_routine() { |
| 767 |
|
| 768 |
|
| 769 |
//get board name from ajax call |
| 770 |
$comparisonData = $_POST['comparisonData']; |
| 771 |
$explodeTheData = explode("^^^", $comparisonData); |
| 772 |
|
| 773 |
$boardIdArray = array(); |
| 774 |
|
| 775 |
foreach($explodeTheData as $board){ |
| 776 |
|
| 777 |
$anotherExplosion = explode("|", $board); |
| 778 |
$boardId = $anotherExplosion[0]; |
| 779 |
$boardName = $anotherExplosion[1]; |
| 780 |
|
| 781 |
array_push($boardIdArray,$boardId); |
| 782 |
|
| 783 |
//now lets change the name of existing taxonomies |
| 784 |
$termObject = get_term($boardId,'boards'); |
| 785 |
|
| 786 |
//if the there's a match lets update the name if it has changed |
| 787 |
if(!is_wp_error($termObject)){ |
| 788 |
|
| 789 |
$termName = $termObject->name; |
| 790 |
|
| 791 |
if($boardName !== $termName){ |
| 792 |
//they don't match so lets update this term name with the new board name |
| 793 |
wp_update_term($boardId,'boards',array('name' => $boardName)); |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
//lets cycle through the existing terms in the taxonomy |
| 801 |
$existingTerms = get_terms('boards',array( "hide_empty" => 0 )); |
| 802 |
|
| 803 |
foreach($existingTerms as $term){ |
| 804 |
|
| 805 |
$termId = $term->term_id; |
| 806 |
|
| 807 |
if(!in_array($termId,$boardIdArray)){ |
| 808 |
//if the term is not in our array delete it because it's not authorised to exist and it will cause confusion |
| 809 |
wp_delete_term($termId,'boards'); |
| 810 |
|
| 811 |
} |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
//die |
| 816 |
wp_die(); |
| 817 |
|
| 818 |
|
| 819 |
} |
| 820 |
add_action( 'wp_ajax_taxonomy_save_routine', 'idea_push_taxonomy_save_routine' ); |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
//add additional body class to the shortcode page for good measure |
| 830 |
function idea_push_add_body_class($class) { |
| 831 |
|
| 832 |
global $post; |
| 833 |
|
| 834 |
if( isset($post->post_content) && has_shortcode( $post->post_content, 'ideapush' ) ) { |
| 835 |
$class[] = 'idea-push'; |
| 836 |
} |
| 837 |
return $class; |
| 838 |
} |
| 839 |
add_filter( 'body_class', 'idea_push_add_body_class' ); |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
//add notification icon to menu item |
| 844 |
|
| 845 |
add_action( 'admin_menu', 'idea_push_menu_bubble' ); |
| 846 |
|
| 847 |
function idea_push_menu_bubble() { |
| 848 |
global $menu; |
| 849 |
|
| 850 |
$count = idea_push_count_pending_ideas() + idea_push_count_ideas_review_status(); |
| 851 |
|
| 852 |
|
| 853 |
if ($count > 0) { |
| 854 |
|
| 855 |
foreach ( $menu as $key => $value ) { |
| 856 |
|
| 857 |
if ( $menu[$key][2] == 'edit.php?post_type=idea' ) { |
| 858 |
|
| 859 |
$menu[$key][0] .= ' <span class="update-plugins"><span class="plugin-count">' . $count . '</span></span>'; |
| 860 |
|
| 861 |
return; |
| 862 |
} |
| 863 |
} |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
function idea_push_above_all_ideas_table() { |
| 869 |
|
| 870 |
$screen = get_current_screen(); |
| 871 |
|
| 872 |
if ( $screen->id == 'edit-idea' ) { |
| 873 |
|
| 874 |
echo '<style> |
| 875 |
|
| 876 |
.idea-tasks div { |
| 877 |
display: inline-block; |
| 878 |
background: #fff; |
| 879 |
padding: 10px; |
| 880 |
border: 1px solid #e5e5e5; |
| 881 |
border-radius: 6px; |
| 882 |
margin-right: 10px; |
| 883 |
margin-top: 10px; |
| 884 |
margin-bottom: -10px; |
| 885 |
|
| 886 |
} |
| 887 |
|
| 888 |
.idea-tasks a { |
| 889 |
text-decoration: none; |
| 890 |
|
| 891 |
} |
| 892 |
|
| 893 |
.pending-count, .reviewed-count { |
| 894 |
display: inline-block; |
| 895 |
vertical-align: top; |
| 896 |
margin: 1px 0 0 5px; |
| 897 |
padding: 0 5px; |
| 898 |
min-width: 7px; |
| 899 |
height: 17px; |
| 900 |
border-radius: 11px; |
| 901 |
background-color: #ca4a1f; |
| 902 |
color: #fff; |
| 903 |
font-size: 9px; |
| 904 |
line-height: 17px; |
| 905 |
text-align: center; |
| 906 |
z-index: 26; |
| 907 |
|
| 908 |
} |
| 909 |
|
| 910 |
.column-status .open { |
| 911 |
background-color: #4eb5e1; |
| 912 |
color: #fff !important; |
| 913 |
} |
| 914 |
|
| 915 |
.column-status .in-progress { |
| 916 |
background-color: #a7a9ac; |
| 917 |
color: #fff !important; |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
.column-status .completed { |
| 922 |
background-color: #414042; |
| 923 |
color: #fff !important; |
| 924 |
} |
| 925 |
|
| 926 |
.column-status .reviewed { |
| 927 |
background-color: #fbbf67; |
| 928 |
color: #fff !important; |
| 929 |
} |
| 930 |
|
| 931 |
.column-status .approved { |
| 932 |
background-color: #5eb46a; |
| 933 |
color: #fff !important; |
| 934 |
} |
| 935 |
|
| 936 |
.column-status .declined { |
| 937 |
background-color: #f05d55; |
| 938 |
color: #fff !important; |
| 939 |
} |
| 940 |
|
| 941 |
.column-status .duplicate { |
| 942 |
background-color: #e2e0e0; |
| 943 |
color: #fff !important; |
| 944 |
} |
| 945 |
|
| 946 |
|
| 947 |
.column-status a { |
| 948 |
|
| 949 |
text-transform: uppercase; |
| 950 |
padding: 3px 6px; |
| 951 |
border-radius: 3px; |
| 952 |
font-weight: 600; |
| 953 |
font-size: smaller; |
| 954 |
} |
| 955 |
|
| 956 |
</style>'; |
| 957 |
|
| 958 |
$pendingEditPage = get_admin_url().'edit.php?post_status=pending&post_type=idea'; |
| 959 |
$reviewEditPage = get_admin_url().'edit.php?post_type=idea&status=reviewed'; |
| 960 |
|
| 961 |
$countPendingIdeas = idea_push_count_pending_ideas(); |
| 962 |
$countReviewStatus = idea_push_count_ideas_review_status(); |
| 963 |
|
| 964 |
|
| 965 |
echo '<div class="idea-tasks">'; |
| 966 |
|
| 967 |
if($countPendingIdeas > 0){ |
| 968 |
echo '<div class="pending-approval">'; |
| 969 |
echo '<a href="'.$pendingEditPage.'" class="pending-count-description">'.__( 'Ideas Pending Release', 'ideapush' ).'</a>'; |
| 970 |
echo '<span class="pending-count">'.$countPendingIdeas.'</span>'; |
| 971 |
echo '</div>'; |
| 972 |
} |
| 973 |
|
| 974 |
if($countReviewStatus > 0){ |
| 975 |
echo '<div class="reviewed-status">'; |
| 976 |
echo '<a href="'.$reviewEditPage.'" class="reviewed-count-description">'.__( 'Ideas Needing Review', 'ideapush' ).'</a>'; |
| 977 |
echo '<span class="reviewed-count">'.$countReviewStatus.'</span>'; |
| 978 |
echo '</div>'; |
| 979 |
} |
| 980 |
|
| 981 |
echo '</div>'; |
| 982 |
|
| 983 |
|
| 984 |
} |
| 985 |
|
| 986 |
|
| 987 |
} |
| 988 |
add_action( 'admin_notices', 'idea_push_above_all_ideas_table' ); |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
add_filter( 'manage_edit-idea_columns', 'mycustomposttype_columns_definition' ) ; |
| 995 |
|
| 996 |
|
| 997 |
function mycustomposttype_columns_definition( $columns ) { |
| 998 |
|
| 999 |
$new = array(); |
| 1000 |
|
| 1001 |
$columns['votes'] = __( 'Votes','ideapush'); |
| 1002 |
unset( $new['taxonomy-status'] ); |
| 1003 |
$columns['status'] = __( 'Status','ideapush'); |
| 1004 |
|
| 1005 |
$customOrder = array('cb','title', 'author','taxonomy-boards' ,'status','taxonomy-tags','votes', 'comments','date'); |
| 1006 |
|
| 1007 |
|
| 1008 |
foreach ($customOrder as $colname) |
| 1009 |
$new[$colname] = $columns[$colname]; |
| 1010 |
return $new; |
| 1011 |
} |
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
add_action( 'manage_idea_posts_custom_column' , 'idea_push_vote_column_content', 10, 2 ); |
| 1017 |
|
| 1018 |
function idea_push_vote_column_content( $column, $post_id ) { |
| 1019 |
switch ( $column ) { |
| 1020 |
|
| 1021 |
// display a thumbnail photo |
| 1022 |
case 'votes' : |
| 1023 |
|
| 1024 |
echo get_post_meta( $post_id , 'votes' , true ); |
| 1025 |
break; |
| 1026 |
|
| 1027 |
case 'status' : |
| 1028 |
|
| 1029 |
$getTerms = get_the_terms( $post_id, 'status' ); |
| 1030 |
|
| 1031 |
if($getTerms !== false){ |
| 1032 |
foreach($getTerms as $term) { |
| 1033 |
$status = $term->name; |
| 1034 |
} |
| 1035 |
|
| 1036 |
$className = strtolower($status); |
| 1037 |
$className = str_replace(" ","-",$className); |
| 1038 |
|
| 1039 |
echo '<a class="'.$className.'" href="'.get_admin_url().'edit.php?post_type=idea&status='.$className.'">'.idea_push_translate_status($status).'</a>'; |
| 1040 |
|
| 1041 |
} |
| 1042 |
|
| 1043 |
break; |
| 1044 |
|
| 1045 |
} |
| 1046 |
} |
| 1047 |
|
| 1048 |
|
| 1049 |
add_filter( 'manage_edit-idea_sortable_columns', 'idea_push_sortable_vote_column' ); |
| 1050 |
|
| 1051 |
function idea_push_sortable_vote_column( $columns ) { |
| 1052 |
$columns['votes'] = 'votes'; |
| 1053 |
return $columns; |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
add_action( 'pre_get_posts', 'idea_push_custom_orderby' ); |
| 1058 |
|
| 1059 |
function idea_push_custom_orderby( $query ) { |
| 1060 |
if ( ! is_admin() ) |
| 1061 |
return; |
| 1062 |
|
| 1063 |
$orderby = $query->get( 'orderby'); |
| 1064 |
|
| 1065 |
if ( 'votes' == $orderby ) { |
| 1066 |
$query->set( 'meta_key', 'votes' ); |
| 1067 |
$query->set( 'orderby', 'meta_value_num' ); |
| 1068 |
} |
| 1069 |
|
| 1070 |
} |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
add_filter( 'template_include', 'idea_push_ip_tag_template', 99 ); |
| 1076 |
|
| 1077 |
function idea_push_ip_tag_template( $template ) { |
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
if ( is_tax( 'tags' )) { |
| 1082 |
$template = dirname( __FILE__ ) . '/inc/templates/ip-tag.php'; |
| 1083 |
return $template; |
| 1084 |
} elseif( is_author() && is_post_type_archive( array( 'idea' ) ) ){ |
| 1085 |
$template = dirname( __FILE__ ) . '/inc/templates/ip-tag.php'; |
| 1086 |
return $template; |
| 1087 |
|
| 1088 |
} else { |
| 1089 |
return $template; |
| 1090 |
} |
| 1091 |
|
| 1092 |
|
| 1093 |
} |
| 1094 |
|
| 1095 |
|
| 1096 |
function idea_push_languages() { |
| 1097 |
load_plugin_textdomain( 'ideapush', false, 'ideapush/inc/languages' ); |
| 1098 |
} |
| 1099 |
add_action('init', 'idea_push_languages'); |
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
//hides boards from WordPress search |
| 1106 |
add_action( 'pre_get_posts', function ( $query ) { |
| 1107 |
|
| 1108 |
if(get_option('idea_push_settings') && array_key_exists('idea_push_board_configuration',get_option('idea_push_settings'))){ |
| 1109 |
|
| 1110 |
//get options |
| 1111 |
$options = get_option('idea_push_settings'); |
| 1112 |
|
| 1113 |
//get board configuration |
| 1114 |
$boardConfiguration = $options['idea_push_board_configuration']; |
| 1115 |
|
| 1116 |
if(isset($boardConfiguration) && strlen($boardConfiguration)>0){ |
| 1117 |
|
| 1118 |
|
| 1119 |
//split board configuration |
| 1120 |
$splitBoardConfiguration = explode('^^^',$boardConfiguration); |
| 1121 |
|
| 1122 |
$boardsToHide = array(); |
| 1123 |
|
| 1124 |
//cycle through boards |
| 1125 |
foreach($splitBoardConfiguration as $boardConfig){ |
| 1126 |
|
| 1127 |
if( !empty($boardConfig) && strlen($boardConfig)>0){ |
| 1128 |
|
| 1129 |
$furtherSplitBoardConfiguration = explode('|',$boardConfig); |
| 1130 |
|
| 1131 |
if(isset($furtherSplitBoardConfiguration[13]) && $furtherSplitBoardConfiguration[13] == 'Yes'){ |
| 1132 |
|
| 1133 |
$term = get_term($furtherSplitBoardConfiguration[0], 'boards' ); |
| 1134 |
|
| 1135 |
if( ! is_null($term) && ! is_wp_error($term) ){ |
| 1136 |
$slug = $term->slug; |
| 1137 |
array_push($boardsToHide,$slug); |
| 1138 |
} |
| 1139 |
} |
| 1140 |
} |
| 1141 |
|
| 1142 |
} |
| 1143 |
|
| 1144 |
|
| 1145 |
global $wp_the_query; |
| 1146 |
if($query === $wp_the_query && $query->is_search() && !is_admin()) { |
| 1147 |
$tax_query = array( |
| 1148 |
array( |
| 1149 |
'taxonomy' => 'boards', |
| 1150 |
'field' => 'slug', |
| 1151 |
'terms' => $boardsToHide, |
| 1152 |
'operator' => 'NOT IN', |
| 1153 |
) |
| 1154 |
); |
| 1155 |
$query->set( 'tax_query', $tax_query ); |
| 1156 |
} |
| 1157 |
|
| 1158 |
} |
| 1159 |
} |
| 1160 |
|
| 1161 |
}); |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
//add custom css to the frontend |
| 1176 |
function idea_push_custom_css() { |
| 1177 |
|
| 1178 |
//get options |
| 1179 |
$options = get_option('idea_push_settings'); |
| 1180 |
|
| 1181 |
|
| 1182 |
if(isset($options['idea_push_custom_css']) && strlen($options['idea_push_custom_css'])>0){ |
| 1183 |
wp_register_style( 'custom-frontend-style-ideapush', plugins_url( '/inc/css/frontendstyle.css', __FILE__ ),array(),idea_push_plugin_get_version()); |
| 1184 |
wp_add_inline_style( 'custom-frontend-style-ideapush', $options['idea_push_custom_css'] ); |
| 1185 |
|
| 1186 |
} |
| 1187 |
|
| 1188 |
} |
| 1189 |
add_action( 'wp_enqueue_scripts', 'idea_push_custom_css', 999 ); |
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
//do pro updates |
| 1208 |
//initialise the update check |
| 1209 |
if($ideapush_is_pro == 'YES'){ |
| 1210 |
|
| 1211 |
require 'inc/pro-ip/plugin-update-checker/plugin-update-checker.php'; |
| 1212 |
|
| 1213 |
global $plugin_update_checker_ideapush; |
| 1214 |
$plugin_update_checker_ideapush = Puc_v4_Factory::buildUpdateChecker( |
| 1215 |
'https://northernbeacheswebsites.com.au/?update_action=get_metadata&update_slug=ideapush', //Metadata URL. |
| 1216 |
__FILE__, //Full path to the main plugin file. |
| 1217 |
'ideapush' //Plugin slug. Usually it's the same as the name of the directory. |
| 1218 |
); |
| 1219 |
|
| 1220 |
|
| 1221 |
//add queries to the update call |
| 1222 |
$plugin_update_checker_ideapush->addQueryArgFilter('filter_update_checks_ideapush'); |
| 1223 |
function filter_update_checks_ideapush($queryArgs) { |
| 1224 |
|
| 1225 |
|
| 1226 |
$pluginSettings = get_option('idea_push_settings'); |
| 1227 |
|
| 1228 |
if(isset($pluginSettings['idea_push_purchase_email']) && isset($pluginSettings['idea_push_order_id'])){ |
| 1229 |
|
| 1230 |
$purchaseEmailAddress = $pluginSettings['idea_push_purchase_email']; |
| 1231 |
$orderId = $pluginSettings['idea_push_order_id']; |
| 1232 |
$siteUrl = get_site_url(); |
| 1233 |
$siteUrl = parse_url($siteUrl); |
| 1234 |
$siteUrl = $siteUrl['host']; |
| 1235 |
|
| 1236 |
if (!empty($purchaseEmailAddress) && !empty($orderId)) { |
| 1237 |
$queryArgs['purchaseEmailAddress'] = $purchaseEmailAddress; |
| 1238 |
$queryArgs['orderId'] = $orderId; |
| 1239 |
$queryArgs['siteUrl'] = $siteUrl; |
| 1240 |
$queryArgs['productId'] = '9719'; |
| 1241 |
} |
| 1242 |
|
| 1243 |
} |
| 1244 |
|
| 1245 |
return $queryArgs; |
| 1246 |
} |
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
// define the puc_request_info_result-<slug> callback |
| 1251 |
$plugin_update_checker_ideapush->addFilter( |
| 1252 |
'request_info_result', 'filter_puc_request_info_result_slug_ideapush', 10, 2 |
| 1253 |
); |
| 1254 |
function filter_puc_request_info_result_slug_ideapush( $plugininfo, $result ) { |
| 1255 |
//get the message from the server and set as transient |
| 1256 |
set_transient('ideapush-update',$plugininfo->{'message'},YEAR_IN_SECONDS * 1); |
| 1257 |
|
| 1258 |
return $plugininfo; |
| 1259 |
}; |
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
$path = plugin_basename( __FILE__ ); |
| 1267 |
|
| 1268 |
add_action("after_plugin_row_{$path}", function( $plugin_file, $plugin_data, $status ) { |
| 1269 |
|
| 1270 |
//get plugin settings |
| 1271 |
$pluginSettings = get_option('idea_push_settings'); |
| 1272 |
|
| 1273 |
|
| 1274 |
if (!empty($pluginSettings['idea_push_purchase_email']) && !empty($pluginSettings['idea_push_order_id'])) { |
| 1275 |
|
| 1276 |
$order_id = $pluginSettings['idea_push_order_id']; |
| 1277 |
|
| 1278 |
//get transient |
| 1279 |
$message = get_transient('ideapush-update'); |
| 1280 |
|
| 1281 |
if($message !== 'Yes' && $message !== false){ |
| 1282 |
|
| 1283 |
$purchaseLink = 'https://northernbeacheswebsites.com.au/ideapush-pro/'; |
| 1284 |
|
| 1285 |
if($message == 'Incorrect Details'){ |
| 1286 |
$displayMessage = 'The Order ID and Purchase ID you entered is not correct. Please double check the details you entered to receive product updates.'; |
| 1287 |
} elseif ($message == 'Licence Expired'){ |
| 1288 |
$displayMessage = 'Your licence has expired. Please <a href="'.$purchaseLink.'" target="_blank">purchase a new licence</a> to receive further updates for this plugin.'; |
| 1289 |
} elseif ($message == 'Website Mismatch') { |
| 1290 |
$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. To change the website assigned to your licence, please click <a href="https://northernbeacheswebsites.com.au/my-account/view-order/'.$order_id.'/" target="_blank">here</a>.'; |
| 1291 |
} else { |
| 1292 |
$displayMessage = ''; |
| 1293 |
} |
| 1294 |
|
| 1295 |
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>'; |
| 1296 |
|
| 1297 |
} |
| 1298 |
|
| 1299 |
} else { |
| 1300 |
|
| 1301 |
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>'; |
| 1302 |
|
| 1303 |
} |
| 1304 |
|
| 1305 |
|
| 1306 |
}, 10, 3 ); |
| 1307 |
|
| 1308 |
/** |
| 1309 |
* |
| 1310 |
* |
| 1311 |
* |
| 1312 |
* Force check for updates |
| 1313 |
*/ |
| 1314 |
function idea_push_force_check_for_updates(){ |
| 1315 |
global $plugin_update_checker_ideapush; |
| 1316 |
|
| 1317 |
$plugin_update_checker_ideapush->checkForUpdates(); |
| 1318 |
} |
| 1319 |
|
| 1320 |
|
| 1321 |
} |
| 1322 |
/** |
| 1323 |
* |
| 1324 |
* |
| 1325 |
* |
| 1326 |
* Add custom links to plugin on plugins page |
| 1327 |
*/ |
| 1328 |
function idea_push_plugin_links( $links, $file ) { |
| 1329 |
if ( strpos( $file, 'ideapush.php' ) !== false ) { |
| 1330 |
$new_links = array( |
| 1331 |
'<a href="https://northernbeacheswebsites.com.au/product/donate-to-northern-beaches-websites/" target="_blank">' . __('Donate') . '</a>', |
| 1332 |
'<a href="https://wordpress.org/support/plugin/ideapush" target="_blank">' . __('Support Forum') . '</a>', |
| 1333 |
); |
| 1334 |
$links = array_merge( $links, $new_links ); |
| 1335 |
} |
| 1336 |
return $links; |
| 1337 |
} |
| 1338 |
add_filter( 'plugin_row_meta', 'idea_push_plugin_links', 10, 2 ); |
| 1339 |
/** |
| 1340 |
* |
| 1341 |
* |
| 1342 |
* |
| 1343 |
* save tab memory |
| 1344 |
*/ |
| 1345 |
function idea_push_save_tab_memory() { |
| 1346 |
|
| 1347 |
//get board name from ajax call |
| 1348 |
$tabName = sanitize_text_field($_POST['tab']); |
| 1349 |
|
| 1350 |
//set a transient for the tab memory |
| 1351 |
set_transient('ideapush-tab-memory',$tabName,WEEK_IN_SECONDS*1); |
| 1352 |
|
| 1353 |
echo 'SUCCESS'; |
| 1354 |
|
| 1355 |
//die |
| 1356 |
wp_die(); |
| 1357 |
|
| 1358 |
|
| 1359 |
} |
| 1360 |
add_action( 'wp_ajax_save_tab_memory', 'idea_push_save_tab_memory' ); |
| 1361 |
/** |
| 1362 |
* |
| 1363 |
* |
| 1364 |
* |
| 1365 |
* Change archive title for tag archives which have board text |
| 1366 |
*/ |
| 1367 |
add_filter( 'get_the_archive_title', 'idea_push_change_the_tag_title'); |
| 1368 |
|
| 1369 |
function idea_push_change_the_tag_title( $title ) { |
| 1370 |
|
| 1371 |
if (strpos($title, 'BoardTag') !== false) { |
| 1372 |
$title_exploded = explode('-',$title); |
| 1373 |
$title = $title_exploded[2]; |
| 1374 |
} |
| 1375 |
|
| 1376 |
return $title; |
| 1377 |
|
| 1378 |
} |
| 1379 |
|
| 1380 |
?> |