【发布时间】:2020-03-03 03:19:59
【问题描述】:
下午好开发人员,我开发了一个项目,其中包含用户个人资料,其中包含使用 ACF 字段创建的记录,包括图片库字段,我的问题是......因为我只使用一个页面来显示此个人资料,图片库即使使用“附加到帖子”选项也可以共享,因为我只使用一个页面,例如“/profile?userid=userid”。
还有其他好的做法吗?
我想要建议。
零件轮廓编辑
function acf_profile_edit( $atts ) {
$a = shortcode_atts( array(
'field_group' => ''
), $atts );
$uid = get_current_user_id();
if ( ! empty ( $a['field_group'] ) && ! empty ( $uid ) ) {
$options = array(
'post_id' => 'user_'.$uid,
'field_groups' => array( intval( $a['field_group'] ) ),
'return' => add_query_arg( 'updated', 'true', get_permalink() )
);
ob_start();
acf_form( $options );
$form = ob_get_contents();
ob_end_clean();
}
return $form;
}
add_shortcode( 'profile_edit', 'acf_profile_edit' );
编辑... 这段代码解决了我的问题
add_filter('ajax_query_attachments_args', 'restrict_images_to_user');
function restrict_images_to_user($query) {
$gallery_images = 'field_5e4d799b34145';
$gallery_videos = 'field_5e5597e37f2c7';
if ( isset($_POST['query']['_acfuploader'] )
&& ( isset($_POST['query']['_acfuploader']) == $gallery_images || isset($_POST['query']['_acfuploader']) == $gallery_videos ) ) {
$author = get_current_user_id();
$query['author'] = $author;
}
return $query;
}
【问题讨论】:
-
如果你使用 userid=userid 怎么能不被黑?
-
感谢您的回答,在“/profile?userid=userid”的情况下,我只在显示个人资料页面上使用它,在编辑页面上我使用 word_press 函数 get_current_user_id()。我编辑了答案
标签: wordpress advanced-custom-fields