Changeset 11558
- Timestamp:
- 05/17/2017 06:57:32 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r11555 r11558 476 476 function groups_get_id( $group_slug ) { 477 477 return BP_Groups_Group::group_exists( $group_slug ); 478 } 479 480 /** 481 * Get a group ID by checking against old (not currently active) slugs. 482 * 483 * @since 2.9.0 484 * 485 * @param string $group_slug The group's slug. 486 * @return int|null The group ID on success; null on failure. 487 */ 488 function groups_get_id_by_previous_slug( $group_slug ) { 489 return BP_Groups_Group::get_id_by_previous_slug( $group_slug ); 478 490 } 479 491 -
trunk/src/bp-groups/classes/class-bp-groups-group.php
r11544 r11558 707 707 public static function get_id_from_slug( $slug ) { 708 708 return BP_Groups_Group::group_exists( $slug ); 709 } 710 711 /** 712 * Get whether a group exists for an old slug. 713 * 714 * @since 2.9.0 715 * 716 * @param string $slug Slug to check. 717 * 718 * @return int|null|false Group ID if found; null if not; false if missing parameters. 719 */ 720 public static function get_id_by_previous_slug( $slug ) { 721 global $wpdb; 722 723 if ( empty( $slug ) ) { 724 return false; 725 } 726 727 $args = array( 728 'meta_query' => array( 729 array( 730 'key' => 'previous_slug', 731 'value' => $slug 732 ), 733 ), 734 'orderby' => 'meta_id', 735 'order' => 'DESC', 736 'per_page' => 1, 737 'page' => 1, 738 'update_meta_cache' => false, 739 'show_hidden' => true, 740 ); 741 $groups = BP_Groups_Group::get( $args ); 742 743 $group_id = null; 744 if ( $groups['groups'] ) { 745 $group_id = current( $groups['groups'] )->id; 746 } 747 748 return $group_id; 709 749 } 710 750 -
trunk/tests/phpunit/testcases/groups/functions.php
r11555 r11558 826 826 } 827 827 828 /** 829 * @group groups_get_id_by_previous_slug 830 */ 831 public function test_groups_get_id_by_previous_slug() { 832 $slug = 'circe'; 833 $g1 = $this->factory->group->create( array( 'slug' => $slug ) ); 834 $g2 = $this->factory->group->create( array( 'slug' => 'loom' ) ); 835 836 groups_edit_base_group_details( array( 837 'group_id' => $g1, 838 'slug' => 'newslug', 839 ) ); 840 841 // Function should return the group ID as an integer. 842 $this->assertSame( $g1, groups_get_id_by_previous_slug( $slug ) ); 843 } 844 845 /** 846 * @group groups_get_id_by_previous_slug 847 */ 848 public function test_groups_get_id_by_previous_slug_null_no_results() { 849 $this->assertNull( groups_get_id_by_previous_slug( 'woohoo' ) ); 850 } 851 828 852 }
Note: See TracChangeset
for help on using the changeset viewer.