| @@ -2,83 +2,51 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: NodeInfo |
| 4 | 4 | * Plugin URI: https://github.com/pfefferle/wordpress-nodeinfo/ |
| 5 | 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.3.1 | |
| 6 | + * Version: 3.1.0 | |
| 7 | 7 | * Author: Matthias Pfefferle |
| 8 | 8 | * Author URI: https://notiz.blog/ |
| 9 | 9 | * License: MIT |
| 10 | 10 | * License URI: http://opensource.org/licenses/MIT |
| 11 | 11 | * Text Domain: nodeinfo |
| 12 | - * Domain Path: /languages | |
| 12 | + * | |
| 13 | + * @package Nodeinfo | |
| 13 | 14 | */ |
| 14 | 15 | |
| 15 | -/** | |
| 16 | - * Initialize plugin | |
| 17 | - */ | |
| 18 | -function nodeinfo_init() { | |
| 19 | - require_once __DIR__ . '/includes/class-nodeinfo-endpoint.php'; | |
| 20 | - require_once __DIR__ . '/includes/functions.php'; | |
| 16 | +defined( 'ABSPATH' ) || exit; | |
| 21 | 17 | |
| 22 | - // Configure the REST API route | |
| 23 | - add_action( 'rest_api_init', array( 'Nodeinfo_Endpoint', 'register_routes' ) ); | |
| 18 | +define( 'NODEINFO_PLUGIN_FILE', __FILE__ ); | |
| 19 | +define( 'NODEINFO_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); | |
| 24 | 20 | |
| 25 | - // Add Webmention and Host-Meta discovery | |
| 26 | - add_filter( 'webfinger_user_data', array( 'Nodeinfo_Endpoint', 'render_jrd' ), 10, 3 ); | |
| 27 | - add_filter( 'webfinger_post_data', array( 'Nodeinfo_Endpoint', 'render_jrd' ), 10, 3 ); | |
| 28 | - add_filter( 'host_meta', array( 'Nodeinfo_Endpoint', 'render_jrd' ) ); | |
| 29 | -} | |
| 30 | -add_action( 'init', 'nodeinfo_init', 9 ); | |
| 21 | +// Require the autoloader. | |
| 22 | +require_once NODEINFO_PLUGIN_DIR . 'includes/class-autoloader.php'; | |
| 31 | 23 | |
| 32 | -/** | |
| 33 | - * Plugin Version Number. | |
| 34 | - */ | |
| 35 | -function nodeinfo_version() { | |
| 36 | - $meta = nodeinfo_get_plugin_meta( array( 'Version' => 'Version' ) ); | |
| 24 | +// Register the autoloader. | |
| 25 | +Nodeinfo\Autoloader::register_path( 'Nodeinfo', NODEINFO_PLUGIN_DIR . 'includes' ); | |
| 37 | 26 | |
| 38 | - return $meta['Version']; | |
| 39 | -} | |
| 27 | +// Require global functions. | |
| 28 | +require_once NODEINFO_PLUGIN_DIR . 'includes/functions.php'; | |
| 40 | 29 | |
| 30 | +// Require deprecated classes for backwards compatibility. | |
| 31 | +require_once NODEINFO_PLUGIN_DIR . 'includes/class-nodeinfo-endpoint.php'; | |
| 32 | + | |
| 41 | 33 | /** |
| 42 | - * Add rewrite rules | |
| 34 | + * Plugin initialization function. | |
| 35 | + * | |
| 36 | + * @return Nodeinfo\Nodeinfo The plugin instance. | |
| 43 | 37 | */ |
| 44 | -function nodeinfo_add_rewrite_rules() { | |
| 45 | - add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/nodeinfo/discovery', 'top' ); | |
| 46 | - add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/nodeinfo2/1.0', 'top' ); | |
| 38 | +function nodeinfo_plugin() { | |
| 39 | + return Nodeinfo\Nodeinfo::get_instance(); | |
| 47 | 40 | } |
| 48 | -add_action( 'init', 'nodeinfo_add_rewrite_rules', 1 ); | |
| 49 | 41 | |
| 50 | -/** | |
| 51 | - * `get_plugin_data` wrapper | |
| 52 | - * | |
| 53 | - * @return array the plugin metadata array | |
| 54 | - */ | |
| 55 | -function nodeinfo_get_plugin_meta( $default_headers = array() ) { | |
| 56 | - if ( ! $default_headers ) { | |
| 57 | - $default_headers = array( | |
| 58 | - 'Name' => 'Plugin Name', | |
| 59 | - 'PluginURI' => 'Plugin URI', | |
| 60 | - 'Version' => 'Version', | |
| 61 | - 'Description' => 'Description', | |
| 62 | - 'Author' => 'Author', | |
| 63 | - 'AuthorURI' => 'Author URI', | |
| 64 | - 'TextDomain' => 'Text Domain', | |
| 65 | - 'DomainPath' => 'Domain Path', | |
| 66 | - 'Network' => 'Network', | |
| 67 | - 'RequiresWP' => 'Requires at least', | |
| 68 | - 'RequiresPHP' => 'Requires PHP', | |
| 69 | - 'UpdateURI' => 'Update URI', | |
| 70 | - ); | |
| 42 | +// Initialize the plugin after all plugins are loaded. | |
| 43 | +add_action( | |
| 44 | + 'plugins_loaded', | |
| 45 | + function () { | |
| 46 | + nodeinfo_plugin()->init(); | |
| 71 | 47 | } |
| 48 | +); | |
| 72 | 49 | |
| 73 | - return get_file_data( __FILE__, $default_headers, 'plugin' ); | |
| 74 | -} | |
| 75 | - | |
| 76 | -/** | |
| 77 | - * Flush rewrite rules; | |
| 78 | - */ | |
| 79 | -function nodeinfo_flush_rewrite_rules() { | |
| 80 | - nodeinfo_add_rewrite_rules(); | |
| 81 | - flush_rewrite_rules(); | |
| 82 | -} | |
| 83 | -register_activation_hook( __FILE__, 'nodeinfo_flush_rewrite_rules' ); | |
| 84 | -register_deactivation_hook( __FILE__, 'flush_rewrite_rules' ); | |
| 50 | +// Register activation and deactivation hooks. | |
| 51 | +register_activation_hook( __FILE__, array( Nodeinfo\Nodeinfo::class, 'activate' ) ); | |
| 52 | +register_deactivation_hook( __FILE__, array( Nodeinfo\Nodeinfo::class, 'deactivate' ) ); | |