0

When I write answers for questions on WPSE, or when I want to try a piece of short and simple code, I need a place to quickly test the results without actually doing permanent change to any file.

For example, let's say I want to test this:

<?php echo get_post_meta(); ?>

I can put this at the end of my single.php and open a single post to check the results, but then each time I need to modify my templates and then revert the changes.

Is there any way to test WordPress codes quickly?

A method that crossed my mind was to create a php file and then load WordPress by using require_once( dirname(__FILE__) . '/wp-load.php' ); for development purposes. However I'm not sure if it's the best way to do this.

3

I actually use free online development environments to test, such as c9. It allows very quick installation and setup of wordpress. You can easily try different plugins/codes without endangering your files.

Moreover, if you mess any thing up you can always delete that installation and create a new one.

Another great feature is the cloning of the environment. So if you are about to work on something dangerous. You can clone your environment prior to it and work freely on the new plugins/themes you are working on.

It provides a very nice text editor with similar functions to sublime and great test environment. You can use command line just like any normal server. The only thing to keep in mind is that it is only a development environment. It does not support Production.

Besides wordpress, it also provides other dev environment for many other languages.

Edit

Additional Tip: I keep a separate Wordpress installation in c9 with the unit test data imported. Follow here for more instructions and the benefit for having test data.

This allows me to quickly test someone's code or a new plugin without having to mess with my actual project.

This is especially beneficial for stack members.

Image is from their official website

Edit 5/9/2018

As of July 14, 2016, Cloud9 is part of Amazon AWS. you can read the announcement of the c9's acquisition by AWS here.

Some of the benefits listed on the official AWS Cloud9 are:

  • CODE WITH JUST A BROWSER

    AWS Cloud9 gives you the flexibility to run your development environment on a managed Amazon EC2 instance or any existing Linux server that supports SSH

  • CODE TOGETHER IN REAL TIME

    AWS Cloud9 makes collaborating on code easy. You can share your development environment with your team in just a few clicks and pair program together. While collaborating, your team members can see each other type in real time, and instantly chat with one another from within the IDE.

  • BUILD SERVERLESS APPLICATIONS WITH EASE

    AWS Cloud9 makes it easy to write, run, and debug serverless application

  • DIRECT TERMINAL ACCESS TO AWS

    AWS Cloud9 comes with a terminal that includes sudo privileges to the managed Amazon EC2 instance that is hosting your development environment and a preauthenticated AWS Command Line Interface.

  • START NEW PROJECTS QUICKLY

    AWS Cloud9 makes it easy for you to start new projects. Cloud9’s development environment comes prepackaged with tooling for over 40 programming languages, including Node.js, JavaScript, Python, PHP, Ruby, Go, and C++.

1

The answer is quite simple: test your code in WordPress environment.

I have a standard WordPress instance running (and if I don't, I create one via EasyEngine) in my local environment with a custom _s child theme and a custom plugin (this one, though I realize the repo needs to be updated) . Both are Git repositories, so every change I make can be diffed and in the end it is simple to undo.

WP-CLI makes this even simpler to maintain:

$ wp core update && wp theme update --all && wp plugin update --all
  • Thank you, but I was hoping for something like PHPStorm or GithubDesktop, but capable of running WordPress's functions. – Jack Johansson Jul 18 '17 at 22:33
  • @JackJohansson The problem with this is, you'll always be waiting only your 3rd party updates/patches/whatevs. So why not get it directly from the source? You can keep using PHPStorm to write your code, testing it with the environment you want it to run on is something else imo – kero Jul 18 '17 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.