PHP code example of gebruederheitz / wp-theme-docs
1. Go to this page and download the library: Download gebruederheitz/wp-theme-docs 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/ */
gebruederheitz / wp-theme-docs example snippets
# functions.php (or controller class)
use Gebruederheitz\Wordpress\Documentation\AdminPage;
new AdminPage('my-extra-admin-page', 'Extra Tools', 'tools.php');
// or use the factory method
AdminPage::factory('my-extra-admin-page', 'Extra Tools', 'tools.php');
use Gebruederheitz\Wordpress\Documentation\AdminPage ;
$page = new AdminPage('extras');
$page->addSection(new MySection());
// Using AdminPage's factory method:
AdminPage::factory('extras')->addSection($mySection);
// Adding multiple sections with addSection() or addSections()
AdminPage::factory('extras')
->addSection($mySection)
->addSection($otherSection);
AdminPage::factory('extras')
->addSections([
new MySection(),
new OtherSection(),
]);
use Gebruederheitz\Wordpress\Documentation\AdminPage ;
$page = new AdminPage('extras');
function ghwp_add_doc_section(array $sections) {
$sections[] = new MyDocSection();
return $sections;
}
add_filter($page->getSectionsHook(), 'ghwp_add_doc_section');
// OR, using 'ghwp_filter_sections_' and the page's slug:
add_filter('ghwp_filter_sections_extras', 'ghwp_add_doc_section');
use Gebruederheitz\Wordpress\AdminPage\AbstractAdminPageSection;
class MyDocsSection extends AbstractAdminPageSection {
public function getTitle() : string{
return 'Documentation for my amazing feature';
}
protected function getDefaultPartial() : string{
return __DIR__. '/../template-parts/meta/docs/feature.php';
}
/* Optional: Define an override path that can be used instead of your default */
protected function getOverridePath() : string{
return get_theme_file_path('template-parts/meta/overrides/feature.php');
}
/* Optional: Expose public methods for your template to use */
public function getSomeData() {
return [/* ... */];
}
}
use Gebruederheitz\Wordpress\AdminPage\AdminPageSectionInterface
use Gebruederheitz\Wordpress\AdminPage\AbstractAdminPageSection;
class MySecondDocsSection extends AbstractAdminPageSection {
/* ... */
/**
* @override
*/
public function render(AdminPage $docs)
{
get_template_part('template-parts/meta/docs/documentation', 'page', [$docs, $this]);
}
}
/** Example of a section not extending the abstract base implementation */
class MyThirdDocsSection implements AdminPageSectionInterface {
public function onPageSections(array $sections): array
{
$sections[] = $this;
return $sections;
}
public function getTitle(): string
{
return 'My Third Docs Section is the best to date!';
}
public function render(DocumentationMenu $docs)
{
get_template_part('template-parts/meta/docs/documentation', 'page', [$docs, $this]);
}
}
# functions.php (or controller class)
use Gebruederheitz\Wordpress\AdminPage\Documentation\DocumentationMenu;
new DocumentationMenu();
new DocumentationMenu([$sectionOne, $sectionTwo]);
new \Gebruederheitz\Wordpress\Documentation\DocumentationMenu(null, 'Theme Docs!');
new DocumentationMenu(null, null, 'template-parts/special/docs.php');
use Gebruederheitz\Wordpress\AdminPage\Documentation\DocumentationMenu;
use Gebruederheitz\Wordpress\AdminPage\Documentation\Section\Shortcodes;
use Gebruederheitz\Wordpress\AdminPage\Documentation\Section\Icons;
new DocumentationMenu(
'My Theme',
[
new Shortcodes(),
new Icons(),
]
);
// or
$docs = new DocumentationMenu();
$docs->addSection(new Shortcodes())->addSection(new Icons());
// or
$docs->addSections([new Shortcodes(), new Icons()]);
// or
add_filter($docs->getSectionsHook(), function(array $sections): array {
$sections[] = new Shortcodes();
return $sections;
});
use Gebruederheitz\Wordpress\AdminPage\Documentation\Traits\withShortcodeDocumentation;
use Gebruederheitz\Wordpress\AdminPage\Documentation\Annotations\ShortcodeDocumentation;
/**
* Class MyShortcode
*
* @package Ghwp\Shortcode
*
* @ShortcodeDocumentation(
* shortcode="ghwp-my-shortcode",
* description="Renders a thing.",
* parameters={
* "id": "The post ID you wish to display."
* },
* examples={
* "[ghwp-my-shortcode id=123 /]"
* }
* )
*/
class MyShortcode {
use withShortcodeDocumentation;
/* With a dynamic class instance... */
public function __construct()
{
self::addDocumentation();
add_shortcode('ghwp-my-shortcode', [$this, 'renderShortcode'));
}
/* ...or with a static class / method */
public static function init()
{
self::addDocumentation();
add_shortcode('ghwp-my-shortcode', [self::class, 'renderShortcode']);
}
}
MyShortcode::init();
/* or*/
new MyShortcode();
use Gebruederheitz\Wordpress\AdminPage\Documentation\Annotations\ShortcodeDocumentation;
use Gebruederheitz\Wordpress\AdminPage\Documentation\Section\Shortcodes;
/**
* @ShortcodeDocumentation(
* shortcode="ghwp-my-shortcode",
* description="Renders a thing.",
* parameters={
* "id": "The post ID you wish to display."
* },
* examples={
* "[ghwp-my-shortcode id=123 /]"
* }
* )
*/
class MyShortcode {
/* With a dynamic class instance... */
public function __construct()
{
add_filter(Shortcodes::HOOK_SHORTCODE_DOCS, [$this, 'onShortcodeDocs']);
add_shortcode('ghwp-my-shortcode', [$this, 'renderShortcode'));
}
public function onShortcodeDocs(array $docs)
{
$docs[] = self::class;
return $docs;
}
}
class MyShortcodes extends Shortcodes {
// skip this if you want to keep the default partial and only
// change the override location
protected function getDefaultPartial(): string
{
return __DIR__ . '/../../templates/shortcodes.php';
}
protected function getOverridePath(): string
{
return 'template-parts/meta/docs/shortcodes.php';
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.