Skip to content

Commit 3e5e773

Browse files
authored
Add settings ui for endpoints and update readme (#181)
1 parent 752897e commit 3e5e773

File tree

6 files changed

+89
-11
lines changed

6 files changed

+89
-11
lines changed

includes/class-micropub-admin.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function init() {
2222

2323
// Register Setting
2424
register_setting(
25-
'micropub_writing',
25+
'micropub',
2626
'micropub_default_post_status', // Setting Name
2727
array(
2828
'type' => 'string',
@@ -57,6 +57,7 @@ public static function admin_init() {
5757
*/
5858
public static function admin_menu() {
5959
$title = 'Micropub';
60+
$cls = get_called_class();
6061
// If the IndieWeb Plugin is installed use its menu.
6162
if ( class_exists( 'IndieWeb_Plugin' ) ) {
6263
$options_page = add_submenu_page(
@@ -65,15 +66,15 @@ public static function admin_menu() {
6566
$title,
6667
'manage_options',
6768
'micropub',
68-
array( 'Micropub_Admin', 'settings_page' )
69+
array( $cls, 'settings_page' )
6970
);
7071
} else {
7172
$options_page = add_options_page(
7273
$title,
7374
$title,
7475
'manage_options',
7576
'micropub',
76-
array( 'Micropub_Admin', 'settings_page' )
77+
array( $cls, 'settings_page' )
7778
);
7879
}
7980

includes/class-micropub-authorize.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class Micropub_Authorize {
3434
public static function init() {
3535
$cls = get_called_class();
3636

37+
add_action( 'admin_init', array( $cls, 'admin_init' ), 11 );
38+
3739
add_action( 'wp_head', array( $cls, 'html_header' ), 99 );
3840
add_action( 'send_headers', array( $cls, 'http_header' ) );
3941
add_filter( 'host_meta', array( $cls, 'jrd_links' ) );
@@ -45,6 +47,73 @@ public static function init() {
4547
add_filter( 'rest_authentication_errors', array( $cls, 'rest_authentication_errors' ), 10 );
4648
add_filter( 'rest_post_dispatch', array( $cls, 'return_micropub_error' ), 10, 3 );
4749

50+
// Register Setting
51+
register_setting(
52+
'micropub',
53+
'indieauth_authorization_endpoint', // Setting Name
54+
array(
55+
'type' => 'string',
56+
'description' => 'IndieAuth Authorization Endpoint',
57+
'sanitize_callback' => 'esc_url',
58+
'show_in_rest' => true,
59+
)
60+
);
61+
// Register Setting
62+
register_setting(
63+
'micropub',
64+
'indieauth_token_endpoint', // Setting Name
65+
array(
66+
'type' => 'string',
67+
'description' => 'IndieAuth Token Endpoint',
68+
'sanitize_callback' => 'esc_url',
69+
'show_in_rest' => true,
70+
)
71+
);
72+
73+
}
74+
75+
public static function admin_init() {
76+
$cls = get_called_class();
77+
$page = 'micropub';
78+
add_settings_section(
79+
'micropub_authorize',
80+
'Micropub Authorization Settings',
81+
array( $cls, 'auth_settings' ),
82+
$page
83+
);
84+
add_settings_field(
85+
'indieauth_authorization_endpoint',
86+
__( 'Authorization Endpoint', 'micropub' ),
87+
array( $cls, 'endpoint_field' ),
88+
$page,
89+
'micropub_authorize',
90+
array(
91+
'label_for' => 'indieauth_authorization_endpoint',
92+
'class' => 'widefat',
93+
'default' => MICROPUB_AUTHENTICATION_ENDPOINT,
94+
)
95+
);
96+
add_settings_field(
97+
'indieauth_token_endpoint',
98+
__( 'Token Endpoint', 'micropub' ),
99+
array( $cls, 'endpoint_field' ),
100+
$page,
101+
'micropub_authorize',
102+
array(
103+
'label_for' => 'indieauth_token_endpoint',
104+
'class' => 'widefat',
105+
'default' => MICROPUB_TOKEN_ENDPOINT,
106+
)
107+
);
108+
}
109+
110+
111+
public static function endpoint_field( $args ) {
112+
printf( '<label for="%1$s"><input id="%1$s" name="%1$s" type="url" value="%2$s" />', esc_attr( $args['label_for'] ), esc_url( get_option( $args['label_for'], $args['default'] ) ) );
113+
}
114+
115+
public static function auth_settings() {
116+
echo 'Server Settings for Indieauth';
48117
}
49118

50119
public static function get_error() {

micropub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Author: Ryan Barrett
88
* Author URI: https://snarfed.org/
99
* Text Domain: micropub
10-
* Version: 2.0.4
10+
* Version: 2.0.5
1111
*/
1212

1313
/* See README for supported filters and actions.

readme.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ Install from the WordPress plugin directory. No setup needed.
126126

127127
These configuration options can be enabled by adding them to your wp-config.php
128128

129-
* `define('MICROPUB_AUTHENTICATION_ENDPOINT', 'https://indieauth.com/auth')` - Define a custom authentication endpoint.
130-
* `define('MICROPUB_TOKEN_ENDPOINT', 'https://tokens.indieauth.com/token')` - Define a custom token endpoint
129+
* `define('MICROPUB_AUTHENTICATION_ENDPOINT', 'https://indieauth.com/auth')` - Define a custom authentication endpoint. Can be overridden in the settings interface
130+
* `define('MICROPUB_TOKEN_ENDPOINT', 'https://tokens.indieauth.com/token')` - Define a custom token endpoint. Can be overridden in the settings interface.
131131
* `define('MICROPUB_NAMESPACE', 'micropub/1.0' )` - By default the namespace for micropub is micropub/1.0. This would allow you to change this for your endpoint
132132
* `define('MICROPUB_DISABLE_NAG', 1 ) - Disable notices for insecure sites
133133
* `define('MICROPUB_LOCAL_AUTH', 1 ) - Disable built in AUTH in favor of your own plugin. Recommend plugin developers use the filter `disable_micropub_auth` for this.
@@ -205,6 +205,11 @@ into markdown and saved to readme.md.
205205
## Changelog
206206

207207

208+
### 2.0.5 (2018-11-23)
209+
* Move syndication trigger to after micropub hook in order to ensure final version is rendered before sending syndication
210+
* Add settings UI for alternate authorization endpoint and token endpoint which will be hidden if Indieauth plugin is enabled
211+
212+
208213
### 2.0.4 (2018-11-17)
209214
* Issues raised on prior release.
210215
* Removed generating debug messages when the data is empty

readme.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: micropub, publish, indieweb, microformats
44
Requires at least: 4.7
55
Requires PHP: 5.3
66
Tested up to: 4.9.8
7-
Stable tag: 2.0.4
7+
Stable tag: 2.0.5
88
License: CC0
99
License URI: http://creativecommons.org/publicdomain/zero/1.0/
1010
Donate link: -
@@ -128,8 +128,8 @@ Install from the WordPress plugin directory. No setup needed.
128128

129129
These configuration options can be enabled by adding them to your wp-config.php
130130

131-
* `define('MICROPUB_AUTHENTICATION_ENDPOINT', 'https://indieauth.com/auth')` - Define a custom authentication endpoint.
132-
* `define('MICROPUB_TOKEN_ENDPOINT', 'https://tokens.indieauth.com/token')` - Define a custom token endpoint
131+
* `define('MICROPUB_AUTHENTICATION_ENDPOINT', 'https://indieauth.com/auth')` - Define a custom authentication endpoint. Can be overridden in the settings interface
132+
* `define('MICROPUB_TOKEN_ENDPOINT', 'https://tokens.indieauth.com/token')` - Define a custom token endpoint. Can be overridden in the settings interface.
133133
* `define('MICROPUB_NAMESPACE', 'micropub/1.0' )` - By default the namespace for micropub is micropub/1.0. This would allow you to change this for your endpoint
134134
* `define('MICROPUB_DISABLE_NAG', 1 ) - Disable notices for insecure sites
135135
* `define('MICROPUB_LOCAL_AUTH', 1 ) - Disable built in AUTH in favor of your own plugin. Recommend plugin developers use the filter `disable_micropub_auth` for this.
@@ -200,6 +200,10 @@ into markdown and saved to readme.md.
200200

201201
== Changelog ==
202202

203+
= 2.0.5 (2018-11-23) =
204+
* Move syndication trigger to after micropub hook in order to ensure final version is rendered before sending syndication
205+
* Add settings UI for alternate authorization endpoint and token endpoint which will be hidden if Indieauth plugin is enabled
206+
203207
= 2.0.4 (2018-11-17) =
204208
* Issues raised on prior release.
205209
* Removed generating debug messages when the data is empty

templates/micropub-settings.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
<h1>Micropub Options</h1>
33
<form method="post" action="options.php">
44
<?php
5-
//add_settings_section callback is displayed here. For every new section we need to call settings_fields.
6-
settings_fields("micropub_writing");
5+
settings_fields("micropub");
76
// all the add_settings_field callbacks is displayed here
87
do_settings_sections("micropub");
98

0 commit comments

Comments
 (0)