Disable "quick edit" for specific pages in functions.php

I know how to remove quick edit and/or other page actions for all pages in the WordPress Pages list. Now, I need to be more specific and remove certain actions from specific pages.

I can hide actions for specific pages using CSS, but would prefer to remove the source code entirely.

The following code will remove the quick edit, edit and beaver builder page action. It is not unique and referenced many times in other responses:

add_filter( 'page_row_actions', 'remove_page_row_actions', 10, 1 );
function remove_page_row_actions( $actions ) {
  if( get_post_type() == 'page' ) {
    unset( $actions['inline hide-if-no-js'] );
    unset( $actions['edit'] );
    unset( $actions['fl-builder'] );
  }
  return $actions;
}

I want to extend my if statement to include specific pages (or post ids), however I am not having any success when attempting to call/reference a post_id.

Is it possible to remove actions from a specific post id, e.g. 222?

Topic row-actions Wordpress

Category Web


To reference the post ID you need the post object itself.

<?php
// Increase the number of arguments passed.
add_filter( 'page_row_actions', 'remove_page_row_actions', 10, 2 ); // 2, not 1

// pass $post object as second argument.
function remove_page_row_actions( $actions, $post ) {

    $post_types_affected = array('page');
    $post_ids_affected   = array( 111, 222 );

    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['fl-builder'] );
    }
    return $actions;
}

Don't forget that page_row_actions filter is intended for non-hierarchical post types. Use post_row_actions for hierarchical ones.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.