PHP code example of moehrenzahn / wp-toolkit

1. Go to this page and download the library: Download moehrenzahn/wp-toolkit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

moehrenzahn / wp-toolkit example snippets



$client = new \Moehrenzahn\Toolkit\Api\Client();


// Entry point for all actions is the Client object
$client = new \Moehrenzahn\Toolkit\Api\Client();
$stylesheets = $client->getStylesheetManager();
$stylesheets->add('eule-stylesheet', 'src/css/style.css', '1.0.0');


$client = new \Moehrenzahn\Toolkit\Api\Client();
$shortcodes = $client->getShortcodeManager();
$shortcodes->add(
    'my-shortcode',
    $client->getViewFactory()->create('shortcode-template.phtml')
);


$client = new \Moehrenzahn\Toolkit\Api\Client();
$client->getAdminPageManager()->addSettingsPage(
    'Sample settings page',
    'sample-settings-page',
    getSections($client)
);

/**
 * @param \Moehrenzahn\Toolkit\Api\Client $client
 * @return Moehrenzahn\Toolkit\View\Settings\Section[]
 */
function getSections(\Moehrenzahn\Toolkit\Api\Client $client): array
{
    $sectionBuilder = $client->getSettingsSectionBuilder();
    $sectionBuilder->addSetting(
        'my-sample-setting',
        'A sample setting title',
        \Moehrenzahn\Toolkit\AdminPage\SettingsSectionBuilder::SETTING_TYPE_BOOLEAN,
        'A sample setting description.'
    );

    $sectionBuilder->addSetting(
        'my-sample-select',
        'Select your thing',
        \Moehrenzahn\Toolkit\AdminPage\SettingsSectionBuilder::SETTING_TYPE_SELECT,
        'You can also do select inputs!',
       [
           'sample-option-value' => 'Sample option label',
           'another-option-value' => 'Another option!',
       ]
    );
    
    return [$sectionBuilder->create('sample-section', 'A sample settings section')];
}

 /** @var \Moehrenzahn\Toolkit\View $view */ 

 
$client = new \Moehrenzahn\Toolkit\Api\Client();
$objectManager = $client->getObjectManager();
/**
 * The object manager will try to automatically and recursively
 * resolve all dependencies of the given class.
 * Don't use this for very large projects since it can impact performance.
 */
$customObject = $objectManager->getSingleton(YourCustomClass::class);