API Reference

Complete API reference for WPZylos Scaffold classes.

PluginContext

The PluginContext class (app/Core/PluginContext.php) implements WPZylos\Framework\Core\Contracts\ContextInterface.

Creating a Context

use MyPlugin\Core\PluginContext;

$context = PluginContext::create([
    'file'       => __FILE__,
    'slug'       => 'my-plugin',
    'prefix'     => 'myplugin_',
    'textDomain' => 'my-plugin',
    'version'    => '1.0.0',
]);

All five parameters are required.

Methods

Identity Methods

MethodReturn TypeDescription
slug()stringPlugin slug
prefix()stringDatabase/option prefix
textDomain()stringTranslation text domain
version()stringPlugin version
file()stringMain plugin file path
$context->slug();       // 'my-plugin'
$context->prefix();     // 'myplugin_'
$context->textDomain(); // 'my-plugin'
$context->version();    // '1.0.0'
$context->file();       // '/path/to/my-plugin.php'

Path Methods

MethodReturn TypeDescription
path($relative)stringAbsolute filesystem path
url($relative)stringPlugin URL
$context->path();              // '/path/to/my-plugin/'
$context->path('config/');     // '/path/to/my-plugin/config/'
$context->url();               // 'https://site.com/wp-content/plugins/my-plugin/'
$context->url('assets/js/');   // 'https://site.com/wp-content/plugins/my-plugin/assets/js/'

Prefixing Methods

MethodReturn TypeDescription
hook($name)stringPrefixed hook name
optionKey($key)stringPrefixed option key
transientKey($key)stringPrefixed transient key
cronHook($name)stringPrefixed cron hook
tableName($name, $scope)stringFull table name
metaKey($key)stringPrefixed meta key (underscore prefix)
assetHandle($handle)stringPrefixed asset handle
$context->hook('init');              // 'myplugin_init'
$context->optionKey('settings');     // 'myplugin_settings'
$context->transientKey('cache');     // 'myplugin_cache'
$context->cronHook('daily_task');    // 'myplugin_daily_task'
$context->tableName('orders');       // 'wp_myplugin_orders'
$context->tableName('logs', 'network'); // 'wp_myplugin_logs' (multisite base prefix)
$context->metaKey('data');           // '_myplugin_data'
$context->assetHandle('main');       // 'my-plugin-main'

Helper Functions

Global helpers available after bootstrap (app/Support/helpers.php).

Escaping Helpers

FunctionMaps ToDescription
zylos_e($text)esc_html()Escape for HTML output
zylos_ea($text)esc_attr()Escape for HTML attribute
zylos_eu($url)esc_url()Escape URL
zylos_ej($text)esc_js()Escape for JavaScript
zylos_kses($html, $context)wp_kses_*()Filter HTML
echo zylos_e($title);                    // esc_html($title)
echo '<input value="' . zylos_ea($val) . '">'; // esc_attr($val)
echo '<a href="' . zylos_eu($url) . '">'; // esc_url($url)
echo 'var x = "' . zylos_ej($str) . '";'; // esc_js($str)

// KSES contexts: 'post', 'data', 'strip'
echo zylos_kses($html);         // wp_kses_post()
echo zylos_kses($html, 'data'); // wp_kses_data()
echo zylos_kses($html, 'strip'); // wp_kses() with empty allowed

Application Helpers

FunctionDescription
zylos_app()Get application instance
zylos_app($abstract)Resolve service from container
context()Get PluginContext instance
$app = zylos_app();                    // Application instance
$service = zylos_app(MyService::class); // Resolve from container
$ctx = context();                       // PluginContext instance

Translation Helpers

FunctionDescription
zylos_m($text)Translate text with plugin text domain
zylos_em($text)Echo translated text
$msg = zylos_m('Hello World');  // __('Hello World', 'my-plugin')
zylos_em('Hello World');        // echo translated