Skip to content

OG Lightbox developer's guide

This page lists the hooks, REST routes, JavaScript functions and stored data in OG Lightbox. For the settings screens, see the user guide.

Actions

OG Lightbox listens to these actions. Fire them from your own code when it makes sense.

Action Arguments What OG Lightbox does
ogretina_cdn_settings_changed none Clears all cached photo details, because cached URLs may point to the old CDN host. OG Picture Perfect fires it.
oggl_gallery_created $atts, $image_ids, $layout Fired by OG Gallery when it renders a gallery. OG Lightbox hooks in so OG Gallery images are handled.
oggl_collection_created $atts, $image_ids, $layout The same, for OG Gallery collections.

On save_post (updates only) the cached details for that page are cleared. On edit_attachment the cached details for that image are cleared.

Filters

Access

Filter Arguments When it runs
oglb_allow_setup bool $allowed (default: current_user_can( 'manage_options' )) Permission check for the settings, reset and diagnostics REST routes.
oglb_allow_usage bool $allowed (default: current_user_can( 'upload_files' )) Permission check for the log REST routes.

Photo details

Each runs when OG Lightbox builds the details for an image, before they reach the browser. All take ( $value, int $media_id, array $meta ), where $meta is the attachment metadata.

Filter Value
oglb_img_title Title
oglb_img_caption Caption
oglb_img_description Description
oglb_img_alt_text ALT text
oglb_img_camera Camera model
oglb_img_lens Lens
oglb_img_aperture Aperture
oglb_img_focal_length Focal length
oglb_img_iso ISO
oglb_img_shutter_speed Shutter speed
oglb_img_date Date taken
oglb_img_copyright Copyright
oglb_img_author Author
oglb_img_keywords Keywords
oglb_img_gps GPS coordinates as "lat,lng"
oglb_download_link The URL used by the Download button

OG Lightbox adds its own callbacks at priority 5 to format camera, lens, aperture (f/2.8), focal length (35mm), ISO (ISO 100), shutter speed (1/250), copyright, keywords and GPS, and to turn empty values into N/A. Use a later priority to work on the formatted value.

// Show a friendlier name for one camera body.
add_filter( 'oglb_img_camera', function ( $camera, $media_id, $meta ) {
    return $camera === 'Canon 5D Mark IV' ? 'Canon EOS 5D Mark IV' : $camera;
}, 10, 3 );

// Hide the location of images you have marked with a custom field.
add_filter( 'oglb_img_gps', function ( $gps, $media_id, $meta ) {
    return get_post_meta( $media_id, 'hide_location', true ) ? 'N/A' : $gps;
}, 10, 3 );

Values are cached, but the filters run on every request, so changes to your callbacks show at once.

Image detection

Filter Arguments When it runs
oglb_image_attributes array $attributes When an image has no wp-image-{ID} class, OG Lightbox reads the media ID from these HTML attributes. The list includes data-oglb-img-id.
oglb_component_sources array $sources Gallery components that keep their image IDs in a JSON data attribute. Each entry has selector, data_attribute and ids_key. The default entry reads image_ids from [data-gallery-options].
// Let OG Lightbox read media IDs from your own attribute.
add_filter( 'oglb_image_attributes', function ( $attributes ) {
    $attributes[] = 'data-my-media-id';
    return $attributes;
} );

// A slider that stores <div data-slides='{"ids":[12,34]}'>.
add_filter( 'oglb_component_sources', function ( $sources ) {
    $sources[] = array(
        'selector'       => '[data-slides]',
        'data_attribute' => 'data-slides',
        'ids_key'        => 'ids',
    );
    return $sources;
} );

REST API

Namespace: og-lightbox/v1

Method Route Permission Purpose
GET /all_settings oglb_allow_setup Returns all settings.
POST /update_option oglb_allow_setup Saves settings. JSON body: { "options": { ... } } (the full settings array).
POST /reset_options oglb_allow_setup Deletes the settings so defaults apply.
POST /reset_cache oglb_allow_setup Clears cached photo details and page caches.
GET /diagnostics oglb_allow_setup Runs the server-side checks for the Diagnostics tab.
GET /get_logs oglb_allow_usage Returns the debug log, newest line first.
GET /clear_logs oglb_allow_usage Deletes the debug log file.
POST /regenerate_oglb_data Public Returns photo details for images that appeared after page load. Body: images (array of { id, url }, at most 100 used) and page_url (same-site URLs only).
GET /ping Public Returns success, logged_in and version. Used by the diagnostics.

The two public routes must be reachable by logged-out visitors. If a firewall, CDN or security plugin blocks /wp-json/og-lightbox/, images that load after the page will open without details.

Options, meta keys and tables

OG Lightbox creates no database tables.

Name Type Contents
oglb_options Option All settings in one array (not autoloaded). Keys match the settings, for example theme, selector, anti_selector, exif_camera, map, map_engine, googlemaps_token.
oglb_prefix_moved Option Set to 1 after a one-time move of older settings.
_oglb_geo Attachment meta Cached GPS coordinates read from the file, as "lat,lng". Empty when the file has none.
_oglb_lens Attachment meta Cached lens name read from the file.
oglb_exif_v2_{ID}_{flags} Transient Cached details for one image, kept for 3 months.
oglb_page_dynamic_v2_{md5} Transient Cached details of late-loading images for one page, kept for 24 hours.

These live in {prefix}options and {prefix}postmeta. With Debug Logs on, the log file is uploads/oglb_{random}.log.

The Reset GPS Data link in the OG GPS box calls wp-admin/?oglb_reset_gps={ID} (administrators only), which deletes _oglb_geo for that image.

Constants

Constant Value
OGLB_VERSION Plugin version, for example 1.0.20.
OGLB_PREFIX oglb
OGLB_DOMAIN Text domain, og-lightbox
OGLB_PATH Plugin folder path
OGLB_URL Plugin folder URL
OGLB_ENTRY Main plugin file

JavaScript

Globals set by the plugin

Global Contents
oglb_settings api_url, rest_nonce, plugin_url, version, is_admin, diagnostics_url and a settings object with the front-end settings.
oglb_i18n Translated button and label texts. Translate them through the og-lightbox text domain.
oglb_data Details of the images found on the page, keyed by media ID. Printed in the footer (or before </body> with Output Buffering).
oglb_url_index Map of image URLs to media IDs.
oglb_map Map settings for the licensed map view: the default map engine, its API key and style, and the zoom level. Only printed when the licence is active.

Functions you can call

Use these when your theme or another script adds images after the page has loaded.

Function What it does
renderOgLightbox( delay ) Processes queued images and rebuilds the lightbox.
renderOgLightboxWithSelector( selector, delay ) Adds the images inside every element matching selector.
renderOgLightboxWithParentElement( element, delay ) Adds the images inside one element.
addToOgLightboxQueue( img ) Queues one <img> element. Call renderOgLightbox() after.
destroyFromOgLightbox( element ) Removes the lightbox from the images inside an element.
startOgLightboxObserver() / stopOgLightboxObserver() Starts or stops watching the page for new images.
// After your gallery loads more photos:
document.addEventListener('my-gallery:loaded', function (e) {
  window.renderOgLightboxWithParentElement(e.target);
});

Data attributes and classes

  • data-oglb-img-id="123" on an <img> tells OG Lightbox which Media Library item it is. OG Lightbox adds it itself when it can.
  • Add the class no-lightbox to an image or its container to skip it (it is in the default Anti Selector).

With Deep Linking on, the address becomes #{slug}-{mediaID}, for example #oglb-123. Opening a page with that hash opens the lightbox on that image.