PluginProbe
Webmention / 3.2.0
Webmention v3.2.0
5.9.1 5.9.0 5.8.1 trunk 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.2.0 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.5.0 2.6.0 2.6.1 3.0.0 3.0.1 3.1.0 3.1.1 3.2.0 All 83 releases
webmention / webmention.php

webmention.php in Webmention 3.2.0, at webmention.php

145 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Webmention
4 * Plugin URI: https://github.com/pfefferle/wordpress-webmention
5 * Description: Webmention support for WordPress posts
6 * Author: Matthias Pfefferle
7 * Author URI: https://notiz.blog/
8 * Version: 3.2.0
9 * License: MIT
10 * License URI: http://opensource.org/licenses/MIT
11 * Text Domain: webmention
12 * Domain Path: /languages
13 */
14
15 defined( 'WEBMENTION_COMMENT_APPROVE' ) || define( 'WEBMENTION_COMMENT_APPROVE', 0 );
16 defined( 'WEBMENTION_COMMENT_TYPE' ) || define( 'WEBMENTION_COMMENT_TYPE', 'webmention' );
17
18 define( 'WEBMENTION_PROCESS_TYPE_ASYNC', 'async' );
19 define( 'WEBMENTION_PROCESS_TYPE_SYNC', 'sync' );
20
21 defined( 'WEBMENTION_PROCESS_TYPE' ) || define( 'WEBMENTION_PROCESS_TYPE', WEBMENTION_PROCESS_TYPE_SYNC );
22
23 add_action( 'plugins_loaded', array( 'Webmention_Plugin', 'init' ) );
24
25 /**
26 * Webmention Plugin Class
27 *
28 * @author Matthias Pfefferle
29 */
30 class Webmention_Plugin {
31
32 /**
33 * Initialize Webmention Plugin
34 */
35 public static function init() {
36 // Add a new feature type to posts for webmentions
37 add_post_type_support( 'post', 'webmentions' );
38 if ( 1 == get_option( 'webmention_support_pages' ) ) {
39 add_post_type_support( 'page', 'webmentions' );
40 }
41 if ( WP_DEBUG ) {
42 require_once( dirname( __FILE__ ) . '/includes/debug.php' );
43 }
44
45 // will be removed in one of the following major releases
46 require_once( dirname( __FILE__ ) . '/includes/deprecations.php' );
47
48 // list of various public helper functions
49 require_once( dirname( __FILE__ ) . '/includes/functions.php' );
50
51 // initialize Webmention Sender
52 require_once( dirname( __FILE__ ) . '/includes/class-webmention-sender.php' );
53 add_action( 'init', array( 'Webmention_Sender', 'init' ) );
54
55 // initialize Webmention Receiver
56 require_once( dirname( __FILE__ ) . '/includes/class-webmention-receiver.php' );
57 add_action( 'init', array( 'Webmention_Receiver', 'init' ) );
58
59 // Default Comment Status
60 add_filter( 'get_default_comment_status', array( 'Webmention_Plugin', 'get_default_comment_status' ), 11, 3 );
61
62 // initialize admin settings
63 add_action( 'admin_init', array( 'Webmention_Plugin', 'admin_register_settings' ) );
64
65 add_action( 'admin_comment_types_dropdown', array( 'Webmention_Plugin', 'comment_types_dropdown' ) );
66 add_action( 'comment_form_after', array( 'Webmention_Plugin', 'comment_form' ), 11 );
67 }
68
69 public static function get_default_comment_status( $status, $post_type, $comment_type ) {
70 if ( 'webmention' === $comment_type ) {
71 return post_type_supports( $post_type, 'webmentions' ) ? 'open' : 'closed' ;
72 }
73 // Since support for the pingback comment type is used to keep pings open...
74 if ( ( 'pingback' === $comment_type ) ) {
75 return ( post_type_supports( $post_type, 'webmentions' ) ? 'open' : $status );
76 }
77
78 return $status;
79 }
80
81 /**
82 * Register Webmention admin settings.
83 */
84 public static function admin_register_settings() {
85 register_setting( 'discussion', 'webmention_disable_selfpings_same_url', array(
86 'type' => 'boolean',
87 'description' => __( 'Disable Self Webmentions on the Same URL', 'webmention' ),
88 'show_in_rest' => true,
89 'default' => 1,
90 ) );
91 register_setting( 'discussion', 'webmention_disable_selfpings_same_domain', array(
92 'type' => 'boolean',
93 'description' => __( 'Disable Self Webmentions on the Same Domain', 'webmention' ),
94 'show_in_rest' => true,
95 'default' => 0,
96 ) );
97 register_setting( 'discussion', 'webmention_support_pages', array(
98 'type' => 'boolean',
99 'description' => __( 'Enable Webmention Support for Pages', 'webmention' ),
100 'show_in_rest' => true,
101 'default' => 1,
102 ) );
103 register_setting( 'discussion', 'webmention_show_comment_form', array(
104 'type' => 'boolean',
105 'description' => __( 'Show Webmention Comment Form', 'webmention' ),
106 'show_in_rest' => true,
107 'default' => 1,
108 ) );
109
110 add_settings_field( 'webmention_discussion_settings', __( 'Webmention Settings', 'webmention' ), array( 'Webmention_Plugin', 'discussion_settings' ), 'discussion', 'default' );
111 }
112
113 /**
114 * Add Webmention options to the WordPress discussion settings page.
115 */
116 public static function discussion_settings() {
117 load_template( plugin_dir_path( __FILE__ ) . 'templates/webmention-discussion-settings.php' );
118 }
119
120 /**
121 * render the comment form
122 */
123 public static function comment_form() {
124 $template = apply_filters( 'webmention_comment_form', plugin_dir_path( __FILE__ ) . 'templates/webmention-comment-form.php' );
125
126 if ( 1 == get_option( 'webmention_show_comment_form' ) ) {
127 load_template( $template );
128 }
129 }
130
131 /**
132 * Extend the "filter by comment type" of in the comments section
133 * of the admin interface with "webmention"
134 *
135 * @param array $types the different comment types
136 *
137 * @return array the filtert comment types
138 */
139 public static function comment_types_dropdown( $types ) {
140 $types['webmention'] = __( 'Webmentions', 'webmention' );
141
142 return $types;
143 }
144 }
145