PHP API
All methods are static and available after init.
php// Get all snippets
$snippets = OCI_Snippets::get_all();
// Get a single snippet
$snippet = OCI_Snippets::get_by_id( 'uuid' );
// Save (create or update) — omit id to create
$id = OCI_Snippets::save_snippet([
'id' => '',
'title' => 'My Script',
'type' => 'js',
'code' => 'alert(1);',
'location' => 'footer',
'active' => true,
'priority' => 10,
'pages' => '',
'page_types' => ['all'],
'user_condition' => 'all',
]);
// Delete
OCI_Snippets::delete_snippet( 'uuid' );
// Toggle active state — returns new state (bool)
$is_active = OCI_Snippets::toggle_snippet( 'uuid' );
// Duplicate — returns new ID
$new_id = OCI_Snippets::duplicate_snippet( 'uuid' );
// Settings
$enabled = OCI_Settings::is_enabled();
$safe_mode = OCI_Settings::is_safe_mode();
$can_access = OCI_Settings::can_access();
// Error log
OCI_Settings::log_error( 'uuid', 'Error message' );
AJAX Endpoints
All endpoints require nonce (from ociAdmin.nonce) and manage_options capability.
| Action | Parameters | Response |
|---|---|---|
oci_save_snippet | snippet_id, title, type, code, location, active, priority, pages, page_types[], user_condition | {id, snippet} |
oci_delete_snippet | snippet_id | {} |
oci_toggle_snippet | snippet_id | {active: bool} |
oci_duplicate_snippet | snippet_id | {id, snippet} |
oci_import_snippets | json (string) | {imported: int} |
oci_save_settings | enabled, safe_mode, allowed_roles[] | {} |
oci_clear_error_log | — | {} |
Pro Hooks
php// Fire before a snippet is injected
add_action( 'oci_before_inject', function( array $snippet, string $location ) {}, 10, 2 );
// Decide whether a snippet should fire
add_filter( 'oci_should_inject', function( bool $should, array $snippet ): bool {
return $should;
}, 10, 2 );
// Get all active snippets for a location
$snippets = oci_get_snippets( 'head' );