Welcome to ManageWP.org

Register to share, discuss and vote for the best WordPress stories every day, find new ideas and inspiration for your business and network with other members of the WordPress community. Join the #1 WordPress news community!

×

4 min read Shawn Hooper
Tutorials | shawnhooper.ca | Aug. 8, 2017

How to Run WP-CLI Commands on a Remote Server

A step by step tutorial on running WP-CLI commands against a WordPress site installed on another computer.

How to Run WP-CLI Commands on a Remote Server

Tutorials | shawnhooper.ca | Aug. 8, 2017

This weekend at WordCamp Minneapolis I presented an introduction to the power of WP-CLI, a tool that allows you to manage your WordPress website from the command line. I’ve given this talk several times now, but am always looking for cool new features to include. This weekend’s addition to my talk was the ability to run WP-CLI commands from my local machine against a remote site…. which is very cool, and saves even more time.
The Old Way
SSH into Remote Server
Change Directory to where my WordPress Site is installed
Execute WP-CLI command.
The New Way
Execute WP-CLI Command
Step 1: Setting It Up
In order to run commands remotely, you need to install WP-CLI on both the computer you want to run the command from and the server on which your site is located.
I would also recommend setting up passwordless-ssh on your server so that you don’t need to enter your password every time you run a WP-CLI command.
Step 2: Execute the Remote Command
The trick to running commands on a remote server is the –ssh option. Adding this option to any command will tell it to SSH into the remote server and execute the command there. For example, running
wp --ssh=shawn@example.com/var/www/html/

5 min read Matt Cromwell
Community | shawnhooper.ca | Dec. 7, 2015

Looking To The Future – Shawn Hooper - WordPress Developer & Speaker

Great analysis and summary and predictions from Matt Mullenwegs State of the Word

Looking To The Future – Shawn Hooper - WordPress Developer & Speaker

Community | shawnhooper.ca | Dec. 7, 2015

Today was the closing day of the inaugural WordCamp US, a gathering of over 1,800 of the amazing people that make up the WordPress ecosystem. The most anticipated part of this event was WordPress co-founder & CEO Matt Mullenweg’s annual State of the Word (SoTW) keynote delivered at the closing of the conference. This keynote celebrates the achievements of the past year and sets the direction for the next. As I am no longer a freelance WordPress developer, but in charge of setting the direction of technology for an enterprise, I wanted to look at this year’s address with a different perspective. I love WordPress, but now need to look at it as part of the larger picture. Many of the points that Matt made during the SoTW address, while they apply to WordPress, as equally as relevant to the larger web. My takeaways are as follows:
Learn JavaScript, Deeply – This was the “homework” Matt gave everyone in the community. With the release of Calypso, and the WP REST API coming out shortly, there’s no question that knowing JavaScript will play an important role in the future of WordPress development. This is something that we’ve known for a while now. JavaScript has become the de facto language

5 min read Shawn Hooper
Tutorials | shawnhooper.ca | Aug. 23, 2017

Scheduling WordPress Tasks and WP-CLI Commands to Run from System Cron – Shawn Hooper - WordPress Developer & Speaker

WP-Cron is a really handy, but not perfect way of running scheduled tasks on your WordPress site. This article will show you how to improve that setup by triggering WP-Cron events or WP-CLI commands from your *nix server's cron service.

Scheduling WordPress Tasks and WP-CLI Commands to Run from System Cron – Shawn Hooper - WordPress Developer & Speaker

Tutorials | shawnhooper.ca | Aug. 23, 2017

WordPress comes with a built-in task scheduler called WP-Cron. This is the part of core that regularly checks to see if WordPress itself needs updating, or if any of your plugins and themes have updates available. Named after the Unix Cron service that runs various system tasks at specified intervals, WordPress’ implementation isn’t a true cron service though – there is no guarantee that your task will run exactly when you have it scheduled to. This is because WP-Cron is triggered when a page on your site is viewed. The upside to this is that you don’t have to fiddle with cron jobs to get WordPress’ tasks running, it’s just part of the web application. The downside though: if your site has occasional traffic, tasks will only be run when the next page visit happens.
If you want WordPress tasks to run reliably, you can disable the built-in trigger to run cron jobs, and instead configure your server’s system cron service to trigger the WordPress scheduler.
Prerequisites
To implement the solutions shown below, you will need to be able to modify your system cron file. Your ability to do so will depend on your web host’s setup. For example,

2 min read Shawn Hooper
Development | shawnhooper.ca | Feb. 9, 2017

jQuery Tip: Submitting All Form Fields via AJAX to a REST Endpoint

If you're working with the REST API, here's a quick tip on how to submit all fields on an HTML to a REST endpoint using jQuery.ajax()

jQuery Tip: Submitting All Form Fields via AJAX to a REST Endpoint

Development | shawnhooper.ca | Feb. 9, 2017

While working with the WordPress REST API, I found I was writing jQuery AJAX calls with data objects that were getting longer and longer as I submitted more complex forms. I used to list out each form field that I wanted to submit, like this: jQuery.ajax({
url : '/wp-json/my-namespace/v1/my-endpoint/',
async : true,
dataType: 'json',
type : 'POST',
data : {
first_name: jQuery("#first_name").val(),
last_name: jQuery("#last_name").val(),
email: jQuery("#email").val(),
language_preference: jQuery("#language").val(),
country_code: jQuery("#country_code").val(),
phone_number: jQuery("#phone").val(),
start_date: jQuery("#start_date").val()
}
}).done(function() {
// Handle Success
}).fail(function(xhr, status, error) {
// Handle Failure
});
Then I discovered jQuery’s serialize function. You can use it to take each element in a form and serialize their values into a string. The resulting code now looks like:
jQuery.ajax({
url

5 min read Shawn Hooper
Development | shawnhooper.ca | Feb. 2, 2017

WordPress REST API in the Wild: Cache Clearing – Shawn Hooper - WordPress Developer & Speaker

I'm using the WordPress REST API to remotely trigger the clearing of a key in the Object Cache. Find out how.

WordPress REST API in the Wild: Cache Clearing – Shawn Hooper - WordPress Developer & Speaker

Development | shawnhooper.ca | Feb. 2, 2017

In the last few weeks, I’ve been doing a lot of work integrating & automating some of the systems we use at Actionable.co. This week, I found an interesting use for the WordPress REST API that I thought I’d share. We have a web page on one of our public sites that shows the names, locations and headshots of our consultant network. This data does not originate in WordPress, but in a separate platform. I make a REST call to that platform to retrieve the most up-to-date information to display on this page. For reasons of performance, I cache this data. Until this week, I had instructed WordPress to keep this data for 24 hours.
Here’s a snippet of that code (originated in a class, which is why you’ll see $this used.
1
2
3
4
5
6
7
8
9
10
11
12
// Retrieve Consultant List from Cache
$this->consultantJsonData = wp_cache_get( 'active_consultant_list', 'gem_acp_network_data' );
 
// If no cached version exists, retrieve consultant list from the
// Conversations API, and then cache it for future use.
if ( $this->consultantJsonData === false ) {
$response = wp_remote_get( 'https://example.com/api/Consultants/consultantList' );
if ( is_array( $response

Development | shawnhooper.ca | Jul. 17, 2017

Automated UI Testing using Selenium (WPCampus Presentation)

Shawn Hooper's presentation from WPCampus conference in Buffalo, NY. Selenium is a great tool that we use as well.

Automated UI Testing using Selenium (WPCampus Presentation)

Development | shawnhooper.ca | Jul. 17, 2017

This week I had the pleasure of speaking at the WPCampus conference in Buffalo, New York. WPCampus is a fantastic conference for those in the higher education sector who use WordPress. This year I spoke about automated user interface testing using Selenium. Thank you to everyone who attended. If you weren’t able to attend, the session was recorded and I’ll update this post with a link when it’s available.
If you’re looking for the slides I used for the presentation, here you go:
Finally, here’s a few links to the software and services I mentioned during the talk:
(Photo: Closing Remarks at WPCampus 2017.)

6 min read Shawn Hooper
Development | shawnhooper.ca | Feb. 16, 2017

The WordPress REST API's Undocumented Validation Options – Shawn Hooper - WordPress Developer & Speaker

I discovered a few awesome tricks for validating the input of your custom REST endpoint arguments. Here they are.

The WordPress REST API's Undocumented Validation Options – Shawn Hooper - WordPress Developer & Speaker

Development | shawnhooper.ca | Feb. 16, 2017

The WordPress REST API is still very new. As with many early early technologies, documentation seems to be the last thing to get updated. This is why it can be fun/educational to read through the source code in open source projects. You’ll find things the documentation didn’t teach you! (Or at least not in any documentation I could easily find.) The custom endpoint I was creating required quite a few arguments when called. I wanted to include sanitization and/or validation of these arguments. Setting up a schema for the endpoint made sense. I knew I could perform validation by specifying a ‘validate_callback’ function in the argument definition.
However browsing the source code in WordPress’ core revealed a few bonuses built right into the core, in a function called rest_validate_value_from_schema.
The ‘type’ attribute
By including in a ‘type‘ attribute when defining an argument, the REST API’s validation will automatically check if the value passed into this argument is of the appropriate data type.
register_rest_route( 'route/v1', '/endpoint/', array(
'methods' => 'POST',
'callback' => array( $this, 'endpoint_post_handler'

6 min read Matt Cromwell
Community | shawnhooper.ca | Jun. 21, 2016

Improving Session Feedback at WordCamp – Shawn Hooper - WordPress Developer & Speaker

WordCamp Ottowa took Speaker feedback to a whole new level. Detailed write-up on their process by Shawn Hooper.

Improving Session Feedback at WordCamp – Shawn Hooper - WordPress Developer & Speaker

Community | shawnhooper.ca | Jun. 21, 2016

What a weekend! We just wrapped up WordCamp Ottawa 2016 at Carleton University here in Ottawa, Canada. We had approximately 160 attendees show up for the weekend, with one day full of full-length (45 min) and lightning (20 min) talks, and a second day of hands-on workshops and “un-conference” activities. One thing we tried to do differently this year was to improve the feedback that our wonderful speakers received about the presentations they spent so much time preparing for our camp. Having attended many conferences in Canada and the United States, I’ve seen this done in various ways.
Send out a survey to all attendees by e-mail the at the end of the conference asking them to provide their feedback on the talks they saw, as well as the overall event.
Use an online speaker feedback service that requires attendees to create an account and login to provide their comments
Hand out paper forms at the event
Do nothing (it amazes me that some conferences don’t seem to focus on session feedback)
We took the analog approach. That’s right, we asked all the attendees to fill out a short paper survey after every talk.
The result? We saw a significantly higher level

4 min read Shawn Hooper
Development | shawnhooper.ca | Feb. 27, 2017

Expose Localhost Websites Publicly with ngrok – Shawn Hooper - WordPress Developer & Speaker

Being able to access your localhost sites from the outside world can be really handy for testing. Here's how to do it, using ngrok.

Expose Localhost Websites Publicly with ngrok – Shawn Hooper - WordPress Developer & Speaker

Development | shawnhooper.ca | Feb. 27, 2017

If you’re doing any web development work, I hope you have a local development environment running on your computer, and that you aren’t FTP’ing your code to the server and then loading the page each time to see if your change works. (I’ve seen people do this, it’s painful, and slow). If you don’t have a local development environment setup, there are lots of options. WordPress developers, check out DesktopServer, VVV, or Local by Flywheel as great options for getting up and running with a local development environment quickly. When working with local development environments, you can typically only access your sites from localhost (your computer). Accessing your sites from another computer on the same network, or from elsewhere not the Internet, is not possible.
There are many reasons you may want to do get temporaryaccess to your local environment from the outside. I say temporary because your computer should not be used as a web server for many reasons including performance and security. In my experience temporary local access is handy mostly for testing scenarios, such as:
Testing your sites from mobile devices
Testing your REST API endpoints from

4 min read Shawn Hooper
Development | shawnhooper.ca | Jan. 12, 2017

WordPress 4.7's do_shortcode_tag filter

I stumbled on a filter introduced in WordPress 4.7 that allows you to modify the output of a shortcode.

WordPress 4.7's do_shortcode_tag filter

Development | shawnhooper.ca | Jan. 12, 2017

For the last few months I’ve been using a modified version of “Better Click to Tweet“, a WordPress plugin by The WP Steward. It implements a simple shortcode that enables “Click to Tweet” functionality on a piece of text in your page or post. The problem was, I wanted to append content to the output of the shortcode each time it was used. I’d looked at the plugin source, and there were no filters that I could implement do this. So my solution was to modify the plugin’s source and use my forked version on my sites. Anyone who’s done this knows what’s coming next…. a new version of the plugin came out. Oh bother, now I need to download the new version and re-apply my changes.
TFW when you had to modify a plugin and now you need to redo your changes before upgrading…. without docs. Time to diff the original…
— Shawn Hooper (@ShawnHooper) January 11, 2017
This time around, I thought… “There has to be a better way!” and dug into WordPress’ core code. Lo and behold – WordPress 4.7 has a new filter that helps me do exactly what I needed to!
Enter: do_shortcode_tag
The new do_shortcode_tag