rogierkn / pages-for-wp

此包最新版本(dev-master)没有可用的许可证信息。

以结构化方式开发WordPress插件的引导工具

dev-master 2016-07-29 13:12 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:42:11 UTC


README

WordPress页面

轻松引导您的WordPress插件。

在您的 plugin.php 文件中

use Rogierkn\PagesForWp\App;
use Rogierkn\PagesForWp\DatabaseConnection;

// Or any other PDO object
$databaseConnection = DatabaseConnection::getInstance('localhost', 'wordpress', 'user', 'strongPassword');

$app = new App($databaseConnection);

$app->pages->register([
    ExamplePage::class
]);

$app->setViewsFolder(__DIR__ . '/views/');
$app->run();

示例页面.php

use Rogierkn\PagesForWp\Pages\Page;

class ExamplePage extends Page
{
    /**
    * The wordpress event to bind to
    */
    public function event()
    {
        return 'admin_menu';
    }

    /**
    * Called when the above event occurs
    * This example binds to the options page
    */
    public function register()
    {
        // Any related wordpress function can be used for this
        return function () {
            add_options_page('Page Title', 'Menu Title', 'capability', "slug", $this->handle());
        };
    }

    /**
    * Handle your Page's actions in here
    * You have access to the $request and $db in here
    */
    public function handle()
    {
        return $this->render('superView.html.twig', ["name" => "John Doe"]);
    }
}