| 1 |
<?php |
| 2 |
/** |
| 3 |
* Post Type Functions |
| 4 |
* |
| 5 |
* @package Give |
| 6 |
* @subpackage Functions |
| 7 |
* @copyright Copyright (c) 2016, GiveWP |
| 8 |
* @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 |
* @since 1.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Registers and sets up the Donation Forms (give_forms) custom post type |
| 19 |
* |
| 20 |
* @return void |
| 21 |
* @since 1.0 |
| 22 |
*/ |
| 23 |
function give_setup_post_types() { |
| 24 |
|
| 25 |
// Give Forms single post and archive options. |
| 26 |
$give_forms_singular = give_is_setting_enabled( give_get_option( 'forms_singular', 'enabled' ) ); |
| 27 |
$give_forms_archives = give_is_setting_enabled( give_get_option( 'forms_archives', 'enabled' ) ); |
| 28 |
|
| 29 |
// Enable/Disable give_forms links if form is saving. |
| 30 |
if ( Give_Admin_Settings::is_saving_settings() ) { |
| 31 |
if ( isset( $_POST['forms_singular'] ) ) { |
| 32 |
$give_forms_singular = give_is_setting_enabled( give_clean( $_POST['forms_singular'] ) ); |
| 33 |
flush_rewrite_rules(); |
| 34 |
} |
| 35 |
|
| 36 |
if ( isset( $_POST['forms_archives'] ) ) { |
| 37 |
$give_forms_archives = give_is_setting_enabled( give_clean( $_POST['forms_archives'] ) ); |
| 38 |
flush_rewrite_rules(); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
$give_forms_slug = defined( 'GIVE_SLUG' ) ? GIVE_SLUG : 'donations'; |
| 43 |
// Support for old 'GIVE_FORMS_SLUG' constant |
| 44 |
if ( defined( 'GIVE_FORMS_SLUG' ) ) { |
| 45 |
$give_forms_slug = GIVE_FORMS_SLUG; |
| 46 |
} |
| 47 |
|
| 48 |
$give_forms_rewrite = defined( 'GIVE_DISABLE_FORMS_REWRITE' ) && GIVE_DISABLE_FORMS_REWRITE ? false : [ |
| 49 |
'slug' => $give_forms_slug, |
| 50 |
'with_front' => false, |
| 51 |
]; |
| 52 |
|
| 53 |
$give_forms_labels = apply_filters( |
| 54 |
'give_forms_labels', |
| 55 |
[ |
| 56 |
'name' => __( 'Donation Forms', 'give' ), |
| 57 |
'singular_name' => __( 'Form', 'give' ), |
| 58 |
'add_new' => __( 'Add Form', 'give' ), |
| 59 |
'add_new_item' => __( 'Add New Donation Form', 'give' ), |
| 60 |
'edit_item' => __( 'Edit Donation Form', 'give' ), |
| 61 |
'new_item' => __( 'New Form', 'give' ), |
| 62 |
'all_items' => __( 'All Forms', 'give' ), |
| 63 |
'view_item' => __( 'View Form', 'give' ), |
| 64 |
'search_items' => __( 'Search Forms', 'give' ), |
| 65 |
'not_found' => __( 'No forms found.', 'give' ), |
| 66 |
'not_found_in_trash' => __( 'No forms found in Trash.', 'give' ), |
| 67 |
'parent_item_colon' => '', |
| 68 |
'menu_name' => apply_filters( 'give_menu_name', __( 'Donations', 'give' ) ), |
| 69 |
'name_admin_bar' => apply_filters( 'give_name_admin_bar_name', __( 'Donation Form', 'give' ) ), |
| 70 |
] |
| 71 |
); |
| 72 |
|
| 73 |
// Default give_forms supports. |
| 74 |
$give_form_supports = [ |
| 75 |
'title', |
| 76 |
'thumbnail', |
| 77 |
'excerpt', |
| 78 |
'revisions', |
| 79 |
'author', |
| 80 |
]; |
| 81 |
|
| 82 |
// Has the user disabled the excerpt? |
| 83 |
if ( ! give_is_setting_enabled( give_get_option( 'forms_excerpt' ) ) ) { |
| 84 |
unset( $give_form_supports[2] ); |
| 85 |
} |
| 86 |
|
| 87 |
// Has user disabled the featured image? |
| 88 |
if ( ! give_is_setting_enabled( give_get_option( 'form_featured_img' ) ) ) { |
| 89 |
unset( $give_form_supports[1] ); |
| 90 |
remove_action( 'give_before_single_form_summary', 'give_show_form_images' ); |
| 91 |
} |
| 92 |
|
| 93 |
$give_forms_args = [ |
| 94 |
'labels' => $give_forms_labels, |
| 95 |
'public' => $give_forms_singular, |
| 96 |
'show_ui' => true, |
| 97 |
'show_in_menu' => true, |
| 98 |
'show_in_rest' => true, |
| 99 |
'query_var' => true, |
| 100 |
'rewrite' => $give_forms_rewrite, |
| 101 |
'map_meta_cap' => true, |
| 102 |
'capability_type' => 'give_form', |
| 103 |
'has_archive' => $give_forms_archives, |
| 104 |
'menu_icon' => 'dashicons-give', |
| 105 |
'hierarchical' => false, |
| 106 |
'supports' => apply_filters( 'give_forms_supports', $give_form_supports ), |
| 107 |
]; |
| 108 |
register_post_type( 'give_forms', apply_filters( 'give_forms_post_type_args', $give_forms_args ) ); |
| 109 |
|
| 110 |
/** Donation Post Type */ |
| 111 |
$payment_labels = [ |
| 112 |
'name' => _x( 'Donations', 'post type general name', 'give' ), |
| 113 |
'singular_name' => _x( 'Donation', 'post type singular name', 'give' ), |
| 114 |
'add_new' => __( 'Add New', 'give' ), |
| 115 |
'add_new_item' => __( 'Add New Donation', 'give' ), |
| 116 |
'edit_item' => __( 'Edit Donation', 'give' ), |
| 117 |
'new_item' => __( 'New Donation', 'give' ), |
| 118 |
'all_items' => __( 'All Donations', 'give' ), |
| 119 |
'view_item' => __( 'View Donation', 'give' ), |
| 120 |
'search_items' => __( 'Search Donations', 'give' ), |
| 121 |
'not_found' => __( 'No donations found.', 'give' ), |
| 122 |
'not_found_in_trash' => __( 'No donations found in Trash.', 'give' ), |
| 123 |
'parent_item_colon' => '', |
| 124 |
'menu_name' => __( 'Donations', 'give' ), |
| 125 |
]; |
| 126 |
|
| 127 |
$payment_args = [ |
| 128 |
'labels' => apply_filters( 'give_payment_labels', $payment_labels ), |
| 129 |
'public' => false, |
| 130 |
'query_var' => false, |
| 131 |
'rewrite' => false, |
| 132 |
'map_meta_cap' => true, |
| 133 |
'capability_type' => 'give_payment', |
| 134 |
'supports' => [ 'title' ], |
| 135 |
'can_export' => true, |
| 136 |
]; |
| 137 |
register_post_type( 'give_payment', $payment_args ); |
| 138 |
|
| 139 |
} |
| 140 |
|
| 141 |
add_action( 'init', 'give_setup_post_types', 1 ); |
| 142 |
|
| 143 |
|
| 144 |
/** |
| 145 |
* Give Setup Taxonomies |
| 146 |
* |
| 147 |
* Registers the custom taxonomies for the give_forms custom post type |
| 148 |
* |
| 149 |
* @return void |
| 150 |
* @since 1.0 |
| 151 |
*/ |
| 152 |
function give_setup_taxonomies() { |
| 153 |
|
| 154 |
$slug = defined( 'GIVE_FORMS_SLUG' ) ? GIVE_FORMS_SLUG : 'donations'; |
| 155 |
|
| 156 |
/** Categories */ |
| 157 |
$category_labels = [ |
| 158 |
'name' => _x( 'Form Categories', 'taxonomy general name', 'give' ), |
| 159 |
'singular_name' => _x( 'Category', 'taxonomy singular name', 'give' ), |
| 160 |
'search_items' => __( 'Search Categories', 'give' ), |
| 161 |
'all_items' => __( 'All Categories', 'give' ), |
| 162 |
'parent_item' => __( 'Parent Category', 'give' ), |
| 163 |
'parent_item_colon' => __( 'Parent Category:', 'give' ), |
| 164 |
'edit_item' => __( 'Edit Category', 'give' ), |
| 165 |
'update_item' => __( 'Update Category', 'give' ), |
| 166 |
'add_new_item' => __( 'Add New Category', 'give' ), |
| 167 |
'new_item_name' => __( 'New Category Name', 'give' ), |
| 168 |
'menu_name' => __( 'Categories', 'give' ), |
| 169 |
]; |
| 170 |
|
| 171 |
$category_args = apply_filters( |
| 172 |
'give_forms_category_args', |
| 173 |
[ |
| 174 |
'hierarchical' => true, |
| 175 |
'labels' => apply_filters( 'give_forms_category_labels', $category_labels ), |
| 176 |
'show_ui' => true, |
| 177 |
'show_in_rest' => true, |
| 178 |
'query_var' => 'give_forms_category', |
| 179 |
'rewrite' => [ |
| 180 |
'slug' => $slug . '/category', |
| 181 |
'with_front' => false, |
| 182 |
'hierarchical' => true, |
| 183 |
], |
| 184 |
'capabilities' => [ |
| 185 |
'manage_terms' => 'manage_give_form_terms', |
| 186 |
'edit_terms' => 'edit_give_form_terms', |
| 187 |
'assign_terms' => 'assign_give_form_terms', |
| 188 |
'delete_terms' => 'delete_give_form_terms', |
| 189 |
], |
| 190 |
] |
| 191 |
); |
| 192 |
|
| 193 |
/** Tags */ |
| 194 |
$tag_labels = [ |
| 195 |
'name' => _x( 'Form Tags', 'taxonomy general name', 'give' ), |
| 196 |
'singular_name' => _x( 'Tag', 'taxonomy singular name', 'give' ), |
| 197 |
'search_items' => __( 'Search Tags', 'give' ), |
| 198 |
'all_items' => __( 'All Tags', 'give' ), |
| 199 |
'parent_item' => __( 'Parent Tag', 'give' ), |
| 200 |
'parent_item_colon' => __( 'Parent Tag:', 'give' ), |
| 201 |
'edit_item' => __( 'Edit Tag', 'give' ), |
| 202 |
'update_item' => __( 'Update Tag', 'give' ), |
| 203 |
'add_new_item' => __( 'Add New Tag', 'give' ), |
| 204 |
'new_item_name' => __( 'New Tag Name', 'give' ), |
| 205 |
'menu_name' => __( 'Tags', 'give' ), |
| 206 |
'choose_from_most_used' => __( 'Choose from most used tags.', 'give' ), |
| 207 |
]; |
| 208 |
|
| 209 |
$tag_args = apply_filters( |
| 210 |
'give_forms_tag_args', |
| 211 |
[ |
| 212 |
'hierarchical' => false, |
| 213 |
'labels' => apply_filters( 'give_forms_tag_labels', $tag_labels ), |
| 214 |
'show_ui' => true, |
| 215 |
'show_in_rest' => true, |
| 216 |
'query_var' => 'give_forms_tag', |
| 217 |
'rewrite' => [ |
| 218 |
'slug' => $slug . '/tag', |
| 219 |
'with_front' => false, |
| 220 |
'hierarchical' => true, |
| 221 |
], |
| 222 |
'capabilities' => [ |
| 223 |
'manage_terms' => 'manage_give_form_terms', |
| 224 |
'edit_terms' => 'edit_give_form_terms', |
| 225 |
'assign_terms' => 'assign_give_form_terms', |
| 226 |
'delete_terms' => 'delete_give_form_terms', |
| 227 |
], |
| 228 |
] |
| 229 |
); |
| 230 |
|
| 231 |
// Does the user want category? |
| 232 |
$enable_category = give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) ); |
| 233 |
|
| 234 |
// Does the user want tag? |
| 235 |
$enable_tag = give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) ); |
| 236 |
|
| 237 |
// Enable/Disable category and tag if form is saving. |
| 238 |
if ( Give_Admin_Settings::is_saving_settings() ) { |
| 239 |
if ( isset( $_POST['categories'] ) ) { |
| 240 |
$enable_category = give_is_setting_enabled( give_clean( $_POST['categories'] ) ); |
| 241 |
flush_rewrite_rules(); |
| 242 |
} |
| 243 |
|
| 244 |
if ( isset( $_POST['tags'] ) ) { |
| 245 |
$enable_tag = give_is_setting_enabled( give_clean( $_POST['tags'] ) ); |
| 246 |
flush_rewrite_rules(); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
if ( $enable_category ) { |
| 251 |
register_taxonomy( 'give_forms_category', [ 'give_forms' ], $category_args ); |
| 252 |
register_taxonomy_for_object_type( 'give_forms_category', 'give_forms' ); |
| 253 |
} |
| 254 |
|
| 255 |
if ( $enable_tag ) { |
| 256 |
register_taxonomy( 'give_forms_tag', [ 'give_forms' ], $tag_args ); |
| 257 |
register_taxonomy_for_object_type( 'give_forms_tag', 'give_forms' ); |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
add_action( 'init', 'give_setup_taxonomies', 0 ); |
| 262 |
|
| 263 |
|
| 264 |
/** |
| 265 |
* Get Default Form Labels |
| 266 |
* |
| 267 |
* @return array $defaults Default labels |
| 268 |
* @since 1.0 |
| 269 |
*/ |
| 270 |
function give_get_default_form_labels() { |
| 271 |
$defaults = [ |
| 272 |
'singular' => __( 'Form', 'give' ), |
| 273 |
'plural' => __( 'Forms', 'give' ), |
| 274 |
]; |
| 275 |
|
| 276 |
return apply_filters( 'give_default_form_name', $defaults ); |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* Get Singular Forms Label |
| 281 |
* |
| 282 |
* @param bool $lowercase |
| 283 |
* |
| 284 |
* @return string $defaults['singular'] Singular label |
| 285 |
* @since 1.0 |
| 286 |
*/ |
| 287 |
function give_get_forms_label_singular( $lowercase = false ) { |
| 288 |
$defaults = give_get_default_form_labels(); |
| 289 |
|
| 290 |
return ( $lowercase ) ? strtolower( $defaults['singular'] ) : $defaults['singular']; |
| 291 |
} |
| 292 |
|
| 293 |
/** |
| 294 |
* Get Plural Forms Label |
| 295 |
* |
| 296 |
* @return string $defaults['plural'] Plural label |
| 297 |
* @since 1.0 |
| 298 |
*/ |
| 299 |
function give_get_forms_label_plural( $lowercase = false ) { |
| 300 |
$defaults = give_get_default_form_labels(); |
| 301 |
|
| 302 |
return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural']; |
| 303 |
} |
| 304 |
|
| 305 |
/** |
| 306 |
* Change default "Enter title here" input |
| 307 |
* |
| 308 |
* @param string $title Default title placeholder text |
| 309 |
* |
| 310 |
* @return string $title New placeholder text |
| 311 |
* @since 1.0 |
| 312 |
*/ |
| 313 |
function give_change_default_title( $title ) { |
| 314 |
// If a frontend plugin uses this filter (check extensions before changing this function) |
| 315 |
if ( ! is_admin() ) { |
| 316 |
$title = __( 'Enter form title here', 'give' ); |
| 317 |
|
| 318 |
return $title; |
| 319 |
} |
| 320 |
|
| 321 |
$screen = get_current_screen(); |
| 322 |
|
| 323 |
if ( 'give_forms' == $screen->post_type ) { |
| 324 |
$title = __( 'Enter form title here', 'give' ); |
| 325 |
} |
| 326 |
|
| 327 |
return $title; |
| 328 |
} |
| 329 |
|
| 330 |
add_filter( 'enter_title_here', 'give_change_default_title' ); |
| 331 |
|
| 332 |
/** |
| 333 |
* Registers Custom Post Statuses which are used by the Payments |
| 334 |
* |
| 335 |
* @return void |
| 336 |
* @since 1.0 |
| 337 |
*/ |
| 338 |
function give_register_post_type_statuses() { |
| 339 |
// Payment Statuses |
| 340 |
register_post_status( |
| 341 |
'refunded', |
| 342 |
[ |
| 343 |
'label' => __( 'Refunded', 'give' ), |
| 344 |
'public' => true, |
| 345 |
'exclude_from_search' => false, |
| 346 |
'show_in_admin_all_list' => true, |
| 347 |
'show_in_admin_status_list' => true, |
| 348 |
'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'give' ), |
| 349 |
] |
| 350 |
); |
| 351 |
register_post_status( |
| 352 |
'failed', |
| 353 |
[ |
| 354 |
'label' => __( 'Failed', 'give' ), |
| 355 |
'public' => true, |
| 356 |
'exclude_from_search' => false, |
| 357 |
'show_in_admin_all_list' => true, |
| 358 |
'show_in_admin_status_list' => true, |
| 359 |
'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'give' ), |
| 360 |
] |
| 361 |
); |
| 362 |
register_post_status( |
| 363 |
'revoked', |
| 364 |
[ |
| 365 |
'label' => __( 'Revoked', 'give' ), |
| 366 |
'public' => true, |
| 367 |
'exclude_from_search' => false, |
| 368 |
'show_in_admin_all_list' => true, |
| 369 |
'show_in_admin_status_list' => true, |
| 370 |
'label_count' => _n_noop( 'Revoked <span class="count">(%s)</span>', 'Revoked <span class="count">(%s)</span>', 'give' ), |
| 371 |
] |
| 372 |
); |
| 373 |
register_post_status( |
| 374 |
'cancelled', |
| 375 |
[ |
| 376 |
'label' => __( 'Cancelled', 'give' ), |
| 377 |
'public' => true, |
| 378 |
'exclude_from_search' => false, |
| 379 |
'show_in_admin_all_list' => true, |
| 380 |
'show_in_admin_status_list' => true, |
| 381 |
'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'give' ), |
| 382 |
] |
| 383 |
); |
| 384 |
register_post_status( |
| 385 |
'abandoned', |
| 386 |
[ |
| 387 |
'label' => __( 'Abandoned', 'give' ), |
| 388 |
'public' => true, |
| 389 |
'exclude_from_search' => false, |
| 390 |
'show_in_admin_all_list' => true, |
| 391 |
'show_in_admin_status_list' => true, |
| 392 |
'label_count' => _n_noop( 'Abandoned <span class="count">(%s)</span>', 'Abandoned <span class="count">(%s)</span>', 'give' ), |
| 393 |
] |
| 394 |
); |
| 395 |
register_post_status( |
| 396 |
'processing', |
| 397 |
[ |
| 398 |
'label' => _x( 'Processing', 'Processing payment status', 'give' ), |
| 399 |
'public' => true, |
| 400 |
'exclude_from_search' => false, |
| 401 |
'show_in_admin_all_list' => true, |
| 402 |
'show_in_admin_status_list' => true, |
| 403 |
'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'give' ), |
| 404 |
] |
| 405 |
); |
| 406 |
|
| 407 |
register_post_status( |
| 408 |
'preapproval', |
| 409 |
[ |
| 410 |
'label' => _x( 'Preapproval', 'Preapproval payment status', 'give' ), |
| 411 |
'public' => true, |
| 412 |
'exclude_from_search' => false, |
| 413 |
'show_in_admin_all_list' => true, |
| 414 |
'show_in_admin_status_list' => true, |
| 415 |
'label_count' => _n_noop( 'Preapproval <span class="count">(%s)</span>', 'Preapproval <span class="count">(%s)</span>', 'give' ), |
| 416 |
] |
| 417 |
); |
| 418 |
|
| 419 |
} |
| 420 |
|
| 421 |
add_action( 'init', 'give_register_post_type_statuses' ); |
| 422 |
|
| 423 |
/** |
| 424 |
* Updated Messages |
| 425 |
* |
| 426 |
* Returns an array of with all updated messages. |
| 427 |
* |
| 428 |
* @param array $messages Post updated message |
| 429 |
* |
| 430 |
* @return array $messages New post updated messages |
| 431 |
* @since 1.0 |
| 432 |
*/ |
| 433 |
function give_updated_messages( $messages ) { |
| 434 |
global $post, $post_ID; |
| 435 |
|
| 436 |
if ( ! give_is_setting_enabled( give_get_option( 'forms_singular' ) ) ) { |
| 437 |
|
| 438 |
$messages['give_forms'] = [ |
| 439 |
1 => __( 'Form updated.', 'give' ), |
| 440 |
4 => __( 'Form updated.', 'give' ), |
| 441 |
6 => __( 'Form published.', 'give' ), |
| 442 |
7 => __( 'Form saved.', 'give' ), |
| 443 |
8 => __( 'Form submitted.', 'give' ), |
| 444 |
]; |
| 445 |
|
| 446 |
} else { |
| 447 |
|
| 448 |
$messages['give_forms'] = [ |
| 449 |
1 => sprintf( '%1$s <a href="%2$s">%3$s</a>', __( 'Form updated.', 'give' ), get_permalink( $post_ID ), __( 'View Form', 'give' ) ), |
| 450 |
4 => sprintf( '%1$s <a href="%2$s">%3$s</a>', __( 'Form updated.', 'give' ), get_permalink( $post_ID ), __( 'View Form', 'give' ) ), |
| 451 |
6 => sprintf( '%1$s <a href="%2$s">%3$s</a>', __( 'Form published.', 'give' ), get_permalink( $post_ID ), __( 'View Form', 'give' ) ), |
| 452 |
7 => sprintf( '%1$s <a href="%2$s">%3$s</a>', __( 'Form saved.', 'give' ), get_permalink( $post_ID ), __( 'View Form', 'give' ) ), |
| 453 |
8 => sprintf( '%1$s <a href="%2$s">%3$s</a>', __( 'Form submitted.', 'give' ), get_permalink( $post_ID ), __( 'View Form', 'give' ) ), |
| 454 |
]; |
| 455 |
|
| 456 |
} |
| 457 |
|
| 458 |
return $messages; |
| 459 |
} |
| 460 |
|
| 461 |
add_filter( 'post_updated_messages', 'give_updated_messages' ); |
| 462 |
|
| 463 |
/** |
| 464 |
* Ensure post thumbnail support is turned on |
| 465 |
*/ |
| 466 |
function give_add_thumbnail_support() { |
| 467 |
if ( ! give_is_setting_enabled( give_get_option( 'form_featured_img' ) ) ) { |
| 468 |
return; |
| 469 |
} |
| 470 |
|
| 471 |
if ( ! current_theme_supports( 'post-thumbnails' ) ) { |
| 472 |
add_theme_support( 'post-thumbnails' ); |
| 473 |
} |
| 474 |
|
| 475 |
add_post_type_support( 'give_forms', 'thumbnail' ); |
| 476 |
} |
| 477 |
|
| 478 |
add_action( 'after_setup_theme', 'give_add_thumbnail_support', 10 ); |
| 479 |
|
| 480 |
/** |
| 481 |
* Give Sidebars |
| 482 |
* |
| 483 |
* This option adds Give sidebars; registered late so it display last in list |
| 484 |
*/ |
| 485 |
function give_widgets_init() { |
| 486 |
|
| 487 |
// Single Give Forms (disabled if single turned off in settings) |
| 488 |
if ( |
| 489 |
give_is_setting_enabled( give_get_option( 'forms_singular' ) ) |
| 490 |
&& give_is_setting_enabled( give_get_option( 'form_sidebar' ) ) |
| 491 |
) { |
| 492 |
|
| 493 |
register_sidebar( |
| 494 |
apply_filters( |
| 495 |
'give_forms_single_sidebar', |
| 496 |
[ |
| 497 |
'name' => __( 'GiveWP Single Form Sidebar', 'give' ), |
| 498 |
'id' => 'give-forms-sidebar', |
| 499 |
'description' => __( 'Widgets in this area will be shown on the single GiveWP forms aside area. This sidebar will not display for embedded forms.', 'give' ), |
| 500 |
'before_widget' => '<div id="%1$s" class="widget %2$s">', |
| 501 |
'after_widget' => '</div>', |
| 502 |
'before_title' => '<h3 class="widgettitle widget-title">', |
| 503 |
'after_title' => '</h3>', |
| 504 |
] |
| 505 |
) |
| 506 |
); |
| 507 |
|
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
add_action( 'widgets_init', 'give_widgets_init', 999 ); |
| 512 |
|
| 513 |
|
| 514 |
/** |
| 515 |
* Remove "Quick Edit" for the give_forms CPT. |
| 516 |
* |
| 517 |
* @param array $actions |
| 518 |
* @param null $post |
| 519 |
* |
| 520 |
* @return array |
| 521 |
* @since 2.3.0 |
| 522 |
*/ |
| 523 |
function give_forms_disable_quick_edit( $actions = [], $post = null ) { |
| 524 |
|
| 525 |
// Abort if the post type is not "give_forms". |
| 526 |
if ( ! is_post_type_archive( 'give_forms' ) ) { |
| 527 |
return $actions; |
| 528 |
} |
| 529 |
|
| 530 |
// Remove the Quick Edit link. |
| 531 |
if ( isset( $actions['inline hide-if-no-js'] ) ) { |
| 532 |
unset( $actions['inline hide-if-no-js'] ); |
| 533 |
} |
| 534 |
|
| 535 |
// Return the set of links without Quick Edit. |
| 536 |
return $actions; |
| 537 |
|
| 538 |
} |
| 539 |
|
| 540 |
add_filter( 'post_row_actions', 'give_forms_disable_quick_edit', 10, 2 ); |
| 541 |
|
| 542 |
/** |
| 543 |
* Removes the screen options pull down. It is reset later in a different position. |
| 544 |
* |
| 545 |
* @param bool $display_boolean Whether to display screen options. |
| 546 |
* @param WP_Screen $wp_screen_object The screen object. |
| 547 |
* |
| 548 |
* @return bool Whether to display screen options. |
| 549 |
* @since 2.5.0 |
| 550 |
*/ |
| 551 |
function give_remove_screen_options( $display_boolean, $wp_screen_object ) { |
| 552 |
|
| 553 |
if ( false !== strpos( $wp_screen_object->id, 'give' ) ) { |
| 554 |
return false; |
| 555 |
} |
| 556 |
|
| 557 |
// Don't mess with other screens. |
| 558 |
return $display_boolean; |
| 559 |
} |
| 560 |
|
| 561 |
// add_filter( 'screen_options_show_screen', 'give_remove_screen_options', 10, 2 ); |
| 562 |
|
| 563 |
/** |
| 564 |
* Renders the screen options back after admin bar to ensure it pushes down the banner rather than overlaps them as is default in WordPress. |
| 565 |
* |
| 566 |
* @since 2.5.0 |
| 567 |
*/ |
| 568 |
function give_render_screen_options() { |
| 569 |
if ( ! is_admin() ) { |
| 570 |
return; |
| 571 |
} |
| 572 |
|
| 573 |
$current_screen = get_current_screen(); |
| 574 |
|
| 575 |
if ( empty( $current_screen ) ) { |
| 576 |
return; |
| 577 |
} |
| 578 |
|
| 579 |
if ( false !== strpos( $current_screen->id, 'give' ) ) { |
| 580 |
// Render Screen Options above the banner. |
| 581 |
$current_screen->render_screen_meta(); |
| 582 |
} |
| 583 |
} |
| 584 |
|
| 585 |
add_action( 'wp_after_admin_bar_render', 'give_render_screen_options' ); |
| 586 |
|