| @@ -1,43 +1,33 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Load the ActivityPub integrations. |
| 4 | - * | |
| 5 | - * @package Activitypub | |
| 6 | 4 | */ |
| 7 | 5 | |
| 8 | 6 | namespace Activitypub\Integration; |
| 9 | 7 | |
| 10 | -use function Activitypub\site_supports_blocks; | |
| 11 | - | |
| 12 | -\Activitypub\Autoloader::register_path( __NAMESPACE__, __DIR__ ); | |
| 13 | - | |
| 14 | -/** | |
| 15 | - * Initialize the ActivityPub integrations. | |
| 16 | - */ | |
| 17 | 8 | function plugin_init() { |
| 18 | 9 | /** |
| 19 | - * Adds Akismet support. | |
| 10 | + * Adds WebFinger (plugin) support. | |
| 20 | 11 | * |
| 21 | - * This class handles the compatibility with the Akismet plugin. | |
| 12 | + * This class handles the compatibility with the WebFinger plugin | |
| 13 | + * and coordinates the internal WebFinger implementation. | |
| 22 | 14 | * |
| 23 | - * @see https://wordpress.org/plugins/akismet/ | |
| 15 | + * @see https://wordpress.org/plugins/webfinger/ | |
| 24 | 16 | */ |
| 25 | - if ( \defined( 'AKISMET_VERSION' ) ) { | |
| 26 | - Akismet::init(); | |
| 27 | - } | |
| 17 | + require_once __DIR__ . '/class-webfinger.php'; | |
| 18 | + Webfinger::init(); | |
| 28 | 19 | |
| 29 | 20 | /** |
| 30 | - * Adds Classic Editor support. | |
| 21 | + * Adds NodeInfo (plugin) support. | |
| 31 | 22 | * |
| 32 | - * This class handles the compatibility with the Classic Editor plugin | |
| 33 | - * and sites without block editor support. | |
| 23 | + * This class handles the compatibility with the NodeInfo plugin | |
| 24 | + * and coordinates the internal NodeInfo implementation. | |
| 34 | 25 | * |
| 35 | - * @see https://wordpress.org/plugins/classic-editor/ | |
| 26 | + * @see https://wordpress.org/plugins/nodeinfo/ | |
| 36 | 27 | */ |
| 37 | - if ( \class_exists( '\Classic_Editor' ) || \function_exists( 'classicpress_version' ) || ! site_supports_blocks() ) { | |
| 38 | - Classic_Editor::init(); | |
| 39 | - } | |
| 28 | + require_once __DIR__ . '/class-nodeinfo.php'; | |
| 29 | + Nodeinfo::init(); | |
| 40 | 30 | |
| 41 | 31 | /** |
| 42 | 32 | * Adds Enable Mastodon Apps support. |
| 43 | 33 | * |
| @@ -44,54 +34,12 @@ | ||
| 44 | 34 | * This class handles the compatibility with the Enable Mastodon Apps plugin. |
| 45 | 35 | * |
| 46 | 36 | * @see https://wordpress.org/plugins/enable-mastodon-apps/ |
| 47 | 37 | */ |
| 48 | - if ( \defined( 'ENABLE_MASTODON_APPS_VERSION' ) ) { | |
| 49 | - Enable_Mastodon_Apps::init(); | |
| 50 | - } | |
| 38 | + require_once __DIR__ . '/class-enable-mastodon-apps.php'; | |
| 39 | + Enable_Mastodon_Apps::init(); | |
| 51 | 40 | |
| 52 | 41 | /** |
| 53 | - * Adds Jetpack support. | |
| 54 | - * | |
| 55 | - * This class handles the compatibility with Jetpack. | |
| 56 | - * | |
| 57 | - * @see https://jetpack.com/ | |
| 58 | - */ | |
| 59 | - if ( \defined( 'JETPACK__VERSION' ) ) { | |
| 60 | - Jetpack::init(); | |
| 61 | - } | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * Adds LiteSpeed Cache support. | |
| 65 | - * | |
| 66 | - * The check for whether LiteSpeed Cache is loaded and initialized happens inside Litespeed_Cache::init(). | |
| 67 | - * | |
| 68 | - * @see https://wordpress.org/plugins/litespeed-cache/ | |
| 69 | - */ | |
| 70 | - Litespeed_Cache::init(); | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * Adds Multisite Language Switcher support. | |
| 74 | - * | |
| 75 | - * This class handles the compatibility with the Multisite Language Switcher plugin. | |
| 76 | - * | |
| 77 | - * @see https://wordpress.org/plugins/multisite-language-switcher/ | |
| 78 | - */ | |
| 79 | - if ( \defined( 'MSLS_PLUGIN_VERSION' ) ) { | |
| 80 | - Multisite_Language_Switcher::init(); | |
| 81 | - } | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * Adds NodeInfo (plugin) support. | |
| 85 | - * | |
| 86 | - * This class handles the compatibility with the NodeInfo plugin | |
| 87 | - * and coordinates the internal NodeInfo implementation. | |
| 88 | - * | |
| 89 | - * @see https://wordpress.org/plugins/nodeinfo/ | |
| 90 | - */ | |
| 91 | - Nodeinfo::init(); | |
| 92 | - | |
| 93 | - /** | |
| 94 | 42 | * Adds OpenGraph support. |
| 95 | 43 | * |
| 96 | 44 | * This class handles the compatibility with the OpenGraph plugin. |
| 97 | 45 | * |
| @@ -97,37 +45,22 @@ | ||
| 97 | 45 | * |
| 98 | 46 | * @see https://wordpress.org/plugins/opengraph/ |
| 99 | 47 | */ |
| 100 | 48 | if ( '1' === \get_option( 'activitypub_use_opengraph', '1' ) ) { |
| 49 | + require_once __DIR__ . '/class-opengraph.php'; | |
| 101 | 50 | Opengraph::init(); |
| 102 | 51 | } |
| 103 | 52 | |
| 104 | 53 | /** |
| 105 | - * Adds Podlove Podcast Publisher support. | |
| 54 | + * Adds Jetpack support. | |
| 106 | 55 | * |
| 107 | - * This class handles the compatibility with Podlove Podcast Publisher. | |
| 56 | + * This class handles the compatibility with Jetpack. | |
| 108 | 57 | * |
| 109 | - * @see https://wordpress.org/plugins/podlove-podcasting-plugin-for-wordpress/ | |
| 58 | + * @see https://jetpack.com/ | |
| 110 | 59 | */ |
| 111 | - if ( \defined( 'Podlove\PLUGIN_FILE' ) ) { | |
| 112 | - // Enable ActivityPub support for the podcast post type. | |
| 113 | - \add_post_type_support( 'podcast', 'activitypub' ); | |
| 114 | - | |
| 115 | - \add_filter( | |
| 116 | - 'activitypub_transformer', | |
| 117 | - static function ( $transformer, $data, $object_class ) { | |
| 118 | - if ( | |
| 119 | - 'WP_Post' === $object_class && | |
| 120 | - 'podcast' === $data->post_type && | |
| 121 | - \Podlove\Model\Episode::find_one_by_post_id( $data->ID ) | |
| 122 | - ) { | |
| 123 | - return new Podlove_Podcast_Publisher( $data ); | |
| 124 | - } | |
| 125 | - return $transformer; | |
| 126 | - }, | |
| 127 | - 10, | |
| 128 | - 3 | |
| 129 | - ); | |
| 60 | + if ( \defined( 'JETPACK__VERSION' ) && ! \defined( 'IS_WPCOM' ) ) { | |
| 61 | + require_once __DIR__ . '/class-jetpack.php'; | |
| 62 | + Jetpack::init(); | |
| 130 | 63 | } |
| 131 | 64 | |
| 132 | 65 | /** |
| 133 | 66 | * Adds Seriously Simple Podcasting support. |
| @@ -138,14 +71,16 @@ | ||
| 138 | 71 | */ |
| 139 | 72 | if ( \defined( 'SSP_VERSION' ) ) { |
| 140 | 73 | add_filter( |
| 141 | 74 | 'activitypub_transformer', |
| 142 | - static function ( $transformer, $data, $object_class ) { | |
| 75 | + // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound | |
| 76 | + function( $transformer, $object, $object_class ) { | |
| 143 | 77 | if ( |
| 144 | 78 | 'WP_Post' === $object_class && |
| 145 | - \get_post_meta( $data->ID, 'audio_file', true ) | |
| 79 | + \get_post_meta( $object->ID, 'audio_file', true ) | |
| 146 | 80 | ) { |
| 147 | - return new Seriously_Simple_Podcasting( $data ); | |
| 81 | + require_once __DIR__ . '/class-seriously-simple-podcasting.php'; | |
| 82 | + return new Seriously_Simple_Podcasting( $object ); | |
| 148 | 83 | } |
| 149 | 84 | return $transformer; |
| 150 | 85 | }, |
| 151 | 86 | 10, |
| @@ -151,80 +86,53 @@ | ||
| 151 | 86 | 10, |
| 152 | 87 | 3 |
| 153 | 88 | ); |
| 154 | 89 | } |
| 90 | +} | |
| 91 | +\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' ); | |
| 155 | 92 | |
| 156 | - /** | |
| 157 | - * Adds Stream support. | |
| 158 | - * | |
| 159 | - * This class handles the compatibility with the Stream plugin. | |
| 160 | - * | |
| 161 | - * @see https://wordpress.org/plugins/stream/ | |
| 162 | - */ | |
| 163 | - Stream\Stream::init(); | |
| 93 | +/** | |
| 94 | + * Register the Stream Connector for ActivityPub. | |
| 95 | + * | |
| 96 | + * @param array $classes The Stream connectors. | |
| 97 | + * | |
| 98 | + * @return array The Stream connectors with the ActivityPub connector. | |
| 99 | + */ | |
| 100 | +function register_stream_connector( $classes ) { | |
| 101 | + require plugin_dir_path( __FILE__ ) . '/class-stream-connector.php'; | |
| 164 | 102 | |
| 165 | - /** | |
| 166 | - * Adds Surge support. | |
| 167 | - * | |
| 168 | - * Only load code that needs Surge to run once Surge is loaded and initialized. | |
| 169 | - * | |
| 170 | - * @see https://wordpress.org/plugins/surge/ | |
| 171 | - */ | |
| 172 | - Surge::init(); | |
| 103 | + $class_name = '\Activitypub\Integration\Stream_Connector'; | |
| 173 | 104 | |
| 174 | - /** | |
| 175 | - * Adds WebFinger (plugin) support. | |
| 176 | - * | |
| 177 | - * This class handles the compatibility with the WebFinger plugin | |
| 178 | - * and coordinates the internal WebFinger implementation. | |
| 179 | - * | |
| 180 | - * @see https://wordpress.org/plugins/webfinger/ | |
| 181 | - */ | |
| 182 | - Webfinger::init(); | |
| 105 | + if ( ! class_exists( $class_name ) ) { | |
| 106 | + return; | |
| 107 | + } | |
| 183 | 108 | |
| 184 | - /** | |
| 185 | - * Adds WP REST Cache support. | |
| 186 | - * | |
| 187 | - * This class handles the compatibility with the WP REST Cache plugin. | |
| 188 | - * | |
| 189 | - * @see https://wordpress.org/plugins/wp-rest-cache/ | |
| 190 | - */ | |
| 191 | - if ( \class_exists( 'WP_Rest_Cache_Plugin\Includes\Plugin' ) ) { | |
| 192 | - WP_Rest_Cache::init(); | |
| 109 | + wp_stream_get_instance(); | |
| 110 | + $class = new $class_name(); | |
| 111 | + | |
| 112 | + if ( ! method_exists( $class, 'is_dependency_satisfied' ) ) { | |
| 113 | + return; | |
| 193 | 114 | } |
| 194 | 115 | |
| 195 | - /** | |
| 196 | - * Adds WPML Multilingual CMS (plugin) support. | |
| 197 | - * | |
| 198 | - * This class handles the compatibility with the WPML plugin. | |
| 199 | - * | |
| 200 | - * @see https://wpml.org/ | |
| 201 | - */ | |
| 202 | - if ( \defined( 'ICL_SITEPRESS_VERSION' ) ) { | |
| 203 | - WPML::init(); | |
| 116 | + if ( $class->is_dependency_satisfied() ) { | |
| 117 | + $classes[] = $class; | |
| 204 | 118 | } |
| 205 | 119 | |
| 206 | - /** | |
| 207 | - * Adds Yoast SEO support. | |
| 208 | - * | |
| 209 | - * This class handles the compatibility with Yoast SEO. | |
| 210 | - * | |
| 211 | - * @see https://wordpress.org/plugins/wordpress-seo/ | |
| 212 | - */ | |
| 213 | - if ( \defined( 'WPSEO_VERSION' ) ) { | |
| 214 | - Yoast_Seo::init(); | |
| 215 | - } | |
| 120 | + return $classes; | |
| 216 | 121 | } |
| 217 | -\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' ); | |
| 122 | +add_filter( 'wp_stream_connectors', __NAMESPACE__ . '\register_stream_connector' ); | |
| 218 | 123 | |
| 219 | -// Register activation and deactivation hooks for Surge integration. | |
| 220 | -\register_activation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\Surge', 'add_cache_config' ) ); | |
| 221 | -\register_deactivation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\Surge', 'remove_cache_config' ) ); | |
| 124 | +// Excluded ActivityPub post types from the Stream. | |
| 125 | +add_filter( | |
| 126 | + 'wp_stream_posts_exclude_post_types', | |
| 127 | + function( $post_types ) { | |
| 128 | + $post_types[] = 'ap_follower'; | |
| 129 | + $post_types[] = 'ap_extrafield'; | |
| 130 | + $post_types[] = 'ap_extrafield_blog'; | |
| 131 | + return $post_types; | |
| 132 | + } | |
| 133 | +); | |
| 222 | 134 | |
| 223 | -// Register activation and deactivation hooks for LiteSpeed Cache integration. | |
| 224 | -\register_activation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\LiteSpeed_Cache', 'add_htaccess_rules' ) ); | |
| 225 | -\register_deactivation_hook( ACTIVITYPUB_PLUGIN_FILE, array( __NAMESPACE__ . '\LiteSpeed_Cache', 'remove_htaccess_rules' ) ); | |
| 226 | - | |
| 227 | 135 | /** |
| 228 | 136 | * Load the BuddyPress integration. |
| 229 | 137 | * |
| 230 | 138 | * Only load code that needs BuddyPress to run once BP is loaded and initialized. |
| @@ -230,5 +138,12 @@ | ||
| 230 | 138 | * Only load code that needs BuddyPress to run once BP is loaded and initialized. |
| 231 | 139 | * |
| 232 | 140 | * @see https://buddypress.org/ |
| 233 | 141 | */ |
| 234 | -\add_action( 'bp_include', array( __NAMESPACE__ . '\Buddypress', 'init' ), 0 ); | |
| 142 | +add_action( | |
| 143 | + 'bp_include', | |
| 144 | + function () { | |
| 145 | + require_once __DIR__ . '/class-buddypress.php'; | |
| 146 | + Buddypress::init(); | |
| 147 | + }, | |
| 148 | + 0 | |
| 149 | +); | |