Use hook_node_access_records and hook_node_grants (graphical combination (personal understanding is not authoritative, for reference only) to replace hook_node_access
1. First, we will introduce hook_node_access. It uses code writing to determine whether the user has the permission to access, edit, and delete a node, as shown below:
function modulename_node_access($node, $op, $account) {
// Here, the following results are returned based on your conditions.
return NODE_ACCESS_IGNORE;
<pre name="code" class="php"> return NODE_ACCESS_DENY;
return NODE_ACCESS_ALLOW;
}
2. Use the graphical combination of hook_node_access_records and hook_node_grants.
First, declare the hook_node_grants hook to be called in the following three cases of node, and add the corresponding records to the node_access Table, as follows:
The three functions are in node. module.
Node_save
Node_access_rebuild contains a batch (_ node_access_rebuild_batch_operation)
function modulename_node_access_records($node) {
$grants[] = array(
'realm' => 'node_access_custom_edit',
'gid' => $gid,
'grant_view' => 1,
'grant_update' => 1,
'grant_delete' => 1,
'priority' => 0,
);
</pre><p></p><p></p><pre name="code" class="php"> $grants[] = array(
'realm' => 'node_access_custom_author',
'gid' => $node->uid,
'grant_view' => 1,
'grant_update' => 1,
'grant_delete' => 1,
'priority' => 0,
);
return $grants;
}
Second, permission comparison:
Use this function in hook_node_access
Module_implements ('node _ grants') implements all node_grants as follows:
Function node_access_example_node_grants ($ account, $ OP ){
$ Grants = array ();
// First grant a grant to the author for own content.
// Do not grant to anonymous user else all anonymous users wocould be author.
If ($ account-> UID ){
$ Grants ['node _ access_example_author '] = array ($ account-> UID );
}
// Then, if "access any private content" is allowed to the account,
// Grant view, update, or Delete as necessary.
If ($ op = 'view' & user_access ('Access any private content', $ account )){
$ Grants ['node _ access_example_view '] = array (node_access_example_grant_all );
}
If ($ op = 'update' | $ op = 'delete') & user_access ('edit any private content', $ account )){
$ Grants ['node _ access_example_edit '] = array (node_access_example_grant_all );
}
Return $ grants;
}
Perform real GID as a group of multiple conditions for obtaining or. For details, see node_access function implementation,
For the rest, you just need to configure the graphic interface in the background.