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 simple 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.
Generic Documentation Sections
This module will create a documentation section for users based
on the attribute class DocumentationSection.
You will need to initialize the processing of these generic section in your AdminPage or DocumentationMenu instance you want them rendered in:
The generic sections can render Markdown content if the third-party package
fastvolt/markdown is installed and the markdown property is set to true:
// Like code blocks
echo "Hello, World!";
Shortcode Documentation Annotations
This module will automatically create a shortcode documentation for users based
on the attribute class ShortcodeDocumentation.
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 attribute 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 |
array<string, string> | A map of parameter names and their descriptions, so users will know which parameters to pass and when. |
examples |
array |
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:
Alternatively, you can register your attribute 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 >= 8.0
- optional: DDEV
- Composer 2.x
- asdf tool version manager with nodeJS LTS (v24.x)
- go-task / Taskfiles
Migration
v2 to v3
We've removed the deprecated Doctrine\Annotations and replaced them with native PHP attributes. If you were using the ShortcodeDocumentation annotation, you'll need to change your code to use the attribute instead. We've also added a new method for registering shortcode documentation that does not require importing the trait.
If you wish to continue using the traits, they now use the more conventional
PascalCase naming, so withShortcodeDocumentation is now WithShortcodeDocumentation:
v1 to v2
- The PSR-4 namespaces changed; so instead of using
Gebruederheitz\Wordpress\Documentation\DocumentationPageyou will need to useGebruederheitz\Wordpress\AdminPage\Documentation\DocumentationPageetc. AdminPageSectionInterfacereplacesDocumentationSectionInterface,AbstractAdminPageSectionsreplacesAbstractDocumentationSection.- For a complete list of namespace and class name changes refer to the table below.
- Sections do not extend
Singletonanymore, 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_sectionstoghwp_filter_sections_ghwp-help. You can not useDocumentationPage::HOOK_SECTIONSanymore; 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 |