BP_XProfile_Component

创建我们的Xprofile组件。

描述

来源

文件:bp-xprofile /类/ class-bp-xprofile-component.php

类BP_XProfile_Component扩展了BP_Component {/ ** *配置文件字段类型。* * @since buddypress 1.5.0 * @var array * / public $ field_types;/ ** * Xprofile字段的可接受可见性等级。* * @see bp_xprofile_get_visibility_Levels()* * * * @since buddypress 1.6.0 * @var array * / public $ visibility_levels = array();/ ** *启动Xprofile组件创建过程。* * @since buddypress 1.5.0 * / public function __construct(){garent :: start('xprofile',__('profile字段','buddyboss'),buddypress() - > plugin_dir,array('adminbar_myaccount_order'=> 20));$ this-> setup_hooks();} / ** *包含文件。* * @since buddypress 1.5.0 * * * @param数组$包括要包含的文件数组。* /公共函数包括($包括= array()){$包括=数组('cssjs','cache','caps','filters','模板','函数','Reporters',); // Conditional includes. if ( bp_is_active( 'activity' ) ) { $includes[] = 'activity'; } if ( bp_is_active( 'notifications' ) ) { $includes[] = 'notifications'; } if ( bp_is_active( 'settings' ) ) { $includes[] = 'settings'; } if ( is_admin() ) { $includes[] = 'admin'; } parent::includes( $includes ); } /** * Late includes method. * * Only load up certain code when on specific pages. * * @since BuddyPress 3.0.0 */ public function late_includes() { // Bail if PHPUnit is running. if ( defined( 'BP_TESTS_DIR' ) ) { return; } // Bail if not on a user page. if ( ! bp_is_user() ) { return; } // User nav. if ( bp_is_profile_component() ) { require $this->path . 'bp-xprofile/screens/public.php'; // Action - Delete avatar. if ( is_user_logged_in()&& bp_is_user_change_avatar() && bp_is_action_variable( 'delete-avatar', 0 ) ) { require $this->path . 'bp-xprofile/actions/delete-avatar.php'; } // Sub-nav items. if ( is_user_logged_in() && in_array( bp_current_action(), array( 'edit', 'change-avatar', 'change-cover-image' ), true ) ) { require $this->path . 'bp-xprofile/screens/' . bp_current_action() . '.php'; } } // Settings. if ( is_user_logged_in() && bp_is_user_settings_profile() ) { require $this->path . 'bp-xprofile/screens/settings-profile.php'; } } /** * Setup globals. * * The BP_XPROFILE_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since BuddyPress 1.5.0 * * @param array $args Array of globals to set up. */ public function setup_globals( $args = array() ) { $bp = buddypress(); // Define a slug, if necessary. if ( !defined( 'BP_XPROFILE_SLUG' ) ) { define( 'BP_XPROFILE_SLUG', 'profile' ); } // Assign the base group and fullname field names to constants // to use in SQL statements. // Defined conditionally to accommodate unit tests. if ( ! defined( 'BP_XPROFILE_BASE_GROUP_NAME' ) ) { define( 'BP_XPROFILE_BASE_GROUP_NAME', stripslashes( bp_core_get_root_option( 'avatar_default' ) ) ); } if ( ! defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) ) { define( 'BP_XPROFILE_FULLNAME_FIELD_NAME', stripslashes( bp_core_get_root_option( 'bp-xprofile-fullname-field-name' ) ) ); } /** * Filters the supported field type IDs. * * @since BuddyPress 1.1.0 * * @param array $value Array of IDs for the supported field types. */ $this->field_types = apply_filters( 'xprofile_field_types', array_keys( bp_xprofile_get_field_types() ) ); // 'option' is a special case. It is not a top-level field, so // does not have an associated BP_XProfile_Field_Type class, // but it must be whitelisted. $this->field_types[] = 'option'; // Register the visibility levels. See bp_xprofile_get_visibility_levels() to filter. $this->visibility_levels = array( 'public' => array( 'id' => 'public', 'label' => __( 'Public', 'buddyboss' ) ), 'adminsonly' => array( 'id' => 'adminsonly', 'label' => __( 'Only Me', 'buddyboss' ) ), 'loggedin' => array( 'id' => 'loggedin', 'label' => __( 'All Members', 'buddyboss' ) ) ); if ( bp_is_active( 'friends' ) ) { $this->visibility_levels['friends'] = array( 'id' => 'friends', 'label' => __( 'My Connections', 'buddyboss' ) ); } // Tables. $global_tables = array( 'table_name_data' => $bp->table_prefix . 'bp_xprofile_data', 'table_name_groups' => $bp->table_prefix . 'bp_xprofile_groups', 'table_name_fields' => $bp->table_prefix . 'bp_xprofile_fields', 'table_name_meta' => $bp->table_prefix . 'bp_xprofile_meta', ); $meta_tables = array( 'xprofile_group' => $bp->table_prefix . 'bp_xprofile_meta', 'xprofile_field' => $bp->table_prefix . 'bp_xprofile_meta', 'xprofile_data' => $bp->table_prefix . 'bp_xprofile_meta', ); $globals = array( 'slug' => BP_XPROFILE_SLUG, 'has_directory' => false, 'notification_callback' => 'xprofile_format_notifications', 'global_tables' => $global_tables, 'meta_tables' => $meta_tables, ); parent::setup_globals( $globals ); } /** * Set up navigation. * * @since BuddyPress 1.5.0 * * @global BuddyPress $bp The one true BuddyPress instance * * @param array $main_nav Array of main nav items to set up. * @param array $sub_nav Array of sub nav items to set up. */ public function setup_nav( $main_nav = array(), $sub_nav = array() ) { // Determine user to use. if ( bp_displayed_user_domain() ) { $user_domain = bp_displayed_user_domain(); } elseif ( bp_loggedin_user_domain() ) { $user_domain = bp_loggedin_user_domain(); } else { return; } $access = bp_core_can_edit_settings(); $slug = bp_get_profile_slug(); $profile_link = trailingslashit( $user_domain . $slug ); // Add 'Profile' to the main navigation. $main_nav = array( 'name' => __( 'Profile', 'buddyboss' ), 'slug' => $slug, 'position' => 20, 'screen_function' => 'xprofile_screen_display_profile', 'default_subnav_slug' => 'public', 'item_css_id' => $this->id ); // Add the subnav items to the profile. $sub_nav[] = array( 'name' => __( 'View', 'buddyboss' ), 'slug' => 'public', 'parent_url' => $profile_link, 'parent_slug' => $slug, 'screen_function' => 'xprofile_screen_display_profile', 'position' => 10 ); // Edit Profile. $sub_nav[] = array( 'name' => __( 'Edit', 'buddyboss' ), 'slug' => 'edit', 'parent_url' => $profile_link, 'parent_slug' => $slug, 'screen_function' => 'xprofile_screen_edit_profile', 'position' => 20, 'user_has_access' => $access ); // Change Avatar. if ( buddypress()->avatar->show_avatars ) { $sub_nav[] = array( 'name' => __( 'Profile Photo', 'buddyboss' ), 'slug' => 'change-avatar', 'parent_url' => $profile_link, 'parent_slug' => $slug, 'screen_function' => 'xprofile_screen_change_avatar', 'position' => 30, 'user_has_access' => $access ); } // Change cover photo. if ( bp_displayed_user_use_cover_image_header() ) { $sub_nav[] = array( 'name' => __( 'Cover Photo', 'buddyboss' ), 'slug' => 'change-cover-image', 'parent_url' => $profile_link, 'parent_slug' => $slug, 'screen_function' => 'xprofile_screen_change_cover_image', 'position' => 40, 'user_has_access' => $access ); } // The Settings > Profile nav item can only be set up after // the Settings component has run its own nav routine. add_action( 'bp_settings_setup_nav', array( $this, 'setup_settings_nav' ) ); parent::setup_nav( $main_nav, $sub_nav ); } /** * Set up the Settings > Profile nav item. * * Loaded in a separate method because the Settings component may not * be loaded in time for BP_XProfile_Component::setup_nav(). * * @since BuddyPress 2.1.0 */ public function setup_settings_nav() { if ( ! bp_is_active( 'settings' ) ) { return; } // Determine user to use. if ( bp_displayed_user_domain() ) { $user_domain = bp_displayed_user_domain(); } elseif ( bp_loggedin_user_domain() ) { $user_domain = bp_loggedin_user_domain(); } else { return; } // Get the settings slug. $settings_slug = bp_get_settings_slug(); bp_core_new_subnav_item( array( 'name' => __( 'Privacy', 'buddyboss' ), 'slug' => 'profile', 'parent_url' => trailingslashit( $user_domain . $settings_slug ), 'parent_slug' => $settings_slug, 'screen_function' => 'bp_xprofile_screen_settings', 'position' => 30, 'user_has_access' => bp_core_can_edit_settings() ), 'members' ); } /** * Set up the Admin Bar. * * @since BuddyPress 1.5.0 * * @param array $wp_admin_nav Admin Bar items. */ public function setup_admin_bar( $wp_admin_nav = array() ) { // Menus for logged in user. if ( is_user_logged_in() ) { // Profile link. $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() ); // Add the "Profile" sub menu. $wp_admin_nav[] = array( 'parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __( 'Profile', 'buddyboss' ), 'href' => $profile_link ); // View Profile. $wp_admin_nav[] = array( 'parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-public', 'title' => __( 'View', 'buddyboss' ), 'href' => $profile_link, 'position' => 10 ); // Edit Profile. $wp_admin_nav[] = array( 'parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-edit', 'title' => __( 'Edit', 'buddyboss' ), 'href' => trailingslashit( $profile_link . 'edit' ), 'position' => 20 ); // Edit Avatar. if ( buddypress()->avatar->show_avatars ) { $wp_admin_nav[] = array( 'parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-change-avatar', 'title' => __( 'Profile Photo', 'buddyboss' ), 'href' => trailingslashit( $profile_link . 'change-avatar' ), 'position' => 30 ); } if ( bp_displayed_user_use_cover_image_header() ) { $wp_admin_nav[] = array( 'parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-change-cover-image', 'title' => __( 'Cover Photo', 'buddyboss' ), 'href' => trailingslashit( $profile_link . 'change-cover-image' ), 'position' => 40 ); } } parent::setup_admin_bar( $wp_admin_nav ); } /** * Add custom hooks. * * @since BuddyPress 2.0.0 */ public function setup_hooks() { add_filter( 'bp_settings_admin_nav', array( $this, 'setup_settings_admin_nav' ), 2 ); } /** * Sets up the title for pages and . * * @since BuddyPress 1.5.0 */ public function setup_title() { if ( bp_is_profile_component() ) { $bp = buddypress(); if ( bp_is_my_profile() ) { $bp->bp_options_title = __( 'My Profile', 'buddyboss' ); } else { $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => bp_displayed_user_id(), 'type' => 'thumb', 'alt' => sprintf( __( 'Profile photo of %s', 'buddyboss' ), bp_get_displayed_user_fullname() ) ) ); $bp->bp_options_title = bp_get_displayed_user_fullname(); } } parent::setup_title(); } /** * Setup cache groups. * * @since BuddyPress 2.2.0 */ public function setup_cache_groups() { // Global groups. wp_cache_add_global_groups( array( 'bp_xprofile', 'bp_xprofile_data', 'bp_xprofile_fields', 'bp_xprofile_groups', 'xprofile_meta' ) ); parent::setup_cache_groups(); } /** * Adds "Settings > Profile" subnav item under the "Settings" adminbar menu. * * @since BuddyPress 2.0.0 * * @param array $wp_admin_nav The settings adminbar nav array. * @return array */ public function setup_settings_admin_nav( $wp_admin_nav ) { // Setup the logged in user variables. $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() ); // Add the "Profile" subnav item. $wp_admin_nav[] = array( 'parent' => 'my-account-' . buddypress()->settings->id, 'id' => 'my-account-' . buddypress()->settings->id . '-profile', 'title' => __( 'Privacy', 'buddyboss' ), 'href' => trailingslashit( $settings_link . 'profile' ), 'position' => 30 ); return $wp_admin_nav; } }</pre>
               </div>
               <p class="source-code-links"><span><a href="#" class="show-complete-source">展开完整的源代码</a><a href="#" class="less-complete-source">折叠全源代码</a></span></p>
              </section>
              <section class="changelog">
               <h3 id="ref-changelog" class="ref-context">更新日志<span id="ref-changelog-link" class="ref-context-link"></span></h3>
               <table>
                <caption class="screen-reader-text">
                 更新日志</caption>
                <thead>
                 <tr>
                  <th class="changelog-version">版本</th>
                  <th class="changelog-desc">描述</th>
                 </tr>
                </thead>
                <tbody>
                 <tr>
                  <td><a href="//www.zdfhmy.com/resources/reference/since/buddypress.1.5.0/" alt="WordPress BuddyPress 1.5.0">Buddypress 1.5.0.</a></td>
                  <td>介绍。</td>
                 </tr>
                </tbody>
               </table>
              </section>
              <section class="related">
               <h2 id="ref-related" class="ref-context">有关的<span id="ref-related-link" class="ref-context-link"></span></h2>
               <article class="uses">
                <h3>用途</h3>
                <table id="uses-table">
                 <caption class="screen-reader-text">
                  用途</caption>
                 <thead>
                  <tr>
                   <th>用途</th>
                   <th class="related-desc">描述</th>
                  </tr>
                 </thead>
                 <tbody>
                  <tr>
                   <td><span>bp-core / classes / class-bp-component.php:</span><a href="//www.zdfhmy.com/resources/reference/classes/bp_component/">BP_Component.</a></td>
                   <td class="related-desc"><p>Buddypress组件类。</p></td>
                  </tr>
                 </tbody>
                 <tbody></tbody>
                </table>
               </article>
              </section>
              <section class="class-methods">
               <h2 id="ref-methods" class="ref-context">方法<span id="ref-methods-link" class="ref-context-link"></span></h2>
               <ul>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/__construct/">__构造</a>- 启动Xprofile组件创建过程。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/includes/">包括</a>- 包括文件。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/late_includes/">laze_includes.</a>-后期包括方法。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/rest_api_init/">rest_api_init</a>-  initudeboss休息API。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/setup_admin_bar/">setup_admin_bar.</a>- 设置管理栏。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/setup_cache_groups/">setup_cache_groups.</a>- 设置缓存组。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/setup_globals/">setup_globals.</a>——设置全局变量。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/setup_hooks/">setup_hooks.</a>-添加自定义钩子。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/setup_nav/">setup_nav.</a>- 设置导航。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/setup_settings_admin_nav/">setup_settings_admin_nav</a>- 在“设置”adminbar菜单下添加“设置>配置文件”子区域。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/setup_settings_nav/">setup_settings_nav</a>- 设置设置>配置文件NAV项。</li>
                <li><a href="//www.zdfhmy.com/resources/reference/classes/bp_xprofile_component/setup_title/">setup_title.</a>- 为页面和页面设置标题。</li>
               </ul>
              </section>
              <section class="ref-feedback-wrap">
               <h3>问题?</h3>
               <p>我们总是很乐意帮助您可能拥有的代码或其他问题!搜索我们<a href="//www.zdfhmy.com/resources/reference/">开发人员文档</a>那<a href="//www.zdfhmy.com/my-account/?tab=helpscouttickets">联系支持</a>,或与我们联系<a href="//www.zdfhmy.com/buddypress-developers/">销售团队</a>。</p>
              </section>
             </div>
            </div>
           </div>
          </div>
         </article>
        </main>
        <!-- #main -->
       </div>
       <!-- #primary -->
      </div>
      <!-- #primary -->
     </div>
     <!-- .bb-grid -->
    </div>
    <!-- .container -->
   </div>
   <!-- #content -->
   <footer class="footer-bottom bb-footer style-1">
    <div class="container flex">
     <div class="footer-bottom-left">
      <div class="copyright">
       ©2021•BuddyBoss</div>
     </div>
     <div class="footer-bottom-right push-right"></div>
    </div>
   </footer>
  </div>
  <!-- #page -->
 <div style="text-align:center;margin-bottom:5px;"><form action="http://www.baidu.com/baidu" target="_blank"><div bgcolor="#FFFFFF" style="text-align:center;"><input name="tn" type="hidden" value="baidu"><a href="http://www.baidu.com/"><img src="http://img.baidu.com/img/logo-80px.gif" width="80px" height="29px" alt="Baidu" align="bottom" border="0"></a><input type="text" name="word" size="30" placeholder="" value=""><input type="submit" value="百度搜索"></div></form></div><div id="so360" style="text-align:center;margin-bottom:5px;"><form action="https://www.so.com/" target="_blank" id="so360form"><img src="http://p1.qhimg.com/d/_onebox/search.png" width="100px" height="25px"> <input type="text" autocomplete="off" name="q" id="so360_keyword" placeholder="" value="">  <input type="submit" id="so360_submit" value="360搜索"> <input type="hidden" name="ie" value="gbk"><input type="hidden" name="src" value="zz"> <input type="hidden" name="site" value="so.com"> <input type="hidden" name="rg" value="1"></form></div><div id="sogou" style="text-align:center;margin-bottom:5px;"><form action="https://www.sogou.com/" target="_blank" id="so360form"><img src="https://www.sogou.com/web/index/images/logo_440x140.v.4.png" width="100px" height="25px"> <input type="text" autocomplete="off" name="q" id="sogou.com_keyword" placeholder="" value="">  <input type="submit" id="sogou_submit" value="搜 狗"> <input type="hidden" name="ie" value="gbk"><input type="hidden" name="src" value="zz"> <input type="hidden" name="site" value="so.com"> <input type="hidden" name="rg" value="1"></form></div></body>
</html>