Site icon Hip-Hop Website Design and Development

how to dynamically remove all edit and delete functionality of a page

I have split up my code into part 1 , part 2, and part 3

part 1 and 2 are working just fine… they are checking post types and scanning for metadata

Its only Part 3 that I am completely missing the bill

/*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;
}

what I am trying to do is for these roles from 1 when interacting with posts from 2, I want to remove ALL EDIT and TRASH capabilities.

so obviously right now ive just removed some actions lol such as edit and quickedit.. but I just realized the user can just click on the page edit.php link, or even just change the url to soemthing like
https://mywebsite/wp-admin/post.php?post=2752&action=edit

or

remotely trash or edit it some other way through URL or other method..

how do I just completely remove the edit and trash capability of that role for part 3, so that its view only? and maybe view and comment moderation?

I hope I didnt waste alot of time by trying to hook into page_row_actions and post_row_actions lol… maybe I need to be hooking this code into like admin_init or wp_trash_post or wp_edit_post? but I am sort of a noob and dont know how those work, or what the arguments are.