Changeset 7969
- Timestamp:
- 02/22/2014 10:49:31 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/bp-messages/bp-messages-classes.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-messages/bp-messages-classes.php
r7968 r7969 430 430 } 431 431 432 /** 433 * BuddyPress Notices class. 434 * 435 * Use this class to create, activate, deactivate or delete notices. 436 * 437 * @since BuddyPress (1.0.0) 438 */ 432 439 class BP_Messages_Notice { 440 /** 441 * The notice ID. 442 * 443 * @var int 444 */ 433 445 public $id = null; 446 447 /** 448 * The subject line for the notice. 449 * 450 * @var string 451 */ 434 452 public $subject; 453 454 /** 455 * The content of the notice. 456 * 457 * @var string 458 */ 435 459 public $message; 460 461 /** 462 * The date the notice was created. 463 * 464 * @var string 465 */ 436 466 public $date_sent; 467 468 /** 469 * Whether the notice is active or not. 470 * 471 * @var int 472 */ 437 473 public $is_active; 438 474 475 /** 476 * Constructor. 477 * 478 * @since BuddyPress (1.0.0) 479 */ 439 480 public function __construct( $id = null ) { 440 481 if ( $id ) { 441 482 $this->id = $id; 442 $this->populate($id); 443 } 444 } 445 483 $this->populate(); 484 } 485 } 486 487 /** 488 * Populate method. 489 * 490 * Runs during constructor. 491 * 492 * @since BuddyPress (1.0.0) 493 */ 446 494 public function populate() { 447 495 global $wpdb, $bp; … … 457 505 } 458 506 507 /** 508 * Saves a notice. 509 * 510 * @since BuddyPress (1.0.0) 511 * 512 * @return bool 513 */ 459 514 public function save() { 460 515 global $wpdb, $bp; … … 465 520 do_action_ref_array( 'messages_notice_before_save', array( &$this ) ); 466 521 467 if ( empty( $this->id ) ) 522 if ( empty( $this->id ) ) { 468 523 $sql = $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_notices} (subject, message, date_sent, is_active) VALUES (%s, %s, %s, %d)", $this->subject, $this->message, $this->date_sent, $this->is_active ); 469 else524 } else { 470 525 $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_notices} SET subject = %s, message = %s, is_active = %d WHERE id = %d", $this->subject, $this->message, $this->is_active, $this->id ); 471 472 if ( !$wpdb->query( $sql ) ) 473 return false; 474 475 if ( !$id = $this->id ) 526 } 527 528 if ( ! $wpdb->query( $sql ) ) { 529 return false; 530 } 531 532 if ( ! $id = $this->id ) { 476 533 $id = $wpdb->insert_id; 534 } 477 535 478 536 // Now deactivate all notices apart from the new one. … … 486 544 } 487 545 546 /** 547 * Activates a notice. 548 * 549 * @since BuddyPress (1.0.0) 550 * 551 * @return bool 552 */ 488 553 public function activate() { 489 554 $this->is_active = 1; … … 491 556 } 492 557 558 /** 559 * Deactivates a notice. 560 * 561 * @since BuddyPress (1.0.0) 562 * 563 * @return bool 564 */ 493 565 public function deactivate() { 494 566 $this->is_active = 0; … … 496 568 } 497 569 570 /** 571 * Deletes a notice. 572 * 573 * @since BuddyPress (1.0.0) 574 * 575 * @return bool 576 */ 498 577 public function delete() { 499 578 global $wpdb, $bp; … … 501 580 $sql = $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id ); 502 581 503 if ( !$wpdb->query( $sql ) ) 504 return false; 582 if ( ! $wpdb->query( $sql ) ) { 583 return false; 584 } 505 585 506 586 return true; … … 510 590 511 591 /** 512 * Pulls up a list of notices 592 * Pulls up a list of notices. 513 593 * 514 594 * To get all notices, pass a value of -1 to pag_num 515 595 * 516 * @param array $args See $defaults for explanation of accepted arguments 517 * @return array $notices 596 * @since BuddyPress (1.0.0) 597 * 598 * @param array $data { 599 * Array of parameters. 600 * @type int $pag_num Number of notices per page. Defaults to 20. 601 * @type int $pag_page The page number. Defaults to 1. 602 * } 603 * @return array 518 604 */ 519 605 public static function get_notices( $args = array() ) { … … 535 621 } 536 622 623 /** 624 * Returns the total number of recorded notices. 625 * 626 * @since BuddyPress (1.0.0) 627 * 628 * @return int 629 */ 537 630 public static function get_total_notice_count() { 538 631 global $wpdb, $bp; … … 543 636 } 544 637 638 /** 639 * Returns the active notice that should be displayed on the frontend. 640 * 641 * @since BuddyPress (1.0.0) 642 * 643 * @return object The BP_Messages_Notice object 644 */ 545 645 public static function get_active() { 546 646 global $wpdb, $bp;
Note: See TracChangeset
for help on using the changeset viewer.