我正在做一个令人沮丧的项目,需要帮助。我需要从正在查看的个人资料页面中获取$user_id,并将该值插入到短码的id = "_“$atts字段中。我使用终极会员作为我的会员插件。我需要插入$user_id的短码如下所示...
echo do_shortcode( '[aiovg_user_videos id=" '.$user_id.' "]' ); }
该快捷代码将进入一个名为" videos“的个人资料选项卡中,该选项卡中将包含用户上传和导入的视频。到目前为止,我想出的是,尽管它还没有工作,如下所示…
add_filter('um_profile_tabs', 'videos_tab', 1000 );
function videos_tab( $tabs ) {
$tabs['videos'] = array(
'name' => 'Videos',
'icon' => 'um-icon-ios-videocam',
'custom' => true
);
return $tabs;
}
/* Tell the tab what to display */
// If is current user's profile (profile.php)
if ( defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE ) {
$user_id = get_current_user_id();
// If is another user's profile page
} elseif (! empty($_GET['user_id']) && is_numeric($_GET['user_id']) ) {
$user_id = $_GET['user_id'];
echo do_shortcode( "[aiovg_user_videos id=" . $user_id . "]" ); }我不是一个程序员,但我正在学习,所以我真的不知道我还需要什么才能实现这一点。我尝试了很多东西,这些东西让我一次又一次地出错。简单地说,我想让快捷码从正在查看的用户配置文件中抓取用户id,这样我就可以显示自动填写id的快捷码。
更新:
以下是插件中videos.php文件的原始代码...
* Run the shortcode [aiovg_user_videos].
*
* @since 1.0.0
* @param array $atts An associative array of attributes.
*/
public function run_shortcode_user_videos( $atts ) {
$user_slug = get_query_var( 'aiovg_user' );
$content = '';
if ( empty( $user_slug ) ) {
if ( ! empty( $atts['id'] ) ) {
$user_slug = get_the_author_meta( 'user_nicename', (int) $atts['id'] );
} elseif ( is_user_logged_in() ) {
$user_slug = get_the_author_meta( 'user_nicename', get_current_user_id() );
}
}
if ( ! empty( $user_slug ) ) {
$attributes = shortcode_atts( $this->get_defaults(), $atts );
$attributes['user_slug'] = $user_slug;
$content = $this->get_content( $attributes );
}
if ( empty( $content ) ) {
$content = aiovg_get_message( 'videos_empty' );
}
return $content;
}它所做的是从帖子的作者中拉出昵称,所以当你点击作者的名字时,它会将其添加到这个url的末尾:https://hairbowtutorials.com/user-videos/NICENAME。但如果你将id添加到短代码中,你可以将它放在任何页面上,它将显示来自该人的视频。我想将此短代码添加到配置文件页面,并让id根据它所在的配置文件自动填写。我不确定这是否可能,或者我是否需要创建一个全新的短码。但这是开发商给我的.
“你只需要使用下面的模板函数并动态构建短码,
<?php
$member_user_id = 1;
echo do_shortcode( "[aiovg_user_videos id=" . $member_user_id . "]" );
?>您只需找到成员配置文件的用户id并将其存储在$member_user_id变量中即可。
更新2:这是终极会员用来从个人资料中获取帖子的内容。我想我可以用类似的方法来设置它...
<?php if ( ! defined( 'ABSPATH' ) ) exit;
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
//Only for AJAX loading posts
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
UM()->get_template( 'profile/posts-single.php', '', array( 'post' => $post ), true );
}
}
} else {
if ( ! empty( $posts ) ) { ?>
<div class="um-ajax-items">
<?php foreach ( $posts as $post ) {
UM()->get_template( 'profile/posts-single.php', '', array( 'post' => $post ), true );
}
if ( $count_posts > 10 ) { ?>
<div class="um-load-items">
<a href="javascript:void(0);" class="um-ajax-paginate um-button" data-hook="um_load_posts"
data-author="<?php echo esc_attr( um_get_requested_user() ); ?>" data-page="1"
data-pages="<?php echo esc_attr( ceil( $count_posts / 10 ) ); ?>">
<?php _e( 'load more posts', 'ultimate-member' ); ?>
</a>
</div>
<?php } ?>
</div>
<?php } else { ?>
<div class="um-profile-note">
<span>
<?php if ( um_profile_id() == get_current_user_id() ) {
_e( 'You have not created any posts.', 'ultimate-member' );
} else {
_e( 'This user has not created any posts.', 'ultimate-member' );
} ?>
</span>
</div>
<?php }
}发布于 2020-06-16 08:41:53
所以它可能就像这样简单:
//very close to your initial code
add_filter( 'um_profile_tabs', 'um_videos_tab', 1000 );
function um_videos_tab( $tabs ) {
$tabs['videos'] = array(
'name' => 'Videos',
'icon' => 'um-icon-ios-videocam',
'custom' => true
) ;
return $tabs ;
}
//profile tab content
//based on how it appears UM has set up its action hooks
add_action( 'um_profile_content_videos', 'um_profile_content_videos' ) ;
function um_profile_content_videos() {
//got to watch the apostrophes vs quotes so things don't get mixed up
echo do_shortcode( ' [aiovg_user_videos id="' . um_profile_id() . '"] ' ) ;
}我的不确定性在一定程度上是基于这样一个事实:我既没有UM,也没有生成aiovg_user_videos短码的工具,因此无法进行测试或调试。考虑到我有点盲目,在深入研究UM代码之前,我的下一次尝试是在add_action语句中的“标记”和“处理程序”中添加_default -所以add_action( 'um_profile_content_videos_default', 'um_profile_content_videos_default' ) ;只是为了防止这是这些钩子的需要。
发布于 2020-06-16 09:33:40
我终于想通了!这就是最终成功的方法!!
/**
* Add a new Profile tab
* @param array $tabs
* @return array
*/
function um_videos_add_tab( $tabs ) {
$tabs[ 'videos' ] = array(
'name' => 'Videos',
'icon' => 'um-icon-ios-videocam',
'custom' => true
);
UM()->options()->options[ 'profile_tab_' . 'videos' ] = true;
return $tabs;
}
add_filter( 'um_profile_tabs', 'um_videos_add_tab', 1000 );
/**
* Render tab content
* @param array $args
*/
function um_profile_content_videos_default( $args ) {
/* START. You can paste your content here, it's just an example. */
$action = 'videos';
$member_user_id = um_get_requested_user();
echo do_shortcode( "[aiovg_user_videos id=" . $member_user_id . "]" );
/* END. You can paste your content here, it's just an example. */
}
add_action( 'um_profile_content_videos_default', 'um_profile_content_videos_default' );https://stackoverflow.com/questions/62355855
复制相似问题