InPost Gallery
WordPress plugin that attaches an image set to any post and shows it through shortcode-driven gallery and slider scripts.
- First release
- Active installs
- 700+
- Rating
- Read reviews
About
InPost Gallery keeps a list of images in the post meta of any enabled post type and outputs it through shortcodes. Each shortcode wraps one front-end script (YoxView, Fancybox, Galleria, Nivo Slider, Camera), and a sixth shortcode places a single image.
Most of the engineering is in the editor. In the classic editor (TinyMCE) shortcodes appear as clickable placeholders, and a double click opens a form already filled with the shortcode's current attributes. The plugin has no block editor integration. The image list itself is a meta box on the post edit screen. It declares support from WordPress 3.5 and is tested up to 6.9, a range that includes the TinyMCE API change in WordPress 3.9.
On the front end, thumbnails are cut to the requested size on first use and cached next to the original file. A whole gallery can collapse into one cover image that loads the gallery into a popup by AJAX, which lets a large gallery sit in a sidebar widget.
InPost Gallery · galleries in posts
what was solved
Visual shortcode editor
in the productWhat it givesEditors change galleries through a form in the post editor instead of editing codes by hand, which means fewer broken pages.
- Problem
- Shortcodes with many attributes are hard to edit by hand in post content. The classic editor (TinyMCE) had to show them as objects, open a form with their current values and write them back without damaging the post.
- Solution
A TinyMCE plugin swaps shortcodes for placeholder images on load and back to text on save. The edit form is rendered on the server and gets its values from WordPress's own shortcode parser run in a capture mode.
- Stack
Show shortcodes as editable objects in the visual editorBeforeSetContent swaps shortcodes for placeholders; PostProcess restores the text
The server prints a regex built from the registered shortcode keys. On BeforeSetContent each match gets an sc_id, its original text goes into a map, and it is replaced by an image placeholder with the shortcode's icon and an attribute summary in the title. On PostProcess the placeholders are replaced back from the map, so the saved post contains plain shortcodes and nothing editor-specific.
The edit form must open with the shortcode's current valuesRun do_shortcode() in capture mode so WordPress parses the attributes into the request
In edit mode get_shortcode_template() sets a shortcode_mode_edit flag, keeps only the first registered shortcode from the posted text via get_shortcode_regex(), and runs do_shortcode(). The plugin's shortcode handler sees the flag and stores the parsed attributes instead of rendering HTML. Form fields then read their defaults through set_default_value(), which sanitizes them.
This avoids a second attribute parser: quoting, escaping and spacing are handled by the same code that renders the shortcode on the front end.
Form state must turn back into valid shortcode textSerialize marked fields as attributes; swap double quotes; join list fields with ^
changer() walks every form element marked with data-shortcode-field. Double quotes inside values are replaced with single quotes so they cannot close the attribute. A field named content becomes the enclosed content. Repeating fields marked save_as_one are collected and joined with ^ into one attribute, since shortcode attributes cannot hold arrays.
WordPress 3.9 changed the TinyMCE plugin APIShip two editor builds and pick one by $wp_version when scripts are enqueued
TinyMCE 4 in WordPress 3.9 replaced handlers such as onBeforeSetContent.add() with ed.on('BeforeSetContent'). The plugin keeps the old build in js/wp38/ and the new one in js/, and chooses between them both for the admin script and for the registered TinyMCE plugin.
Adding a gallery type should not need core changesShortcodes discovered from template files; the same list gates which templates load
get_shortcodes_array() scans views/shortcodes/popups/ and registers one shortcode per file name. Each key has a front template and an editor form template. get_shortcode_key_folder() returns the folder only for known keys, so AJAX callers cannot point the include at another file, and get_shortcode_template() falls back to inpost_gallery for unknown names.
Image data and thumbnails
in the productWhat it givesMany images can be picked from the media library at once, one set can feed several galleries, and thumbnails are made once so pages load fast.
- Problem
- Images are picked from the media library as URLs, grouped and reordered per post, and every shortcode asks for its own thumbnail size. Resizing on each page view is too slow, and registering an image size for every possible shortcode setting is not possible.
- Solution
Slides are stored as one array in post meta. Thumbnails are produced on first request with WP_Image_Editor and served from disk afterwards.
- Stack
Each gallery asks for its own thumbnail sizeResize on first use with WP_Image_Editor, save as name-WxH.ext, reuse the file if present
get_image() takes a size alias such as 200x150 and calls a resizer adapted from Aqua Resizer 1.1.7. It computes the target size with image_resize_dimensions(), looks for an existing name-WxH.ext file next to the original and returns its URL, or resizes and saves it on the first request. The class is renamed (Inpg_Aq_ResizePN) and wrapped in class_exists so it cannot clash with themes that bundle the original library.
Selecting many images at once from the media modalIntercept send_to_editor, collect URLs, add slides by sequential AJAX in selection order
The plugin opens the standard media modal and temporarily replaces window.send_to_editor. The inserted HTML is parsed in a hidden buffer for link targets or image sources. add_meta_slide_items() requests one rendered slide at a time and starts the next request in the callback, so the slides keep the order of the selection. The list is sortable and renumbered after each change.
One post's images must feed several different galleriesSlides carry a group number; shortcodes select by group, position list or random N
inpost_gallery_data is an array of slides with imgurl, title and group (1 to max_thumb_groups, 30 by default). The front templates filter it by group, or by a comma list of 1-based positions, and random=N shuffles and keeps N slides (-1 shuffles all).
Galleries built from images of other postsExpression syntax in post_id (takebyid, take), parsed as JSON; query prepared
A post_id that starts with { is treated as an expression. Parentheses become brackets and single quotes become double quotes, then json_decode() parses it. takebyid takes post:count:first|last|rand blocks from listed posts. take selects the N latest published posts of a post type; the sort direction is limited to ASC or DESC and the post type and limit are bound with prepare().
Front-end delivery
in the productWhat it givesA whole gallery can sit in a sidebar as one clickable image, and each page loads only the gallery scripts it actually uses.
- Problem
- A gallery has to fit in a sidebar widget as one image, galleries with different scripts can share a page, and the AJAX endpoint that renders galleries is open to anonymous visitors.
- Solution
The cover image carries a serialized snapshot of the shortcode attributes, and a public AJAX handler re-renders the same template from it through the shortcode registry. Each template enqueues its own assets.
- Stack
Show a whole gallery as one clickable cover imageAttribute snapshot with popup flag off, stored as base64 JSON, rendered by AJAX
draw_html() copies the attributes with show_in_popup set to 0 into an attributes key, then turns the flag on for the cover. The cover template prints the snapshot as base64 JSON. front.js posts it with the shortcode key, and get_gallery_by_shortcode() decodes it, forces show_in_popup to 0 again so the response is always the gallery and never another cover, and renders the same template. A flag on the client blocks double clicks while the request runs.
A public AJAX handler includes PHP templates by nameThe template key must resolve through the registry of known shortcodes before include
get_gallery_by_shortcode() is registered for anonymous users and receives the shortcode key from the client. It includes a template only when get_shortcode_key_folder() finds the key among the shortcodes discovered at init; any other value renders nothing.
Load each slider script only where it is usedTemplates enqueue their own CSS and JS on render; each instance gets a uniqid container
Script and style enqueues sit at the top of each shortcode template, so a page loads only the libraries of the galleries it actually shows, printed in the footer. Every instance gets a uniqid() container ID, so several galleries, including ones on different scripts, can run on one page.
Numbers
wordpress.org- Active installs 700+ wordpress.org counter.
- Reviews 18 Average 4.0 out of 5.
- Years supported 14 Since 24 April 2012, last update 6 March 2026.