PHP code example of pinkcrab / perique-admin-menu

1. Go to this page and download the library: Download pinkcrab/perique-admin-menu 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/ */

    

pinkcrab / perique-admin-menu example snippets


$app = ( new PinkCrab\Perique\Application\App_Factory() )
  // Perique bootstrapping as normal.   
  ->module( Admin_Menu::class )
  ->boot();

class My_Group extends Abstract_Group{
  // Required  
  protected string $group_title = 'My Page Group';
  protected string $primary_page = 'Acme\My_Plugin\Page\Primary_Page';
  protected array $pages = array(
    'Acme\My_Plugin\Page\Secondary_Page',
    'Acme\My_Plugin\Page\Tertiary_Page',
  );
  
  // Optional
  protected string $capability = 'edit_posts';    // Defaults to manage_options
  protected string $icon = 'dashicons-chart-pie'; // Defaults to dashicons-admin-generic
  protected int $position = 24;                   // Defaults to 65
}

class My_Page extends Menu_Page{

  // Required  
  protected string $page_slug = 'acme_pages';
  protected string $page_title = 'Acme Pages';
  protected string $menu_title = 'Acme Pages';
  
  // Optional
  protected ?string $parent_slug = null;       // If null, will be a top level menu item.
  protected string $capability = 'edit_post';  // Default capability for page.
  protected ?int $position = 12;

  // View to render
  protected string $view_template = 'my-page.php';
  protected array $view_data = array('key' => 'value');
}
 
class Settings_Page extends Menu_page{
  // Page definitions.
  protected string $page_slug = 'acme_pages';
  protected string $page_title = 'Acme Pages';
  protected string $menu_title = 'Acme Pages';
  protected string $view_template = 'my-page.php';

  // Custom form handler service.
  private Form_Handler $form_handler;

  // Injected settings service and the form handler.
  public __construct( Settings $settings, Form_Handler $form_handler ){
    $this->form_handler = $form_handler;
    $this->view_data = $settings->as_array();
  }

  // On page load, check if form has been submitted, and if so, handle it.
  public function load( Page $page ): void{
    if( $this->form_handler->is_submitted() ){
      $new_settings = $this->form_handler->handle();
      $this->view_data = $new_settings;
    }
  }
}