-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathblockroll.php
More file actions
93 lines (85 loc) · 2.69 KB
/
Copy pathblockroll.php
File metadata and controls
93 lines (85 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Plugin Name: Blogroll & Podroll Block
* Plugin URI: https://github.com/pfefferle/wordpress-blockroll
* Description: Share the blogs and podcasts you follow, and let other people subscribe to your list.
* Version: 2.1.1
* Requires at least: 6.8
* Requires PHP: 7.4
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: blockroll
*
* @package Blockroll
*/
namespace Blockroll;
defined( 'ABSPATH' ) || exit;
define( 'BLOCKROLL_PLUGIN_FILE', __FILE__ );
\spl_autoload_register(
function ( $class ) {
if ( 0 !== \strpos( $class, 'Blockroll\\' ) ) {
return;
}
$parts = \explode( '\\', \strtolower( \str_replace( array( 'Blockroll\\', '_' ), array( '', '-' ), $class ) ) );
$name = \array_pop( $parts );
$path = __DIR__ . '/includes/' . ( $parts ? \implode( '/', $parts ) . '/' : '' );
foreach ( array( 'class-', 'trait-' ) as $prefix ) {
if ( \file_exists( $path . $prefix . $name . '.php' ) ) {
require $path . $prefix . $name . '.php';
return;
}
}
}
);
/**
* Initialize the plugin.
*/
function init() {
Index::register();
Anchors::register();
Opml::register();
Xfn::register();
// The blogroll renders its list itself, from the attributes of its link
// blocks; the link blocks have no output, so core need not render them.
\register_block_type( __DIR__ . '/build/blogroll', array( 'skip_inner_blocks' => true ) );
\register_block_type( __DIR__ . '/build/link' );
}
\add_action( 'init', __NAMESPACE__ . '\init' );
/**
* Add the rewrite rules and flush them.
*
* On activation the plugin was not loaded when `init` ran, so the rules
* have to be added before flushing.
*/
function activate() {
Opml::add_rewrite_rules();
\flush_rewrite_rules();
}
\register_activation_hook( __FILE__, __NAMESPACE__ . '\activate' );
\register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
\add_filter(
'query_vars',
function ( $vars ) {
// Frontend sorting and paging of the blogroll block.
$vars[] = 'blockroll-sort';
$vars[] = 'blockroll-page';
// OPML output. A query var rather than a rewrite endpoint: no rewrite
// flush, and when the plugin is disabled the URL falls back to the
// page itself instead of a 404. Only the well-known URL, which has
// no page behind it, gets a rewrite rule of its own.
$vars[] = Opml::QUERY_VAR;
// One blogroll of a page, picked by its HTML anchor.
$vars[] = Opml::GROUP;
return $vars;
}
);
\add_action(
'rest_api_init',
function () {
( new Rest\Discovery_Controller() )->register_routes();
( new Rest\Import_Controller() )->register_routes();
( new Rest\Sources_Controller() )->register_routes();
}
);