feat: lit/library-save creates library entries like Divi (E4)
Reuses NewDraft for insert and rollback (P6), requires edit_global_library for scope global (P7), refuses opaque and global roots before wrapping (P11) and checks the node with StoredNodeGuard. The source page is never written. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -120,6 +120,34 @@ class LibraryAccess
|
||||
return $this->isGlobal($item) ? $this->roles->refusal('edit_global_library') : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating an entry: canList(), publish_posts of et_pb_layout (library entries are always
|
||||
* published, F2), the role option save_library and the Tools-tab gate; a global entry
|
||||
* additionally edit_global_library (ruling P7 – the same option as for editing one, F12).
|
||||
*/
|
||||
public function canSave(bool $global = false): ?WP_Error
|
||||
{
|
||||
$refusal = $this->canList();
|
||||
if ($refusal !== null) {
|
||||
return $refusal;
|
||||
}
|
||||
|
||||
$type = get_post_type_object(DiviLibraryStore::POST_TYPE);
|
||||
$publish = is_object($type) && isset($type->cap->publish_posts)
|
||||
? (string) $type->cap->publish_posts
|
||||
: 'publish_posts';
|
||||
if (! current_user_can($publish)) {
|
||||
return Errors::forbidden('Keine Berechtigung, Einträge der Divi-Bibliothek anzulegen (publish_posts).');
|
||||
}
|
||||
|
||||
$refusal = $this->roles->refusal('save_library') ?? $this->writableGate();
|
||||
if ($refusal !== null || ! $global) {
|
||||
return $refusal;
|
||||
}
|
||||
|
||||
return $this->roles->refusal('edit_global_library');
|
||||
}
|
||||
|
||||
/** Refusal while the Tools tab keeps this connection from writing to the library. */
|
||||
public function writableGate(): ?WP_Error
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user