Download the PHP package mehrshaddarzi/wp-trait without Composer
On this page you can find all versions of the php package mehrshaddarzi/wp-trait. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mehrshaddarzi/wp-trait
More information about mehrshaddarzi/wp-trait
Files in mehrshaddarzi/wp-trait
Package wp-trait
Short Description Easy framework for fast and standard development of WordPress plugins
License
Informations about the package wp-trait
Fast and standard development of WordPress plugins
WP-Trait is an easy framework for Standard and Fast development of WordPress plugins according php MVC model.
Table of Contents
- Installation
- install with WP-CLI
- install with Composer
- Create New Model
- Generate Model in Command Line
- Generate New Post-Type Model
- Generate New Taxonomy Model
- Generate Model manually
- Generate Model in Command Line
- Global Function
- How to Change Global variable and function name
- Model Properties
- WordPress Hooks
- Use WPDB
- Current Plugin information
- Get WordPress default Constants
- Get WordPress urls and path
- Time in Seconds and Debug Constants
- Get WordPress Global Variables
- WordPress URL Generation
- Get Current User data
- Collection Class
- Post
- Attachment
- User
- Term
- Option
- Comment
- Meta
- Request
- Handle Error
- Cache and Transient
- REST API
- Cookie
- Session
- Event
- Nonce
- File System
- Log
- Views Templates
- Overriding templates via a theme
- Set template attribute
- Trait For WordPress Hooks
- How To Work Trait Hooks
- List Of Trait With Prefix Method Name
- Example Create Ajax Request with Trait
- Utility
- Singleton Design Pattern
- Starter Plugin
- Contributing
- License
Installation
install with WP-CLI
You Can Generate new plugin with WP-Trait
Structure:
And fill Your Plugin information e.g. slug and namespace:
Read More About wp-cli-trait-command Package.
install with Composer
1) First Create a new directory in your WordPress plugins dir e.g. wp-content/plugins/wp-user-mobile
.
3) Run This Command in your directory:
3) Create plugin main file e.g. wp-user-mobile.php
and write:
4) You can add PSR-4 namespace in your Composer.json file:
Create New Model
Generate Model in Command Line
You Can Create new Model With Custom namespace in WP-CLI:
For Example:
or
Generate New Post-Type Model
Generate New Taxonomy Model
Read More Options wp-cli-trait-command Package.
Generate Model manually
1) Add new Admin.php
file in src/
dir:
2) For Create new instance from this Class add to plugin main file in instantiate method:
Global Function
You can access to all classes method with global template function by your plugin slug.
for example if your plugin slug is wp-user-mobile
, you can call method from Admin
class:
or use global variables:
This function show Code is Poetry
.
How to Change Global variable and function name
You can add global
parameters in PHP Main WordPress File:
and Usage:
Also for disable global function set null
.
List of arguments when Create new Plugin object:
Model Properties
WordPress Hooks
You can use $actions
and $filters
property in all class, for example:
Use WPDB
use $this->db
for run Query in WordPress Database:
Current Plugin information
For get current plugin information use $this->plugin
variable:
Get WordPress default Constants
For get WordPress default Constants use $this->constant
variable:
Get WordPress default urls and path:
Time in Seconds and Debug Constants:
Get WordPress Global Variables
For get WordPress global variables use $this->global
variable:
WordPress URL Generation
Use $this->url
variable:
Get Current User data
for get Current User data use $this->user
variable:
Collection Class
This package has list of WordPress helper class, that you can use it.
Post
Attachment
User
Term
Option
Comment
Meta
Meta data list: post
, user
, term
, comment
.
Request
Handle Error
Cache and Transient
REST API
Cookie
Session
How to start session in WordPress?
Event
Nonce
File System
List of Methods File Systems {See Collection}:
Log
Collections Lists are available under /Collection.
Views Templates
For use template engine in this package, use Views
Collection.
Create a folder with name templates
in your plugin and put your php file, for example:
For Load students/table.php
files in your Model, use render
Method:
Overriding templates via a theme
By default, Users who use your plugin can change plugin templates in your active WordPress theme.
For disable Overriding templates in custom file, set false
in render method:
Set template attribute
There is several Ways for set attribute:
Trait For WordPress Hooks
This package has list of php trait for WordPress Hooks, that you can uses. trait Lists are available under /Hook.
How To Work Trait Hooks
1) First add trait
in your class.
2) every method in your class that have init
prefix in method name call in this action:
List Of Trait With Prefix Method Name
Usage | Method Prefix | Variable option on your model |
use Init; | init_ | public $init; |
use AdminAssets; | admin_enqueue_scripts_ | public $adminAssets; |
use AdminFooter; | admin_footer_ | public $adminFooter; |
use AdminInit; | admin_init_ | public $adminInit; |
use AdminMenu; | admin_menu_ | public $adminMenu; |
use AdminSearchBox; | get_search_fields_ | public $adminSearchBox; |
use Ajax; | admin_ajax_{$method_name} | public $ajax; |
use BulkActions; | bulk_actions_ & handle_bulk_actions_ | public $bulkActions; |
use FrontAssets; | wp_enqueue_scripts_ | public $frontAssets; |
use ImageSize; | setup_image_size_ | public $imageSize; |
use Notice; | admin_notices_ | public $notice; |
use PostTypeColumns; | columns_ & content_columns_ | public $postTypeColumns; |
use PreGetQuery; | pre_get_posts_ & pre_get_users_ & pre_get_terms_ | public $preGetQuery; |
use RestAPI; | rest_api_init_ | public $restAPI; |
use RowActions; | row_actions_ | public $rowActions; |
use Shortcode; | add_shortcode_ | public $shortcode; |
use SortableColumns; | sortable_columns_ | public $sortableColumns; |
use TaxonomyColumns; | columns_ & content_columns_ | public $taxonomyColumns; |
use UserColumns; | columns_ & content_columns_ | public $userColumns; |
use UserProfileFields; | admin_user_profile_fields_ & save_admin_user_profile_fields_ | public $userProfileFields; |
use ViewsSub; | views_edit_sub_ | public $viewsSub; |
Example Create Ajax Request with Trait
You can access top ajax request:
Utility
Singleton Design Pattern
For Create a Singleton Design Pattern, use Singleton
trait in your Class:
Starter Plugin
You Can read example folder ReadMe.md files /example. and start your project very fast.
Contributing
We appreciate you taking the initiative to contribute to this project. Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.
License
The WP-Trait is open-sourced software licensed under the MIT license.
All versions of wp-trait with dependencies
ext-json Version *
ext-mbstring Version *