### Install and Run WP Bones Project Source: https://github.com/wpbones/website-docs/blob/main/README.md Install project dependencies, start the development server, or build for production using yarn commands. ```bash # Install dependencies yarn install # Start development server yarn dev # Build for production yarn build ``` -------------------------------- ### Lando: Start WordPress Project Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/wordpress-environments.mdx Start your Lando-managed WordPress development environment and install WordPress core. ```sh lando start lando wp core install --url=wpbones.lndo.site --title=WPBones \ --admin_user=admin --admin_email=you@example.com ``` -------------------------------- ### GET Example Route Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/rest-api.mdx Defines a simple GET route that returns 'Hello World!'. The endpoint is accessible via `/wp-json/vendor/v1/example`. ```APIDOC ## GET /example ### Description Defines a simple GET route that returns 'Hello World!'. The endpoint is accessible via `/wp-json/vendor/v1/example`. ### Method GET ### Endpoint /vendor/v1/example ### Parameters ### Request Example ### Response #### Success Response (200) - **response** (string) - 'Hello World!' #### Response Example "Hello World!" ``` -------------------------------- ### DDEV: Configure and Start WordPress Project Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/wordpress-environments.mdx Use these commands to set up a new WordPress project with DDEV, download WordPress core, and perform an initial installation. ```sh mkdir wpbones && cd wpbones ddev config --project-type=wordpress --docroot=. ddev start ddev wp core download ddev wp core install --url=https://wpbones.ddev.site --title=WPBones \ --admin_user=admin --admin_email=you@example.com --admin_password=admin ``` -------------------------------- ### Install Laravel Valet and Prerequisites Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/wordpress-environments.mdx Installs necessary tools like PHP, Composer, MySQL, Node, and Yarn via Homebrew, followed by the global installation of Laravel Valet. This is a one-time setup for Valet. ```sh # Homebrew prerequisites brew install php composer mysql node yarn # One-time Valet setup composer global require laravel/valet valet install ``` -------------------------------- ### Migrate to v2 and Install Dependencies Source: https://github.com/wpbones/website-docs/blob/main/content/migrating-to-v2.mdx Run the automated migration command, install dependencies, and build the project. This is the primary command for most plugins. ```sh php bones migrate:to-v2 yarn install yarn build ``` -------------------------------- ### Park Directory and Install WordPress with Valet Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/wordpress-environments.mdx Sets up Valet to serve all sibling directories within ~/Sites as .test domains. It then downloads, configures, and installs WordPress within the 'wpbones' subdirectory. ```sh # Park a folder — every sibling directory becomes .test mkdir -p ~/Sites && cd ~/Sites valet park # Install WordPress inside ~/Sites/wpbones via WP-CLI wp core download --path=wpbones cd wpbones wp config create --dbname=wpbones --dbuser=root --dbpass= wp db create wp core install --url=wpbones.test --title="WPBones" --admin_user=admin --admin_email=you@example.com ``` -------------------------------- ### Install Dependencies and Build After Migration Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/bones-console.mdx Installs new dependencies and builds the project after migrating to v2 infrastructure. ```sh yarn install && yarn build ``` -------------------------------- ### Install Pure CSS Switch Package Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/pure-css-switch.mdx Use the `php bones require` command for automatic renaming or `composer require` for standard installation. ```sh php bones require wpbones/pure-css-switch ``` ```sh composer require wpbones/pure-css-switch ``` -------------------------------- ### Install WP Bones Framework Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/bones-console.mdx Installs the WP Bones framework into your project. ```sh php bones install ``` -------------------------------- ### Complete Widget Service Provider Example Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/widgets.mdx An example of a fully configured widget service provider, demonstrating how to set properties like `id_base`, `name`, `widget_options`, and `control_options`. It also shows how to implement `update`, `defaults`, `viewForm`, and `viewWidget` methods. ```php 'WP Kirk Demo Widget Description' ]; /** * Optional. Passed to wp_register_widget_control() * * - width: required if more than 250px * - height: currently not used but may be needed in the future * * @var array */ public $control_options = [ 'width' => 400, 'height' => 350, ]; /** * Update the widget options. * * @return array */ public function update( $new_instance, $old_instance ) { $old_instance[ 'title' ] = ( $new_instance[ 'title' ] ); return $old_instance; } /** * Retrun a key pairs array with the default value for widget. * * @return array */ public function defaults() { return [ 'title' => 'My Title', ]; } public function viewForm( $instance ) { return WPKirk()->view( 'widgets.form' ); } public function viewWidget( $args, $instance ) { return WPKirk()->view( 'widgets.index' ); } } ``` -------------------------------- ### Define GET and POST Routes Source: https://github.com/wpbones/website-docs/blob/main/content/core-concepts/menus-routing.mdx Use the 'route' key to define specific HTTP verb handlers. This example shows how to map GET requests to 'secondMenu' and POST requests to 'updateValues' in the Dashboard controller. ```php ... 'route' => [ 'get' => 'Dashboard\DashboardController@secondMenu', 'post' => 'Dashboard\DashboardController@updateValues' ] ... ``` -------------------------------- ### Run Development Server Source: https://github.com/wpbones/website-docs/blob/main/CLAUDE.md Starts the development server on localhost:3000. Use this for local development and testing. ```bash yarn dev ``` -------------------------------- ### Install dependencies with npm Source: https://github.com/wpbones/website-docs/blob/main/content/migrating-to-v2.mdx If you prefer npm, delete the `yarn.lock` file and then run `npm install`. ```sh npm install ``` -------------------------------- ### Logger Usage Example Source: https://github.com/wpbones/website-docs/blob/main/content/helpers.mdx A shortcut to get the logger instance for logging messages. Alternatively, use WPKirk()->log(). ```php logger()->info('Your message here'); ``` -------------------------------- ### Example YAML Flags Configuration Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/flags.mdx Define feature flags and their settings in a YAML file. This example shows how to enable a feature and configure its throttle and timeout. ```yaml # The version of the file is 1.0.0 version: '1.0.0' example: # Enable or disable the Example feature enabled: true # Throttle request time in minutes # By setting this value to 0, the feature will be disabled throttle: 5 # Request timeout timeout: 0 ``` -------------------------------- ### Install dependencies with pnpm Source: https://github.com/wpbones/website-docs/blob/main/content/migrating-to-v2.mdx If you prefer pnpm, delete the `yarn.lock` file and then run `pnpm install`. ```sh pnpm install ``` -------------------------------- ### Start wp-env Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/wordpress-environments.mdx Use this command to start the wp-env development environment. This is the recommended option for plugin development. ```bash npx wp-env start ``` -------------------------------- ### `wpbones_console_deploy_start` Action Source: https://github.com/wpbones/website-docs/blob/main/content/wordpress-integration/actions-and-filters.mdx Fired at the beginning of the deploy command execution. Useful for pre-deployment setup or logging. ```APIDOC ## Action: `wpbones_console_deploy_start` ### Description Fired when the deploy command is started. Allows for actions to be taken before the deployment process begins. ### Parameters * **$console** (object) - Required - Instance of WPBones Console. * **$path** (string) - Required - Destination path for the deployment. ### Example ```php add_action('wpbones_console_deploy_start', function ($console, $path) { // Your custom code here }, 10, 2); ``` ``` -------------------------------- ### Run Composer Install Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/pure-css-tabs.mdx After updating composer.json, run this command to install the package and its dependencies. ```sh composer install ``` -------------------------------- ### POST Example Route Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/rest-api.mdx Defines a simple POST route that returns 'Hello World!'. ```APIDOC ## POST /example ### Description Defines a simple POST route that returns 'Hello World!'. ### Method POST ### Endpoint /vendor/v1/example ### Parameters ### Request Example ### Response #### Success Response (200) - **response** (string) - 'Hello World!' #### Response Example "Hello World!" ``` -------------------------------- ### Define a GET Route with Permission Callback Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/rest-api.mdx Define a simple GET route for '/example' that returns 'Hello World!'. The permission_callback ensures that only users with the necessary permissions can access it. If permissions are denied, a 401 status is returned. ```php use WPKirk\WPBones\Routing\API\Route; Route::get('/example', function () { return 'Hello World!'; }, ['permission_callback' => function () { return false; }]); ``` ```json {"code":"rest_forbidden","message":"Sorry, you are not allowed to do that.","data":{"status":401}} ``` -------------------------------- ### Install Dependencies Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/assets.mdx Installs project dependencies using Yarn. Run this command after cloning the project or when updating dependencies. ```sh yarn install ``` -------------------------------- ### Install Geo Localizer with Bones CLI Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/geolocalizer.mdx Use the `bones require` command for automatic renaming and installation. ```sh php bones require wpbones/geolocalizer ``` -------------------------------- ### Install WP Bones Flags via Composer Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/flags.mdx Install the package using the `php bones require` command for automatic renaming, or use `composer require` for direct installation. ```sh php bones require wpbones/flags ``` ```sh composer require wpbones/flags ``` -------------------------------- ### Install User Agent Package with Composer Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/useragent.mdx Install the user agent package using Composer. This is an alternative to the Bones CLI. ```sh composer require wpbones/useragent ``` -------------------------------- ### Basic Seeder Class Example Source: https://github.com/wpbones/website-docs/blob/main/content/database-orm/seeding.mdx This example demonstrates a basic seeder class structure. It defines the table name and includes a `run` method to truncate the table and insert data. ```php truncate(); // and then we are going to insert some data $this->insert( "(id, zone, country, isocode, currency, symbol, symbol_html, code, tax, continent, status) VALUES (1,'','Mauritania','MR','Mauritanian Ouguiya','','','MRO',0.00,'africa','publish')"); } } ``` -------------------------------- ### Install Eloquent ORM with Composer Source: https://github.com/wpbones/website-docs/blob/main/content/database-orm/eloquent-orm.mdx Install the Illuminate Database package using Composer. Ensure you also install laravel/serializable-closure for proper object serialization. ```sh composer install illuminate/database ``` ```sh composer require laravel/serializable-closure ``` -------------------------------- ### Install Pure CSS Tabs Package Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/pure-css-tabs.mdx Use this command to install the package via the WP Bones CLI. This method ensures automatic renaming. ```sh php bones require wpbones/pure-css-tabs ``` -------------------------------- ### basePath Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/plugin.mdx Provides the filesystem path to the plugin installation directory. ```APIDOC ## basePath ### Description Provides the filesystem path to the plugin installation directory. ### Property `basePath` ### Return Type `string` ### Example ```php echo $plugin->basePath; ``` ``` -------------------------------- ### Define Custom Configuration Source: https://github.com/wpbones/website-docs/blob/main/content/core-concepts/architecture-foundations.mdx Example of a custom configuration file. Access this configuration via the plugin instance using `config('custom.sample')`. ```php config( 'custom.sample' )`. | */ return [ 'sample' => 'Hello, Captain!' ]; ``` -------------------------------- ### Install WP Bones Actions and Filters JS Package Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/actions-and-filters-js.mdx Use the `bones require` command for automatic renaming or `composer require` for standard installation. ```sh php bones require wpbones/actions-and-filters-js ``` ```sh composer require wpbones/actions-and-filters-js ``` -------------------------------- ### Install Pure CSS Tabs with Composer Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/pure-css-tabs.mdx Alternatively, you can install the package using Composer. This is useful if you prefer managing dependencies with Composer directly. ```sh composer require wpbones/pure-css-tabs ``` -------------------------------- ### Get showInQuickEdit Property Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/ctt.mdx Indicates if the taxonomy should be available in the quick/bulk edit panel. If not set, the default is inherited from `show_ui`. ```php showInQuickEdit; ``` -------------------------------- ### Install User Agent Package with Bones CLI Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/useragent.mdx Use this command to install the user agent package. It is advised over Composer for automatic renaming. ```sh php bones require wpbones/useragent ``` -------------------------------- ### Install WP Tables via Composer Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/wp-tables.mdx Install the WP Tables package using Composer. This is an alternative to the Bones CLI method. ```sh composer require wpbones/wptables ``` -------------------------------- ### Start Storybook Source: https://github.com/wpbones/website-docs/blob/main/CLAUDE.md Launches Storybook on port 6006, allowing you to develop and test UI components in isolation. Useful for building a component library. ```bash yarn storybook ``` -------------------------------- ### Get Logger Instance Source: https://github.com/wpbones/website-docs/blob/main/content/helpers.mdx Use this utility function to get an instance of the Logger. It's a shortcut for WPKirk()->log(). ```php /* Utility to get an instance of Logger. */ function wpbones_logger() ``` ```php wpbones_logger()->info('Your message here'); ``` ```php $logger = WPKirk()->log(); ``` -------------------------------- ### Get Plugin Version Help Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/bones-console.mdx Displays help information for the version command, including available arguments and options for incrementing versions. ```sh php bones version --help ``` -------------------------------- ### GeoLocalizer Shortcode Usage Examples Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/geolocalizer.mdx Examples demonstrating how to use the registered shortcode with various attributes like city, region, country code, zip code, IP, and time zone. ```txt [my_shortcode_geo city="Rome"] Only for Rome [/my_shortcode_geo] ``` ```txt [my_shortcode_geo city="rome"] Only for Rome [/my_shortcode_geo] ``` ```txt [my_shortcode_geo city="rome,london"] Only for Rome and London [/my_shortcode_geo] ``` ```txt [my_shortcode_geo region_name="lazio"] Only for region Lazio (Italy) [/my_shortcode_geo] ``` ```txt [my_shortcode_geo country_code="IT"] Italy only [/my_shortcode_geo] ``` ```txt [my_shortcode_geo country_name="italy"] Italy only [/my_shortcode_geo] ``` ```txt [my_shortcode_geo zip_code="00137"] Wow [/my_shortcode_geo] ``` ```txt [my_shortcode_geo ip="80.182.82.82"] Only for me [/my_shortcode_geo] ``` ```txt [my_shortcode_geo time_zone="europe\rome"] Rome/Berlin timezone [/my_shortcode_geo] ``` -------------------------------- ### PO File Translation String Example Source: https://github.com/wpbones/website-docs/blob/main/content/int-locale/overview.mdx This is an example of how a translatable string appears within a PO file. It includes the source file and line number, the original string (msgid), and an empty string for the translation (msgstr). ```gettext #: plugin-name.php:123 msgid "Page Title" msgstr "" ``` -------------------------------- ### Define Routes for Options View Source: https://github.com/wpbones/website-docs/blob/main/content/views-template/options-view.mdx Define GET and POST routes for the options view and saving options in the `config/menus.php` file. ```php 'route' => [ 'get' => 'Dashboard\DashboardController@optionsView', 'post' => 'Dashboard\DashboardController@saveOptions' ] ``` -------------------------------- ### Get Custom Page URL Source: https://github.com/wpbones/website-docs/blob/main/content/core-concepts/pages-routing.mdx Retrieve the URL for a custom page route using the `$plugin->getPageUrl` method. The example shows the expected URL format. ```php $url = $plugin->getPageUrl( 'custom_page'); // you'll get something like // http://domain.com/wp-admin/admin.php?page=custom_page ``` -------------------------------- ### Composer JSON Configuration Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/actions-and-filters-js.mdx Add the package to your plugin's `composer.json` file and run `composer install`. ```json { "require": { "php": ">=8.1", "wpbones/wpbones": "~1.10", "wpbones/actions-and-filters-js": "~1.0" }, ``` -------------------------------- ### Get Plugin Filesystem Path Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/plugin.mdx Access the filesystem path to the plugin's installation directory using this property. It's essential for server-side operations that require direct file access. ```php echo $plugin->basePath; ``` -------------------------------- ### Retrieve All Rows From A Table Source: https://github.com/wpbones/website-docs/blob/main/content/database-orm/query-builder.mdx Use the `DB::table` method to start a query on a specific table and chain methods to build your query. The `get` method executes the query and returns a collection of results. ```php get(); } } ``` ```php use WPKirk\WPBones\Database\DB; $users = DB::table('users')->get(); foreach ($users as $user) { echo $user->name; } ``` -------------------------------- ### Deploy Help Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/bones-console.mdx Displays help information for the deploy command. ```sh php bones deploy --help ``` -------------------------------- ### Name Your Plugin and Namespace Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/typical-workflow.mdx Execute the 'php bones install' command to initiate the plugin naming process. Subsequently, use 'php bones rename' to set your plugin's name and namespace. These commands must be run from the WordPress Host. ```shell php bones install ``` ```shell php bones rename ``` -------------------------------- ### Add Dependencies with Yarn Source: https://github.com/wpbones/website-docs/blob/main/content/core-plugin-files/package-json.mdx Use `yarn add` to install runtime dependencies and `yarn add --dev` for development-only dependencies. ```bash yarn add swr # runtime yarn add --dev @types/lodash # dev only ``` -------------------------------- ### Prepare Deploy Version Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/typical-workflow.mdx This command prepares a deployable version of your plugin. It also runs the build command to compress and minify assets. ```shell php bones deploy ../deploy-version ``` -------------------------------- ### Install Geo Localizer with Composer Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/geolocalizer.mdx Install the package using Composer or by manually adding it to your composer.json. ```sh composer require wpbones/geolocalizer ``` ```json { "require": { "php": ">=8.1", "wpbones/wpbones": "~1.10", "wpbones/geolocalizer": "~1.0" }, ``` ```sh composer install ``` -------------------------------- ### Action: Deploy Command Start Source: https://github.com/wpbones/website-docs/blob/main/content/wordpress-integration/actions-and-filters.mdx The `wpbones_console_deploy_start` action is triggered when the WP Bones deploy command begins. It provides access to the console instance and the destination path. ```php /** * Fired when the deploy command is started * * @param object $console Instance of WPBones Console * @param string $path Destination path */ add_action('wpbones_console_deploy_start', function ($console, $path) { // Do something }, 10, 2); ``` -------------------------------- ### Button Creation and Rendering Source: https://github.com/wpbones/website-docs/blob/main/content/views-template/html.mdx Shows how to create a button instance and then explicitly echo or render it. This approach allows for intermediate manipulation of the button object before rendering. ```html
render(); ?>
``` -------------------------------- ### Prepare Deploy Version for WordPress Repository Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/typical-workflow.mdx Use this command to prepare a deployable version specifically for the WordPress repository. This command also runs the build command. ```shell php bones deploy ../deploy-version --wp ``` -------------------------------- ### Create a GET Route Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/rest-api.mdx Define a simple GET route for your API. This is the basic structure for creating a new endpoint. ```php use WPKirk\WPBones\Routing\API\Route; Route::get('/example', function () { return 'Hello World!'; }); ``` -------------------------------- ### Build Production Version Source: https://github.com/wpbones/website-docs/blob/main/CLAUDE.md Generates a production build of the website and creates a Pagefind search index. Run this before deploying. ```bash yarn build ``` -------------------------------- ### Registering Service Providers in Configuration Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/autoload-service-providers.mdx Illustrates how to autoload service providers by listing their fully qualified class names in the `providers` array within the `config/plugin.php` file. This ensures they are loaded automatically on plugin initialization. ```php /* |-------------------------------------------------------------------------- | Autoload Service Providers |-------------------------------------------------------------------------- | | The service providers listed here will be automatically loaded on the | initialization of your plugin. Feel free to add your own services to | this array to provide expanded functionality to your applications. | */ "providers" => [ "YourNamespace\Providers\YourServiceProvider", ], ``` -------------------------------- ### Widget Backend Form View Example Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/widgets.mdx An HTML snippet demonstrating the structure for a widget's backend form view. It shows how to access plugin information and use HTML helpers. ```html

Widget Backend

Name ?>

``` -------------------------------- ### Generate Tabs with openTab and closeTab Methods Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/pure-css-tabs.mdx Manually create tabs by wrapping content with `openTab()` and `closeTab()` methods. Remember to use your own namespace instead of `WPKirk`. ```html

Hello, world! I'm the content of tab-1

Hello, world! I'm the content of tab-2

``` -------------------------------- ### Get Plugin Images URL Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/plugin.mdx Use this property to get the URL for the plugin's public images directory, making it easy to reference image assets. ```php echo $plugin->images; ``` -------------------------------- ### Install MorrisJS PHP Package Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/morris-php.mdx Use the 'php bones require' command for automatic renaming or 'composer require' for standard installation. Adding the package to composer.json is also an option. ```sh php bones require wpbones/morris-php ``` ```sh composer require wpbones/morris-php ``` -------------------------------- ### Deploy Command Usage Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/bones-console.mdx Shows the arguments and options available for the deploy command, including path, WordPress.org release, zip creation, package manager selection, and build skipping. ```sh Usage: deploy Arguments: path The complete path of deploy. [--wp] You are going to release this plugin in the WordPress.org public repository. [--create-zip] Creates an installable plugin zip file instead of deploying in a directory. --pkgm= Forces the deployment to use the specified package manager, Eg. npm, yarn, ... --no-build Forces the deployment to skip the build process. ``` -------------------------------- ### Get Flag Value using Flags Class Instance Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/flags.mdx Instantiate the `Flags` class and use its `get` method to retrieve a flag's value, optionally providing a default. ```php use WpBones\Flags\Flags; $flags = new Flags(); $flags->get('example.enabled', false); ``` -------------------------------- ### Create a new app using WP Bones CLI Source: https://github.com/wpbones/website-docs/blob/main/content/core-plugin-files/webpack-config.mdx Use the `bones make:app` command to scaffold a new application. Avoid using names reserved by WordPress core. ```shell php bones make:app dashboard ``` -------------------------------- ### Define a GET Route with Controller and Permission Callback Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/rest-api.mdx Define a GET route for '/version' that is handled by a controller method. The permission_callback restricts access. If permissions are denied, a 401 status is returned. ```php use WPKirk\WPBones\Routing\API\Route; Route::get('/version', '\WPKirk\API\WPKirkV1Controller@version', [ 'permission_callback' => function () { return false; } ]); ``` ```json {"code":"rest_forbidden","message":"Sorry, you are not allowed to do that.","data":{"status":401}} ``` -------------------------------- ### Usage Example for useOption Hook Source: https://github.com/wpbones/website-docs/blob/main/content/core-concepts/hooks-modules.mdx Demonstrates how to use the custom `useOption` PHP hook to retrieve and update WordPress options, similar to state management in React. ```php list($value, $setValue) = useOption('my_option', 'default value'); ``` ```php [$value, $setValue] = useOption('my_option', 'default value'); echo $value; // default value $value = $setValue('new value'); ``` -------------------------------- ### Create a Module Returning a Class Instance Source: https://github.com/wpbones/website-docs/blob/main/content/core-concepts/hooks-modules.mdx Create a module that instantiates and returns a class object. The constructor will execute upon loading. ```php view()` helper function. Ensure the controller and namespace are correctly set up. ```php view( 'dashboard.index' ); } } ``` -------------------------------- ### Generate .pot File Source: https://github.com/wpbones/website-docs/blob/main/content/int-locale/reactjs-apps.mdx Create a `.pot` (Portable Object Template) file for your application's translatable strings using the `yarn make-pot` command. ```bash yarn make-pot ``` -------------------------------- ### wpbones_logger() Source: https://github.com/wpbones/website-docs/blob/main/content/helpers.mdx Utility to get an instance of the Logger. This is a shortcut for WPKirk()->log(). ```APIDOC ## `wpbones_logger()` ### Description Utility to get an instance of Logger. This is a shortcut for `WPKirk()->log()`. ### Synopsis ```php /* Utility to get an instance of Logger. */ function wpbones_logger() ``` ### Usage ```php wpbones_logger()->info('Your message here'); ``` ``` -------------------------------- ### Get Component Version Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/useragent.mdx Retrieve the version of a specific component using the `version()` method. ```php // Find the version of component. wpbones_user_agent()->version('Android'); ``` -------------------------------- ### Get rewriteHierarchical Property Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/ctt.mdx Retrieves whether the rewrite rules are hierarchical. Defaults to false. ```php rewriteHierarchical; ``` -------------------------------- ### Example log output with context Source: https://github.com/wpbones/website-docs/blob/main/content/core-concepts/logging.mdx Shows the formatted log output including the message and its associated context data, presented in a structured format. ```ansi [10-Oct-2024 06:03:34 UTC] [38;5;7m[DEBUG]: Hello, World { "context": "any" } [0m ``` -------------------------------- ### Access Data in View Source: https://github.com/wpbones/website-docs/blob/main/content/views-template/views.mdx Example of accessing passed data within an HTML view. ```html

Hello, !

``` -------------------------------- ### List Available Bones Commands Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/bones-console.mdx Run this command to see all available commands provided by the Bones CLI. ```bash php bones ``` -------------------------------- ### logger() Source: https://github.com/wpbones/website-docs/blob/main/content/helpers.mdx Provides a shortcut to get an instance of the Logger utility. This function is prone to naming conflicts. ```APIDOC ## logger() ### Description Utility to get an instance of Logger. ### Synopsis ```php /* Utility to get an instance of Logger. */ function logger() ``` ### Usage ```php logger()->info('Your message here'); ``` That's a shortcut to get the instance of the logger. You may use also ```php $logger = WPKirk()->log(); ``` ### See also Since this function is not using the prefix `wpbones_` you should be careful to use it in your code. In fact, if you have another plugin or theme that uses the same function, you will have a conflict. See [`wpbones_logger()`](#wpbones_logger) for a safer way to get the logger instance. ``` -------------------------------- ### Create Shortcode Service Provider Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/shortcodes.mdx Use this command to generate a new shortcode service provider. The provider will be created in the `plugin/Shortcodes` directory by default. ```sh php bones make:shortcode MyShortcodes ``` -------------------------------- ### Get Page URL Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/plugin.mdx Generates and returns the URL for a specific admin page based on its slug. ```php /** * Return the URL of a custom page * * @param string $pageSlug The slug of the page * * @return string */ public function getPageUrl($pageSlug): string ``` ```php $url = $plugin->getPageUrl('my_page_slug'); ``` -------------------------------- ### Enqueue CSS with Dependencies and Version Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/view.mdx Use the `withStyle` method to load a CSS file. Specify the style name, an array of dependencies, and the version number. ```php /** * Load a new CSS resource in theme. * * @param string $name Name of style. * @param array $deps Optional. Array of slug deps * @param array $ver Optional. Version. * @return $this */ public function withStyle($name, $deps = [], $ver = []): View ``` ```php $view->withStyle('theme-style', [], '1.0.0'); ``` -------------------------------- ### Create a New Migration File Source: https://github.com/wpbones/website-docs/blob/main/content/database-orm/migrations.mdx Use the `php bones migrate:create` command followed by a descriptive name to generate a new migration file in the `database/migrations/` directory. ```bash php bones migrate:create MyTable ``` -------------------------------- ### Get showAdminColumn Property Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/ctt.mdx Determines if a column for the taxonomy should be displayed on its post type listing screens. ```php showAdminColumn; ``` -------------------------------- ### Action: Before Building Assets Source: https://github.com/wpbones/website-docs/blob/main/content/wordpress-integration/actions-and-filters.mdx Use the `wpbones_console_deploy_before_build_assets` action to run custom code just before the build assets process starts during deployment. It receives the console instance and the destination path. ```php /** * Fired before building assets * * @param object $console Instance of WPBones Console * @param string $path Destination path */ add_action('wpbones_console_deploy_before_build_assets', function ($console, $path) { // Do something }, 10, 2); ``` -------------------------------- ### Get restNamespace Property Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/ctt.mdx Retrieves the namespace for the REST API route of this taxonomy. Defaults to 'wp/v2'. ```php restNamespace; ``` -------------------------------- ### Create a New Service Provider Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/autoload-service-providers.mdx Use the WP Bones CLI to generate a new service provider. The command creates the provider in the `plugins/Providers` directory by default. ```sh php bones make:provider MyProvider ``` -------------------------------- ### Create Ajax Service Provider Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/ajax.mdx Use this command to generate a new Ajax Service Provider. The provider will be created in the `plugin/Ajax` directory by default. ```sh php bones make:ajax MyAjax ``` -------------------------------- ### Load and Use a Module Returning a Class Instance Source: https://github.com/wpbones/website-docs/blob/main/content/core-concepts/hooks-modules.mdx Load a module that returns an object and interact with its methods. The constructor output will appear when the module is loaded. ```php $my_class = wpbones_module('my-class'); // Hello, I'm a class! $my_class->myMethod(); // Hello, I'm a method! ``` -------------------------------- ### Require Third-Party Package Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/bones-console.mdx Installs third-party packages using composer and automatically renames the package in composer.json. ```sh php bones require ``` -------------------------------- ### Get Value or Execute Closure Source: https://github.com/wpbones/website-docs/blob/main/content/helpers.mdx Returns the given value. If a Closure is provided, it will be executed and its result returned. ```php /** * Return the default value of the given value. * * @param mixed $value * * @return mixed */ function wpbones_value($value) ``` ```php $value = wpbones_value( function() { return 'bar'; }); ``` -------------------------------- ### Get Provider Instance Source: https://github.com/wpbones/website-docs/blob/main/content/helpers.mdx Retrieve a provider instance by its class name. This function is a shortcut for WPKirk()->provider(). ```php /** * Return a provider by name * * @param string $name The Class name of the provider. * * @return mixed|null */ function wpbones_provider($provider) ``` ```php $provider = WPKirk()->provider('my_provider'); ``` -------------------------------- ### ActionsAndFiltersJSProvider Methods Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/actions-and-filters-js.mdx Use static methods to enqueue scripts or get the absolute path to the JavaScript files. ```php // enqueue the minified version ActionsAndFiltersJSProvider::enqueueScripts(); // enqueue the flat version ActionsAndFiltersJSProvider::enqueueScripts( false ); // return the absolute path of the minified CSS ActionsAndFiltersJSProvider::js(); // return the absolute path of the flat CSS ActionsAndFiltersJSProvider::js(); ``` -------------------------------- ### Define a Basic Hook Function Source: https://github.com/wpbones/website-docs/blob/main/content/core-concepts/hooks-modules.mdx Create a PHP file in the 'plugin/hooks' directory to define custom functions that will be automatically loaded. This example shows how to define a simple function. ```php restControllerClass; ``` -------------------------------- ### Deploy Plugin with composer.json Source: https://github.com/wpbones/website-docs/blob/main/content/getting-started/before-submit-to-wordpress-repository.mdx Use this command to deploy your plugin, ensuring the composer.json file is included. This is required if your plugin uses Composer for dependencies. ```bash $ php bones deploy --wp ``` -------------------------------- ### Get publiclyQueryable Property Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/ctt.mdx Retrieves whether the taxonomy is publicly queryable. If not set, the default is inherited from `$public`. ```php publiclyQueryable; ``` -------------------------------- ### Using Views as Fragments Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/view.mdx Render a view and capture its output to be used as a fragment within another view. This allows for modular view composition. ```php $fragment = WPKirk()->view( 'dashboard.fragment' )->render(); return WPKirk()->view( 'dashboard.index' ) ->with( [ 'fragment' => $fragment ] ); ``` -------------------------------- ### Get Plugin Header Information Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/bones-console.mdx Retrieves and displays the current header information from the main plugin file. ```sh php bones plugin ``` -------------------------------- ### Example WP Bones Command Class Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/writing-commands.mdx This is a generated command class. Define the `$signature` for command-line arguments and options, and implement the `handle` method for command logic. ```php options( 'name' ) ) { $this->line( 'Hello, ' . $this->options( 'name' ) ); } else { $this->line( 'Hello, World!' ); } } } ``` -------------------------------- ### Version Detection Source: https://github.com/wpbones/website-docs/blob/main/content/official-packages/useragent.mdx Demonstrates how to retrieve the version of a specific component or operating system. ```APIDOC ## Version Detection ### Description Retrieve the version number for a specified component or operating system. ### Method PHP Function Call ### Endpoint N/A ### Parameters N/A ### Request Example ```php // Find the version of a component. wpbones_user_agent()->version('Android'); ``` ### Response N/A ``` -------------------------------- ### Dumped Query Results Source: https://github.com/wpbones/website-docs/blob/main/content/database-orm/query-builder.mdx Example output from the `dump` method, showing query results in a JSON format. ```json [ { "ID": "1", "user_login": "root", "user_pass": "$P$BcsZ.SCXT1ItPV5vE.sRTwBpqx.vHs0", "user_nicename": "root", "user_email": "wpbones.info@gmail.com", "user_url": "", "user_registered": "2019-05-22 09:50:02", "user_activation_key": "", "user_status": "0", "display_name": "root" } ] ``` -------------------------------- ### Execute WordPress Function in Tinker Source: https://github.com/wpbones/website-docs/blob/main/content/bones-console/bones-console.mdx Example of executing a WordPress function within the interactive tinker shell. ```sh >>> echo get_bloginfo('version'); 6.6.2 ``` -------------------------------- ### boot Method Source: https://github.com/wpbones/website-docs/blob/main/content/core-classes/ctt.mdx The `boot` method is intended to be overridden to register custom actions and filters specific to the taxonomy. It provides a hook for developers to extend the functionality of the taxonomy service provider. ```APIDOC ## boot ### Description This method is intended to be overridden to register custom actions and filters specific to the taxonomy. It provides a hook for developers to extend the functionality of the taxonomy service provider. ### Synopsis `public function boot()` ### Example ```php class MyTaxonomyServiceProvider extends WordPressCustomTaxonomyTypeServiceProvider { public function boot() { $this->plural = 'Categories'; } } ``` ``` -------------------------------- ### Widget Backend Form View with Instance Data Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/widgets.mdx An example of an HTML snippet for a widget's backend form view that includes passing and displaying the `$instance` variable. This allows dynamic content based on widget settings. ```html

Widget Backend

Name ?>

``` -------------------------------- ### Register a Route for a RestController Source: https://github.com/wpbones/website-docs/blob/main/content/services-provider/rest-api.mdx Define a GET route in your `route.php` file that points to a method within your custom RestController. ```php use WPKirk\WPBones\Routing\API\Route; // may use the same route for different methods Route::get('/version', '\WPKirk\API\WPKirkV1Controller@version'); ```