indieweb / wordpress-micropub

A Micropub Endpoint plugin for WordPress
https://wordpress.org/plugins/micropub
52 stars 13 forks source link
indieweb micropub plugin wordpress wordpress-plugin

Micropub

Contributors: indieweb, snarfed, dshanske
Tags: micropub, publish, indieweb, microformats
Requires at least: 4.9.9
Tested up to: 6.5.2
Stable tag: 2.4.0
Requires PHP: 7.2
License: CC0
License URI: http://creativecommons.org/publicdomain/zero/1.0/

Allows you to publish to your site using Micropub clients.

Description

Micropub is an open API standard that is used to create posts on your site using third-party clients. Web apps and native apps (e.g. iPhone, Android) can use Micropub to post short notes, photos, events or other posts to your own site, similar to a Twitter client posting to Twitter.com. Requires the IndieAuth plugin for authentication.

Once you've installed and activated the plugin, try a client such as Quill to create a new post on your site. It walks you through the steps and helps you troubleshoot if you run into any problems. A list of known Micropub clients are available here

Supports the full Micropub spec

As this allows the creation of posts without entering the WordPress admin, it is not subject to any Gutenberg compatibility concerns per se. Posts created will not have Gutenberg blocks as they were not created with Gutenberg, but otherwise there should be no issues at this time.

Available in the WordPress plugin directory at wordpress.org/plugins/micropub.

License

This project is placed in the public domain. You may also use it under the CC0 license.

WordPress details

Filters and hooks

Adds ten filters:

before_micropub( $input )

Called before handling a Micropub request. Returns $input, possibly modified.

micropub_post_content( $post_content, $input )

Called during the handling of a Micropub request. The content generation function is attached to this filter by default. Returns $post_content, possibly modified.

micropub_post_type( $post_type = 'post', $input )

Called during the creation of a Micropub post. This defaults to post, but allows for setting Micropub posts to a custom post type.

micropub_tax_input( $tax_input, $input )

Called during the creation of a Micropub post. This defaults to nothing but allows for a Micropub post to set a custom taxonomy.

micropub_syndicate-to( $synd_urls, $user_id, $input )

Called to generate the list of syndicate-to targets to return in response to a query. Returns $synd_urls, an array, possibly modified. This filter is empty by default

micropub_query( $resp, $input )

Allows you to replace a query response with your own customized version to add additional information

micropub_suggest_title( $mf2 )

Allows a suggested title to be generated. This can be used either to generate the post slug or for individuals who want to use it to set a WordPress title

indieauth_scopes( $scopes )

This returns scopes from a plugin implementing IndieAuth. This filter is empty by default.

indieauth_response( $response )

This returns the token auth response from a plugin implementing IndieAuth. This filter is empty by default.

pre_insert_micropub_post( $args )

This filters the arguments sent to wp_insert_post just prior to its insertion. If the ID key is set, then this will short-circuit the insertion to allow for custom database coding.

...and two hooks:

after_micropub( $input, $wp_args = null)

Called after handling a Micropub request. Not called if the request fails (ie doesn't return HTTP 2xx).

micropub_syndication( $ID, $syndicate_to )

Called only if there are syndication targets $syndicate_to for post $ID. $syndicate_to will be an array of UIDs that are verified as one or more of the UIDs added using the micropub_syndicate-to filter.

Arguments:

Other

Stores microformats2 properties in post metadata with keys prefixed by mf2_. Details here. All values are arrays; use unserialize() to deserialize them.

Does not support multithreading. PHP doesn't really either, so it generally won't matter, but just for the record.

Supports Stable Extensions to Micropub:

Supports Proposed Extensions to Micropub:

Deprecated Extensions still Supported:

Extensions Supported by Other Plugins:

If an experimental property is not set to one of the noted options, the plugin will return HTTP 400 with body:

{
  "error": "invalid_request",
}

WordPress has a whitelist of file extensions that it allows in uploads. If you upload a file in a Micropub extension that doesn't have an allowed extension, the plugin will return HTTP 400 with body:

{
  "error": "invalid_request",
  "error_description": "Sorry, this file is not permitted for security reasons."
}

Authentication and authorization

For reasons of security it is recommended that you only use this plugin on sites that implement HTTPS. Authentication is not built into this plugin.

In order to use this, the IndieAuth plugin is required. Other plugins may be written in future as alternatives and will be noted if they exist.

Installation

Install the IndieAuth plugin from the WordPress plugin directory, then install this plugin. No setup needed.

Configuration Options

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

Frequently Asked Questions

I am experiencing issues in logging in with IndieAuth.

There are a series of troubleshooting steps in the IndieAuth plugin for this. The most common problem involves the token not being passed due the configuration of your hosting provider.

Upgrade Notice

Version 2.4.0

The following option and setting was removed from the plugin as the IndieAuth plugin now allows the creation of a draft token to satisfy this need. Being as this was the only setting the entire settings page was removed.

The older MICROPUB_DRAFT_MODE config override remains in place for now.

Static rendering for newer posts has been replaced by dynamic render. This means that if you disable this plugin, it will not render the microformats on newer posts. This is using the same code used for static rendering but future enhancements are planned.

Version 2.2.3

The Micropub plugin will no longer store published, updated, summary, or name options. These will be derived from the WordPress post properties they are mapped to and returned on query.

Version 2.2.0

The Micropub plugin will no longer function without the IndieAuth plugin installed.

Version 2.0.0

This version changes the Micropub endpoint URL as it now uses the REST API. You may have to update any third-parties that have cached this info.

Screenshots

None.

Development

The canonical repo is http://github.com/indieweb/wordpress-micropub . Feedback and pull requests are welcome!

To add a new release to the WordPress plugin directory, tag it with the version number and push the tag. It will automatically deploy.

To set up your local environment to run the unit tests and set up PHPCodesniffer to test adherence to WordPress Coding Standards and PHP Compatibility:

  1. Install Composer. Composer is only used for development and is not required to run the plugin.
  2. Run composer install which will install PHP Codesniffer, PHPUnit, the standards required, and all dependencies.

To configure PHPUnit

  1. Install and start MySQL. (You may already have it.)
  2. Run ./bin/install-wp-tests.sh wordpress_micropub_test root '' localhost to download WordPress and its unit test library, into your systems tmp directory by default, and create a MySQL db to test against. Background here. Feel free to use a MySQL user other than root. You can set the WP_CORE_DIR and WP_TESTS_DIR environment variables to change where WordPress and its test library are installed. For example, I put them both in the repo dir.
  3. Open wordpress-tests-lib/wp-tests-config.php and add a slash to the end of the ABSPATH value. No clue why it leaves off the slash; it doesn't work without it.
  4. Run phpunit in the repo root dir. If you set WP_CORE_DIR and WP_TESTS_DIR above, you'll need to set them for this too. You should see output like this:

    Installing... ... 1 / 1 (100%) Time: 703 ms, Memory: 33.75Mb OK (1 test, 3 assertions)

To set up PHPCodesniffer to test adherence to WordPress Coding Standards and PHP 5.6 Compatibility:

  1. To list coding standard issues in a file, run composer phpcs
  2. If you want to try to automatically fix issues, run `composer phpcbf``.

To automatically convert the readme.txt file to readme.md, you may, if you have installed composer as noted in the previous section, enter composer update-readme to have the .txt file converted into markdown and saved to readme.md.

Changelog

2.4.0 (2024-06-13)

2.3.3 (2023-03-10)

2.3.2 (2022-06-22 )

2.3.1 (2021-12-25 )

2.3.0 (2021-12-25 )

2.2.5 (2021-09-22 )

2.2.4 (2021-05-06 )

2.2.3 (2020-09-09 )

2.2.2 (2020-08-23 )

2.2.1 (2020-07-31 )

2.2.0 (2020-07-25 )

2.1.0 (2020-02-06 )

2.0.11 (2019-05-25)

2.0.10 (2019-04-13)

2.0.9 (2019-03-25)

2.0.8 (2019-03-08)

2.0.7 (2019-02-18)

2.0.6 (2018-12-30)

2.0.5 (2018-11-23)

2.0.4 (2018-11-17)

2.0.3 (2018-11-17)

2.0.2 (2018-11-12)

2.0.1 (2018-11-04)

2.0.0 (2018-10-22)

1.4.3 (2018-05-27)

1.4.2 (2018-04-19)

1.4.1 (2018-04-15)

1.4 (2018-04-08)

1.3 (2017-12-31)

1.2 (2017-06-25)

1.1 (2017-03-30)

1.0.1

1.0

Substantial update. Supports full W3C Micropub spec, except for optional media endpoint.

0.4

0.3

0.2

0.1

Initial release.