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