Abuja Digital Studio · Est. 2018
Start a Project
DocsOCodeInsertDeveloper reference
Reference

Developer reference

OCodeInsertorravo.com/docs/ocodeinsert/developer

PHP API

All methods are static and available after init.

php$snippets = OCI_Snippets::get_all();
$snippet  = OCI_Snippets::get_by_id( 'uuid' );

$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',
]);

OCI_Snippets::delete_snippet( 'uuid' );
$active = OCI_Snippets::toggle_snippet( 'uuid' );    // returns new bool state
$new_id = OCI_Snippets::duplicate_snippet( 'uuid' );

$enabled    = OCI_Settings::is_enabled();
$safe_mode  = OCI_Settings::is_safe_mode();
$can_access = OCI_Settings::can_access();
OCI_Settings::log_error( 'uuid', 'Error message' );

AJAX endpoints

All require nonce (from ociAdmin.nonce) and manage_options.

ActionParametersResponse
oci_save_snippetsnippet_id, title, type, code, location, active, priority, pages, page_types[], user_condition{id, snippet}
oci_delete_snippetsnippet_id{}
oci_toggle_snippetsnippet_id{active: bool}
oci_duplicate_snippetsnippet_id{id, snippet}
oci_save_settingsenabled, safe_mode, allowed_roles[]{}
oci_clear_error_log-{}

Hooks

phpadd_action( 'oci_before_inject', function( array $snippet, string $location ) {}, 10, 2 );

add_filter( 'oci_should_inject', function( bool $should, array $snippet ): bool {
    return $should;
}, 10, 2 );

$snippets = oci_get_snippets( 'head' );  // all active for a location
Developer reference · OCodeInsert Docs | Orravo