PluginProbe
NodeInfo(2) / 2.0.0
NodeInfo(2) v2.0.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 3.0.0 3.1.0
nodeinfo / nodeinfo.php

nodeinfo.php in NodeInfo(2) 2.0.0, at nodeinfo.php

84 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: NodeInfo
4 * Plugin URI: https://github.com/pfefferle/wordpress-nodeinfo/
5 * Description: NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks.
6 * Version: 2.0.0
7 * Author: Matthias Pfefferle
8 * Author URI: https://notiz.blog/
9 * License: MIT
10 * License URI: http://opensource.org/licenses/MIT
11 * Text Domain: nodeinfo
12 * Domain Path: /languages
13 */
14
15 /**
16 * Initialize plugin
17 */
18 function nodeinfo_init() {
19 require_once dirname( __FILE__ ) . '/includes/class-nodeinfo-endpoint.php';
20
21 // Configure the REST API route
22 add_action( 'rest_api_init', array( 'Nodeinfo_Endpoint', 'register_routes' ) );
23
24 // Add Webmention and Host-Meta discovery
25 add_filter( 'webfinger_user_data', array( 'Nodeinfo_Endpoint', 'render_jrd' ), 10, 3 );
26 add_filter( 'webfinger_post_data', array( 'Nodeinfo_Endpoint', 'render_jrd' ), 10, 3 );
27 add_filter( 'host_meta', array( 'Nodeinfo_Endpoint', 'render_jrd' ) );
28 }
29 add_action( 'plugins_loaded', 'nodeinfo_init' );
30
31 /**
32 * Plugin Version Number.
33 */
34 function nodeinfo_version() {
35 $meta = nodeinfo_get_plugin_meta( array( 'Version' => 'Version' ) );
36
37 return $meta['Version'];
38 }
39
40 /**
41 * Add rewrite rules
42 */
43 function nodeinfo_add_rewrite_rules() {
44 add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/nodeinfo/discovery', 'top' );
45 add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/nodeinfo2/1.0', 'top' );
46 }
47 add_action( 'init', 'nodeinfo_add_rewrite_rules', 1 );
48
49 /**
50 * `get_plugin_data` wrapper
51 *
52 * @return array the plugin metadata array
53 */
54 function nodeinfo_get_plugin_meta( $default_headers = array() ) {
55 if ( ! $default_headers ) {
56 $default_headers = array(
57 'Name' => 'Plugin Name',
58 'PluginURI' => 'Plugin URI',
59 'Version' => 'Version',
60 'Description' => 'Description',
61 'Author' => 'Author',
62 'AuthorURI' => 'Author URI',
63 'TextDomain' => 'Text Domain',
64 'DomainPath' => 'Domain Path',
65 'Network' => 'Network',
66 'RequiresWP' => 'Requires at least',
67 'RequiresPHP' => 'Requires PHP',
68 'UpdateURI' => 'Update URI',
69 );
70 }
71
72 return get_file_data( __FILE__, $default_headers, 'plugin' );
73 }
74
75 /**
76 * Flush rewrite rules;
77 */
78 function nodeinfo_flush_rewrite_rules() {
79 nodeinfo_add_rewrite_rules();
80 flush_rewrite_rules();
81 }
82 register_activation_hook( __FILE__, 'nodeinfo_flush_rewrite_rules' );
83 register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
84