Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an mu-plugin for tweaking the Stream plugin to meet our needs #172

Merged
merged 2 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mu-plugins/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
require_once __DIR__ . '/blocks/global-header-footer/blocks.php';
require_once __DIR__ . '/global-fonts/index.php';
require_once __DIR__ . '/skip-to/skip-to.php';
require_once __DIR__ . '/stream-tweaks/index.php';
22 changes: 22 additions & 0 deletions mu-plugins/stream-tweaks/class-connector-posts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Connector for Posts
*
* This is a hotfix for the Stream plugin to enable logging post changes that happen through an API context (i.e.
* in the block editor). This change has been merged in the GitHub repo for the Stream plugin, but as of version
* 3.8.2 it has not been released to the plugin directory.
*/

namespace WordPressdotorg\MU_Plugins\Stream_Tweaks;

/**
* Class - Connector_Posts
*/
class Connector_Posts extends \WP_Stream\Connector_Posts {
/**
* Register connector in the WP Frontend
*
* @var bool
*/
public $register_frontend = true;
}
34 changes: 34 additions & 0 deletions mu-plugins/stream-tweaks/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace WordPressdotorg\MU_Plugins\Stream_Tweaks;

add_filter( 'wp_stream_connectors', __NAMESPACE__ . '\replace_posts_connector' );

/**
* Substitute Stream's posts connector class for our modified version.
*
* @param array $connector_classes
*
* @return mixed
*/
function replace_posts_connector( $connector_classes ) {
if ( ! function_exists( 'wp_stream_get_instance' ) ) {
return $connector_classes;
}

require_once __DIR__ . '/class-connector-posts.php';

$stream_plugin_instance = wp_stream_get_instance();
$new_posts_connector = new Connector_Posts( $stream_plugin_instance->log ); // WordPressdotorg namespaced version.

// Remove the default posts connector class if it has been initialized.
if ( isset( $connector_classes[ $new_posts_connector->name ] ) ) {
unset( $connector_classes[ $new_posts_connector->name ] );
}

if ( $new_posts_connector->is_dependency_satisfied() ) {
$connector_classes[ $new_posts_connector->name ] = $new_posts_connector;
}

return $connector_classes;
}