- Timestamp:
- 11/22/2015 04:58:34 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/classes/class-bp-group-extension.php
r10248 r10373 36 36 * of your main extension tab. Defaults to 'groups/single/plugins.php'. 37 37 * - 'screens' A multi-dimensional array, described below. 38 * 39 * 38 * - 'access' Which users can visit the plugin's tab. 39 * - 'show_tab' Which users can see the plugin's navigation tab. 40 40 * 41 41 * BP_Group_Extension uses the concept of "settings screens". There are three … … 63 63 * 'screens' => array( 64 64 * 'create' => array( 65 * 66 * 67 * 68 * 69 * 70 * 71 * 65 * 'slug' => 'foo', 66 * 'name' => 'Foo', 67 * 'position' => 55, 68 * 'screen_callback' => 'my_create_screen_callback', 69 * 'screen_save_callback' => 'my_create_screen_save_callback', 70 * ), 71 * 'edit' => array( // ... 72 72 * ), 73 73 * Only provide those arguments that you actually want to change from the … … 272 272 * The content of the group tab. 273 273 * 274 * @param int|null $group_id 274 * @param int|null $group_id ID of the group to display. 275 275 */ 276 276 public function display( $group_id = null ) {} … … 281 281 public function widget_display() {} 282 282 283 // *_screen() displays the settings form for the given context 284 // *_screen_save() processes data submitted via the settings form 285 // The settings_* methods are generic fallbacks, which can optionally 286 // be overridden by the more specific edit_*, create_*, and admin_* 287 // versions. 283 /* 284 * *_screen() displays the settings form for the given context 285 * *_screen_save() processes data submitted via the settings form 286 * The settings_* methods are generic fallbacks, which can optionally 287 * be overridden by the more specific edit_*, create_*, and admin_* 288 * versions. 289 */ 288 290 public function settings_screen( $group_id = null ) {} 289 291 public function settings_screen_save( $group_id = null ) {} … … 354 356 */ 355 357 public function init( $args = array() ) { 356 // Store the raw arguments 358 // Store the raw arguments. 357 359 $this->params_raw = $args; 358 360 … … 361 363 // compatibility with these plugins, we detect whether this is 362 364 // one of those legacy plugins, and parse any legacy arguments 363 // with those passed to init() 365 // with those passed to init(). 364 366 $this->parse_legacy_properties(); 365 367 $args = $this->parse_args_r( $args, $this->legacy_properties_converted ); 366 368 367 // Parse with defaults 369 // Parse with defaults. 368 370 $this->params = $this->parse_args_r( $args, array( 369 371 'slug' => $this->slug, … … 399 401 public function _register() { 400 402 401 // Detect and parse properties set by legacy extensions 403 // Detect and parse properties set by legacy extensions. 402 404 $this->parse_legacy_properties(); 403 405 404 406 // Initialize, if necessary. This should only happen for 405 // legacy extensions that don't call parent::init() themselves 407 // legacy extensions that don't call parent::init() themselves. 406 408 if ( true !== $this->initialized ) { 407 409 $this->init(); 408 410 } 409 411 410 // Set some config values, based on the parsed params 412 // Set some config values, based on the parsed params. 411 413 $this->group_id = $this->get_group_id(); 412 414 $this->slug = $this->params['slug']; … … 418 420 $this->template_file = $this->params['template_file']; 419 421 420 // Configure 'screens': create, admin, and edit contexts 422 // Configure 'screens': create, admin, and edit contexts. 421 423 $this->setup_screens(); 422 424 423 // Configure access-related settings 425 // Configure access-related settings. 424 426 $this->setup_access_settings(); 425 427 426 428 // Mirror configuration data so it's accessible to plugins 427 // that look for it in its old locations 429 // that look for it in its old locations. 428 430 $this->setup_legacy_properties(); 429 431 430 // Hook the extension into BuddyPress 432 // Hook the extension into BuddyPress. 431 433 $this->setup_display_hooks(); 432 434 $this->setup_create_hooks(); … … 468 470 public static function get_group_id() { 469 471 470 // Usually this will work 472 // Usually this will work. 471 473 $group_id = bp_get_current_group_id(); 472 474 473 // On the admin, get the group id out of the $_GET params 475 // On the admin, get the group id out of the $_GET params. 474 476 if ( empty( $group_id ) && is_admin() && ( isset( $_GET['page'] ) && ( 'bp-groups' === $_GET['page'] ) ) && ! empty( $_GET['gid'] ) ) { 475 477 $group_id = (int) $_GET['gid']; … … 477 479 478 480 // This fallback will only be hit when the create step is very 479 // early 481 // early. 480 482 if ( empty( $group_id ) && bp_get_new_group_id() ) { 481 483 $group_id = bp_get_new_group_id(); … … 484 486 // On some setups, the group id has to be fetched out of the 485 487 // $_POST array 486 // @todo Figure out why this is happening during group creation 488 // @todo Figure out why this is happening during group creation. 487 489 if ( empty( $group_id ) && isset( $_POST['group_id'] ) ) { 488 490 $group_id = (int) $_POST['group_id']; … … 552 554 */ 553 555 protected function setup_access_settings() { 554 // Bail if no group ID is available 556 // Bail if no group ID is available. 555 557 if ( empty( $this->group_id ) ) { 556 558 return; 557 559 } 558 560 559 // Backward compatibility 561 // Backward compatibility. 560 562 if ( isset( $this->params['enable_nav_item'] ) ) { 561 563 $this->enable_nav_item = (bool) $this->params['enable_nav_item']; 562 564 } 563 565 564 // Tab Access 566 // Tab Access. 565 567 $this->user_can_visit = false; 566 568 567 569 // Backward compatibility for components that do not provide 568 // explicit 'access' parameter 570 // explicit 'access' parameter. 569 571 if ( empty( $this->params['access'] ) ) { 570 572 if ( false === $this->enable_nav_item ) { … … 576 578 577 579 if ( ! empty( $group->status ) && 'public' === $group->status ) { 578 // Tabs in public groups are accessible to anyone by default 580 // Tabs in public groups are accessible to anyone by default. 579 581 $this->params['access'] = 'anyone'; 580 582 } else { 581 // All other groups have members-only as the default 583 // All other groups have members-only as the default. 582 584 $this->params['access'] = 'member'; 583 585 } … … 585 587 } 586 588 587 // Parse multiple access conditions into an array 589 // Parse multiple access conditions into an array. 588 590 $access_conditions = $this->params['access']; 589 591 if ( ! is_array( $access_conditions ) ) { … … 592 594 593 595 // If the current user meets at least one condition, the 594 // get access 596 // get access. 595 597 foreach ( $access_conditions as $access_condition ) { 596 598 if ( $this->user_meets_access_condition( $access_condition ) ) { … … 600 602 } 601 603 602 // Tab Visibility 604 // Tab Visibility. 603 605 $this->user_can_see_nav_item = false; 604 606 605 607 // Backward compatibility for components that do not provide 606 // explicit 'show_tab' parameter 608 // explicit 'show_tab' parameter. 607 609 if ( empty( $this->params['show_tab'] ) ) { 608 610 if ( false === $this->params['enable_nav_item'] ) { 609 // enable_nav_itemis only false if it's been611 // The enable_nav_item index is only false if it's been 610 612 // defined explicitly as such in the 611 // constructor. So we always trust this value 613 // constructor. So we always trust this value. 612 614 $this->params['show_tab'] = 'noone'; 613 615 … … 616 618 // we assume this is a legacy extension. 617 619 // Legacy behavior is that enable_nav_item=true + 618 // visibility=private implies members-only 620 // visibility=private implies members-only. 619 621 if ( 'public' !== $this->visibility ) { 620 622 $this->params['show_tab'] = 'member'; … … 625 627 } else { 626 628 // No show_tab or enable_nav_item value is 627 // available, so match the value of 'access' 629 // available, so match the value of 'access'. 628 630 $this->params['show_tab'] = $this->params['access']; 629 631 } 630 632 } 631 633 632 // Parse multiple access conditions into an array 634 // Parse multiple access conditions into an array. 633 635 $access_conditions = $this->params['show_tab']; 634 636 if ( ! is_array( $access_conditions ) ) { … … 637 639 638 640 // If the current user meets at least one condition, the 639 // get access 641 // get access. 640 642 foreach ( $access_conditions as $access_condition ) { 641 643 if ( $this->user_meets_access_condition( $access_condition ) ) { … … 697 699 protected function setup_display_hooks() { 698 700 699 // Bail if not a group 701 // Bail if not a group. 700 702 if ( ! bp_is_group() ) { 701 703 return; 702 704 } 703 705 704 // Backward compatibility only 706 // Backward compatibility only. 705 707 if ( ( 'public' !== $this->visibility ) && ! buddypress()->groups->current_group->user_has_access ) { 706 708 return; … … 740 742 ) ); 741 743 742 // When we are viewing the extension display page, set the title and options title 744 // When we are viewing the extension display page, set the title and options title. 743 745 if ( bp_is_current_action( $this->slug ) ) { 744 746 add_filter( 'bp_group_user_has_access', array( $this, 'group_access_protection' ), 10, 2 ); … … 748 750 } 749 751 750 // Hook the group home widget 752 // Hook the group home widget. 751 753 if ( ! bp_current_action() && bp_is_current_action( 'home' ) ) { 752 754 add_action( $this->display_hook, array( &$this, 'widget_display' ) ); … … 790 792 * @since 2.1.0 791 793 * 792 * @param bool $user_can_see_nav_item 793 * 794 * @param bool $user_can_see_nav_item Whether or not the user can see the nav item. 794 795 * @return bool 795 796 */ … … 807 808 * @since 2.1.0 808 809 * 809 * @param bool $user_can_visit 810 * 810 * @param bool $user_can_visit Whether or not the user can visit the tab. 811 811 * @return bool 812 812 */ … … 828 828 * @since 2.1.0 829 829 * 830 * @param bool $user_can_visit 831 * @param array $no_access_args 832 * 830 * @param bool $user_can_visit Whether or not the user can visit the tab. 831 * @param array $no_access_args Array of args to help determine access. 833 832 * @return bool 834 833 */ … … 864 863 $screen = $this->screens['create']; 865 864 866 // Insert the group creation step for the new group extension 865 // Insert the group creation step for the new group extension. 867 866 buddypress()->groups->group_creation_steps[ $screen['slug'] ] = array( 868 867 'name' => $screen['name'], … … 875 874 // correct group creation step). Hooked in separate 876 875 // methods because current creation step info not yet 877 // available at this point 876 // available at this point. 878 877 add_action( 'groups_custom_create_steps', array( $this, 'maybe_create_screen' ) ); 879 878 add_action( 'groups_create_group_step_save_' . $screen['slug'], array( $this, 'maybe_create_screen_save' ) ); … … 894 893 895 894 // The create screen requires an additional nonce field 896 // due to a quirk in the way the templates are built 895 // due to a quirk in the way the templates are built. 897 896 wp_nonce_field( 'groups_create_save_' . bp_get_groups_current_create_step(), '_wpnonce', false ); 898 897 } … … 920 919 */ 921 920 protected function setup_edit_hooks() { 922 // Bail if not in a group 921 // Bail if not in a group. 923 922 if ( ! bp_is_group() ) { 924 923 return; 925 924 } 926 925 927 // Bail if not an edit screen 926 // Bail if not an edit screen. 928 927 if ( ! $this->is_screen_enabled( 'edit' ) || ! bp_is_item_admin() ) { 929 928 return; … … 948 947 ); 949 948 950 // Should we add a menu to the Group's WP Admin Bar 949 // Should we add a menu to the Group's WP Admin Bar. 951 950 if ( ! empty( $screen['show_in_admin_bar'] ) ) { 952 951 $subnav_args['show_in_admin_bar'] = true; 953 952 } 954 953 955 // Add the tab to the manage navigation 954 // Add the tab to the manage navigation. 956 955 bp_core_new_subnav_item( $subnav_args ); 957 956 958 // Catch the edit screen and forward it to the plugin template 957 // Catch the edit screen and forward it to the plugin template. 959 958 if ( bp_is_groups_component() && bp_is_current_action( 'admin' ) && bp_is_action_variable( $screen['slug'], 0 ) ) { 960 959 $this->call_edit_screen_save( $this->group_id ); … … 963 962 964 963 // Determine the proper template and save for later 965 // loading 964 // loading. 966 965 if ( '' !== bp_locate_template( array( 'groups/single/home.php' ), false ) ) { 967 966 $this->edit_screen_template = '/groups/single/home'; … … 973 972 974 973 // We load the template at bp_screens, to give all 975 // extensions a chance to load 974 // extensions a chance to load. 976 975 add_action( 'bp_screens', array( $this, 'call_edit_screen_template_loader' ) ); 977 976 } … … 1015 1014 1016 1015 // When DOING_AJAX, the POST global will be populated, but we 1017 // should assume it's a save 1016 // should assume it's a save. 1018 1017 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { 1019 1018 return; … … 1023 1022 1024 1023 // Detect whether the screen_save_callback is performing a 1025 // redirect, so that we don't do one of our own 1024 // redirect, so that we don't do one of our own. 1026 1025 add_filter( 'wp_redirect', array( $this, 'detect_post_save_redirect' ) ); 1027 1026 1028 // Call the extension's save routine 1027 // Call the extension's save routine. 1029 1028 call_user_func( $this->screens['edit']['screen_save_callback'], $this->group_id ); 1030 1029 1031 // Clean up detection filters 1030 // Clean up detection filters. 1032 1031 remove_filter( 'wp_redirect', array( $this, 'detect_post_save_redirect' ) ); 1033 1032 1034 // Perform a redirect only if one has not already taken place 1033 // Perform a redirect only if one has not already taken place. 1035 1034 if ( empty( $this->post_save_redirect ) ) { 1036 1035 … … 1082 1081 * @param string $screen The screen markup, captured in the output 1083 1082 * buffer. 1084 *1085 1083 * @return string $screen The same markup, with a submit button added. 1086 1084 */ … … 1104 1102 * 1105 1103 * @param string $screen The markup to check. 1106 *1107 1104 * @return bool True if a Submit button is found, otherwise false. 1108 1105 */ … … 1118 1115 * @since 2.1.0 1119 1116 * 1120 * @param string $redirect 1121 * 1117 * @param string $redirect Redirect string. 1122 1118 * @return string 1123 1119 */ … … 1142 1138 } 1143 1139 1144 // Hook the admin screen markup function to the content hook 1140 // Hook the admin screen markup function to the content hook. 1145 1141 add_action( 'bp_groups_admin_meta_box_content_' . $this->slug, array( $this, 'call_admin_screen' ) ); 1146 1142 1147 // Initialize the metabox 1143 // Initialize the metabox. 1148 1144 add_action( 'bp_groups_admin_meta_boxes', array( $this, '_meta_box_display_callback' ) ); 1149 1145 1150 // Catch the metabox save 1146 // Catch the metabox save. 1151 1147 add_action( 'bp_group_admin_edit_after', array( $this, 'call_admin_screen_save' ), 10 ); 1152 1148 } … … 1232 1228 * 1233 1229 * @param string $context Screen context. 'create', 'edit', or 'admin'. 1234 *1235 1230 * @return bool True if the screen is enabled, otherwise false. 1236 1231 */ … … 1282 1277 * @param string $type Screen type. 'screen' or 'screen_save'. Default: 1283 1278 * 'screen'. 1284 *1285 1279 * @return callable A callable function handle. 1286 1280 */ … … 1288 1282 $callback = ''; 1289 1283 1290 // Try the context-specific callback first 1284 // Try the context-specific callback first. 1291 1285 $method = $context . '_' . $type; 1292 1286 $rmethod = $this->class_reflection->getMethod( $method ); … … 1332 1326 * @param array $a First set of arguments. 1333 1327 * @param array $b Second set of arguments. 1334 *1335 1328 * @return array Parsed arguments. 1336 1329 */ … … 1376 1369 * 1377 1370 * @param string $key Property name. 1378 *1379 1371 * @return mixed The value if found, otherwise null. 1380 1372 */ … … 1401 1393 * 1402 1394 * @param string $key Property name. 1403 *1404 1395 * @return bool True if the value is set, otherwise false. 1405 1396 */ … … 1425 1416 * 1426 1417 * @param string $key Property name. 1427 * @param mixed $value Property value.1418 * @param mixed $value Property value. 1428 1419 */ 1429 1420 public function __set( $key, $value ) { … … 1450 1441 break; 1451 1442 1452 // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin' 1443 // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin'. 1453 1444 case 'admin_name' : 1454 1445 $this->screens['edit']['name'] = $value; … … 1527 1518 protected function parse_legacy_properties() { 1528 1519 1529 // Only run this one time 1520 // Only run this one time. 1530 1521 if ( ! empty( $this->legacy_properties_converted ) ) { 1531 1522 return; … … 1534 1525 $properties = $this->get_legacy_property_list(); 1535 1526 1536 // By-reference variable for convenience 1527 // By-reference variable for convenience. 1537 1528 $lpc =& $this->legacy_properties_converted; 1538 1529 1539 1530 foreach ( $properties as $property ) { 1540 1531 1541 // No legacy config exists for this key 1532 // No legacy config exists for this key. 1542 1533 if ( ! isset( $this->{$property} ) ) { 1543 1534 continue; 1544 1535 } 1545 1536 1546 // Grab the value and record it as appropriate 1537 // Grab the value and record it as appropriate. 1547 1538 $value = $this->{$property}; 1548 1539 … … 1564 1555 break; 1565 1556 1566 // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin' 1557 // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin'. 1567 1558 case 'admin_name' : 1568 1559 $lpc['screens']['edit']['name'] = $value; … … 1610 1601 protected function setup_legacy_properties() { 1611 1602 1612 // Only run this one time 1603 // Only run this one time. 1613 1604 if ( ! empty( $this->legacy_properties ) ) { 1614 1605 return; … … 1637 1628 break; 1638 1629 1639 // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin' 1630 // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin'. 1640 1631 case 'admin_name' : 1641 1632 $lp['admin_name'] = $params['screens']['edit']['name']; … … 1663 1654 1664 1655 default : 1665 // All other items get moved over 1656 // All other items get moved over. 1666 1657 $lp[ $property ] = $params[ $property ]; 1667 1658 1668 // Also reapply to the object, for backpat 1659 // Also reapply to the object, for backpat. 1669 1660 $this->{$property} = $params[ $property ]; 1670 1661 … … 1678 1669 * Register a new Group Extension. 1679 1670 * 1680 * @param string Name of the Extension class.1671 * @param string $group_extension_class Name of the Extension class. 1681 1672 * @return false|null Returns false on failure, otherwise null. 1682 1673 */
Note: See TracChangeset
for help on using the changeset viewer.