我在WordPress中使用Yoast SEO插件,并想知道是否有一种方法可以让它只对数据库中的一个特定用户或functions.php文件可见?不是一个角色,一个实际的用户。只对特定用户可见的WordPress SEO插件
0
A
回答
1
我试过一个通用的解决方案,只需添加“插件名称”并将其禁用,但失败。
但是,以示WPSEO只给特定用户(ID
等于2
),以下工作:
add_action('plugins_loaded', 'seo_so_25654837');
function seo_so_25654837()
{
if ('2' == get_current_user_id())
return;
remove_action('plugins_loaded', 'wpseo_admin_init', 15);
}
代码不添加到functions.php
,使用它作为一个normal plugin。
下还需要去除从管理栏的搜索引擎优化的菜单:
add_action('wp_before_admin_bar_render', 'bar_so_25654837');
function bar_so_25654837()
{
if ('2' == get_current_user_id())
return;
global $wp_admin_bar;
$nodes = $wp_admin_bar->get_nodes();
foreach($nodes as $node)
{
if(!$node->parent)
{
if('wpseo-menu' === $node->id)
$wp_admin_bar->remove_menu($node->id);
}
}
}
+0
太棒了!我用你的php代码创建了一个插件,它完美地工作。谢谢你的帮助。 – Brendan 2014-09-04 15:24:37
0
您可以挂钩到pre_current_active_plugins
以在显示表格之前从表格中移除元素。在函数内使用get_current_user_id()
可让您选择性地隐藏插件。
function hide_plugins_by_user($all_plugins=false) {
global $wp_list_table;
// if the current user ID is not 1, hide it.
if (1 != get_current_user_id()){
// the active plugins from the table
$plugins = $wp_list_table->items;
// loop through them
foreach ($plugins as $key => $val) {
// use the dir + filename of the plugin to hide
if ($key == 'plugindir/plugin.php') {
unset($wp_list_table->items[$key]);
}
}
}
}
add_action('pre_current_active_plugins', 'hide_plugins_by_user');
0
此代码工作正常(现金去Hislop):
// Returns true if user has specific role
function check_user_role($role, $user_id = null) {
if (is_numeric($user_id))
$user = get_userdata($user_id);
else
$user = wp_get_current_user();
if (empty($user))
return false;
return in_array($role, (array) $user->roles);
}
// Disable WordPress SEO meta box for all roles other than administrator and seo
function wpse_init(){
if(!(check_user_role('seo') || check_user_role('administrator'))){
// Remove page analysis columns from post lists, also SEO status on post editor
add_filter('wpseo_use_page_analysis', '__return_false');
// Remove Yoast meta boxes
add_action('add_meta_boxes', 'disable_seo_metabox', 100000);
}
}
add_action('init', 'wpse_init');
function disable_seo_metabox(){
remove_meta_box('wpseo_meta', 'post', 'normal');
remove_meta_box('wpseo_meta', 'page', 'normal');
}
只需将它放在functions.php文件。
0
要禁用所有用户的Yoast,并为少数或特定用户启用它,只需将以下代码添加到您的function.php文件中即可。
function remove_wpseo(){
/* if you want to keep it enabled for user with id 2 */
if ('2' == get_current_user_id()) {
return;
}
global $wpseo_front;
if(defined($wpseo_front)){
remove_action('wp_head',array($wpseo_front,'head'),1);
}
else {
$wp_thing = WPSEO_Frontend::get_instance();
remove_action('wp_head',array($wp_thing,'head'),1);
}
}
add_action('template_redirect','remove_wpseo');
参考:https://makersbyte.com/disable-yoast-seo-plugin-specific-page/
相关问题
- 1. 如何使Web部件对SharePoint中的特定用户可见?
- 2. MVC表行只对用户可见
- 3. 的WordPress:使用测试主题只为特定用户
- 4. 禁用特定主题的WordPress插件
- 5. 安装仅对特定用户可见的SQL Server数据库
- 6. WordPress的 - 授予特定的插件访问用户
- 7. 使元素对用户可见,但对事件不可见
- 8. WordPress Yoast SEO插件和opengraph标签
- 9. 如何让网站对特定用户可见?
- 10. 禁用WordPress的特定用户,并防止该用户不使用插件
- 11. Javascript LinkedIn API只读对特定用户
- 12. Protect int,只对指定方法可见
- 13. 用户能力限制访问特定页面只在wordpress
- 14. 只针对特定容器的自定义jQuery插件
- 15. WordPress的3插件来控制小部件的可见性
- 16. 只允许特定用户角色登录WordPress网站
- 17. 在WPF中,如何确定控件是否对用户可见?
- 18. 如何创建用户特定的内容,这对他人是不可见的?
- 19. angularjs只在特定的WordPress的帖子
- 20. Wordpress-如何只为特定页面的标题插入代码?
- 21. 在wordpress插件中获得特殊角色的用户
- 22. 如何才能让广告只对移动用户可见?
- 23. 限制特定WordPress用户对PHP脚本的访问
- 24. Yoast SEO(WordPress的插件) - 获取插件生成的数据手动
- 25. 插入公式只可见细胞
- 26. update_post_meta WordPress的Yoast SEO
- 27. SEO帮助| WordPress的
- 28. 使窗户只能运行一个用户可见的程序
- 29. Wordpress Seo功能
- 30. Wordpress SEO功能
从我的头顶,你可以替换检查与功能检查当前用户的ID,如capabilties功能:'get_current_user_id',它的只是和如果和身份证。 – 2014-09-03 23:01:13