{"id":15292313,"url":"https://github.com/mehrshaddarzi/wp-trait","last_synced_at":"2025-04-13T10:26:04.110Z","repository":{"id":42083688,"uuid":"399842914","full_name":"mehrshaddarzi/wp-trait","owner":"mehrshaddarzi","description":"Fast and standard development of WordPress plugins","archived":false,"fork":false,"pushed_at":"2025-01-27T14:22:46.000Z","size":305,"stargazers_count":16,"open_issues_count":19,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T18:29:40.314Z","etag":null,"topics":["wordpress","wordpress-boilerplate","wordpress-development","wordpress-php-library","wordpress-plugin","wordpress-workflow"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mehrshaddarzi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-25T14:10:28.000Z","updated_at":"2024-12-05T17:13:10.000Z","dependencies_parsed_at":"2024-03-28T08:41:31.186Z","dependency_job_id":"0f7cacd9-4d1a-43ff-830d-bb29441c78a7","html_url":"https://github.com/mehrshaddarzi/wp-trait","commit_stats":{"total_commits":244,"total_committers":4,"mean_commits":61.0,"dds":0.08196721311475408,"last_synced_commit":"f91d4a1e38ac78b7fa724cf1a1fe0ba8834e104d"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehrshaddarzi%2Fwp-trait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehrshaddarzi%2Fwp-trait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehrshaddarzi%2Fwp-trait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehrshaddarzi%2Fwp-trait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehrshaddarzi","download_url":"https://codeload.github.com/mehrshaddarzi/wp-trait/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248697084,"owners_count":21147256,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wordpress","wordpress-boilerplate","wordpress-development","wordpress-php-library","wordpress-plugin","wordpress-workflow"],"created_at":"2024-09-30T16:17:20.183Z","updated_at":"2025-04-13T10:26:04.073Z","avatar_url":"https://github.com/mehrshaddarzi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fast and standard development of WordPress plugins\n\n![Packagist](https://img.shields.io/github/license/mehrshaddarzi/wp-trait)\n![Packagist Version](https://img.shields.io/github/v/release/mehrshaddarzi/wp-trait)\n![GitHub repo size](https://img.shields.io/github/repo-size/mehrshaddarzi/wp-trait)\n\nWP-Trait is an easy framework for Standard and Fast development of WordPress plugins according php MVC model.\n\n## Table of Contents\n\n* [Installation](#installation)\n    + [install with WP-CLI](#install-with-wp-cli)\n    + [install with Composer](#install-with-composer)\n* [Create New Model](#create-new-model)\n    + [Generate Model in Command Line](#generate-model-in-command-line)\n        - [Generate New Post-Type Model](#generate-new-post-type-model)\n        - [Generate New Taxonomy Model](#generate-new-taxonomy-model)\n    + [Generate Model manually](#generate-model-manually)\n* [Global Function](#global-function)\n    + [How to Change Global variable and function name](#how-to-change-global-variable-and-function-name)\n* [Model Properties](#model-properties)\n    + [WordPress Hooks](#wordpress-hooks)\n    + [Use WPDB](#use-wpdb)\n    + [Current Plugin information](#current-plugin-information)\n    + [Get WordPress default Constants](#get-wordpress-default-constants)\n        + [Get WordPress urls and path](#get-wordpress-urls-and-path)\n        + [Time in Seconds and Debug Constants](#time-in-seconds-and-debug-constants)\n    + [Get WordPress Global Variables](#get-wordpress-global-variables)\n    + [WordPress URL Generation](#wordpress-url-generation)\n    + [Get Current User data](#get-current-user-data)\n* [Collection Class](#collection-class)\n    + [Post](#post)\n    + [Attachment](#attachment)\n    + [User](#user)\n    + [Term](#term)\n    + [Option](#option)\n    + [Comment](#comment)\n    + [Meta](#meta)\n    + [Request](#request)\n    + [Handle Error](#handle-error)\n    + [Cache and Transient](#cache-and-transient)\n    + [REST API](#rest-api)\n    + [Cookie](#cookie)\n    + [Session](#session)\n    + [Event](#event)\n    + [Nonce](#nonce)\n    + [File System](#file-system)\n    + [Email](#email)\n    + [Log](#log)\n* [Views Templates](#views-templates)\n    + [Overriding templates via a theme](#overriding-templates-via-a-theme)\n    + [Set template attribute](#set-template-attribute)\n* [Trait For WordPress Hooks](#trait-for-wordpress-hooks)\n    + [How To Work Trait Hooks](#how-to-work-trait-hooks)\n    + [List Of Trait With Prefix Method Name](#list-of-trait-with-prefix-method-name)\n    + [Example Create Ajax Request with Trait](#example-create-ajax-request-with-trait)\n* [Utility](#utility)\n    + [Singleton Design Pattern](#singleton-design-pattern)\n* [Starter Plugin](#starter-plugin)\n* [Contributing](#contributing)\n* [License](#license)\n\n## Installation\n\n### install with WP-CLI\n\nYou Can Generate new plugin with `WP-Trait` Structure:\n\n```console\nwp trait start\n```\n\nAnd fill Your Plugin information e.g. slug and namespace:\n\n```\n1/12 [--slug=\u003cslug\u003e]: wp-plugin\n2/12 [--namespace=\u003cnamespace\u003e]: WP_Plugin\n3/12 [--plugin_name=\u003ctitle\u003e]: plugin-name\n4/12 [--plugin_description=\u003cdescription\u003e]: plugin description\n5/12 [--plugin_author=\u003cauthor\u003e]: Mehrshad Darzi\n6/12 [--plugin_author_uri=\u003curl\u003e]: https://profiles.wordpress.org/mehrshaddarzi/\n7/12 [--plugin_uri=\u003curl\u003e]: https://github.com/mehrshaddarzi/wp-trait\n8/12 [--skip-tests] (Y/n): n\n9/12 [--ci=\u003cprovider\u003e]: travis\n10/12 [--activate] (Y/n): y\n11/12 [--activate-network] (Y/n): n\n12/12 [--force] (Y/n): y\n```\n\nRead More About [wp-cli-trait-command](https://github.com/mehrshaddarzi/wp-cli-trait-command) Package.\n\n### install with Composer\n\n1) First Create a new directory in your WordPress plugins dir e.g. `wp-content/plugins/wp-user-mobile`.\n\n3) Run This Command in your directory:\n\n```console\ncomposer require mehrshaddarzi/wp-trait\n```\n\n3) Create plugin main file e.g. `wp-user-mobile.php` and write:\n\n```php\n/**\n * Plugin Name:       My Basics Plugin\n * Plugin URI:        https://example.com/plugins/the-basics/\n * Description:       Handle the basics with this plugin.\n * Version:           1.10.3\n * Requires at least: 5.2\n * Requires PHP:      7.2\n * Author:            John Smith\n * Author URI:        https://author.example.com/\n * License:           GPL v2 or later\n * License URI:       https://www.gnu.org/licenses/gpl-2.0.html\n * Update URI:        https://example.com/my-plugin/\n * Text Domain:       my-basics-plugin\n * Domain Path:       /languages\n */\n\n# Load Package\nrequire_once dirname(__FILE__) . '/vendor/autoload.php';\n\n# Define Main Class\nclass WP_User_Mobile extends \\WPTrait\\Plugin\n{\n\n    public function __construct($slug, $args = [])\n    {\n        parent::__construct($slug, $args);\n    }\n\n    public function instantiate(){}\n\n    public function register_activation_hook(){}\n\n    public function register_deactivation_hook(){}\n\n    public static function register_uninstall_hook(){}\n}\n\nnew WP_User_Mobile('wp-user-mobile');\n```\n\n4) You can add PSR-4 namespace in your Composer.json file:\n\n```\n{\n    \"require\": {\n        \"mehrshaddarzi/wp-trait\": \"^1.0\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"WP_User_Mobile\\\\\": \"src/\"\n        }\n    }\n}\n```\n\n## Create New Model\n\n### Generate Model in Command Line\n\nYou Can Create new Model With Custom namespace in WP-CLI:\n\n```console\nwp trait make model \u003cclass\u003e\n```\n\nFor Example:\n\n```console\nwp trait make model Option\n```\n\nor\n\n```console\nwp trait make model User\\Register\n```\n\n#### Generate New Post-Type Model\n\n```console\nwp trait make post-type Order\n```\n\n#### Generate New Taxonomy Model\n\n```console\nwp trait make taxonomy City\n```\n\nRead More Options [wp-cli-trait-command](https://github.com/mehrshaddarzi/wp-cli-trait-command) Package.\n\n### Generate Model manually\n\n1) Add new `Admin.php` file in `src/` dir:\n\n```php\nnamespace WP_User_Mobile;\n\nuse WPTrait\\Hook\\Notice;\nuse WPTrait\\Model;\n\nclass Admin extends Model\n{\n    use Notice;\n\n    public function __construct($plugin)\n    {\n        parent::__construct($plugin);\n    }\n\n    public function admin_notices()\n    {\n        $text = __('This Notice is a example from your plugin', $this-\u003eplugin-\u003etextDomain);\n        echo $this-\u003eadd_alert($text, 'info');\n    }\n    \n    public function method_name()\n    {\n        return 'Code is Poetry';\n    }\n}\n```\n\n2) For Create new instance from this Class add to plugin main file in instantiate method:\n\n```php\npublic function instantiate()\n{\n    $this-\u003eAdmin = new \\WP_User_Mobile\\Admin($this-\u003eplugin);\n}\n```\n\n## Global Function\n\nYou can access to all classes method with global template function by your plugin slug.\nfor example if your plugin slug is `wp-user-mobile`, you can call method from `Admin` class:\n\n```php\necho wp_user_mobile()-\u003eAdmin-\u003emethod_name();\n```\n\nor use global variables:\n\n```php\ngloabl $wp_user_mobile;\necho $wp_user_mobile-\u003eAdmin-\u003emethod_name();\n```\n\nThis function show `Code is Poetry`.\n\n### How to Change Global variable and function name\n\nYou can add `global` parameters in PHP Main WordPress File:\n\n```php\nnew WP_User_Mobile('wp-user-mobile', ['global' =\u003e 'my_global']);\n```\n\nand Usage:\n\n```php\necho my_global()-\u003eAdmin-\u003emethod_name();\n```\n\nAlso for disable global function set `null`.\n\n```php\nnew WP_User_Mobile('wp-user-mobile', ['global' =\u003e null]);\n```\n\nList of arguments when Create new Plugin object:\n\n```php\n$default = [\n   'main_file' =\u003e '',\n   'global' =\u003e null,\n   'prefix' =\u003e null,\n   'when_load' =\u003e ['action' =\u003e 'plugins_loaded', 'priority' =\u003e 10]\n];\n```\n\n## Model Properties\n\n### WordPress Hooks\n\nYou can use `$actions` and `$filters` property in all class, for example:\n\n```php\nuse WPTrait\\Model;\n\nclass Post extends Model\n{\n    public $actions = [\n        'init' =\u003e 'init_check_user',\n        'save_post' =\u003e ['save_post_view', 10, 3],\n        'pre_get_posts' =\u003e 'custom_query_action',\n        'admin_notices' =\u003e [\n            ['save_user_address', 12, 1],\n            ['disable_plugin_option', 10, 1]\n        ]\n    ];\n\n    public $filters = [\n        'the_content' =\u003e 'add_custom_text',\n        'show_admin_bar' =\u003e '__return_false',\n        'rest_enabled' =\u003e false,\n        'pre_http_request' =\u003e ['disable_custom_api', 10, 3]\n    ];\n\n    public function add_custom_text($content)\n    {\n        return $content . 'My Text';\n    }\n\n    public function save_post_view($post_ID, $post, $update)\n    {\n        if (!$update) {\n            $this-\u003epost($post_ID)-\u003emeta-\u003esave('views', 1);\n        }\n    }\n    \n    public function disable_custom_api($preempt, $parsed_args, $url) {\n        if( strpos($url, 'https://any_domain.com') !==false ){\n            return new \\WP_Error( 'http_request_block', \"This request is not allowed\" );\n        }\n        return $preempt;\n    }\n}\n```\n\n### Use WPDB\n\nuse `$this-\u003edb` for run Query in WordPress Database:\n\n```php\n// Get List of students from custom WordPress table\n$lists = $this-\u003edb-\u003eget_results(\"SELECT ID, first_name FROM {$this-\u003edb-\u003eprefix}students ORDER BY ID\");\nforeach ($lists as $student) {\n    echo $student-\u003eID;\n}\n\n// Insert new item in Database\n$this-\u003edb-\u003einsert($this-\u003edb-\u003eprefix.'students', [\n'name' =\u003e 'Mehrshad',\n'family' =\u003e Darzi\n]);\necho $this-\u003edb-\u003einsert_id;\n```\n\n### Current Plugin information\n\nFor get current plugin information use `$this-\u003eplugin` variable:\n\n```php\n// Get Plugin Base Url\n$this-\u003eplugin-\u003eurl\n\n// Get Plugin Base Path\n$this-\u003eplugin-\u003epath\n\n// Get Plugin TextDomain\n$this-\u003eplugin-\u003etextDomain\n\n// Get Plugin Main PHP File path\n$this-\u003eplugin-\u003emainFile\n\n// Get Plugin Name\n$this-\u003eplugin-\u003ename\n\n// Get Plugin version\n$this-\u003eplugin-\u003eversion\n\n// Get Plugin description\n$this-\u003eplugin-\u003edescription\n\n// Get Plugin author name\n$this-\u003eplugin-\u003eauthor\n\n// Get Plugin Minimum required version of WordPress\n$this-\u003eplugin-\u003erequiresWP\n\n// Get Plugin Minimum required version of PHP\n$this-\u003eplugin-\u003erequiresPHP\n\n// Whether the plugin can only be activated network-wide. (boolean)\n$this-\u003eplugin-\u003enetwork\n\n// Get file url from plugin\n// https://site.com/wp-contents/plugins/my-plugin/images/logo.png\n$this-\u003eplugin-\u003eurl('images/logo.png')\n\n// Get file path from plugin\n// ~ wp-contents/plugins/my-plugins/templates/email.php\n$this-\u003eplugin-\u003epath('templates/email.php')\n\n// Get All plugins data as Object\n$this-\u003eplugin-\u003edata\n```\n\n### Get WordPress default Constants\n\nFor get WordPress default Constants use `$this-\u003econstant` variable:\n\n#### Get WordPress default urls and path:\n\n```php\n// Get ABSPATH (WordPress Root Directory)\n$this-\u003econstant-\u003eroot\n\n// Get WP-Content Dir Path\n$this-\u003econstant-\u003econtent_dir\n\n// Get WP-Content Dir Url\n$this-\u003econstant-\u003econtent_url\n\n// Get Plugins Dir Path\n$this-\u003econstant-\u003eplugin_dir\n\n// Get Plugins Dir Url\n$this-\u003econstant-\u003eplugin_url\n\n// Get Uploads Directory in WordPress\n// Object {basedir|baseurl|subdir|path|url}\n$this-\u003econstant-\u003euploads\n\n// Get Base Uploads dir path\n$this-\u003econstant-\u003euploads-\u003ebasedir;\n\n// Get Base Uploads dir url\n$this-\u003econstant-\u003euploads-\u003ebaseurl;\n\n// Get Active Theme path\n$this-\u003econstant-\u003etemplate_path;\n\n// Get Active Theme url\n$this-\u003econstant-\u003etemplate_url;\n\n// Get themes dir path\n$this-\u003econstant-\u003etheme_root;\n\n// Get themes directory url\n$this-\u003econstant-\u003etheme_root_url;\n\n// Get Mu-Plugins dir path\n$this-\u003econstant-\u003emu_plugin_dir;\n\n// Get Mu-Plugins dir url\n$this-\u003econstant-\u003emu_plugin_url;\n```\n\n#### Time in Seconds and Debug Constants:\n\n```php\n// Check WP_DEBUG is true (boolean)\n$this-\u003econstant-\u003edebug\n\n// Get WordPress environment type\n$this-\u003econstant-\u003eenvironment\n\n// Check SCRIPT_DEBUG is true (boolean)\n$this-\u003econstant-\u003escript_debug\n\n// Check WP_CACHE is true (boolean)\n$this-\u003econstant-\u003ecache\n\n// Get Time in Seconds\n$this-\u003econstant-\u003eminute\n$this-\u003econstant-\u003ehour\n$this-\u003econstant-\u003eday \n$this-\u003econstant-\u003eweek\n$this-\u003econstant-\u003emonth\n$this-\u003econstant-\u003eyear\n```\n\n### Get WordPress Global Variables\n\nFor get WordPress global variables use `$this-\u003eglobal` variable:\n\n```php\n// WordPress Current global $post data\n$this-\u003eglobal-\u003epost\n\n// WordPress Current global $wp_query data\n$this-\u003eglobal-\u003equery\n\n// WordPress Current Version\n$this-\u003eglobal-\u003eversion\n\n// WordPress Current db Version\n$this-\u003eglobal-\u003edb_version\n\n// WordPress WP Request Object\n$this-\u003eglobal-\u003ewp\n\n// WordPress Rewrite Object Request\n$this-\u003eglobal-\u003erewrite\n\n// WordPress User Roles list\n$this-\u003eglobal-\u003eroles\n\n// WordPress Locale\n$this-\u003eglobal-\u003elocale\n\n// WordPress AdminBar Object\n$this-\u003eglobal-\u003eadmin_bar\n\n// WordPress Current Admin Page Now\n$this-\u003eglobal-\u003epage_now\n\n// Get Current Admin Screen detail\n$this-\u003eglobal-\u003escreen\n\n// Get List Of Admin Menu\n$this-\u003eglobal-\u003emenu\n\n// Get List Of Submenus in Admin\n$this-\u003eglobal-\u003esubmenu\n\n// Get List Of registered Sidebars\n$this-\u003eglobal-\u003esidebars\n\n// Get List of Registered Meta Boxes by current Screen\n$this-\u003eglobal-\u003emeta_boxes\n```\n\n### WordPress URL Generation\n\nUse `$this-\u003eurl` variable:\n\n```php\n// WordPress Home Url\n$this-\u003eurl-\u003ehome\n\n// WordPress Site Url\n$this-\u003eurl-\u003esite\n\n// WordPress Site Url with Custom Path and queries\n// Site.Com/blog?filter=category\u0026ids=3,4\n$this-\u003eurl-\u003eget('/blog', ['filter' =\u003e 'category', 'ids' =\u003e '3,4'])\n\n// WordPress Admin Url\n// Site.com/wp-admin/users.php?sort=ID\n$this-\u003eurl-\u003eadmin('users.php', ['sort' =\u003e 'ID'])\n\n// WordPress Admin Ajax Url\n// Site.com/wp-admin/admin-ajax.php?action=new_user\u0026cache=no\n$this-\u003eurl-\u003eajax('new_user', ['cache' =\u003e 'no'])\n\n// WordPress REST API Url\n// Site.com/wp-json/wp/v2/search?filter=name\u0026s=Mehrshad\n$this-\u003eurl-\u003erest('wp/v2/search', ['filter' =\u003e 'name', 's' =\u003e 'Mehrshad'])\n\n// WordPress REST API Prefix\n// Default is: wp-json\n$this-\u003eurl-\u003erestPrefix()\n\n// WordPress CronJob Url\n// Site.com/wp-cron.php?doing_wp_cron\n$this-\u003eurl-\u003ecron()\n\n// Generate Url\n// https://site.com?query=value\n$this-\u003eurl-\u003egenerate('https://site.com', ['query' =\u003e 'value']);\n\n// Parse URl\n// @see https://www.php.net/manual/en/function.parse-url.php\n$this-\u003eurl-\u003eparse('https://site.com?query=value');\n\n// Sanitize Url\n$this-\u003eurl-\u003esanitize('https://site.com?query=value');\n\n// Validate Url\n$this-\u003eurl-\u003eisValidate('https://site.com\u003cscript\u003ealert(\"xss\")\u003cscript\u003e?query=value');\n\n// Escape Url\n$this-\u003eurl-\u003eesc('https://site.com?query=value');\n```\n\n\n### Get Current User data\n\nfor get Current User data use `$this-\u003euser` variable:\n\n```php\n// Get Current User ID\n// You Can Access All Object From WP_User Class\n$this-\u003euser-\u003eid;\n\n// Get Current User Email\n$this-\u003euser-\u003eemail;\n\n// Get Current User Role\n$this-\u003euser-\u003eroles;\n\n// Get All User Meta\n// Check Meta Collection Class\n$this-\u003euser-\u003emeta-\u003eall();\n```\n\n## Collection Class\n\nThis package has list of WordPress helper class, that you can use it.\n\n### Post\n\n```php\n// Get Post\n$this-\u003epost(1)-\u003eget();\n\n// Get Post Meta\n$this-\u003epost(1)-\u003emeta-\u003eall();\n\n// Get Custom Meta\n$this-\u003epost(1)-\u003emeta-\u003eget('key');\n\n// Get Multiple Custom Meta Keys\n$this-\u003epost(1)-\u003emeta-\u003eonly(['key_1', 'key_2']);\n\n// Save Post Meta\n$this-\u003epost(1)-\u003emeta-\u003esave('key', 'value');\n\n// Delete Post\n$this-\u003epost(1)-\u003edelete();\n\n// Get List Of post\n$this-\u003epost-\u003elist(['type' =\u003e 'post', 'status' =\u003e 'publish', 'cache' =\u003e false]);\n\n// Get Only SQL Query\n$this-\u003epost-\u003etoSql([\n    'type' =\u003e 'post',\n    'status' =\u003e 'publish',\n    'meta' =\u003e [\n        'key' =\u003e 'is_active',\n        'value' =\u003e 'yes',\n        'compare' =\u003e '='\n    ]\n]);\n\n// Get Post Thumbnail\n$this-\u003epost(1)-\u003ethumbnail()-\u003eurl\n\n// Add Post\n$insert_post = $this-\u003epost-\u003eadd(['title' =\u003e '', 'content' =\u003e '']);\nif($this-\u003eerror-\u003ehas($insert_post)){\n    echo $this-\u003eerror-\u003emessage($insert_post);\n}\n\n// Edit Post\n$this-\u003epost(38)-\u003eupdate(['title' =\u003e '']);\n\n// Permalink\n$this-\u003epost(1)-\u003epermalink();\n\n// Check Exist\n$this-\u003epost(53)-\u003eexists();\n\n// Post Terms\n$this-\u003epost(1)-\u003eterms('category');\n\n// Post Comments\n$this-\u003epost(1)-\u003ecomments();\n\n// Collection { Post + Meta + Terms }\n$this-\u003epost(1)-\u003ecollection(['meta_1', 'meta_2'], ['category', 'post_tag']);\n\n```\n\n### Attachment\n\n```php\n\n// Get Attachment\n$attachment = $this-\u003eattachment(1)-\u003eget();\n\n// Get Meta\n$this-\u003eattachment(1)-\u003emeta-\u003eall();\n\n// Delete Attachment\n$this-\u003eattachment(1)-\u003edelete();\n\n// Get Url\n$this-\u003eattachment(1)-\u003eurl();\n\n// Get Image Src in Custom image size\n$this-\u003eattachment(1)-\u003esrc('thumbnail');\n\n// Get Attachment File Path\n$this-\u003eattachment(1)-\u003epath();\n\n// Get Attachment Meta Data\n$this-\u003eattachment(1)-\u003emetadata();\n\n// Auto Upload File in WordPress Library\n$attachment_id = $this-\u003eattachment-\u003eupload('image'); // \u003cinput type=\"file\" name=\"image\" /\u003e\n\n// Regenerate Attachment image Size\n$this-\u003eattachment(1)-\u003egenerate_thumbnail();\n\n// Get List Of WordPres Image Sizes\n$this-\u003eattachment-\u003eget_wordpress_image_sizes();\n\n// Get Uploads Dir\n$this-\u003eattachment-\u003eupload_dir();\n\n// Check Attachment type File (image or video or audio or other)\n$this-\u003eattachment(1)-\u003eis('image');\n\n// Get Size Of Attachment\n$this-\u003eattachment(1)-\u003esize();\n```\n\n### User\n\n```php\n// Get User\n$user = $this-\u003euser(1)-\u003eget();\n/**\n* List of object return:\n* \n* $user-\u003eID\n* $user-\u003euser_login\n* $user-\u003euser_pass\n* $user-\u003euser_nicename\n* $user-\u003euser_email\n* $user-\u003euser_url\n* $user-\u003euser_registered\n* $user-\u003euser_activation_key\n* $user-\u003euser_status\n* $user-\u003edisplay_name\n* $user-\u003efirst_name\n* $user-\u003elast_name\n* $user-\u003ecaps\n* $user-\u003eroles\n* $user-\u003eallcaps\n*/\n\n// Get All Meta\n$this-\u003euser(1)-\u003emeta-\u003eall();\n\n// Get Custom Meta\n$this-\u003euser(1)-\u003emeta-\u003eget('meta_name');\n\n// Save Meta\n$this-\u003euser(1)-\u003emeta-\u003eupdate('phone', '09xxxxxxxx');\n\n// Delete User\n$this-\u003euser(1)-\u003edelete();\n\n// Update User\n$this-\u003euser(1)-\u003eupdate(['name' =\u003e 'Mehrshad Darzi', 'password' =\u003e '12345']);\n\n// Add User\n$this-\u003euser-\u003eadd(['email' =\u003e 'info@site.com', 'username' =\u003e 'mehrshad']);\n\n// Get Current User\n$this-\u003euser-\u003ecurrent();\n\n// Check User is Login\n$this-\u003euser-\u003eauth();\n\n// Get current User id\n$this-\u003euser-\u003eid();\n\n// Check User Has Role\n$this-\u003euser-\u003ehas_role('administrator');\n\n// Check User Has Capability\n$this-\u003euser(1)-\u003ecan('manage_options');\n\n// Check Exist User Id\n$this-\u003euser-\u003eexists(12);\n\n// Login User\n$this-\u003euser-\u003elogin($username, $password, $remember = true);\n\n// Authenticate User [Useful for REST-API or Ajax Without set any Cookie]\n$this-\u003euser-\u003eauthenticate($username, $password);\n\n// Set New Password For User\n$this-\u003euser(1)-\u003epassword-\u003eset('new_password');\n\n// Check User Password\n$this-\u003euser(1)-\u003epassword-\u003echeck($this-\u003erequest-\u003einput('password', 'trim'), $hash);\n\n// Convert PlainText Password To Hash\n$this-\u003euser-\u003epassword-\u003ehash('123456');\n\n// Generate Password With custom length\n$this-\u003euser-\u003epassword-\u003egenerate(8, $special_chars = false);\n\n// Set Role and Capability for User\n$user = $this-\u003euser(1)-\u003eget();\n$user-\u003eset_role('author');\n$user-\u003eadd_cap('cap_name');\n$user-\u003eremove_cap('cap_name');\n$user-\u003eadd_role('role_name');\n$user-\u003eremove_role('role_name');\n$user-\u003eremove_all_caps();\n```\n\n### Term\n\n```php\n// Get Term\n$this-\u003eterm(1)-\u003eget();\n\n// Get Meta\n$this-\u003eterm(1)-\u003emeta-\u003eall();\n\n// Save Meta\n$this-\u003eterm(1)-\u003emeta-\u003eupdate('key', 'value');\n\n// Delete Term\n$this-\u003eterm(1)-\u003edelete();\n\n// Update Term\n$this-\u003eterm(1)-\u003eupdate(['name' =\u003e 'New name']);\n\n// Add Term\n$this-\u003eterm-\u003eadd('term name', ['parent' =\u003e 4, 'description' =\u003e ''], 'post_tag');\n\n// Get List Terms\n$this-\u003eterm-\u003elist(['taxonomy' =\u003e 'product_cat', 'return' =\u003e 'id']);\n\n// Get All Taxonomies in WordPress\n$this-\u003eterms-\u003eget_taxonomies();\n```\n\n### Option\n\n```php\n// Get Option\n$this-\u003eoption('name')-\u003eget();\n\n// Get default Value if Not Found\n$this-\u003eoption('name')-\u003eget($default);\n\n// Get Nested Array Option Value With dot\n$this-\u003eoption('settings.user.id')-\u003eget();\n\n// Save Option\n$this-\u003eoption('name')-\u003esave('value');\n\n// Delete Options\n$this-\u003eoption('name')-\u003edelete();\n\n// Add Option\n$this-\u003eoption-\u003eadd('name', 'value', 'no');\n```\n\n### Comment\n\n```php\n// Get Comment\n$this-\u003ecomment(1)-\u003eget();\n\n// Get Meta\n$this-\u003ecomment(1)-\u003emeta-\u003eall();\n\n// Save Meta\n$this-\u003ecomment(1)-\u003emeta-\u003eupdate('key', 'value');\n\n// Delete Meta\n$this-\u003ecomment(1)-\u003emeta-\u003edelete('key');\n\n// Delete Comment\n$this-\u003ecomment(1)-\u003edelete();\n\n// Update Comment\n$this-\u003ecomment(1)-\u003eupdate(['name' =\u003e 'Ali', 'approved' =\u003e true]);\n\n// Add Comment\n$this-\u003ecomment-\u003eadd(['post_id' =\u003e 1, 'name' =\u003e 'Mehrshad Darzi', 'content' =\u003e '']);\n\n// Get List Comments\n$this-\u003ecomment-\u003elist(['post_id' =\u003e 1, 'nested' =\u003e true]);\n```\n\n### Meta\n\nMeta data list: `post`, `user`, `term`, `comment`.\n\n```php\n// Get All Meta From Object\n$this-\u003epost(1)-\u003emeta-\u003eall();\n\n// Get Custom Meta\n$this-\u003euser(1)-\u003emeta-\u003eget('first_name');\n\n// Get Multiple Custom Meta Keys\n$this-\u003epost(1)-\u003emeta-\u003eonly(['key_1', 'key_2']);\n\n// Get All Meta Key Except Custom keys\n$this-\u003epost(1)-\u003emeta-\u003eexcept(['_edit_lock', '_edit_last']);\n\n// Delete Meta\n$this-\u003euser(1)-\u003emeta-\u003edelete('mobile');\n\n// Save Meta\n$this-\u003eterm(1)-\u003emeta-\u003esave('key', 'value');\n\n// Remove all Meta from Object\n$this-\u003ecomment(1)-\u003emeta-\u003eclean();\n```\n\n### Request\n\n```php\n// Get Request fields { GET + POST }\n$this-\u003erequest-\u003einput('first_name');\n\n// only `GET` fields\n$this-\u003erequest-\u003equery('email');\n\n// Get Field with Custom filter e.g. trim value\n$this-\u003erequest-\u003einput('name', 'trim');\n\n// Get field with multiple filter\n$this-\u003erequest-\u003einput('post_excerpt', ['trim', 'strip_tags']);\n\n// Check Has exists input\n$this-\u003erequest-\u003ehas('first_name');\n\n// Check Exist and Not Empty fields\n$this-\u003erequest-\u003efilled('first_name');\n\n// Check Exist and is Numeric value\n$this-\u003erequest-\u003enumeric('year');\n\n// Check exists fields and Equal with value \n$this-\u003erequest-\u003eequal('first_name', 'mehrshad');\n\n// Check is Numeric value and is positive Number (x \u003e0)\n$this-\u003erequest-\u003enumeric('age', true);\n\n// Check value is Enum list\n$this-\u003erequest-\u003eenum('post_status', ['publish', 'draft']);\n\n// Get Custom Fields From Request\n$this-\u003erequest-\u003eonly(['email', 'last_name']);\n\n// Redirect in WordPress\n$this-\u003erequest-\u003eredirect('https://google.com', 302);\n\n// Get $_FILES by id\n// From Html Form Input: \u003cinput type=\"file\" name=\"image\" /\u003e\n$this-\u003erequest-\u003efile('image'); \n\n// Check Exists File\n$this-\u003erequest-\u003ehasFile('image');\n\n// Get Cookie\n$this-\u003erequest-\u003ecookie('name');\n\n// Get $_SERVER params\n$this-\u003erequest-\u003eserver('REQUEST_URI');\n\n// Check is REST API request\n$this-\u003erequest-\u003eis_rest();\n\n// Check is Ajax Request\n$this-\u003erequest-\u003eis_ajax();\n\n// Check is CronJob Request\n$this-\u003erequest-\u003eis_cron();\n\n// Check is XML-RPC Request\n$this-\u003erequest-\u003eis_xmlrpc();\n\n// Check is WP-CLI Request\n$this-\u003erequest-\u003eis_cli();\n\n// Get Method Of Request\n$this-\u003erequest-\u003eget_method();\n\n// Check Method Of Request {boolean}\n$this-\u003erequest-\u003eis_method('PUT');\n\n// Return Json Response\n$this-\u003eresponse-\u003ejson(['data' =\u003e 'value'], 200);\n```\n\n### Handle Error\n\n```php\n$input_email = $this-\u003erequest-\u003einput('email');\n\n// Define new error Handle system\n$error = $this-\u003eerror-\u003enew();\n\nif(empty($input_email)) {\n    $error-\u003eadd('empty_email', __('Please Fill Your Email', 'my-plugin'));\n}\n\nif(!is_email($input_email)){\n    $error-\u003eadd('valid_email', __('Please Fill valid Email', 'my-plugin'));\n}\n\nif($this-\u003eerror-\u003ehas($error)){\n    return $error; # Or use $error-\u003eget_error_messages();\n} else {\n    return true;\n}\n```\n\n### Cache and Transient\n\n```php\n// Remember Cache last Post in One Hour\n$this-\u003ecache-\u003eremember('latest_post', function(){\n    return $this-\u003epost-\u003elist(['type' =\u003e 'product', 'return' =\u003e 'id'])\n}, 'cache_group_name', $this-\u003econstant-\u003ehour);\n\n// Delete Cache\n$this-\u003ecache-\u003edelete('cache_name', 'group');\n\n// Add Cache\n$this-\u003ecache-\u003eadd('cache_name', $value, 'group_name', 5 * $this-\u003econstant-\u003eminute);\n\n// Get Cache\n$this-\u003ecache-\u003eget('name', 'group');\n\n// Remember Transient\n$this-\u003etransient-\u003eremember('latest_users', function(){\n    return $this-\u003euser-\u003elist(['role' =\u003e 'subscriber', 'return' =\u003e 'id'])\n}, $this-\u003econstant-\u003ehour);\n\n// Delete transient\n$this-\u003etransient-\u003edelete('name');\n\n// Add Transient\n$this-\u003etransient-\u003eadd('name', $value, $this-\u003econstant-\u003eday);\n\n// Get Transient\n$this-\u003etransient-\u003eget('name');\n```\n\n### REST API\n\n```php\n// Get REST API prefix url\n$this-\u003erest-\u003eprefix();\n\n// get REST API url\n$this-\u003erest-\u003eurl('namespace/endpoint');\n\n// Making WordPress REST API Calls Internally\n$this-\u003erest-\u003erequest('GET', 'wp/v2/posts', [ 'per_page' =\u003e 12 ]);\n\n// Define New Custom EndPoint in WordPress REST API\n$this-\u003eroute-\u003eadd('form', 'contact', [\n    'method' =\u003e 'post',\n    'function' =\u003e 'send_form',\n    'arg' =\u003e [\n        'title' =\u003e [\n            'require' =\u003e true,\n        ]\n    ]\n]);\n        \n// Example new route in WordPress REST API with Trait\nclass MY_REST_API extends Model\n{\n    use RestAPI;\n    \n    public function rest_api_init()\n    {\n        $this-\u003eroute-\u003eadd('student', 'register', [\n            'method' =\u003e 'post',\n            'function' =\u003e 'register',\n            'arg' =\u003e [\n                'age' =\u003e [\n                    'require' =\u003e true,\n                    'validate' =\u003e function ($param, $request, $key) {\n                        return is_numeric($param);\n                    }\n                ],\n                'name' =\u003e [\n                    'require' =\u003e true,\n                    'sanitize' =\u003e function ($param, $request, $key) {\n                        return strtolower($param);\n                    }\n                ]\n            ]\n        ]);\n    }\n\n    public function register($request)\n    {\n        # Get Params\n        $name = $request-\u003eget_param('name');\n        $age = $request-\u003eget_param('age');\n\n        # insert To Database\n        $this-\u003edb-\u003einsert(\n            $this-\u003edb-\u003eprefix . 'student',\n            ['name' =\u003e $name, 'age' =\u003e $age]\n        );\n\n        # Result Json\n        return $this-\u003eresponse-\u003ejson(\n            ['message' =\u003e 'Completed Register', 'id' =\u003e $this-\u003edb-\u003einsert_id],\n            200,\n            ['X-Custom-Header' =\u003e 'value']\n        );\n    }\n}\n\n// Remove Route\n$this-\u003eroute-\u003eremove('/wp/v2/posts');\n\n// Get List WordPress REST API routes\n$list = $this-\u003eroute-\u003eall();\n$list-\u003enamespaces;\n$list-\u003eroutes;\n```\n\n### Cookie\n\n```php\n// set new Cookie for One Hour\n$this-\u003ecookie-\u003eset('user_data', ['name' =\u003e 'Mehrshad', 'family' =\u003e 'Darzi'], $this-\u003econstant-\u003ehour);\n\n// Check exist cookie {boolean}\n$this-\u003ecookie-\u003ehas('user_data');\n\n// Get cookie Value { auto convert json to Array }\n$this-\u003ecookie-\u003eget('user_data');\n\n// Remove Cookie\n$this-\u003ecookie-\u003edelete('user_data');\n\n// Get All Cookie in WordPress Site\n$this-\u003ecookie-\u003eall();\n```\n\n### Session\n\n```php\n// set new session\n$this-\u003esession-\u003eset('redirect_from', add_query_arg( 'type', 'error', $this-\u003econstant-\u003ehome ));\n\n// Check exist session {boolean}\n$this-\u003esession-\u003ehas('redirect_from');\n\n// Get session Value\n$this-\u003esession-\u003eget('redirect_from');\n\n// Remove Session\n$this-\u003esession-\u003edelete('redirect_from');\n\n// Get All Session in WordPress Site\n$this-\u003esession-\u003eall();\n\n// Get Session ID\n$this-\u003esession-\u003eid();\n\n// Destroy All Sessions\n$this-\u003esession-\u003edestroy();\n```\n\n##### How to start session in WordPress?\n\n```php\nadd_action('init', 'register_session');\npublic function register_session()\n{\n    if (session_status() == PHP_SESSION_NONE) {\n        session_start([\n            'read_and_close' =\u003e true\n        ]);\n    }\n}\n```\n\n### Event\n\n```php\n// Define single Event\n$this-\u003eevent-\u003esingle($this-\u003econstant-\u003eweek, 'action_name');\n\n// Define recurring Event\n$this-\u003eevent-\u003eadd(time(), 'hourly', 'action_name', []);\n\n// Delete Event\n$this-\u003eevent-\u003edelete('action_name');\n\n// Retrieve supported event recurrence schedules\n$this-\u003eevent-\u003eschedules();\n\n// Get List Current CrobJobs\n$this-\u003eevent-\u003elist();\n```\n\n### Nonce\n\n```php\n// Create new Nonce\n$this-\u003enonce-\u003ecreate('_my_nonce');\n\n// Verify Nonce Field {boolean}\n$this-\u003enonce-\u003everify('input_name', '_my_nonce');\n\n// Generate Html Input Hidden nonce Field for Using form\n$this-\u003enonce-\u003einput('_my_nonce', 'nonce_input_name');\n```\n\n### File System\n\n```php\n// Get Example file Path\n$path = path_join($this-\u003econstant-\u003econtent_dir, 'object.php');\n\n// Check file exits\n$this-\u003efile($path)-\u003eexists();\n\n// Check file missing\n$this-\u003efile($path)-\u003emissing();\n\n// Get File Content\n$this-\u003efile($path)-\u003eget();\n\n// Delete File\n$this-\u003efile($path)-\u003edelete();\n\n// Create File with Content\n$content = '\u003c?php echo \"Hi\"; ?\u003e';\n$this-\u003efile($path)-\u003ecreate($content);\n\n// Create Directory\n$this-\u003efile-\u003emkdir($this-\u003econstant-\u003econtent_dir.'/excel');\n\n// Change Permission File\n$this-\u003efile($path)-\u003echmod(0600);\n\n// Copy File\n$new_path = $this-\u003econstant-\u003econtent_dir.'/backup/object.php';\n$this-\u003efile($path)-\u003ecopy($new_path);\n\n// Move File\n$this-\u003efile($path)-\u003emove($new_path);\n\n// Get File Extension\n$this-\u003efile($path)-\u003eextension();\n\n// Get File BaseName\n$this-\u003efile($path)-\u003ebasename();\n\n// Get file DirName\n$this-\u003efile($path)-\u003edirname();\n\n// Get file last Modified\n$this-\u003efile($path)-\u003elastModified();\n\n// Get file size (bytes)\n$this-\u003efile($path)-\u003esize();\n```\n\nList of Methods File Systems\n{[See Collection](https://github.com/mehrshaddarzi/wp-trait/blob/master/src/Collection/File.php)}:\n\n\n### Email\n\n```php\n// Send Html Body Mail\n$this-\u003eemail('email@site.com')-\u003esend('Subject', '\u003cp\u003eMessage Body\u003c/p\u003e');\n\n// Send to Multiple Email With Custom Header and Attachment\n$headers = [\n    'Content-Type: text/html; charset=UTF-8',\n    'From: Site name \u003cinfo@sitename.com\u003e'\n];\n$attachment = [$this-\u003econstant-\u003euploads-\u003ebasedir.'/file.zip'];\n$this-\u003eemail(['email@site.com', 'mail@domain.com'])\n     -\u003esend('Subject', 'Message Body', $headers, $attachment);\n```\n\n### Log\n\n```php\n// Add text log\n# wp-content/debug.log\n$this-\u003elog('text log', 'debug');\n\n// Add Array log\n$this-\u003elog(['user_id' =\u003e 1, 'status' =\u003e true], 'debug');\n\n// Custom Log File\n# wp-content/db.log\n$this-\u003elog('text log', 'db');\n\n// Custom Condition\n# By Default when WP_DEBUG_LOG === true\n# wp-content/plugin-slug.log\n$is_active_plugin_log = get_option('my_plugin_active_log');\n$this-\u003elog('text log', 'plugin-slug', $is_active_plugin_log);\n\n// Change Datetime in Log File\n# By default the dates are saved in the log file based on `UTC`\nadd_filter('wp_trait_log_date', function ($date, $type) {\n    if ($type == \"my-plugin-slug\") {\n        return date_i18n(get_option( 'date_format' ), current_time('timestamp')) . ' UTC+3.5';\n    }\n    return $date;\n});\n```\n\nCollections Lists are available\nunder [/Collection](https://github.com/mehrshaddarzi/wp-trait/tree/master/src/Collection).\n\n## Views Templates\n\nFor use template engine in this package, use `Views` Collection.\nCreate a folder with name `templates` in your plugin and put your php file, for example:\n\n```php\n# ~/wp-content/plugins/{plugin-slug}/templates/students/table.php\n\u003cp\u003e\u003c?= $title; ?\u003e\u003c/p\u003e\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003c?php _e('Name'); ?\u003e\u003c/td\u003e\n\u003ctd\u003e\u003c?php _e('Family'); ?\u003e\u003c/td\u003e\n\u003c/tr\u003e\n  \u003c?php\n    foreach($students as $student) {\n  ?\u003e\n      \u003ctr\u003e\n      \u003ctd\u003e\u003c?php $student['name']; ?\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003c?php $student['family']; ?\u003e\u003c/td\u003e\n      \u003c/tr\u003e\n  \u003c?php\n    }\n  ?\u003e\n\u003c/table\u003e\n```\n\nFor Load `students/table.php` files in your Model, use `render` Method:\n\n```php\n$data = [\n    'title' =\u003e 'Students List',\n    'students' =\u003e [\n        ['name' =\u003e 'Mehrshad', 'family' =\u003e 'Darzi'],\n        ['name' =\u003e 'John', 'family' =\u003e 'Smith'],\n    ]\n];\n\necho $this-\u003eview-\u003erender('students.table', $data);\n```\n\n### Overriding templates via a theme\n\nBy default, Users who use your plugin can change plugin templates in your active WordPress theme.\n\n```php\n# ~/wp-content/themes/twentyeleven/{plugin-slug}/students/table.php\n\u003cdiv class=\"text-right bg-black text-white\"\u003e\u003c?= $title; ?\u003e\u003c/div\u003e\n\u003c?php\n  foreach($students as $student) {\n?\u003e\n  \u003cdiv class=\"card\"\u003e\n    \u003cdiv class=\"card-body\"\u003e\n      \u003cp\u003e\u003c?php $student['name']; ?\u003e\u003c/p\u003e\n      \u003cp\u003e\u003c?php $student['family']; ?\u003e\u003c/p\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n\u003c?php\n}\n?\u003e\n```\n\nFor disable Overriding templates in custom file, set `false` in render method:\n\n```php\n$this-\u003eview-\u003erender('students.table', $data, [], $canOverride = false);\n```\n\n### Set template attribute\n\nThere is several Ways for set attribute:\n\n```php\n// First Way\n$content = $this-\u003eview()\n  -\u003eattribute('text', $text)\n  -\u003eattribute([\n      'description' =\u003e __('This is the description', $this-\u003eplugin-\u003etextDomain)\n  ])\n  -\u003erender('notice');\necho $this-\u003eadd_alert($content, 'info');\n\n// Second Way\n$content = $this-\u003eview()-\u003erender('notice', [\n  'text' =\u003e $text\n], [\n  'text' =\u003e __('This is the description', $this-\u003eplugin-\u003etextDomain)\n]);\necho $this-\u003eadd_alert($content, 'info');\n\n// Third Way\n$content = $this-\u003eview();\n$content-\u003etext = $text;\necho $this-\u003eadd_alert($content('notice'), 'info');\n\n// Property Way\n$view = $this-\u003eview-\u003erender('notice', [\n  'text' =\u003e $text . ' with property way'\n]);\necho $this-\u003eadd_alert($view, 'info');\n```\n\n## Trait For WordPress Hooks\n\nThis package has list of php trait for WordPress Hooks, that you can uses.\ntrait Lists are available under [/Hook](https://github.com/mehrshaddarzi/wp-trait/tree/master/src/Hook).\n\n### How To Work Trait Hooks\n\n1) First add `trait` in your class.\n\n```php\nuse Init;\n```\n\n2) every method in your class that have `init` prefix in method name call in this action:\n\n```php\npublic function init(){\n  // Code Here\n}\n\npublic function init_check_user_login(){\n  // Code Here\n}\n\npublic function init_save_form_data() {\n  // Code Here\n}\n```\n\n### List Of Trait With Prefix Method Name\n\n\u003ctable\u003e\n\n \u003ctr\u003e\n \u003ctd\u003eUsage\u003c/td\u003e\n \u003ctd\u003eMethod Prefix\u003c/td\u003e\n \u003ctd\u003eVariable option on your model\u003c/td\u003e\n \u003c/tr\u003e\n\n \u003ctr\u003e \n \u003ctd\u003euse Init;\u003c/td\u003e\n \u003ctd\u003einit_\u003c/td\u003e\n \u003ctd\u003epublic $init;\u003c/td\u003e\n \u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse AdminAssets;\u003c/td\u003e\n\u003ctd\u003eadmin_enqueue_scripts_\u003c/td\u003e\n\u003ctd\u003epublic $adminAssets;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse AdminFooter;\u003c/td\u003e\n\u003ctd\u003eadmin_footer_\u003c/td\u003e\n\u003ctd\u003epublic $adminFooter;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse AdminInit;\u003c/td\u003e\n\u003ctd\u003eadmin_init_\u003c/td\u003e\n\u003ctd\u003epublic $adminInit;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse AdminMenu;\u003c/td\u003e\n\u003ctd\u003eadmin_menu_\u003c/td\u003e\n\u003ctd\u003epublic $adminMenu;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse AdminSearchBox;\u003c/td\u003e\n\u003ctd\u003eget_search_fields_\u003c/td\u003e\n\u003ctd\u003epublic $adminSearchBox;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse Ajax;\u003c/td\u003e\n\u003ctd\u003eadmin_ajax_{$method_name}\u003c/td\u003e\n\u003ctd\u003epublic $ajax;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse BulkActions;\u003c/td\u003e\n\u003ctd\u003ebulk_actions_ \u0026 handle_bulk_actions_\u003c/td\u003e\n\u003ctd\u003epublic $bulkActions;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse FrontAssets;\u003c/td\u003e\n\u003ctd\u003ewp_enqueue_scripts_\u003c/td\u003e\n\u003ctd\u003epublic $frontAssets;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse ImageSize;\u003c/td\u003e\n\u003ctd\u003esetup_image_size_\u003c/td\u003e\n\u003ctd\u003epublic $imageSize;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse Notice;\u003c/td\u003e\n\u003ctd\u003eadmin_notices_\u003c/td\u003e\n\u003ctd\u003epublic $notice;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse PostTypeColumns;\u003c/td\u003e\n\u003ctd\u003ecolumns_ \u0026 content_columns_\u003c/td\u003e\n\u003ctd\u003epublic $postTypeColumns;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse PreGetQuery;\u003c/td\u003e\n\u003ctd\u003epre_get_posts_ \u0026 pre_get_users_ \u0026 pre_get_terms_\u003c/td\u003e\n\u003ctd\u003epublic $preGetQuery;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse RestAPI;\u003c/td\u003e\n\u003ctd\u003erest_api_init_\u003c/td\u003e\n\u003ctd\u003epublic $restAPI;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse RowActions;\u003c/td\u003e\n\u003ctd\u003erow_actions_\u003c/td\u003e\n\u003ctd\u003epublic $rowActions;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse Shortcode;\u003c/td\u003e\n\u003ctd\u003eadd_shortcode_\u003c/td\u003e\n\u003ctd\u003epublic $shortcode;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse SortableColumns;\u003c/td\u003e\n\u003ctd\u003esortable_columns_\u003c/td\u003e\n\u003ctd\u003epublic $sortableColumns;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse TaxonomyColumns;\u003c/td\u003e\n\u003ctd\u003ecolumns_ \u0026 content_columns_\u003c/td\u003e\n\u003ctd\u003epublic $taxonomyColumns;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse UserColumns;\u003c/td\u003e\n\u003ctd\u003ecolumns_ \u0026 content_columns_\u003c/td\u003e\n\u003ctd\u003epublic $userColumns;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e \n\u003ctd\u003euse UserProfileFields;\u003c/td\u003e\n\u003ctd\u003eadmin_user_profile_fields_ \u0026 save_admin_user_profile_fields_\u003c/td\u003e\n\u003ctd\u003epublic $userProfileFields;\u003c/td\u003e\n\u003c/tr\u003e\n\n\n\u003ctr\u003e \n\u003ctd\u003euse ViewsSub;\u003c/td\u003e\n\u003ctd\u003eviews_edit_sub_\u003c/td\u003e\n\u003ctd\u003epublic $viewsSub;\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/table\u003e\n\n### Example Create Ajax Request with Trait\n\n```php\nuse WPTrait\\Hook\\Ajax;\n\nclass Admin extends Model\n{\n    use Ajax;\n\n    public $ajax = [\n        'methods' =\u003e ['signup_user']\n    ];\n\n    public function admin_ajax_signup_user()\n    {\n        # Check User is Auth\n        if ($this-\u003euser-\u003eauth()) {\n            $this-\u003eresponse-\u003ejson(['message' =\u003e __('You are a user of the site', 'wp-plugin')], 400);\n        }\n\n        # Get Input Email\n        $email = $this-\u003erequest-\u003einput('email');\n\n        # Create User\n        $user_id = $this-\u003euser-\u003eadd([\n            'email' =\u003e $email,\n            'username' =\u003e $email\n        ]);\n        if ($this-\u003eerror-\u003ehas($user_id)) {\n            $this-\u003eresponse-\u003ejson(['message' =\u003e $this-\u003eerror-\u003emessage($user_id)], 400);\n        }\n\n        # Return Success\n        $this-\u003eresponse-\u003ejson(['user_id' =\u003e $user_id], 200);\n    }\n}\n```\n\nYou can access top ajax request:\n\n```\nhttp://site.com/wp-admin/admin-ajax.php?action=signup_user\u0026email=info@site.com\n```\n\n## Utility\n\n### Singleton Design Pattern\n\nFor Create a Singleton Design Pattern, use `Singleton` trait in your Class:\n\n```php\n// Class which uses singleton trait.\nclass MyClass {\n    use Singleton;\n}\n\n// To get the instance of the class.\n$instance = MyClass::instance();\n```\n\n## Starter Plugin\n\nYou Can read example folder ReadMe.md files [/example](https://github.com/mehrshaddarzi/wp-trait/tree/master/example).\nand start your project very fast.\n\n## Contributing\n\n- [Mehrshad Darzi](https://www.linkedin.com/in/mehrshaddarzi/)\n\nWe appreciate you taking the initiative to contribute to this project.\nContributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by\nwriting tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our\ndocumentation.\n\n## License\n\nThe WP-Trait is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehrshaddarzi%2Fwp-trait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehrshaddarzi%2Fwp-trait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehrshaddarzi%2Fwp-trait/lists"}