Download the PHP package mikenolimits/corcel without Composer
On this page you can find all versions of the php package mikenolimits/corcel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mikenolimits/corcel
More information about mikenolimits/corcel
Files in mikenolimits/corcel
Package corcel
Short Description Use WordPress backend with any PHP framework
License MIT
Homepage http://github.com/corcel/corcel
Informations about the package corcel
Corcel
This package allows you to use WordPress as backend (admin panel) and retrieve its data using Eloquent, with any PHP project or even framework.
Corcel is a class collection created to retrieve WordPress database data using a better syntax. It uses the Eloquent ORM developed for the Laravel Framework, but you can use Corcel in any type of PHP project, with any framework, including Laravel.
This way, you can use WordPress as the backend (admin panel), to insert posts, custom types, etc, and you can use whatever you want in the frontend, like Silex, Slim Framework, Laravel, Zend, or even pure PHP (why not?). So, just use Corcel to retrieve data from WordPress.
Installation
To install Corcel, just run the following command:
Usage
I'm using Laravel
If you are using Laravel you do not need to configure database again. It's all already set by Laravel. So you have only to change the config/database.php
config file and set yours connections. You can use just one connection or two (one for your Laravel app and another to Corcel). Your file will look like this:
Now you should create your own Post
model class. Laravel stores model classes in app
directory, inside App
namespace (or the name you gave it). Your Post
class should extends Corcel\Post
and set the connection name you're using, in this case wordpress
:
So, now you can fetch database data:
I'm using another PHP Framework
Here you have to configure the database to fit the Corcel requirements. First, you should include the Composer autoload
file if not already loaded:
Now you must set your WordPress database params:
You can specify all Eloquent params, but some are default (but you can override them).
Posts
Every time you see
Post::method()
, if you're using your own Post class (where you set the connection name), likeApp\Post
you should useApp\Post::method()
and notPost::method()
. All the examples are assuming you already know this difference.
You can retrieve meta data from posts too.
Updating post custom fields:
Inserting custom fields:
Advanced Custom Fields (ACF)
If you want to retrieve a custom field created by the Advanced Custom Fields (ACF) plugin, you have to install the corcel/acf
plugin and call the custom field like this:
Custom Post Type
You can work with custom post types too. You can use the type(string)
method or create your own class.
Using type()
method will make Corcel to return all objects as Corcel\Post
. Using your custom class you have the advantage to customize classes, including custom methods and properties, return all objects as Video
, for example.
Custom post types and meta data:
Single Table Inheritance
If you choose to create a new class for your custom post type, you can have this class be returned for all instances of that post type.
You can also do this for inbuilt classes, such as Page or Post. Simply register the Page or Post class with the associated post type string, and that object will be returned instead of the default one.
This is particular useful when you are intending to get a Collection of Posts of different types (e.g. when fetching the posts defined in a menu).
Shortcodes
You can add shortcodes by calling the addShortcode
method on the Post
model :
If you are using Laravel, we suggest adding your shortcodes handlers in App\Providers\AppServiceProvider
, in the boot
method.
The thunderer/shortcode library is used to parse the shortcodes. For more information, click here.
Taxonomies
You can get taxonomies for a specific post like:
Or you can search for posts using its taxonomies:
Post Format
You can also get the post format, like the WordPress function get_post_format()
:
Pages
Pages are like custom post types. You can use Post::type('page')
or the Page
class.
Categories & Taxonomies
Get a category or taxonomy or load posts from a certain category. There are multiple ways to achieve it.
Attachment and Revision
Getting the attachment and/or revision from a Post
or Page
.
Menu
To get a menu by its slug, use the syntax below.
The menu items will be loaded in the nav_items
variable. The currently supported menu items are: Pages, Posts, Links, Categories, Tags.
To handle multi-levels menus, loop through all the menu items to put them on the right levels in an array. Then, you can walk through the items recursively.
Here's just a basic example:
Users
You can manipulate users in the same manner you work with posts:
Authentication
Using laravel
You will have to register Corcel's authentication service provider in config/app.php
:
And then, define the user provider in config/auth.php
:
To make Laravel's Password Reset work with Corcel, we have to override how passwords are stored in the database. To do this, you must change Auth/PasswordController.php
from :
to
Using something else
You can use the AuthUserProvider
class to authenticate an user :
Running tests
To run the phpunit tests, execute the following command :
If you have the global phpunit
command installed you can just type:
Contributing
All contributions are welcome to help improve Corcel.
Before you submit your pull request consider the following guidelines:
- Make your changes in a new git branch, based on the dev branch:
git checkout -b my-fix-branch dev
-
Create your patch/feature, including appropriate test cases.
-
Run the unit tests, and ensure that all tests pass.
- In GitHub, send a pull request to
corcel:dev
.
Licence
MIT License © Junior Grossi
All versions of corcel with dependencies
illuminate/database Version ~5.3.0
illuminate/contracts Version ~5.3.0
illuminate/support Version ~5.3.0
hautelook/phpass Version 0.3.4
thunderer/shortcode Version ^0.6.2