在另一个bp页面上使用buddypress头像上传和裁剪功能 [英] Using buddypress avatar upload and crop function on another bp page

查看:269
本文介绍了在另一个bp页面上使用buddypress头像上传和裁剪功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用BP Avatar在网站上创建用户个人资料图片。

Currently I am using BP Avatar to create user profile picture in the website.

现在,我想将BP Avatar的上传和裁剪+预览功能用于另一个页面,并使用自定义设置另一个图像用途。

Now, I want to use the upload and crop + preview function of BP Avatar for another page and another image purpose with custom settings also.

我试图在新页面中复制和编辑代码,但它无法工作,甚至是预览。

I have tried to copy and edit the code in the new page but it can't work, even the preview.

希望有人可以帮助。

谢谢。

推荐答案

这是代码。当bbp没有检测到用户时,我发现问题就开始了,因为在bbp核心中,他们从url获取用户id,而在我的情况下,它不起作用。我编写了需要完成的代码片段。在我的情况下,我将端点内的视图插入到woocommerce的my-account中。

Here is the code. I detect the problems start when bbp not detect the user because in the bbp core they get the user id from url, and in my case that dont work. I number the need pieces of code to accomplish. In my case i insert the view inside an endpoint to my-account from woocommerce.


  1. 覆盖脚本获取数据的功能。

  2. 包含所有必需的脚本。

  3. 插入我的内容功能。

我将此过滤器用于 bp_attachment_avatar_script_data

    /**
     * Override  the avatar script data
     *
     * @param $script_data
     * @param $object
     *
     * @return int
     */
    public function noys_avatar_script_data( $script_data, $object ) {
        $user_id  = get_current_user_id();

        if ( ! empty( $user_id ) ) {
            // Should we load the the Webcam Avatar javascript file.
            if ( bp_avatar_use_webcam() ) {
                $script_data['extra_js'] = array_merge( $script_data['extra_js'], array( 'bp-webcam' ) );
            }

            $script_data['bp_params'] = array(
                'object'     => 'user',
                'item_id'    => $user_id,
                'has_avatar' => bp_get_user_has_avatar( $user_id ),
                'nonces'     => array(
                    'set'    => wp_create_nonce( 'bp_avatar_cropstore' ),
                    'remove' => wp_create_nonce( 'bp_delete_avatar_link' ),
                ),
            );

            // Set feedback messages.
            $script_data['feedback_messages'] = array(
                1 => __( 'There was a problem cropping your profile photo.', 'buddypress' ),
                2 => __( 'Your new profile photo was uploaded successfully.', 'buddypress' ),
                3 => __( 'There was a problem deleting your profile photo. Please try again.', 'buddypress' ),
                4 => __( 'Your profile photo was deleted successfully!', 'buddypress' ),
            );
        }

        return $script_data;
    }

这是我将内容包含在woocommerce端点的功能。

And this is my function to include the content to woocommerce endpoint.

/**
 * Endpoint HTML content.
 */
public function profile_picture_endpoints_content1() {
    $bd = buddypress();
    bp_core_register_common_scripts();
    wp_enqueue_style( 'thickbox' );
    wp_enqueue_script( 'media-upload' );

    bp_core_add_jquery_cropper();

    bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
    bp_attachments_get_template_part( 'avatars/index' );
}

这就是解决这个无证问题所需的全部内容!

That is all i need to resolve this undocumented problem!

这篇关于在另一个bp页面上使用buddypress头像上传和裁剪功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆