Arthur

Pemberton

Full-stack web applications developer


Welcome to my blog

As I discover new things in my field and solve troublesome problems, I will attempt to document my finds here.

Blog

On October 1, 2013, by Arthur Pemberton, 0 Comments

Welcome to my blog

As I discover new things in my field and solve troublesome problems, I will attempt to document my finds here.

Web Application Development

On June 4, 2015, by Arthur Pemberton, 0 Comments

Providing custom web application and web service API development with hourly bill rates, or fixed project estimates. Solutions are developed using flexible, tested tools, and scalable platforms to best meet defined requirements. Specializing is back-end, secure, web interfaces for small to high loads based on horizontally scalable architectures.

Commonly Requested Features

  • Audit/Revision logs
  • Integration into existing authentication systems
  • Integration into existing data stores
  • Mobile device friendly user interfaces
  • Reporting data exported to CSV or Microsoft Excel
  • Subscription based notifications

Application Stack

For details on my preferred choice of software, tools, and supporting services, see my description of my web application stack.

Trigger WordPress 404 when using parse_request

On September 13, 2022, by Arthur Pemberton, 0 Comments

I was recently working on an website using an abandoned plugin whose functionality I needed. I noticed however, that all rewritten URLs defined by the plugin return HTTP 200 regardless of if the references resource existed. I tracked the issue down to the code in the parse_request action handler doing nothing after failing to find the resource. So it needed to trigger/raise the 404 status, and to do so was as simple as setting $query->query_vars['error'] = '404';. See an example snippet bellow.

add_action( 'parse_request', 'custom_parse_request' );

function custom_parse_request( $query ) {
	$query_item_exists = false;

	// implement code to lookup item based on query

	if ( $query_item_exists ) {
		// handle changes to query
	}
	else {
		// trigger 404 response
		$query->query_vars['error'] = '404';
	}
}

After this change, WordPress correctly returned HTTP 404 when the resource did not exist, and the 404.php was correctly used.