How to do rest APi with wordpress

First of all you should re-submit permalink to enable rest api in your wordpress. your rest api url is: http://your-site.com/wp-json/ And you can register new endpoind with bellow code: add_action( ‘rest_api_init’, function () { register_rest_route( ‘myplugin/v1’, ‘/author/(?P<id>\d+)’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘my_awesome_func’, ) ); } );

Add class as plugin for other plugins

You can check if the class is already include / exists, and if it not exists include it. In your plugin, depending on how you can be sure that the install has plugin activated, you’ll maybe need to include your class inw every plugin. if(!class_exists(‘Excel_Writer’){ include_once(‘excelwriter.inc.php’); $excel = new Excel_Writer(‘myxls.xls’); } Be carefull with files … Read more

GET web api method from a WordPress PHP script

wp_remote_get was causing the issue and switch over to a curl solution. The code below replaced my old solution: $serverIP = ‘x.x.x.x’; $serviceAPI = ‘/Get_VacationRequest’; $jsonData = urlencode(json_encode($_REQUEST)); // Set up the server information where we will consume the API $url=”http://” . $serverIP . $serviceAPI . ‘?name=” . $jsonData; // Start the curl session $curl … Read more

My plugin can’t see my files

Answering my own question just in case someone comes across it looking for an answer. Managed to figure it out! We have to get the URL as follows, we can’t just reference it like we normally would on a server plugins_url( ‘products.csv’, __FILE__ ); The above code returns the information we need, rather than just … Read more

WordPress Cron function is not working

Are you constructing the class properly? Is the file writable? Do you need the interval or can you add the scheduled item if it doesn’t exist. This example is working, and sets an event 10 seconds into the future. wp_schedule_event( time() + 10, null, ‘ga_order_syn’ ); class CronTest { function __construct() { add_action( ‘init’, array … Read more

Can’t find variable is_single in my jQuery plugin

The easiest way in WP to write php into JS is using wp_footer function sse246626_js() { if(is_single()) { echo ‘<script type=”text/javascript”>’; echo ‘jQuery(document).ready(function($) {‘; echo ‘$(“#mydiv”).hide();’; echo ‘});’; echo ‘</script>’; } } add_action(‘wp_footer’, ‘sse246626_js’); This way gives you access to the WP functions as you need, there are probably better ways of doing it if … Read more