我已将代码分为第1部分、第2部分和第3部分
第1部分和第2部分工作正常。。。他们正在检查帖子类型并扫描元数据
只有第三部分我完全没有收到账单
/*remove Edit Trash, and quickedit of pages with specific metavalues for certain roles
*/
add_filter( \'page_row_actions\', \'remove_page_row_actions\', 10, 2 ); // 2, not 1
add_filter( \'post_row_actions\', \'remove_page_row_actions\', 10, 2 ); // 2, not 1
// pass $post object as second argument.
function remove_page_row_actions( $actions, $post ) {
//PART 1 SPECIFY USERS
global $current_user;
get_currentuserinfo();
if(
(
//specify roles except administrator (but you need to add child roles based off administrator ex. adminsub)
(
!current_user_can(\'administrator\')
||
current_user_can(\'adminsub\')
)
||
// specify a list of role(s)
(
current_user_can(\'adminsub\')
||
current_user_can(\'author\')
)
)
)
{
// PART 2 SEARCH WHICH TYPES OF POSTS TO GET A SPECIFIC METADATA FROM
$post_types_affected = array(\'page\' , \'post\'); // I ADDED POST HERE STILL WORKS
// print_r($post_types_affected); // use this to see which posts are affected
//only get post IDs for a metavalue which has ALL of the following EXACT values (I changed it to just 1)
//$array_of_values_to_match = array( \'1\', \'1\', \'1\' );
$array_of_values_to_match = array( 1 );
$metakey_to_match = \'checkboxmeta1\';
$args = array(
\'post_type\' => get_post_types(),
\'meta_query\' => array(),
\'numberposts\' => -1,
);
// if there\'s more than 1 value, add the relation arg
if( 1 < count( $array_of_values_to_match ) ){
$args[\'meta_query\'][\'relation\'] = \'AND\';
}
// for each of the array values, add a meta query for that value
foreach( $array_of_values_to_match as $val ){
$args[\'meta_query\'][] = array(
\'key\' => $metakey_to_match,
\'value\' => $val,
\'compare\' => \'=\'
);
}
$postlistarray = get_posts( $args );
//end of function which an array or post arrays which each contain a post ID and a metakey of 1
//must create an array column, becuase that is what $x = array(111,212) does
$post_ids_affected = array_column($postlistarray, \'ID\');
//PART 3 check array_column for post IDs, and remove functionality below from posts which had the metadata
if ( in_array( $post->post_type, $post_types_affected )
&& in_array( $post->ID, $post_ids_affected ) ) {
unset( $actions[\'inline hide-if-no-js\'] );
unset( $actions[\'edit\'] );
unset( $actions[\'trash\'] );
unset( $actions[\'pa_duplicator\'] );
}
}
return $actions;
}
我想做的是针对1中的这些角色,当与2中的帖子交互时,我想删除所有编辑和垃圾功能。
所以很明显,现在我刚刚删除了一些操作,比如编辑和快速编辑。。但我刚刚意识到用户只需点击页面编辑即可。php链接,甚至只是将url更改为soemthinglikehttps://mywebsite/wp-admin/post.php?post=2752&;操作=编辑
或
通过URL或其他方法远程丢弃或编辑它。。
如何完全删除第3部分中该角色的编辑和垃圾功能,使其仅显示视图?或许可以查看和评论中庸?
我希望我没有浪费太多的时间去尝试挂接page\\u row\\u操作和post\\u row\\u操作lol。。。也许我需要将此代码挂接到admin\\u init或wp\\u trash\\u post或wp\\u edit\\u post?但我有点不知所措,不知道这些是怎么回事,也不知道这些论点是什么。