Use WordPress core as PHP framework

For a task I required using headless WordPress, just the core without a template. Using as a PHP framework. More info about integration is available at http://codex.wordpress.org/Integrating_Wordpress_with_Your_Website

Power tip:
To avoid plugins redirecting after requiring wp-blog-header.php define DOING_CRON const or might be DOING_AJAX or WP_ADMIN. Gist snippet. You could also check defined constants. To avoid redirect you also might redefine wp_redirect() function.

 

<?php

define('DOING_CRON', true);
require dirname(__FILE__).'/wp-blog-header.php';

// Your code goes here...
Advertisements

About Michal Zuber

Biker and rollerblader. Owner and developer at http://nevilleweb.sk/ Co-founded http://neville.sk/ Blog at https://michalzuber.wordpress.com/
This entry was posted in php, wordpress and tagged , , . Bookmark the permalink.

2 Responses to Use WordPress core as PHP framework

  1. Dennis Snell says:

    Not sure what you are doing, but don’t forget to take a look and see if the REST API is a good fit for your project. Strong decoupling from PHP makes for an awesome development experience while retaining the strong management and plugability of WordPress.

    • Michal Zuber says:

      Thanks Dennis 😉 The REST API is looking great. I did an import of products from XML into WooCommerce. WC has also API, maybe I try that next time if I don’t forget.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s