Skip to content

Instantly share code, notes, and snippets.

@lordspace
Created December 8, 2013 05:29
Show Gist options
  • Select an option

  • Save lordspace/7853704 to your computer and use it in GitHub Desktop.

Select an option

Save lordspace/7853704 to your computer and use it in GitHub Desktop.
How to return JSON from a WordPress plugin without an external plugin
<?php
/*
Plugin Name: Orbisius Sample Code
Plugin URI: http://club.orbisius.com/products/
Description: Sample plugin to return JSON
Version: 1.0.0
Author: Svetoslav Marinov (Slavi)
Author URI: http://orbisius.com
License: GPL v2
*/
add_action('init', 'orbisius_example_code', 0);
/**
* Based on the parameters will output some JSON
*/
function orbisius_example_code() {
if (!empty($_REQUEST['orb_cmd']) && $_REQUEST['orb_cmd'] == 'test') {
echo json_encode( array( 'status' => 1, 'message' => 'hello' ) );
die;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment