forked from pfefferle/wordpress-webmention
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebmention.php
executable file
·200 lines (165 loc) · 6.19 KB
/
webmention.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/**
* Plugin Name: Webmention
* Plugin URI: https://github.com/pfefferle/wordpress-webmention
* Description: Webmention support for WordPress posts
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* Version: 4.0.8
* License: MIT
* License URI: https://opensource.org/licenses/MIT
* Text Domain: webmention
* Domain Path: /languages
*/
defined( 'WEBMENTION_ALWAYS_SHOW_HEADERS' ) || define( 'WEBMENTION_ALWAYS_SHOW_HEADERS', 0 );
defined( 'WEBMENTION_COMMENT_APPROVE' ) || define( 'WEBMENTION_COMMENT_APPROVE', 0 );
defined( 'WEBMENTION_COMMENT_TYPE' ) || define( 'WEBMENTION_COMMENT_TYPE', 'webmention' );
defined( 'WEBMENTION_GRAVATAR_CACHE_TIME' ) || define( 'WEBMENTION_GRAVATAR_CACHE_TIME', WEEK_IN_SECONDS );
define( 'WEBMENTION_PROCESS_TYPE_ASYNC', 'async' );
define( 'WEBMENTION_PROCESS_TYPE_SYNC', 'sync' );
defined( 'WEBMENTION_PROCESS_TYPE' ) || define( 'WEBMENTION_PROCESS_TYPE', WEBMENTION_PROCESS_TYPE_SYNC );
defined( 'WEBMENTION_VOUCH' ) || define( 'WEBMENTION_VOUCH', false );
// initialize admin settings.
require_once dirname( __FILE__ ) . '/includes/class-webmention-admin.php';
add_action( 'admin_init', array( 'Webmention_Admin', 'init' ) );
add_action( 'admin_menu', array( 'Webmention_Admin', 'admin_menu' ) );
/**
* Initialize Webmention Plugin
*/
function webmention_init() {
// Add support for webmentions to custom post types.
$post_types = get_option( 'webmention_support_post_types', array( 'post', 'page' ) ) ? get_option( 'webmention_support_post_types', array( 'post', 'page' ) ) : array();
foreach ( $post_types as $post_type ) {
add_post_type_support( $post_type, 'webmentions' );
}
if ( WP_DEBUG ) {
require_once dirname( __FILE__ ) . '/includes/debug.php';
}
// Request Handler.
require_once dirname( __FILE__ ) . '/includes/class-webmention-request.php';
// Comment Type Class
require_once dirname( __FILE__ ) . '/includes/class-webmention-comment-type.php';
// list of various public helper functions.
require_once dirname( __FILE__ ) . '/includes/functions.php';
// load local avatar support.
require_once dirname( __FILE__ ) . '/includes/class-webmention-avatar-handler.php';
add_action( 'init', array( 'Webmention_Avatar_Handler', 'init' ) );
// load HTTP 410 support.
require_once dirname( __FILE__ ) . '/includes/class-webmention-410.php';
add_action( 'init', array( 'Webmention_410', 'init' ) );
// initialize Webmention Sender.
require_once dirname( __FILE__ ) . '/includes/class-webmention-sender.php';
add_action( 'init', array( 'Webmention_Sender', 'init' ) );
// initialize Webmention Receiver.
require_once dirname( __FILE__ ) . '/includes/class-webmention-receiver.php';
add_action( 'init', array( 'Webmention_Receiver', 'init' ) );
// initialize Webmention Notifications
//require_once dirname( __FILE__ ) . '/includes/class-webmention-notifications.php';
//add_action( 'init', array( 'Webmention_Notifications', 'init' ) );
// initialize Webmention Vouch
if ( WEBMENTION_VOUCH ) {
require_once dirname( __FILE__ ) . '/includes/class-webmention-vouch.php';
add_action( 'init', array( 'Webmention_Vouch', 'init' ) );
}
// Default Comment Status.
add_filter( 'get_default_comment_status', 'webmention_get_default_comment_status', 11, 3 );
add_filter( 'pings_open', 'webmention_pings_open', 10, 2 );
// Load language files.
webmention_plugin_textdomain();
add_action( 'comment_form_after', 'webmention_comment_form', 11 );
add_action( 'comment_form_comments_closed', 'webmention_comment_form' );
add_filter( 'nodeinfo_data', 'webmention_nodeinfo', 10, 2 );
add_filter( 'nodeinfo2_data', 'webmention_nodeinfo2', 10 );
// remove old Webmention code.
remove_action( 'init', array( 'WebMentionFormPlugin', 'init' ) );
remove_action( 'init', array( 'WebMentionForCommentsPlugin', 'init' ) );
}
add_action( 'plugins_loaded', 'webmention_init' );
/**
* Retrieve the default comment status for a given post type.
*
* @since 3.8.9
*
* @param string $status Default status for the given post type,
* either 'open' or 'closed'.
* @param string $post_type Post type to check.
* @param string $comment_type Type of comment. Default is `comment`.
*
* @return string
*/
function webmention_get_default_comment_status( $status, $post_type, $comment_type ) {
if ( 'webmention' === $comment_type ) {
return post_type_supports( $post_type, 'webmentions' ) ? 'open' : 'closed';
}
// Since support for the pingback comment type is used to keep pings open...
if ( ( 'pingback' === $comment_type ) ) {
return ( post_type_supports( $post_type, 'webmentions' ) ? 'open' : $status );
}
return $status;
}
/**
* Render the webmention comment form.
*
* Can be filtered to load a custom template of your choosing.
*
* @since 3.8.9
*/
function webmention_comment_form() {
$template = apply_filters( 'webmention_comment_form', plugin_dir_path( __FILE__ ) . 'templates/webmention-comment-form.php' );
if ( ( 1 === (int) get_option( 'webmention_show_comment_form', 1 ) ) && pings_open() ) {
load_template( $template );
}
}
/**
* Return enabled status of Homepage Webmentions.
*
* @since 3.8.9
*
* @param bool $open Whether the current post is open for pings.
* @param int $post_id The post ID.
* @return boolean if pings are open
*/
function webmention_pings_open( $open, $post_id ) {
if ( get_option( 'webmention_home_mentions' ) === $post_id ) {
return true;
}
return $open;
}
/**
* Load language files.
*
* @since 3.8.9
*/
function webmention_plugin_textdomain() {
load_plugin_textdomain( 'webmention', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Extend NodeInfo data.
*
* @since 3.8.9
*
* @param array $nodeinfo NodeInfo data.
* @param array $version Updated data.
* @return array
*/
function webmention_nodeinfo( $nodeinfo, $version ) {
if ( '2.0' === $version ) {
$nodeinfo['protocols'][] = 'webmention';
} else {
$nodeinfo['protocols']['inbound'][] = 'webmention';
$nodeinfo['protocols']['outbound'][] = 'webmention';
}
return $nodeinfo;
}
/**
* Extend NodeInfo2 data.
*
* @since 3.8.9
*
* @param array $nodeinfo NodeInfo2 data.
* @return array
*/
function webmention_nodeinfo2( $nodeinfo ) {
$nodeinfo['protocols'][] = 'webmention';
return $nodeinfo;
}