OG Gallery developer's guide¶
This page lists the hooks, shortcodes, block, REST routes and storage of OG Gallery. For the settings screen and everyday use, see the user guide.
All hook names start with oggl_. Features marked licence only run when the plugin's licence is active.
Actions¶
| Action | Arguments | When it fires |
|---|---|---|
oggl_gallery_created |
array $atts, array $image_ids, string $layout |
After a gallery's images and layout are worked out, before the HTML is built. |
oggl_{layout}_gallery_created |
string $layout |
Same moment, once per layout. For example oggl_masonry_gallery_created. |
oggl_collection_created |
array $atts, array $gallery_ids, string $layout |
When an [og-collection] is rendered. Licence. |
oggl_scripts_registered |
string $handle |
After the front-end script oggl-js is registered and given its settings. Use it to add your own data with wp_localize_script(). |
The front-end script and stylesheet are only enqueued once oggl_gallery_created or oggl_collection_created has fired, so pages without a gallery load nothing extra.
// Load a small script only on pages that show a masonry gallery.
add_action( 'oggl_masonry_gallery_created', function () {
wp_enqueue_script( 'my-masonry-extras', get_stylesheet_directory_uri() . '/masonry-extras.js', [], '1.0', true );
} );
Filters¶
| Filter | Arguments | When it runs |
|---|---|---|
oggl_ids |
array $ids, array $atts |
After the image IDs are collected from ids, id, include, tags, posts, latest_posts or attachments. Return the IDs to show. |
oggl_sort_ahead |
array $ids, string $layout, array $atts |
Before the gallery is built. Reorder the IDs first. |
oggl_sort |
array $ids, array $images, string $layout, array $atts |
When the images are read from the database. Final order. |
oggl_tags_taxonomies |
array $taxonomies |
Taxonomies searched by the tags attribute. Default post_tag, media_tag, attachment_tag, attachment_category. |
oggl_is_archive_context |
bool $is_archive, array $atts |
Decides if the gallery is on a listing page and should be cut to Truncate Count. |
oggl_media_size |
string $size |
The image size a gallery asks for. Default from the size attribute, else large. |
oggl_sizes |
string $sizes, string $layout, WP_Post $attachment, array $attr |
The sizes attribute of each gallery image's srcset. |
oggl_caption |
string $caption, int $id |
Each image's caption. Only strong, b, em and i tags are kept afterwards. |
oggl_attributes |
string $attributes, int $id, array $data |
Extra data- attributes for an image, as a space-separated key=value string. |
oggl_link_attributes |
array $link_attr, int $id, array $data |
The link of each image. Keys: href, target, type (media or link), rel. A type of link switches the lightbox off for that image. |
oggl_custom_link_classes |
string $classes, array $image |
CSS classes on the <a> around an image that has a link. |
oggl_video |
string $url, int $id, array $data |
The URL of a video attachment in a gallery. Return an empty value to show nothing for it. |
oggl_gallery_written |
string $html, string $layout |
The HTML of each image (or video) in a gallery. |
oggl_force_rewrite_oglb_data |
array $ids |
The image IDs handed to a lightbox. |
oggl_collection_ids |
array $ids, array $atts |
The gallery IDs inside a collection. Licence. |
oggl_allow_setup |
bool $allowed |
Who can use the settings and manager REST routes. Default: manage_options. The settings screen itself always needs manage_options. |
oggl_allow_usage |
bool $allowed |
Who can use the block and read galleries in the editor. Default: upload_files. |
oggl_allow_load_images |
bool $allowed |
Whether the public /images/ REST route answers. Default: only when infinite scroll is on and licensed. |
OG Gallery also runs the WordPress filter shortcode_atts_gallery on the attributes of [gallery] and [og-gallery], and shortcode_atts_collection on [og-collection].
// Show the newest images first in every gallery.
add_filter( 'oggl_sort', function ( $ids ) {
rsort( $ids, SORT_NUMERIC );
return $ids;
}, 10, 1 );
// Let Editors use the settings and manager REST routes.
// The settings screen in wp-admin stays admin-only.
add_filter( 'oggl_allow_setup', function ( $allowed ) {
return $allowed || current_user_can( 'edit_others_posts' );
} );
// Search one more taxonomy with the tags attribute.
add_filter( 'oggl_tags_taxonomies', function ( $taxonomies ) {
$taxonomies[] = 'my_media_category';
return $taxonomies;
} );
Shortcodes¶
[gallery] and [og-gallery]¶
Both run the same code. OG Gallery takes over [gallery] unless Gallery Shortcode Override is set to Disable. [og-gallery] always works.
Choose the images (use one source, or combine as noted):
| Attribute | Example | What it does |
|---|---|---|
ids |
ids="12,15,18" |
Image IDs, in this order. |
include |
include="12,15" |
Same as ids. |
id |
id="abc123" |
A gallery saved in the Gallery Manager. Other attributes still override its settings. |
tags |
tags="travel,france" |
Images with these tag slugs. Added to any IDs given. |
posts |
posts="10,22" |
The featured images of these posts. |
latest_posts |
latest_posts="6" |
The featured images of the newest posts. Merged with posts. |
attachments |
attachments="true" |
The images attached to the current post. |
collection |
collection="xyz789" |
Renders that collection instead. Licence. |
og |
og="false" |
Use the standard WordPress gallery for this one. |
Change the look:
| Attribute | Values | Notes |
|---|---|---|
layout |
tiles, masonry, justified, square, cascade, horizontal, carousel, map |
default uses the setting. carousel and map need a licence. |
animation |
zoom-out, zoom-in, fade-out, fade-in, colorize, highlight |
Licence. |
link |
media, file, attachment |
Leave it out to use the setting. |
captions |
none, on-hover, always |
false is treated as none. |
orderby (or order_by) |
ids, random, date, modified, title, menu, none |
Add -asc or -desc, for example orderby="date-desc", or use order. |
order |
asc, desc |
|
size |
Any registered image size | |
custom-class |
my-class |
Extra CSS class on the gallery. |
gutter |
Number (pixels) | All layouts. |
columns |
Number | Masonry and Square. |
row-height |
Number (pixels) | Justified. |
density |
low, medium, high |
Tiles, all screen sizes. |
image_height |
Number (pixels) | Horizontal and Carousel. |
hide_scrollbar |
true, false |
Horizontal. |
arrow_nav_enabled, dot_nav_enabled |
true, false |
Carousel. |
keep-aspect-ratio |
1, 0 |
Carousel. |
hero |
true |
Carousel built from posts or latest_posts: shows the post title and excerpt and links to the post. |
map_height |
Number (pixels) | Map. |
[gallery tags="iceland" layout="justified" row-height="260" orderby="date-desc"]
[og-gallery latest_posts="5" layout="carousel" hero="true"]
[og-collection]¶
Shows a collection made in the Collection Manager. Licence. Without a licence it prints a notice instead.
| Attribute | What it does |
|---|---|
id |
The collection ID from the Collection Manager. |
ids |
A comma-separated list of Gallery Manager gallery IDs, instead of a saved collection. |
layout |
bento (default) or menu. |
Blocks¶
| Block | Notes |
|---|---|
og-gallery/gallery |
Title OG Gallery, category Layout. It saves a [gallery] shortcode (not [og-gallery]) with your chosen attributes into the post, so turning off Gallery Shortcode Override also turns these back into standard WordPress galleries. A core Gallery block can be transformed into it, and back into image blocks. |
REST API¶
Namespace: og-gallery/v1. Settings and manager routes need the oggl_allow_setup check (default manage_options). Editor routes need oggl_allow_usage (default upload_files). Send the X-WP-Nonce header from a logged-in session.
| Method | Route | Permission | Purpose |
|---|---|---|---|
| POST | /update_option |
setup | Save settings. |
| GET | /all_settings |
setup | Read all settings. |
| POST | /reset_options |
setup | Reset settings to defaults. |
| GET | /latest_photos |
setup | Recent images for the media picker. Args: search, offset, except. |
| POST | /save_shortcode |
setup | Create or update a Gallery Manager gallery. |
| POST | /remove_shortcode |
setup | Delete a Gallery Manager gallery. |
| POST | /update_gallery_rank |
setup | Reorder galleries in the manager. |
| GET | /rml_folders |
setup | Media folders for the folder source, when a supported folder plugin is active. |
| POST | /save_collection |
setup | Create or update a collection. |
| POST | /remove_collection |
setup | Delete a collection. |
| POST | /fetch_shortcodes |
usage | List Gallery Manager galleries. |
| POST | /fetch_gallery_items |
usage | Read the images of a saved gallery. |
| POST | /fetch_collections |
usage | List collections. |
| POST | /fetch_posts |
usage | Search posts for the Dynamic source. Args: search, offset, limit. Respects post visibility. |
| POST | /preview |
usage | Render the block preview (up to 12 images). |
| POST | /load_gallery_collection |
public | Opens a gallery from inside a collection. Only the gallery named by search_slug and id is rendered; attributes that pick other content are stripped. |
| POST | /images |
oggl_allow_load_images |
Loads the next batch of images for infinite scroll. Closed unless infinite scroll is on. |
Options, meta keys and tables¶
| Name | Type | What it holds |
|---|---|---|
oggl_options |
Option (array) | Every setting, for example layout, link, animation, image_size, caption_source, captions, captions_alignment, captions_background, truncate_on_listing, truncate_count, use_attachments_on_empty, debug_logs, tiles_*, masonry_*, justified_*, square_*, cascade_gutter, horizontal_*, carousel_*, map_*, googlemaps_token, mapbox_token, maptiler_token, stylish_*, infinite, infinite_buffer, gallery_shortcode_override_disabled, skeleton_loading, right_click. |
oggl_db_version |
Option | Version of the gallery tables. |
_gallery_link_url, _gallery_link_target |
Post meta (read only) | Read from each image when Link is None. Written by OG Gallery Custom Links. |
{prefix}oggl_gallery_shortcodes |
Table | Gallery Manager galleries: id, name, description, layout, medias, lead_image_id, order_by, is_post_mode, is_hero_mode, posts, latest_posts, tags, dynamic_source, rml, pref_rank, and timestamps. |
{prefix}oggl_collections |
Table | Collections: id, name, description, layout, galleries_ids, and more. |
Without a licence, the licensed options in oggl_options are reset to their defaults each time the settings are read.
Constants¶
| Constant | Value |
|---|---|
OGGL_VERSION |
Plugin version, for example 1.0.20. |
OGGL_PREFIX |
oggl |
OGGL_DOMAIN |
Text domain, og-gallery. |
OGGL_ENTRY |
Full path of the main plugin file. |
OGGL_PATH |
Plugin folder path. |
OGGL_URL |
Plugin folder URL. |
JavaScript¶
Script and style handles
| Handle | File | Loaded |
|---|---|---|
oggl-js |
app/galleries.js |
Front end, in the footer, only on pages with a gallery. |
oggl-admin-js |
app/admin.js |
Admin: settings screen and block editor. |
oggl-css |
app/style.min.css |
Front end and admin. |
oggl-pro-css |
app/style-pro.min.css |
Same, when licensed. |
Globals
| Global | What it is |
|---|---|
oggl_settings |
Front-end settings: infinite_buffer, tiles.density, api_url, rest_nonce, options. |
oggl_map |
Map engine, height and per-engine keys and styles. Licence. |
oggl_gallery |
Admin-only data for the settings screen and block. |
window.renderOgGalleries() |
Renders the OG Gallery galleries on the page. Call it after you insert gallery HTML with JavaScript. |
window.renderOgCollections() |
Same for collections. |
window.oggl_load_more( el ) |
Loads the next batch of an infinite-scroll gallery. el is the gallery element, its ID, or an element inside it. Only defined when infinite scroll is on. |