Download the PHP package thezombieguy/wpc without Composer
On this page you can find all versions of the php package thezombieguy/wpc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thezombieguy/wpc
More information about thezombieguy/wpc
Files in thezombieguy/wpc
Package wpc
Short Description Custom WordPress features to allow for caching, theming and simple API endpoint creation.
License MIT
Informations about the package wpc
Wordpress Custom Theme library
This library is intended to give WordPress developers a little extra functionality when building custom themes.
This library includes advanced theme templates with variable injection, API wrapper for easier endpoint development, and a simple caching system that stores cached objects to the file system.
Install
You can install with composer
Usage
More information is available in the docs folder.
Theme
First create a template in your theme folder. For this example, we will create templates/test.php
And now, in one of your page templates, add the following code.
The wpc_theme function takes 2 parameters. The location of the template relative to your wordpress theme directory (not that you do not need to provide the php extension, just the name), and a set of variables that you want to pass to your template.
Each array variable will be passed to the template and extracted as its own variable. You may also access the Theme class directly by invoking the \WPC\Theme class.
Cache
Create a new cache object. This will create a wpc_cache folder in your uploads folder if it doesn't already exist. Make sure you have the correct permissions.
Now cache some data to the filesystem.
Once it is cached, you can retrieve it later.
Cache returns an object when calling cached data.
$myCacheData->time
represents when this ws cached.
$myCacheData->data
is the data you put into the cache.
You can check the $myCacheData->time
and after a certain amount of time, you can delete and recache trhe object again with updated information.
You can also wipe the cache folder with
This will destory all cached objects.
API
Create endpoints that will call back to a custom PHP class.
First create a callback class that will handle your endpoint.
Now create an array of endpoints to wish to register. Note the handler/callback parameters in the url string must match you class/method created above.
Now go and update your permalinks in WordPress or you will not see this in action. Go to Settings->Permalinks and click Save changes.
Now when you go to your endpoint url http://example.com/api/numbers/1/2 you will see a json string output with the values you specified.
The redirect string MUST contain the __api, handler, and callback variables or your endpoint will not execute.