Skip to content

OG Picture Core: developer's guide

OG Picture Core's internal prefix is ogplr. Folders and collections live in the plugin's own tables, not in a taxonomy. A "collection" and a "gallery" mean the same thing in the code. Folders are collections with is_folder = 1.

Actions

These are the hooks an extension uses to mirror the Lightroom structure into a theme or another plugin. Resync with Extensions replays the create and add actions for the whole structure; Reset with Extensions fires ogplr_reset.

Media

Action Arguments Fires
ogplr_presync_media $lrinfo (object), $tmp_path (string) Before a file sent from Lightroom is processed
ogplr_add_media $wp_id (int) A sync created a new attachment
ogplr_update_media $wp_id (int), $gallery_ids (int[]) A sync replaced the file of an existing attachment
ogplr_sync_media $sync (object) After a sync finished and the link was saved
ogplr_remove_media $wp_id (int) A synced attachment was removed through the sync

Folders and collections

Action Arguments Fires
ogplr_create_folder $wp_col_id, $parent_folder_id, array( 'name' => ... ) A folder was created
ogplr_create_collection $wp_col_id, $parent_folder_id, array( 'name' => ... ) A collection was created
ogplr_move_folder $wp_col_id, $new_parent_id, $old_parent_id A folder moved
ogplr_move_collection $wp_col_id, $new_parent_id, $old_parent_id A collection moved
ogplr_remove_folder $wp_col_id Before a folder is deleted
ogplr_remove_collection $wp_col_id Before a collection is deleted
ogplr_add_media_to_collection $wp_id, $wp_col_id A photo was added to a collection
ogplr_remove_media_from_collection $wp_id, $wp_col_id A photo was removed from a collection
ogplr_order_collection $media_ids (int[]), $wp_col_id The photos in a collection were reordered

Keywords

Keyword IDs are Lightroom keyword IDs.

Action Arguments Fires
ogplr_add_tag $tag_id, $name, $parent_id A keyword was created
ogplr_update_tag $tag_id, $name, $parent_id (optional) A keyword was renamed, or lost its parent
ogplr_move_tag $tag_id, $new_parent_id, $old_parent_id A keyword moved
ogplr_remove_tag $tag_id A keyword was deleted
ogplr_add_media_tag $wp_id, $tag_id A keyword was added to a photo
ogplr_remove_media_tag $wp_id, $tag_id A keyword was removed from a photo

Maintenance

Action Arguments Fires
ogplr_clean none Before Clean DB runs
ogplr_reset none Reset with Extensions: extensions should undo their use of the structure

Example: keep a custom post meta list of the collections a photo belongs to.

add_action( 'ogplr_add_media_to_collection', function ( $wp_id, $wp_col_id ) {
    $ids = (array) get_post_meta( $wp_id, 'my_collections', true );
    $ids[] = $wp_col_id;
    update_post_meta( $wp_id, 'my_collections', array_unique( $ids ) );
}, 10, 2 );

Filters

Filter Arguments Use
ogplr_allow_setup $allowed (bool, default manage_options) Who can change settings and use the admin-only REST routes
ogplr_allow_usage $allowed (bool, default upload_files) Who can use the Organizer and its REST routes
ogplr_sync_ajax_nonce $valid (bool) Result of the nonce check on the plugin's AJAX actions
ogplr_sync_ajax_user_can $allowed (bool, default manage_options) Capability check on the plugin's AJAX actions
ogplr_extensions $names (string[]) Register your extension's name so it shows under Extensions
ogplr_issues $issues (string[]) Add a warning to Possible problems
ogplr_sync_api_sync_args $args (array) Change the data Lightroom sent (title, caption, desc, altText, tags and so on) before a file is synced
ogplr_file_exists $exists (null), $file (string) Return true or false to check files another way, for example on remote storage. Return null to use file_exists()
ogplr_calculate_pHash $hash (null), $path (string) Return your own perceptual hash for an image. Return null to use the built-in one

Example: register an extension and add a check.

add_filter( 'ogplr_extensions', function ( $names ) {
    $names[] = 'My Theme';
    return $names;
} );

add_filter( 'ogplr_issues', function ( $issues ) {
    if ( ! function_exists( 'my_theme_setup' ) ) {
        $issues[] = 'My Theme is not active, so its portfolio will not update.';
    }
    return $issues;
} );

Shortcodes

OG Picture Core does not register a shortcode of its own. It adds attributes to the core [gallery] shortcode through shortcode_atts_gallery. When one of these attributes finds photos, the gallery uses them in collection order (orderby="post__in").

Attribute Value Result
ogplr-collection Collection IDs, comma-separated Photos in those collections
ogplr-collections Same as above Same as above
ogplr-folder A folder ID Photos in every collection directly inside the folder
ogplr-keyword Keyword IDs, comma-separated Photos with any of the keywords
ogplr-keywords Same as above Same as above
ogplr-keywords-and Keyword IDs, comma-separated Only photos that have all of the keywords
[gallery ogplr-collection="12" columns="4" size="large"]
[gallery ogplr-keywords-and="7,9"]

It also filters the attributes of a [collection] shortcode (shortcode_atts_collection) when another plugin registers one. With ogplr-folder="5" it adds an ogplr-thumbnails attribute: one entry per collection in the folder, with its ID, data and featured image. Add ogplr-recursive="true" to include the collections of sub-folders.

REST API

Admin routes: ogplr-sync/v1

Used by the settings screen and the Organizer. They are only registered for users who can upload files, and need a logged-in user with a REST nonce (X-WP-Nonce).

Settings (permission: ogplr_allow_setup)

Route Method Does
/all_settings GET All settings for the settings screen
/update_option POST Saves one setting
/generate_auth_token POST New Public API token and QR payload (Public API must be on)
/regenerate_user_token POST New personal token for the current user
/entries GET Lists for Consolidate with Lightroom (show: unlinked, duplicates, ignored)
/delete_hierarchy POST Deletes folders and collections
/keywords_hierarchy GET The stored keyword tree
/delete_keywords_hierarchy POST Deletes a keyword (delete_keyword)

Organizer (permission: ogplr_allow_usage)

Route Method Does
/wp_hierarchy, /lr_hierarchy GET WordPress or Lightroom folder and collection tree
/all_media, /unassigned_entries GET All media, or media in no collection
/folder_content POST Collections in a folder
/gallery_content GET Photos in a collection
/create_folder, /create_gallery POST Create a folder or collection
/update_folder, /update_gallery POST Rename a folder or collection
/delete_folder, /delete_gallery POST Delete a folder or collection
/move_collection POST Move a folder or collection
/move_media, /copy_media, /remove_media POST Move, copy or remove photos
/reorder_media POST Reorder photos in a collection
/update_media POST Edit title, description, caption, ALT text
/update_featured_image POST Set a collection's featured image
/sync_info, /link, /unlink POST Read, create or remove a Lightroom link
/extensions_init, /extensions_query, /extensions_reset POST Resync and Reset with Extensions
/clean, /repair POST Clean DB and Repair DB

Public API: ogplr/v1

Read-only, for external apps. Each request needs the Auth Token from the settings screen. Send it as a Bearer token in the Authorization header, as an ogplr_auth_token cookie, or as an ogplr_auth_token query argument. The token only exists while Public API is on.

Route Method Returns
/auth GET A success message if the token is valid
/hierarchy GET The folder and collection tree
/gallery/<id> GET One collection and its photos
curl -H "Authorization: Bearer YOUR_AUTH_TOKEN" https://example.com/wp-json/ogplr/v1/hierarchy

Lightroom endpoint

The Lightroom plugin talks to https://example.com/?ogplr-sync-api. A GET returns a greeting, which is a quick way to check that nothing blocks the address. Other requests are POSTs with a user's personal token (token) and an action: sync (multipart file upload), presync, sync_collection, delete_collection, order_collection, delete, userinfo, list_wpids, link, unlink, linkinfo, linkinfo_upload, linkinfo_bulk, list_unlinks, list_sync_media.

The token's user must be able to upload files, and must be able to edit or delete each attachment the request touches. After 20 failed tokens from one IP address, that address is refused for 15 minutes.

AJAX actions

All on admin-ajax.php, logged-in only.

Action Does
ogplrsync_generate_auth_token Creates a personal token for the current user (profile page)
ogplrsync_link, ogplrsync_unlink Link or unlink a photo and a Lightroom ID
ogplrsync_clean Clean DB
ogplrsync_extensions_init, ogplrsync_extensions_query, ogplrsync_extensions_reset Resync and reset with extensions

The admin actions check a nonce named after the action and manage_options (see the two ogplr_sync_ajax_* filters).

Data stored

Tables

Table Holds
{prefix}lrsync Links between attachments (wp_id) and Lightroom photos (lr_id, lr_file, lastsync)
{prefix}lrsync_collections Folders and collections (wp_col_id, lr_col_id, wp_folder_id, name, slug, is_folder, featured_id, source)
{prefix}lrsync_relations Which photo is in which collection, with sort order
{prefix}lrsync_meta Keyword names, keyword parents and photo keywords

The tables are created and repaired when needed, for example by Repair DB.

Options

Option Setting
ogplr_media_organizer Media Organizer
ogplr_media_modals Media Modals
ogplr_media_library Media Library
ogretina_big_image_size_threshold Image Threshold > Disable
ogplr_public_api Public API
ogplr_use_taken_date Use Capture Date
ogplr_upload_folder Upload Folder
ogplr_filename_accents Sanitization > Disable
ogplr_check_same_file Double Processing > Avoid
ogplr_enable_keywords Create the Keywords Taxonomy
ogplr_sync_keywords Sync Keywords (taxonomy name)
ogplr_debugging_enabled Debug
ogplr_catch_errors Catch Errors
ogplr_debuglogs Advanced Logs
ogplr_library_show_hierarchy, ogplr_library_show_filters, ogplr_hide_extensions, ogplr_protocol, ogplr_plugins Older settings, still read

Other data

Key Type Holds
ogplr_auth_token User meta A user's personal token for Lightroom
ogplr_auth_token Transient The Public API token (one year)
ogplr_api_fail_{hash} Transient Failed sign-in count per IP address (15 minutes)
_ogplr_phash Post meta Cached perceptual hash of an image
_media_version Post meta Increases each time Lightroom replaces the file
attachment_keyword Taxonomy The Keywords taxonomy, with /keyword/ archives, when enabled

Advanced Logs writes to ogplr-sync.log inside the plugin's classes folder.

Constants

Constant Value
OGPLR_SYNC_VERSION Plugin version
OGPLR_SYNC_PREFIX ogplr_sync
OGPLR_SYNC_DOMAIN og-photo-engine (text domain)
OGPLR_SYNC_PATH, OGPLR_SYNC_URL, OGPLR_SYNC_ENTRY Plugin folder, URL and main file
DOING_OGPLR_REQUEST Defined during a request to the Lightroom endpoint

JavaScript

On its own screens and in the Media Library, the plugin loads pEngine and passes a global object, also named pEngine. It holds api_url (the ogplr-sync/v1 base), rest_url, rest_nonce, plugin_url, hierarchy (the folder and collection tree), col_id and the current settings. Treat it as internal: its shape can change between versions.