Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Give_Donate_Form often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Give_Donate_Form, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class Give_Donate_Form { |
||
| 33 | |||
| 34 | /** |
||
| 35 | * The donation ID. |
||
| 36 | * |
||
| 37 | * @since 1.0 |
||
| 38 | * @access public |
||
| 39 | * |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | public $ID = 0; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * The donation price. |
||
| 46 | * |
||
| 47 | * @since 1.0 |
||
| 48 | * @access private |
||
| 49 | * |
||
| 50 | * @var float |
||
| 51 | */ |
||
| 52 | private $price; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * The minimum donation price. |
||
| 56 | * |
||
| 57 | * @since 1.3.6 |
||
| 58 | * @access private |
||
| 59 | * |
||
| 60 | * @var float |
||
| 61 | */ |
||
| 62 | private $minimum_price; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The donation prices, if Price Levels are enabled. |
||
| 66 | * |
||
| 67 | * @since 1.0 |
||
| 68 | * @access private |
||
| 69 | * |
||
| 70 | * @var array |
||
| 71 | */ |
||
| 72 | private $prices; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * The donation goal. |
||
| 76 | * |
||
| 77 | * @since 1.0 |
||
| 78 | * @access private |
||
| 79 | * |
||
| 80 | * @var float |
||
| 81 | */ |
||
| 82 | private $goal; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * The form's sale count. |
||
| 86 | * |
||
| 87 | * @since 1.0 |
||
| 88 | * @access private |
||
| 89 | * |
||
| 90 | * @var int |
||
| 91 | */ |
||
| 92 | private $sales; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The form's total earnings |
||
| 96 | * |
||
| 97 | * @since 1.0 |
||
| 98 | * @access private |
||
| 99 | * |
||
| 100 | * @var float |
||
| 101 | */ |
||
| 102 | private $earnings; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Declare the default properties in WP_Post as we can't extend it |
||
| 106 | * Anything we've declared above has been removed. |
||
| 107 | */ |
||
| 108 | |||
| 109 | /** |
||
| 110 | * The post author |
||
| 111 | * |
||
| 112 | * @since 1.0 |
||
| 113 | * @access public |
||
| 114 | * |
||
| 115 | * @var int |
||
| 116 | */ |
||
| 117 | public $post_author = 0; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * The post date |
||
| 121 | * |
||
| 122 | * @since 1.0 |
||
| 123 | * @access public |
||
| 124 | * |
||
| 125 | * @var string |
||
| 126 | */ |
||
| 127 | public $post_date = '0000-00-00 00:00:00'; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * The post GTM date |
||
| 131 | * |
||
| 132 | * @since 1.0 |
||
| 133 | * @access public |
||
| 134 | * |
||
| 135 | * @var string |
||
| 136 | */ |
||
| 137 | public $post_date_gmt = '0000-00-00 00:00:00'; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * The post content |
||
| 141 | * |
||
| 142 | * @since 1.0 |
||
| 143 | * @access public |
||
| 144 | * |
||
| 145 | * @var string |
||
| 146 | */ |
||
| 147 | public $post_content = ''; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * The post title |
||
| 151 | * |
||
| 152 | * @since 1.0 |
||
| 153 | * @access public |
||
| 154 | * |
||
| 155 | * @var string |
||
| 156 | */ |
||
| 157 | public $post_title = ''; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * The post excerpt |
||
| 161 | * |
||
| 162 | * @since 1.0 |
||
| 163 | * @access public |
||
| 164 | * |
||
| 165 | * @var string |
||
| 166 | */ |
||
| 167 | public $post_excerpt = ''; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * The post status |
||
| 171 | * |
||
| 172 | * @since 1.0 |
||
| 173 | * @access public |
||
| 174 | * |
||
| 175 | * @var string |
||
| 176 | */ |
||
| 177 | public $post_status = 'publish'; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * The comment status |
||
| 181 | * |
||
| 182 | * @since 1.0 |
||
| 183 | * @access public |
||
| 184 | * |
||
| 185 | * @var string |
||
| 186 | */ |
||
| 187 | public $comment_status = 'open'; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * The ping status |
||
| 191 | * |
||
| 192 | * @since 1.0 |
||
| 193 | * @access public |
||
| 194 | * |
||
| 195 | * @var string |
||
| 196 | */ |
||
| 197 | public $ping_status = 'open'; |
||
| 198 | |||
| 199 | /** |
||
| 200 | * The post password |
||
| 201 | * |
||
| 202 | * @since 1.0 |
||
| 203 | * @access public |
||
| 204 | * |
||
| 205 | * @var string |
||
| 206 | */ |
||
| 207 | public $post_password = ''; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * The post name |
||
| 211 | * |
||
| 212 | * @since 1.0 |
||
| 213 | * @access public |
||
| 214 | * |
||
| 215 | * @var string |
||
| 216 | */ |
||
| 217 | public $post_name = ''; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Ping |
||
| 221 | * |
||
| 222 | * @since 1.0 |
||
| 223 | * @access public |
||
| 224 | * |
||
| 225 | * @var string |
||
| 226 | */ |
||
| 227 | public $to_ping = ''; |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Pinged |
||
| 231 | * |
||
| 232 | * @since 1.0 |
||
| 233 | * @access public |
||
| 234 | * |
||
| 235 | * @var string |
||
| 236 | */ |
||
| 237 | public $pinged = ''; |
||
| 238 | |||
| 239 | /** |
||
| 240 | * The post modified date |
||
| 241 | * |
||
| 242 | * @since 1.0 |
||
| 243 | * @access public |
||
| 244 | * |
||
| 245 | * @var string |
||
| 246 | */ |
||
| 247 | public $post_modified = '0000-00-00 00:00:00'; |
||
| 248 | |||
| 249 | /** |
||
| 250 | * The post modified GTM date |
||
| 251 | * |
||
| 252 | * @since 1.0 |
||
| 253 | * @access public |
||
| 254 | * |
||
| 255 | * @var string |
||
| 256 | */ |
||
| 257 | public $post_modified_gmt = '0000-00-00 00:00:00'; |
||
| 258 | |||
| 259 | /** |
||
| 260 | * The post filtered content |
||
| 261 | * |
||
| 262 | * @since 1.0 |
||
| 263 | * @access public |
||
| 264 | * |
||
| 265 | * @var string |
||
| 266 | */ |
||
| 267 | public $post_content_filtered = ''; |
||
| 268 | |||
| 269 | /** |
||
| 270 | * The post parent |
||
| 271 | * |
||
| 272 | * @since 1.0 |
||
| 273 | * @access public |
||
| 274 | * |
||
| 275 | * @var int |
||
| 276 | */ |
||
| 277 | public $post_parent = 0; |
||
| 278 | |||
| 279 | /** |
||
| 280 | * The post GUID |
||
| 281 | * |
||
| 282 | * @since 1.0 |
||
| 283 | * @access public |
||
| 284 | * |
||
| 285 | * @var string |
||
| 286 | */ |
||
| 287 | public $guid = ''; |
||
| 288 | |||
| 289 | /** |
||
| 290 | * The menu order |
||
| 291 | * |
||
| 292 | * @since 1.0 |
||
| 293 | * @access public |
||
| 294 | * |
||
| 295 | * @var int |
||
| 296 | */ |
||
| 297 | public $menu_order = 0; |
||
| 298 | |||
| 299 | /** |
||
| 300 | * The mime type0 |
||
| 301 | * |
||
| 302 | * @since 1.0 |
||
| 303 | * @access public |
||
| 304 | * |
||
| 305 | * @var string |
||
| 306 | */ |
||
| 307 | public $post_mime_type = ''; |
||
| 308 | |||
| 309 | /** |
||
| 310 | * The comment count |
||
| 311 | * |
||
| 312 | * @since 1.0 |
||
| 313 | * @access public |
||
| 314 | * |
||
| 315 | * @var int |
||
| 316 | */ |
||
| 317 | public $comment_count = 0; |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Filtered |
||
| 321 | * |
||
| 322 | * @since 1.0 |
||
| 323 | * @access public |
||
| 324 | * |
||
| 325 | * @var string |
||
| 326 | */ |
||
| 327 | public $filter; |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Class Constructor |
||
| 331 | * |
||
| 332 | * Set up the Give Donate Form Class. |
||
| 333 | * |
||
| 334 | * @since 1.0 |
||
| 335 | * @access public |
||
| 336 | * |
||
| 337 | * @param bool $_id Post id. Default is false. |
||
| 338 | * @param array $_args Arguments passed. |
||
| 339 | */ |
||
| 340 | public function __construct( $_id = false, $_args = array() ) { |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Given the donation form data, let's set the variables |
||
| 349 | * |
||
| 350 | * @since 1.5 |
||
| 351 | * @access private |
||
| 352 | * |
||
| 353 | * @param WP_Post $donation_form WP_Post Object for the donation form. |
||
| 354 | * |
||
| 355 | * @return bool If the setup was successful or not. |
||
| 356 | */ |
||
| 357 | private function setup_donation_form( $donation_form ) { |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Magic __get function to dispatch a call to retrieve a private property |
||
| 389 | * |
||
| 390 | * @since 1.0 |
||
| 391 | * @access public |
||
| 392 | * |
||
| 393 | * @param string $key |
||
| 394 | * |
||
| 395 | * @return mixed |
||
| 396 | */ |
||
| 397 | View Code Duplication | public function __get( $key ) { |
|
| 398 | |||
| 399 | if ( method_exists( $this, 'get_' . $key ) ) { |
||
| 400 | |||
| 401 | return call_user_func( array( $this, 'get_' . $key ) ); |
||
| 402 | |||
| 403 | } else { |
||
| 404 | |||
| 405 | /* translators: %s: property key */ |
||
| 406 | return new WP_Error( 'give-form-invalid-property', sprintf( esc_html__( 'Can\'t get property %s.', 'give' ), $key ) ); |
||
| 407 | |||
| 408 | } |
||
| 409 | |||
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Creates a donation form |
||
| 414 | * |
||
| 415 | * @since 1.5 |
||
| 416 | * @access public |
||
| 417 | * |
||
| 418 | * @param array $data Array of attributes for a donation form. |
||
| 419 | * |
||
| 420 | * @return bool|int False if data isn't passed and class not instantiated for creation, or New Form ID. |
||
| 421 | */ |
||
| 422 | public function create( $data = array() ) { |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Retrieve the ID |
||
| 461 | * |
||
| 462 | * @since 1.0 |
||
| 463 | * @access public |
||
| 464 | * |
||
| 465 | * @return int Donation form ID. |
||
| 466 | */ |
||
| 467 | public function get_ID() { |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Retrieve the donation form name |
||
| 473 | * |
||
| 474 | * @since 1.5 |
||
| 475 | * @access public |
||
| 476 | * |
||
| 477 | * @return string Donation form name. |
||
| 478 | */ |
||
| 479 | public function get_name() { |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Retrieve the price |
||
| 485 | * |
||
| 486 | * @since 1.0 |
||
| 487 | * @access public |
||
| 488 | * |
||
| 489 | * @return float Price. |
||
| 490 | */ |
||
| 491 | View Code Duplication | public function get_price() { |
|
| 492 | |||
| 493 | if ( ! isset( $this->price ) ) { |
||
| 494 | |||
| 495 | $this->price = give_maybe_sanitize_amount( |
||
| 496 | give_get_meta( |
||
| 497 | $this->ID, |
||
| 498 | '_give_set_price', |
||
| 499 | true |
||
| 500 | ) |
||
| 501 | ); |
||
| 502 | |||
| 503 | if ( ! $this->price ) { |
||
| 504 | $this->price = 0; |
||
| 505 | } |
||
| 506 | |||
| 507 | } |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Override the donation form set price. |
||
| 511 | * |
||
| 512 | * @since 1.0 |
||
| 513 | * |
||
| 514 | * @param string $price The donation form price. |
||
| 515 | * @param string|int $id The form ID. |
||
| 516 | */ |
||
| 517 | return apply_filters( 'give_get_set_price', $this->price, $this->ID ); |
||
| 518 | } |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Retrieve the minimum price. |
||
| 522 | * |
||
| 523 | * @since 1.3.6 |
||
| 524 | * @access public |
||
| 525 | * |
||
| 526 | * @return float Minimum price. |
||
| 527 | */ |
||
| 528 | public function get_minimum_price() { |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Retrieve the variable prices |
||
| 546 | * |
||
| 547 | * @since 1.0 |
||
| 548 | * @access public |
||
| 549 | * |
||
| 550 | * @return array Variable prices. |
||
| 551 | */ |
||
| 552 | public function get_prices() { |
||
| 571 | |||
| 572 | /** |
||
| 573 | * Retrieve the goal |
||
| 574 | * |
||
| 575 | * @since 1.0 |
||
| 576 | * @access public |
||
| 577 | * |
||
| 578 | * @return float Goal. |
||
| 579 | */ |
||
| 580 | View Code Duplication | public function get_goal() { |
|
| 581 | |||
| 582 | if ( ! isset( $this->goal ) ) { |
||
| 583 | |||
| 584 | $this->goal = give_get_meta( $this->ID, '_give_set_goal', true ); |
||
| 585 | |||
| 586 | if ( ! $this->goal ) { |
||
| 587 | $this->goal = 0; |
||
| 588 | } |
||
| 589 | |||
| 590 | } |
||
| 591 | |||
| 592 | return apply_filters( 'give_get_set_goal', $this->goal, $this->ID ); |
||
| 593 | |||
| 594 | } |
||
| 595 | |||
| 596 | /** |
||
| 597 | * Determine if single price mode is enabled or disabled |
||
| 598 | * |
||
| 599 | * @since 1.0 |
||
| 600 | * @access public |
||
| 601 | * |
||
| 602 | * @return bool |
||
| 603 | */ |
||
| 604 | View Code Duplication | public function is_single_price_mode() { |
|
| 605 | |||
| 606 | $option = give_get_meta( $this->ID, '_give_price_option', true ); |
||
| 607 | $ret = 0; |
||
| 608 | |||
| 609 | if ( empty( $option ) || $option === 'set' ) { |
||
| 610 | $ret = 1; |
||
| 611 | } |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Override the price mode for a donation when checking if is in single price mode. |
||
| 615 | * |
||
| 616 | * @since 1.0 |
||
| 617 | * |
||
| 618 | * @param bool $ret Is donation form in single price mode? |
||
| 619 | * @param int|string $ID The ID of the donation form. |
||
| 620 | */ |
||
| 621 | return (bool) apply_filters( 'give_single_price_option_mode', $ret, $this->ID ); |
||
| 622 | |||
| 623 | } |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Determine if custom price mode is enabled or disabled |
||
| 627 | * |
||
| 628 | * @since 1.6 |
||
| 629 | * @access public |
||
| 630 | * |
||
| 631 | * @return bool |
||
| 632 | */ |
||
| 633 | public function is_custom_price_mode() { |
||
| 653 | |||
| 654 | /** |
||
| 655 | * Has Variable Prices |
||
| 656 | * |
||
| 657 | * Determine if the donation form has variable prices enabled |
||
| 658 | * |
||
| 659 | * @since 1.0 |
||
| 660 | * @access public |
||
| 661 | * |
||
| 662 | * @return bool |
||
| 663 | */ |
||
| 664 | View Code Duplication | public function has_variable_prices() { |
|
| 665 | |||
| 666 | $option = give_get_meta( $this->ID, '_give_price_option', true ); |
||
| 667 | $ret = 0; |
||
| 668 | |||
| 669 | if ( $option === 'multi' ) { |
||
| 670 | $ret = 1; |
||
| 671 | } |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Filter: Override whether the donation form has variables prices. |
||
| 675 | * |
||
| 676 | * @param bool $ret Does donation form have variable prices? |
||
| 677 | * @param int|string $ID The ID of the donation form. |
||
| 678 | */ |
||
| 679 | return (bool) apply_filters( 'give_has_variable_prices', $ret, $this->ID ); |
||
| 680 | |||
| 681 | } |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Retrieve the donation form type, set or multi-level |
||
| 685 | * |
||
| 686 | * @since 1.5 |
||
| 687 | * @access public |
||
| 688 | * |
||
| 689 | * @return string Type of donation form, either 'set' or 'multi'. |
||
| 690 | */ |
||
| 691 | View Code Duplication | public function get_type() { |
|
| 692 | |||
| 693 | if ( ! isset( $this->type ) ) { |
||
| 694 | |||
| 695 | $this->type = give_get_meta( $this->ID, '_give_price_option', true ); |
||
| 696 | |||
| 697 | if ( empty( $this->type ) ) { |
||
| 698 | $this->type = 'set'; |
||
| 699 | } |
||
| 700 | |||
| 701 | } |
||
| 702 | |||
| 703 | return apply_filters( 'give_get_form_type', $this->type, $this->ID ); |
||
| 704 | |||
| 705 | } |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Get form tag classes. |
||
| 709 | * |
||
| 710 | * Provides the classes for the donation <form> html tag and filters for customization. |
||
| 711 | * |
||
| 712 | * @since 1.6 |
||
| 713 | * @access public |
||
| 714 | * |
||
| 715 | * @param $args |
||
| 716 | * |
||
| 717 | * @return string |
||
| 718 | */ |
||
| 719 | public function get_form_classes( $args ) { |
||
| 738 | |||
| 739 | /** |
||
| 740 | * Get form wrap Classes. |
||
| 741 | * |
||
| 742 | * Provides the classes for the donation form div wrapper and filters for customization. |
||
| 743 | * |
||
| 744 | * @access public |
||
| 745 | * |
||
| 746 | * @param $args |
||
| 747 | * |
||
| 748 | * @return string |
||
| 749 | */ |
||
| 750 | public function get_form_wrap_classes( $args ) { |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Get if form type set or not. |
||
| 773 | * |
||
| 774 | * @since 1.6 |
||
| 775 | * @access public |
||
| 776 | * |
||
| 777 | * @return bool |
||
| 778 | */ |
||
| 779 | public function is_set_type_donation_form() { |
||
| 784 | |||
| 785 | /** |
||
| 786 | * Get if form type multi or not. |
||
| 787 | * |
||
| 788 | * @since 1.6 |
||
| 789 | * @access public |
||
| 790 | * |
||
| 791 | * @return bool True if form type is 'multi' and false otherwise. |
||
| 792 | */ |
||
| 793 | public function is_multi_type_donation_form() { |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Retrieve the sale count for the donation form |
||
| 802 | * |
||
| 803 | * @since 1.0 |
||
| 804 | * @access public |
||
| 805 | * |
||
| 806 | * @return int Donation form sale count. |
||
| 807 | */ |
||
| 808 | View Code Duplication | public function get_sales() { |
|
| 809 | |||
| 810 | if ( ! isset( $this->sales ) ) { |
||
| 811 | |||
| 812 | if ( '' == give_get_meta( $this->ID, '_give_form_sales', true ) ) { |
||
| 813 | add_post_meta( $this->ID, '_give_form_sales', 0 ); |
||
| 814 | } // End if |
||
| 815 | |||
| 816 | $this->sales = give_get_meta( $this->ID, '_give_form_sales', true ); |
||
| 817 | |||
| 818 | if ( $this->sales < 0 ) { |
||
| 819 | // Never let sales be less than zero |
||
| 820 | $this->sales = 0; |
||
| 821 | } |
||
| 822 | |||
| 823 | } |
||
| 824 | |||
| 825 | return $this->sales; |
||
| 826 | |||
| 827 | } |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Increment the sale count by one |
||
| 831 | * |
||
| 832 | * @since 1.0 |
||
| 833 | * @access public |
||
| 834 | * |
||
| 835 | * @param int $quantity The quantity to increase the donations by. Default is 1. |
||
| 836 | * |
||
| 837 | * @return int|false New number of total sales. |
||
| 838 | */ |
||
| 839 | public function increase_sales( $quantity = 1 ) { |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Decrement the sale count by one |
||
| 858 | * |
||
| 859 | * @since 1.0 |
||
| 860 | * @access public |
||
| 861 | * |
||
| 862 | * @param int $quantity The quantity to decrease by. Default is 1. |
||
| 863 | * |
||
| 864 | * @return int|false New number of total sales. |
||
| 865 | */ |
||
| 866 | public function decrease_sales( $quantity = 1 ) { |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Retrieve the total earnings for the form |
||
| 892 | * |
||
| 893 | * @since 1.0 |
||
| 894 | * @access public |
||
| 895 | * |
||
| 896 | * @return float Donation form total earnings. |
||
| 897 | */ |
||
| 898 | View Code Duplication | public function get_earnings() { |
|
| 899 | |||
| 900 | if ( ! isset( $this->earnings ) ) { |
||
| 901 | |||
| 902 | if ( '' == give_get_meta( $this->ID, '_give_form_earnings', true ) ) { |
||
| 903 | add_post_meta( $this->ID, '_give_form_earnings', 0 ); |
||
| 904 | } |
||
| 905 | |||
| 906 | $this->earnings = give_get_meta( $this->ID, '_give_form_earnings', true ); |
||
| 907 | |||
| 908 | if ( $this->earnings < 0 ) { |
||
| 909 | // Never let earnings be less than zero |
||
| 910 | $this->earnings = 0; |
||
| 911 | } |
||
| 912 | |||
| 913 | } |
||
| 914 | |||
| 915 | return $this->earnings; |
||
| 916 | |||
| 917 | } |
||
| 918 | |||
| 919 | /** |
||
| 920 | * Increase the earnings by the given amount |
||
| 921 | * |
||
| 922 | * @since 1.0 |
||
| 923 | * @access public |
||
| 924 | * |
||
| 925 | * @param int $amount Amount of donation. Default is 0. |
||
| 926 | * |
||
| 927 | * @return float|false |
||
| 928 | */ |
||
| 929 | View Code Duplication | public function increase_earnings( $amount = 0 ) { |
|
| 930 | |||
| 931 | $earnings = give_get_form_earnings_stats( $this->ID ); |
||
| 932 | $new_amount = $earnings + (float) $amount; |
||
| 933 | |||
| 934 | if ( $this->update_meta( '_give_form_earnings', $new_amount ) ) { |
||
| 935 | |||
| 936 | $this->earnings = $new_amount; |
||
| 937 | |||
| 938 | return $this->earnings; |
||
| 939 | |||
| 940 | } |
||
| 941 | |||
| 942 | return false; |
||
| 943 | |||
| 944 | } |
||
| 945 | |||
| 946 | /** |
||
| 947 | * Decrease the earnings by the given amount |
||
| 948 | * |
||
| 949 | * @since 1.0 |
||
| 950 | * @access public |
||
| 951 | * |
||
| 952 | * @param int $amount Amount of donation. |
||
| 953 | * |
||
| 954 | * @return float|false |
||
| 955 | */ |
||
| 956 | View Code Duplication | public function decrease_earnings( $amount ) { |
|
| 957 | |||
| 958 | $earnings = give_get_form_earnings_stats( $this->ID ); |
||
| 959 | |||
| 960 | if ( $earnings > 0 ) { |
||
| 961 | // Only decrease if greater than zero |
||
| 962 | $new_amount = $earnings - (float) $amount; |
||
| 963 | |||
| 964 | |||
| 965 | if ( $this->update_meta( '_give_form_earnings', $new_amount ) ) { |
||
| 966 | |||
| 967 | $this->earnings = $new_amount; |
||
| 968 | |||
| 969 | return $this->earnings; |
||
| 970 | |||
| 971 | } |
||
| 972 | |||
| 973 | } |
||
| 974 | |||
| 975 | return false; |
||
| 976 | |||
| 977 | } |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Determine if the donation is free or if the given price ID is free |
||
| 981 | * |
||
| 982 | * @since 1.0 |
||
| 983 | * @access public |
||
| 984 | * |
||
| 985 | * @param int $price_id Price ID. Default is false. |
||
| 986 | * |
||
| 987 | * @return bool |
||
| 988 | */ |
||
| 989 | public function is_free( $price_id = false ) { |
||
| 1007 | |||
| 1008 | /** |
||
| 1009 | * Determine if donation form closed or not |
||
| 1010 | * |
||
| 1011 | * Form will be close if: |
||
| 1012 | * a. form has fixed goal |
||
| 1013 | * b. close form when goal achieved cmb2 setting is set to 'Yes' |
||
| 1014 | * c. goal has been achieved |
||
| 1015 | * |
||
| 1016 | * @since 1.4.5 |
||
| 1017 | * @access public |
||
| 1018 | * |
||
| 1019 | * @return bool |
||
| 1020 | */ |
||
| 1021 | public function is_close_donation_form() { |
||
| 1040 | |||
| 1041 | /** |
||
| 1042 | * Updates a single meta entry for the donation form |
||
| 1043 | * |
||
| 1044 | * @since 1.5 |
||
| 1045 | * @access private |
||
| 1046 | * |
||
| 1047 | * @param string $meta_key The meta_key to update. |
||
| 1048 | * @param string|array|object $meta_value The value to put into the meta. |
||
| 1049 | * |
||
| 1050 | * @return bool The result of the update query. |
||
| 1051 | */ |
||
| 1052 | private function update_meta( $meta_key = '', $meta_value = '' ) { |
||
| 1068 | |||
| 1069 | } |
||
| 1070 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.