Download the PHP package gebruederheitz/wp-theme-docs without Composer
On this page you can find all versions of the php package gebruederheitz/wp-theme-docs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gebruederheitz/wp-theme-docs
More information about gebruederheitz/wp-theme-docs
Files in gebruederheitz/wp-theme-docs
Package wp-theme-docs
Short Description Add simply admin pages or a Wordpress theme documentation page to the editor.
License GPL-3.0-only
Informations about the package wp-theme-docs
Wordpress Theme Admin Page and Documentation Maker
Add simply admin pages or a Wordpress theme documentation page to the editor.
Installation
via composer:
Make sure you have Composer autoload or an alternative class loader present.
Usage
This will set up a basic admin page under the "Tools" tab in
the Wordpress backend with the translated title __('Extra Tools', 'ghwp')
(/wordpress/wp-admin/tools.php?page=my-extra-admin-page
).
In its most basic state, this renders a page empty except for the title. You will need to register sections to add some content.
Constructor (and factory) arguments
argument | description |
---|---|
menuSlug | Where the menu will be available under $menuLocation (?page={{this}} ) |
title | A title displayed as <h1> at the top of the page, will be run through __() . |
menuLocation | Where to append the new submenu. Popular places are themes.php or tools.php . |
menuTitle | An alternative text for the menu entry. Defaults to $title . |
overridePath | An alternative path where consumers can put overrides templates to use instead of template-parts/meta/docs/documentation-page.php . |
i18nNamespace | The namespace used for translations for menu titles, titles and within the default templates (__(somestring, 'ghwp') ) |
Adding sections
Section registration & custom sections
Any section you add must implement the AdminPageSectionInterface
. You can
use the method addSection()
or the filter hook to add your section to a page:
using addSection()
using the hook
For convenience, you can extend the AbstractAdminPageSection
, which already
has the interface implemented, only requiring you to implement three abstract
getters to get it to run.
The above example sets up a section with the title Documentation for my amazing feature
rendering from the template partial at the given path.
The template is passed the instance of AdminPage
and the current
section:
Instead of setting the $partial
property (or even extending the abstract class),
you can also implement a custom rendering method:
The theme documentation page
This will set up the basic documentation page under the "Appearance" tab in
the Wordpress backend with the translated title __('Theme-Help', 'ghwp')
(/wordpress/wp-admin/themes.php?page=ghwp-help
).
It's simply a preconfigured AdminPage
, so you will need to add sections. In
this case, you can add them right through the constructor by passing an array
as the first argument:
Warning
Due to how PHP inheritance works, AdminPage's static
::factory()
method is available on DocumentationMenu, but it should not be used, as it will return a simple AdminPage object, not a DocumentationMenu instance.
DocumentationMenu: Changing the title and the template used
You can change the title displayed on the documentation page by passing a string as the constructor's second argument:
You can override the default template by creating a file in your theme's root
directory under template-parts/meta/docs/documentation-page.php
.
Alternatively you may override this default path by supplying a second argument to the constructor:
Included sections
The sections included in this package all extend AbstractAdminPageSection
.
This will register the sections and add them to the help page.
Shortcode Documentation Annotations
This module will automatically create a shortcode documentation for users based
on the annotation class ShortcodeDocumentation
. It is based on Doctrine's
annotation reader.
Documenting shortcodes
This assumes you add your shortcodes via individual classes for each shortcode
and have both the DocumentationMenu
page class and the Shortcodes
section
class up and running.
Available annotation properties:
Property | Type | Description |
---|---|---|
shortcode |
string | The actual shortcode that you use for registration. |
description |
string | A short description of what your shortcode is good for. |
parameters |
map | A map of parameter names and their descriptions, so users will know which parameters to pass and when. |
examples |
string list | A list of strings that will be wrapped in <pre><code></code></pre> , providing your users some examples of the shortcode's usage. |
The simplest way to document your Shortcode is to use the trait provided:
Alternatively, you can register your annotation yourself:
Changing the template partial for the section
As with all section classes extending AbstractAdminPageSection
, you have
two options of modifying the default output:
Using the default override template
Create a file in your theme's root directory under template-parts/meta/docs/shortcodes.php
.
This template will be used instead of the provided default.
The section template will be called with two arguments: an instance each of
DocumentationMenu
and the section (Shortcodes
):
Using a different template partial location
You'll need to extend the Shortcodes
class and provide an alternative getter:
List of SVG icon partials
This module will render a list of all icons that can be used by editors (for
instance via shortcodes). By default it searches template-parts/svg/
in your
theme's root directory recursively for .php
files, assuming they are templates
containing SVG markup.
This is most useful in conjunction with a shortcode that can render these SVG partials, for instance into button blocks.
Setting a different path for SVG partials
Same as with the Shortcodes section.
Development
Dependencies
- PHP >= 7.4
- Composer 2.x
- NVM and nodeJS LTS (v16.x)
- Nice to have: GNU Make (or drop-in alternative)
Migration
v1 to v2
- The PSR-4 namespaces changed; so instead of using
Gebruederheitz\Wordpress\Documentation\DocumentationPage
you will need to useGebruederheitz\Wordpress\AdminPage\Documentation\DocumentationPage
etc. AdminPageSectionInterface
replacesDocumentationSectionInterface
,AbstractAdminPageSections
replacesAbstractDocumentationSection
.- For a complete list of namespace and class name changes refer to the table below.
- Sections do not extend
Singleton
anymore, so you will have to construct them like any regular class instead of calling::getInstance()
. - The filter hook for documentation sections has changed from
ghwp_filter_documentation_sections
toghwp_filter_sections_ghwp-help
. You can not useDocumentationPage::HOOK_SECTIONS
anymore; either use the literal hook name, get the name via$documentationPageInstance->getSectionsHook()
, or (preferred) use$documentationPageInstance->addSection(AdminPageSectionInterface
changed | v1 | v2 |
---|---|---|
moved | Gebruederheitz\Wordpress\Documentation\DocumentationPage | Gebruederheitz\Wordpress\AdminPage\Documentation\DocumentationPage |
renamed | Gebruederheitz\Wordpress\Documentation\DocumentationSectionInterface | Gebruederheitz\Wordpress\AdminPage\AdminPageSectionInterface |
renamed, moved | Gebruederheitz\Wordpress\Documentation\Sections\AbstractDocumentationSection | Gebruederheitz\Wordpress\AdminPage\AbstractAdminPageSection |
moved | Gebruederheitz\Wordpress\Documentation\Sections\Shortcode | Gebruederheitz\Wordpress\AdminPage\Documentation\Section\Shortcode |
moved | Gebruederheitz\Wordpress\Documentation\Sections\Icons | Gebruederheitz\Wordpress\AdminPage\Documentation\Section\Icons |
moved | Gebruederheitz\Wordpress\Documentation\Annotations\ShortcodeDocumentation | Gebruederheitz\Wordpress\AdminPage\Documentation\Annotations\ShortcodeDocumentation |
moved | Gebruederheitz\Wordpress\Documentation\Traits\withShortcodeDocumentation | Gebruederheitz\Wordpress\AdminPage\Documentation\Traits\withShortcodeDocumentation |
--> | Gebruederheitz\Wordpress\Documentation\Helper\AnnotationReader | Gebruederheitz\Wordpress\AdminPage\Helper\AnnotationReader |
new | -- | Gebruederheitz\Wordpress\AdminPage\AdminPage |
All versions of wp-theme-docs with dependencies
gebruederheitz/simple-singleton Version ^1.0
doctrine/annotations Version ^1.13