Skip to content

OG Media File Renamer developer's guide

This page lists the hooks, REST routes, WP-CLI commands and data that OG Media File Renamer uses. For the settings and everyday use, see the user guide.

Hooks marked Pro are only added or fired when the licence is active and the Pro features are installed.

Actions

Action Arguments When it fires
ogmr_media_renamed $post (array), $old_filepath, $new_filepath, $undo (bool), $method (string) After a media file has been renamed or moved. $method is the method used, for example media_title, manual, vision or move.
ogmr_path_renamed $post, $old_filepath, $new_filepath After each physical file is renamed: the main file, every image size and retina copies.
ogmr_url_renamed $post, $orig_image_url, $new_image_url, $size For each URL that changed. The Side Updates (posts, excerpts, post meta, options) listen to this.
ogmr_media_resync $post, $use_vision (bool), $time_filter (int), $only_empty (bool), $mode When fields are re-synced from the Dashboard (Sync Fields).
ogmr_initialize_parsers none On init, so the page builder and plugin parsers can load (Pro).
ogmr_delayed_on_upload $attachment_id Scheduled event, five minutes after an upload, when Run Later (5 min) is on.

Example: write every rename to your own log.

add_action( 'ogmr_media_renamed', function ( $post, $old_path, $new_path, $undo, $method ) {
    error_log( sprintf( 'Media %d renamed (%s): %s -> %s', $post['ID'], $method, basename( $old_path ), basename( $new_path ) ) );
}, 10, 5 );

Filters

Filter Arguments When it runs
ogmr_new_filename $new_filename, $old_filename_no_ext, $media (array, or 0 on upload) Every time a new filename (without extension) is worked out. Prefix, suffix, replace rules and transliteration use it.
ogmr_new_filename_attached $new_filename, $old_filename_no_ext, $media, $attached_post Same, but only for media attached to a post (Pro).
ogmr_allow_rename $allowed (bool), $media (ID, array or WP_Post), $manual_filename Before a rename. Return false to block it.
ogmr_allowed_extensions $extensions (array) The file extensions the plugin will rename.
ogmr_replace_rules $special_chars (array) The character replacements used when cleaning a name.
ogmr_method $method, $suffix ('', _secondary or _tertiary) The Auto method in use.
ogmr_base_for_rename $base, $media_id, $preview, $skipped_methods The text a new name is built from (Pro).
ogmr_unique $method The unique filename method: none, increment, hash or random.
ogmr_force_rename $force (bool) Whether to update references even if the file rename failed (Pro).
ogmr_after_upload $metadata, $attachment_id After the upload handling. Return the attachment metadata.
ogmr_ai_prompt $prompt, $metadata_type, $entry, $keywords The prompt sent to OG AI Core for a suggestion. $metadata_type is filename, title, alt, description or caption.
ogmr_vision_suggestion $result, $media_id, $binary_path, $prompt Produces an AI Vision suggestion. Return a string to supply your own.
ogmr_ffmpeg_path $path (string) Path to ffmpeg for taking a frame from a video. Empty means the plugin looks for ffmpeg on the server path.
ogmr_rewrite_title, ogmr_rewrite_alt, ogmr_rewrite_description, ogmr_rewrite_caption $value, $post A synced field value just before it is saved (Pro).
ogmr_clean_upload_alt $value The ALT text written by Clean Upload.
ogmr_exif_upload_alt $value The ALT text written by EXIF Title on upload.
ogmr_vision_upload_alt $value The ALT text written by AI Vision on upload.
ogmr_exif_upload_{field} $value Other fields written on upload (title, description, caption), for all upload methods.
ogmr_update_content_urls array( $orig_url, $new_url ) URLs used when updating post content.
ogmr_update_excerpts_urls array( $orig_url, $new_url ) URLs used when updating excerpts.
ogmr_update_postmeta_urls array( $orig_url, $new_url ) URLs used when updating post meta.
ogmr_update_database_options_urls array( $orig_url, $new_url ) URLs used when updating options.
ogmr_allow_usage $allowed (bool) Who can use the rename features. Default: users with the administrator role.
ogmr_allow_setup $allowed (bool) Who can open the settings. Default: manage_options.

Example: your own Auto method. Set the Auto method to None, then build the name yourself.

add_filter( 'ogmr_new_filename', function ( $new, $old, $media ) {
    if ( empty( $media['ID'] ) ) {
        return $new; // Upload: no attachment yet.
    }
    return sanitize_title( get_bloginfo( 'name' ) . '-' . $media['ID'] );
}, 20, 3 );

Example: never rename PDFs, and let editors use the renamer.

add_filter( 'ogmr_allow_rename', function ( $allowed, $media ) {
    $id = is_array( $media ) ? $media['ID'] : ( $media instanceof WP_Post ? $media->ID : (int) $media );
    return get_post_mime_type( $id ) === 'application/pdf' ? false : $allowed;
}, 10, 2 );

add_filter( 'ogmr_allow_usage', function () {
    return current_user_can( 'edit_others_posts' );
} );

Example: point the plugin at ffmpeg.

add_filter( 'ogmr_ffmpeg_path', fn() => '/usr/local/bin/ffmpeg' );

REST API

Namespace: og-media-renamer/v1. All routes need a logged-in user and a wp_rest nonce. Settings means the ogmr_allow_setup check; Usage means the ogmr_allow_usage check. The routes serve the plugin's own screens and may change between versions.

Method Route Permission Purpose
GET /all_settings Settings All settings.
POST /update_option Settings Save settings.
POST /reset_options Usage Reset settings to defaults.
POST /reset_metadata Usage Remove lock and renamed status from all media.
POST /toggle_parser Usage Turn a parser on or off.
POST /test_rules Usage Test the filename rules on a sample name.
GET /stats Usage Counts for the Dashboard filters.
GET /media Usage List media for the Dashboard.
GET /media/id Usage One media entry.
GET /uploads_directory_hierarchy Usage Folders in uploads, for Move.
POST /analyze Usage Check media for pending renames.
POST /reanalyze_pending Usage Re-analyse the library.
POST /auto_attach Usage Attach media to the posts that use them.
POST /get_all_ids Usage IDs of all media in the current view.
POST /get_all_post_ids Usage IDs of posts, for Auto-Attach.
POST /set_lock Usage Lock or unlock media.
POST /clear_pending Usage Keep the current filename and remove from Pending.
POST /rename Usage Rename a media file (auto or manual).
POST /move Usage Move a media file to another folder.
POST /undo Usage Restore the original filename.
POST /status Usage Rename status and proposed name for media.
POST /update_media Usage Update title, ALT text, caption or description.
POST /sync_fields Usage Re-sync metadata fields.
POST /ai_suggest Usage Get AI suggestions for a field.
POST /create_folder Usage Create a folder in uploads.
POST /refresh_logs Usage Read the log.
POST /clear_logs Usage Clear the log.

WP-CLI

Needs an active licence. The command is wp ogmr; wp og-media-renamer is the same.

Command What it does
wp ogmr help Lists the commands.
wp ogmr list [--format=csv] Lists pending renames.
wp ogmr info [<id>...] Shows details of media files.
wp ogmr rename_auto <id> [<id>...] Renames files with the Auto methods.
wp ogmr rename_manual <id> <filename> Renames one file to the name you give.
wp ogmr rename_all [--dry-run] Renames all unlocked files. --dry-run only shows what would change.
wp ogmr lock <id> [<id>...] / wp ogmr lock_all Locks files.
wp ogmr unlock <id> [<id>...] / wp ogmr unlock_all Unlocks files.
wp ogmr manual_title <id> <title> Sets the title.
wp ogmr manual_alt <id> <alt text> Sets the ALT text.
wp ogmr manual_caption <id> <caption> Sets the caption.
wp ogmr manual_desc <id> <description> Sets the description.
wp ogmr set_methods <primary> [secondary] [tertiary] Sets the Auto methods: none, media_title, alt_text, post_title, post_acf_field, anonymize_md5 or vision.
wp ogmr rename_all --dry-run
wp ogmr set_methods vision media_title

Options, meta keys and tables

The plugin adds no database tables.

Options

Key Contents
ogmr_options All settings, as one array.

Main setting keys inside ogmr_options:

Key Setting Default
auto_rename, auto_rename_secondary, auto_rename_tertiary Auto methods media_title, none, none
on_upload_method, on_upload_method_secondary, on_upload_method_tertiary On Upload methods (none, upload_clean, upload_exif, upload_vision) none
on_upload_run_later Run Later (5 min) false
rename_on_save, rename_on_save_post_types, rename_on_save_title_changed On Post Save false, post/page/product, true
trigger_on_attachment_update Attachment Update false
sync_{method}_{field} Fields Syncing, for example sync_manual_alt or sync_on_upload_vision_title false
manual_rename, manual_sanitize Rename Field, Sanitize true, true
manual_rename_ai, vision_rename_ai, vision_rename_ai_cache AI Suggestions, AI Vision, cache in seconds false, false, 86400
exif_context, attached_post_context, manual_prompt, manual_prompt_{field} AI context and prompts
convert_to_ascii, unique_files Transliteration, Unique Filenames false, none
filename_prefix, filename_suffix, filename_replace, filename_replace_regex Rules empty
images_only, featured_only Scope false
update_posts, update_excerpts, update_postmeta, update_database_options Side Updates true, false, false, false
parsers Parser list with exists and enabled
rename_slug, rename_guid Slug/Permalink, GUID false
lock, autolock_auto, autolock_manual, hide_locked Locking false, false, true, true
undo, move, history, history_limit Advanced features false, false, false, 4
force_rename, case_insensitive_check, delay For Developers false, false, 100
log, logsql, php_error_logs, logs_path Logging false
clean_uninstall Plugin Data (remove on uninstall) false
expert, dev_tools, dashboard, media_library_field Interface false, false, true, full

Post meta on attachments

Key Meaning
_original_filename The filename before the first rename. Used by Undo.
_manual_file_renaming The file is locked.
_require_file_renaming The file is pending a rename.
_ogmfr_keep_filename The current name was kept for this Auto method.
_ogmfr_proposed_filename, _ogmfr_ideal_filename, _ogmfr_used_method, _ogmfr_proposed_filename_exists Cached result of the last analysis.
_ogmfr_history Rename history, when History is on.

Post meta on posts

Key Meaning
_ogmfr_skip_rename_on_save Skip Rename on Save is ticked for this post. Registered for the REST API.

Other data

Name Type Meaning
ogmr_vision_{media_id} Transient Cached AI description of an image (AI Vision Cache).
ogmr_skip_on_upload Browser cookie Set to 1 when the user skips On Upload renaming.
uploads/ogmr_*.log File The plugin log.
uploads/ogmr_sql.log, uploads/ogmr_sql_revert.log File SQL Logs and the revert queries.

On uninstall with Plugin Data ticked, the plugin deletes options matching ogmr_% and the meta keys _manual_file_renaming, _require_file_renaming, _original_filename and _ogmfr_keep_filename from {prefix}postmeta.

Constants

Constant Value
OGMFR_VERSION Plugin version. OGMR_VERSION is the same.
OGMFR_PREFIX ogmfr
OGMFR_DOMAIN og-media-renamer (text domain)
OGMFR_ENTRY Path of the main plugin file.
OGMFR_PATH Plugin folder path.
OGMFR_URL Plugin folder URL.

OGMR_PREFIX, OGMR_DOMAIN, OGMR_ENTRY, OGMR_PATH and OGMR_URL are defined with the same values.

JavaScript

Name What it is
window.ogmr Data for the admin screens: api_url, rest_url, rest_nonce, plugin_url, prefix, domain, is_pro, is_registered, has_seo_engine, options and post_types.
ogmr (script handle) The admin app, loaded on the plugin's screens, the Media Library, Edit Media and Upload New Media.
ogmr-editor (script handle) The block editor panel with Skip Rename on Save. Registered as the editor plugin ogmr-rename-on-save.

PHP functions

Function What it does
ogmr_rename( $media_id, $manual = null ) Renames a media file with the Auto methods, or to $manual when given.
ogmr_move( $media_id, $new_path ) Moves a media file to a folder relative to uploads, for example 2026/12.
ogmr_get_instance() Returns the plugin's core object.
// Rename media 123 to a name you choose.
ogmr_rename( 123, 'blue-jellybean-mascot.png' );