ACF Gallery Saved to Specific Folder

Recently we had a client that wanted to make sure all of the files in one of their galleries was in a specific directory instead of the default upload/year/month directory.

Here is a simple function to make sure that happens, including updating all previous files uploaded to that gallery.

 

JS Capitalize a String

Just a simple String prototype to capitalize the first letter of the string.

 

Convert Form to JS Object

This function will take your entire HTML form and convert all the inputs into a single JS object! Thanks to Dave over at Stack Overflow!

Usage is as simple as:

var formObject= $(‘form’).serializeObject();
Requires jQuery

Search Post Title and Meta

Unfortunately when you are doing a custom query in WordPress by default you can’t search by the “s” parameter and a meta_query. A common technique was to just do two queries and merge them. That works, but it is not efficient.

User Satbir Kira over at StackOverflow posted this great solution. Simply add this function to your functions.php file and replace the “s” parameter in your custom query with a “_meta_or_title” parameter.

Here is what an example query might look like.

 

Limit User Role to Certain Posts

There are a variety of plugins out there for managing user role access. User Role Editor (URE) and Advanced Access Manager (AAM) are both good plugins I can recommend.URE is great for…editing roles. The problem with URE is that it doesn’t allow more narrow scope restrictions…like a single post. AAM is great at limiting individual posts and hiding admin menus. AAM however requires a LOT of setup if you have a lot of pages / a lot of roles and starts to become unpractical for highly restrictive page editing.

All that said, I ended up turning to good ol’ taxonomies.

First, setup your taxonomy for your posts. In this case I am targeting a “Departments” custom post type.

See jp_register_cpt and jb_register_taxonomy for info on these functions.

Second, setup your roles with URE. I’ll leave this to you, but I usually start with copying either the “Contributor” or the “Subscriber” default roles and going from there. Mine looks like this:

Third, Add a new admin taxonomy in the new taxonomy you just created. Make sure to give it the same slug as the user role ID, this is just for ease of use later and for reference. Example:

Forth, add this function to your PHP file.

All done! Now this user role should not be able to view or edit any posts that do not have this category.

Using TinyMCE outside of WordPress

Recently we had to setup a TinyMCE WYSIWYG outside of WordPress so we couldn’t use the wp_editor function.

TinyMCE has changed a lot since I last used it as a stand alone feature so I wanted to make a post about how to set this up so I don’t have to look around for this info again.

Step number one is setting up the script, like so

Unfortunately you do need to setup an account and get an API key in order to correctly use TinyMCE. You also need to setup the domains you want this script to work on, this is done in your TinyMCE account.

Once we have that in place we can setup our WYSIWYG!

And there we go! That is all you need to get a basic TinyMCE instance going.

NOTE: I had to make sure I had the editor.on(‘change’) function working or else my textarea wasn’t updating quite right. You might not need this for your use case.

TinyMCE also offers additional plugins which are really neat, unfortunately they require paying a monthly subscription 🙁

If you are using TinyMCE in multiple places and NEED those plugins, it would definitely be worth it, but the default functionality is probably good enough for most users.