Plugin: Automatic submenu items

At some point our navigation menu started to mimic the hierarchical structure of the posts itself. Manually adding all items just seemed silly. This sounded like a good candidate for wp_list_pages(). Hardcoding the menu would mean losing flexibility, however. It would be nice if all child posts would be added automatically, with the option of overriding that behaviour by manually adding menu items.

With WordPress it’s like “Filter all the Things”, hence the Submenu 3000 plugin.

Continue reading “Plugin: Automatic submenu items”

Sublime Text Plugin: WordPress Coding Standards whitelist flags

A Sublime Text 2/3 autocomplete plug-in for WordPress Coding Standards whitelist flags.
Install the plugin via Sublime Text’s Package Control by searching for WPCS whitelist flags.

Use

An autocomplete popup will open when you type `wpcs`.


Fork, create an issue or pull request on GitHub

Plugin: Prevent automatically attaching unattached attachments when inserting into post

In an effort to keep things simple and also to keep the post content and its images separated, I created an image gallery from the images attached to a post. To add an image to the post’s gallery, the user just needed to upload an image to that the post, without inserting it into the post content. Great for product pages and such.

As things go it then turned out that this made it impossible super inconvenient to also add images, say a sponsor logo, to the post content if you don’t want that image to also end up in the post’s gallery.

When you insert an item into a post via the media modal’s ‘Media Library’ tab: even when you didn’t upload that image via the current post edit screen, WordPress will mark that attachment as attached to that specific post if it was not already attached to another post. Now what?

Filters to the rescue

add_filter( 'wp_insert_post_parent', 'prefix_filter_insert_post_parent', 10, 2 );

function prefix_filter_insert_post_parent( $post_parent, $post_ID ) {

	// The 'send-attachment-to-editor' action is set when inserting attachments into the editor.
	if ( ! isset( $_REQUEST['action'] ) || 'send-attachment-to-editor' !== $_REQUEST['action'] ) {
		return $post_parent;
	}

	$post_before = get_post( $post_ID );

	// If the attachment already has a parent, return its ID.
	if ( 0 !== $post_before->post_parent ) {
		return $post_parent;
	}

	// Else, sadly, but convenient for us, the attachment needs to stay an orphan...
	return 0;
}

In the unlikely case you run into the same problem: the XQR-Z100A WordPress plugin takes care of that now.

Thanks for your help J.D.!

Plugin: Attachments Only

Sometimes you don’t need all the bells and whistles of the WordPress attachment media view. For instance when you’d want all media files related to a post to actually be attachments of that post. This plugin takes that to the extreme and replaces the default WordPress media uploader view with a simplified version: it only allows adding, removing and rearranging attachments to a post.

Download, fork, create an issue or pull request on GitHub.