0

我希望这个论坛上的某个人可以帮助我创建我正在尝试为 Buddypress 创建的自定义头像上传页面。提前为这封冗长的电子邮件道歉,但我想尽可能清楚,希望能得到一个明确而具体的答案:)

该页面是用户在注册网站后完成的三步“开始”过程的一部分(1. 填写个人资料字段 2. 上传头像 3. 邀请朋友)。

我不是代码专家,但我已经通过分别从 profile/edit.php 和invite-anyone/by-email/by-email.php 文件中复制和编辑代码来对第 1 步和第 3 步进行排序,然后执行重定向 onsubmit 到下一步。

为了使第 1 步正常工作,我还必须编辑 bp-xprofile-template.php 文件以包含 if is_page ... else ... 以便页面使用loggedin_user 而不是displayed_user。

通过第 2 步,我的页面显示正确,但是在我为头像选择图像并点击上传后,页面刷新并且没有进行裁剪,如果您在 change-avatar 上上传头像就会这样做个人资料中的页面。

如果我将表单操作更改为重定向到登录用户配置文件中的更改头像页面(默认情况下没有操作),则会出现裁剪,但我不想让用户离开“步骤”。

我想也许我需要更改 bp-core-template.php 中的 avatar_admin 函数集中的某些内容,以便它可以在其他页面上运行,但这并没有超出我的能力范围。我真的希望有人能帮助解决这个问题,因为这是完成这个过程的最后一道障碍。

下面是 change-avatar.php 的代码,这是我已经复制并尝试在自定义页面上工作的代码。我的页面在“if ('crop-image' == bp_get_avatar_admin_step()”处停止正常工作。提前致谢。

    <h4><?php _e( 'Change Avatar', 'buddypress' ) ?></h4>

<?php do_action( 'bp_before_profile_avatar_upload_content' ) ?>

<?php if ( !(int)bp_get_option( 'bp-disable-avatar-uploads' ) ) : ?>

    <p><?php _e( 'Your avatar will be used on your profile and throughout the site. If there is a <a href="http://gravatar.com">Gravatar</a> associated with your account email we will use that, or you can upload an image from your computer.', 'buddypress') ?></p>

    <form action="" method="post" id="avatar-upload-form" class="standard-form" enctype="multipart/form-data">

        <?php if ( 'upload-image' == bp_get_avatar_admin_step() ) : ?>

            <?php wp_nonce_field( 'bp_avatar_upload' ) ?>
            <p><?php _e( 'Click below to select a JPG, GIF or PNG format photo from your computer and then click \'Upload Image\' to proceed.', 'buddypress' ) ?></p>

            <p id="avatar-upload">
                <input type="file" name="file" id="file" />
                <input type="submit" name="upload" id="upload" value="<?php _e( 'Upload Image', 'buddypress' ) ?>" />
                <input type="hidden" name="action" id="action" value="bp_avatar_upload" />
            </p>

            <?php if ( bp_get_user_has_avatar() ) : ?>
                <p><?php _e( "If you'd like to delete your current avatar but not upload a new one, please use the delete avatar button.", 'buddypress' ) ?></p>
                <p><a class="button edit" href="<?php bp_avatar_delete_link() ?>" title="<?php _e( 'Delete Avatar', 'buddypress' ) ?>"><?php _e( 'Delete My Avatar', 'buddypress' ) ?></a></p>
            <?php endif; ?>

        <?php endif; ?>

        <?php if ( 'crop-image' == bp_get_avatar_admin_step() ) : ?>

            <h5><?php _e( 'Crop Your New Avatar', 'buddypress' ) ?></h5>

            <img src="<?php bp_avatar_to_crop() ?>" id="avatar-to-crop" class="avatar" alt="<?php _e( 'Avatar to crop', 'buddypress' ) ?>" />

            <div id="avatar-crop-pane">
                <img src="<?php bp_avatar_to_crop() ?>" id="avatar-crop-preview" class="avatar" alt="<?php _e( 'Avatar preview', 'buddypress' ) ?>" />
            </div>

            <input type="submit" name="avatar-crop-submit" id="avatar-crop-submit" value="<?php _e( 'Crop Image', 'buddypress' ) ?>" />

            <input type="hidden" name="image_src" id="image_src" value="<?php bp_avatar_to_crop_src() ?>" />
            <input type="hidden" id="x" name="x" />
            <input type="hidden" id="y" name="y" />
            <input type="hidden" id="w" name="w" />
            <input type="hidden" id="h" name="h" />

            <?php wp_nonce_field( 'bp_avatar_cropstore' ) ?>

        <?php endif; ?>

    </form>

<?php else : ?>

    <p><?php _e( 'Your avatar will be used on your profile and throughout the site. To change your avatar, please create an account with <a href="http://gravatar.com">Gravatar</a> using the same email address as you used to register with this site.', 'buddypress' ) ?></p>

<?php endif; ?>

<?php do_action( 'bp_after_profile_avatar_upload_content' ) ?>
4

3 回答 3

0

感谢您提供有用的建议。只是要补充一点,@Zenvied 的建议效果很好。唯一的事情是我必须添加我自己的“bp_core_add_cropper_inline_js()”和“bp_core_add_cropper_inline_css()”实现,然后从我的“xprofile_screen_change_avatar()”实现中调用它们。所以代替这个:

 wp_enqueue_style( 'jcrop' );
 wp_enqueue_script( 'jcrop', array( 'jquery' ) );
 add_action( 'wp_footer', 'bp_core_add_cropper_inline_js' );
 add_action( 'wp_footer', 'bp_core_add_cropper_inline_css' );

我这样做了:

self::bp_custom_core_add_cropper_inline_css();
self::bp_custom_core_add_cropper_inline_js();
wp_enqueue_style( 'jcrop' );
wp_enqueue_script( 'jcrop', array( 'jquery' ) );

希望这对某人有帮助!:-)

于 2014-05-05T14:53:02.093 回答
0

我刚刚完成了实现我自己的自定义头像页面的工作,并且遇到了同样的问题。我想我实际上已经失去了头发。哈哈。我最终调整了我的代码,以确保 bp 仍然可以通过获取一些相关代码块并将其构建到一个新函数中作为我主题的一部分来升级。

问题是隐藏的提交值 'w' 是许多wordpress 保留条款之一。

<input type="hidden" name="image_src" id="image_src" value="<?php bp_avatar_to_crop_src(); ?>" />
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />

您需要将此值更改为其他任何值,然后实现您自己的处理函数版本:

buddypress/bp-xprofile/bp-xprofile-screens.php->xprofile_screen_change_avatar();

另外,也许还有更好的方法,但是为了使裁剪工作,我必须对

bp_core_add_jquery_cropper(){
 wp_enqueue_style( 'jcrop' );
 wp_enqueue_script( 'jcrop', array( 'jquery' ) );
 add_action( 'wp_head', 'bp_core_add_cropper_inline_js' );
 add_action( 'wp_head', 'bp_core_add_cropper_inline_css' );
}

 wp_enqueue_style( 'jcrop' );
 wp_enqueue_script( 'jcrop', array( 'jquery' ) );
 add_action( 'wp_footer', 'bp_core_add_cropper_inline_js' );
 add_action( 'wp_footer', 'bp_core_add_cropper_inline_css' );

在我自己的 profile_screen_change_avatar() 实现中。

希望这对您或其他人仍然有用。让我知道这一切是否有意义(好与否;))。

于 2014-02-13T19:17:58.510 回答
0

我的页面在“if ('crop-image' == bp_get_avatar_admin_step()”处停止正常工作

那么 bp_get_avatar_admin_step() = 在那一点上是什么?回显出来看看。

头像真的上传了吗?如果是这样,您必须弄清楚如何推进 admin_step。

我想也许我需要更改 bp-core-template.php 中的 avatar_admin 函数集中的某些内容,但这并不超出我的能力范围

与其改变,不如弄清楚它们是如何被调用的。

于 2012-05-16T14:20:47.577 回答