How To Create And Execute Your Own PHP Run Code Snippets Across All Your Sites

The ManageWP user base is growing. Our own community of expert WordPress users is starting to emerge, and with it the spirit of community and open source development remains strong. Now you can create your own PHP code snippets and execute them across all of your ManageWP websites. But that’s not all – you can share your creations and use those created by others!

How To Create And Execute Your Own PHP Run Code Snippets Across All Your Sites

There are a lot of reasons to love WordPress (as we discussed just the other day), but its secret sauce is formulated with the ingredients of community and open source.

WordPress is open source, which means that anyone can do anything they want to make it behave in any possible number of ways. And it is supported by an enormous community of talented folk, who are entirely responsible for its past and continuing development. It is at the intersection of community and open source that the magic happens with WordPress.

And at ManageWP, we appreciate that fact. Our CEO is a highly accomplished WordPress plugin developer (both premium and free), so he knows a thing or two about community and the spirit of open source. Our user base is growing at a rapid rate, and it is chock full of advanced WordPress users. At this stage, we would be fools to not spot the potential of our own community.

And that is where one of newest features (announced just a couple of weeks ago) comes in.

Run Code Snippets

The WordPress API allows any competent PHP programmer to extract and manipulate an enormous amount of data and variables. If you are a WordPress developer, there are multiple reasons why you might wish to run particular PHP code snippets on a regular basis. Wouldn’t it be good if you could save such snippets and run them on multiple sites, all with just a few clicks?

Well now of course you can. We have implemented a new Run Code feature into the ManageWP dashboard – you can access it from the sidebar. Not only can you create code snippets, you can also save and publish them to a public repository so that others can use them too. And of course, that also means you can use code snippets created by others, and alter them for your own purposes. It is open source code snippet sharing, brought to you by the ManageWP community.

The run code tool is split into three sections.

1. Select Websites

Select Websites

This is where the true power of ManageWP comes into play. When choosing to run an existing code snippet (or an entirely new one), you can select it to run on any (or all) of the websites in your ManageWP account. You can do so by simply selecting a website from the left hand box, or a particular group from the right hand box. You can also select multiple websites or groups.

2. Enter PHP Code

This is where you can enter your own snippets, or where code for existing snippets will be displayed.

If you are creating a new code snippet, you will probably want to save it. Once you are finished, just hit the “Save” button, enter a title and a description, and choose whether or not you would like to make the snippet available for everyone to use:

WordPress Code Snippet

Hit “Save” again, and your snippet will be saved.

3. Code Snippets

At the bottom of the screen, you will see a tabbed display:

Code Snippets

This is where all of your saved snippets, in addition to all public code snippets, are stored. In order to use a snippet, just hover over its title and click on “Load”:

Load Snippet

The PHP Code box will be populated with the code snippet, ready for you to execute. When you hit the “Execute” button, the code will be run on whichever site(s) you chose. In the above “Update Timezone” example, the snippet will return a confirmation that the timezone has been updated:

Update Timezone Code Snippet

That’s it! This example alone shows how powerful this tool can be – you can update the timezone across all of your ManageWP sites with just a few clicks.

Now It’s Your Turn!

We have set up a few example public code snippets to demonstrate what this tool is capable of doing, but we have really only scratched the surface. If you know your way around PHP, you can probably think of a number of different ways in which our Run Code feature can be used to make the management of your website portfolio more efficient.

So don’t be shy – start creating and sharing code snippets! What ideas do you have, or what would you like to see? Let us know in the comments section!

Creative Commons photo courtesy of trekkyandy

Tom Ewer

Tom Ewer is the founder of WordCandy.co. He has been a huge fan of WordPress since he first laid eyes on it, and has been writing educational and informative content for WordPress users since 2011. When he's not working, you're likely to find him outdoors somewhere – as far away from a screen as possible!

2 Comments

  1. enstinemuki

    This is excellent! I want to try this for a first hand experience

  2. kurav773

    hey,

    great job with implementing the code snippets.., this really expands on what can be done with ManageWP.

    Where are snippets examples?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>