-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to override templates #28
Changes from all commits
90ae468
77476c6
c26980e
f72e034
afe392e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Contributing | ||
|
||
## Running locally | ||
Start local site with: | ||
|
||
```shell | ||
wp-env start | ||
``` | ||
|
||
Change permalink structure: | ||
|
||
```shell | ||
wp-env run cli "wp rewrite structure '/%postname%'" | ||
``` | ||
|
||
The site is now available at http://localhost:8888. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,17 +65,47 @@ function oidc_clients() { | |
} | ||
``` | ||
|
||
## Development | ||
Start local site with: | ||
## Overriding templates | ||
The pages provided by this plugin are rendered using templates. If you so wish, you can use your own templates instead of this plugins's [default templates](templates). | ||
|
||
To do so, you should create an `openid-connect/` directory under your theme, containing only the templates you wish to override. For example, if you wanted to override `authenticate/main.php` and `authenticate/forbidden.php` you would create them under an `openid-connect/` directory in your theme: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am confused by the use of the directory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
At the moment there is only one page, but there might be other pages in the future, for example a page where you remove previously granted consent. Each page would get its own subdirectory under Starting with subdirectories since day one, even if there is only one page at the moment, allows us to not break backwards compatibility once (or if) we do introduce other pages. Because users can override these templates, moving them would break backwards compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the paths in the docs were wrong here, I fixed that in #33 |
||
|
||
```shell | ||
wp-env start | ||
wp-content/themes/my-theme/ | ||
│── openid-connect/ | ||
│──── main.php | ||
└──── forbidden.php | ||
``` | ||
psrpinto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Change permalink structure: | ||
If your theme is a child theme, this plugin will first look for templates under the child theme, and then in the parent theme. If it doesn't find a template, it will fall back to using the default template. | ||
|
||
```shell | ||
wp-env run cli "wp rewrite structure '/%postname%'" | ||
### Data | ||
Templates are passed a single `$data` variable containing the values necessary to render said template. For example, you can access the name of the OIDC client as follows: | ||
|
||
```php | ||
// wp-content/themes/my-theme/main.php | ||
|
||
/** @var stdClass $data **/ | ||
|
||
/** @var string $client_name The OIDC client name */ | ||
$client_name = $data->client_name; | ||
``` | ||
|
||
You can of course also call any other WordPress function, like you would in any other file in your theme. | ||
|
||
### Partials | ||
In your templates, you can include partial templates (aka partials) by calling `$data->templates->partial()`: | ||
|
||
```php | ||
// wp-content/themes/my-theme/main.php | ||
|
||
/** @var stdClass $data **/ | ||
|
||
/** @var \OpenIDConnectServer\Templating\Templating $templates */ | ||
$templates = $data->templates; | ||
|
||
// Renders the <form> in the 'authenticate/form.php' partial. | ||
$templates->partial( 'authenticate/form' ) | ||
``` | ||
|
||
The site is now available at http://localhost:8888. | ||
Partials are also passed the `$data` variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty big thing to ask for. Why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something I noticed is needed at the moment, so I documented it. There's an issue for it at #19, once that is fixed these instructions can be removed.