Last active
October 22, 2019 12:05
-
-
Save bhwebworks/11384243 to your computer and use it in GitHub Desktop.
Prevent unwanted results from appearing in (future) Stream records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Prevent unwanted results from appearing in (future) Stream records - v 1.x | |
add_filter( 'wp_stream_record_array', 'bhww_core_wp_stream_filter_record_array', 10, 1 ); | |
function bhww_core_wp_stream_filter_record_array( $recordarr ) { | |
// BackupBuddy (iThemes) entries | |
$context = 'settings'; | |
$option = 'ithemes-updater-cache'; | |
if ( isset( $recordarr['contexts'][ $context ] ) && $option == $recordarr['meta']['option'] ) { | |
$recordarr = array(); | |
} | |
// WP Help entries | |
$context = 'wp-help'; | |
$singular_name = 'help document'; | |
if ( isset( $recordarr['contexts'][ $context ] ) && $singular_name == $recordarr['meta']['singular_name'] ) { | |
$recordarr = array(); | |
} | |
return $recordarr; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Prevent unwanted results from appearing in (future) Stream records - v 2.x | |
add_filter( 'wp_stream_record_array', 'bhww_core_wp_stream_filter_record_array', 10, 1 ); | |
function bhww_core_wp_stream_filter_record_array( $recordarr ) { | |
if ( ! isset( $recordarr[0] ) ) | |
return array(); | |
// BackupBuddy (iThemes) entries | |
if ( 'settings' === $recordarr[0]['connector'] && isset( $recordarr[0]['stream_meta']['option'] ) && 'ithemes-updater-cache' === $recordarr[0]['stream_meta']['option'] ) | |
return array(); | |
// WP Help entries | |
if ( 'wp-help' === $recordarr[0]['context'] && isset( $recordarr[0]['stream_meta']['singular_name'] ) && 'help document' == $recordarr[0]['stream_meta']['singular_name'] ) | |
return array(); | |
// All other entries | |
return $recordarr; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Prevent unwanted results from appearing in (future) Stream records - v 3.x | |
add_filter( 'wp_stream_record_array', 'bhww_core_wp_stream_filter_record_array', 10, 1 ); | |
function bhww_core_wp_stream_filter_record_array( $recordarr ) { | |
if ( ! isset( $recordarr ) ) | |
return array(); | |
// BackupBuddy (iThemes) entries | |
if ( 'settings' === $recordarr['connector'] && isset( $recordarr['meta']['option'] ) && 'ithemes-updater-cache' === $recordarr['meta']['option'] ) | |
return array(); | |
if ( 'settings' === $recordarr['connector'] && isset( $recordarr['meta']['option'] ) && 'pb_backupbuddy_notifications' === $recordarr['meta']['option'] ) | |
return array(); | |
// Jetpack Protect entries | |
if ( 'jetpack' === $recordarr['connector'] && isset( $recordarr['meta']['option'] ) && 'jetpack_protect_blocked_attempts' === $recordarr['meta']['option'] ) | |
return array(); | |
// WP Help entries | |
if ( 'wp-help' === $recordarr['context'] && isset( $recordarr['meta']['singular_name'] ) && 'help document' == $recordarr['meta']['singular_name'] ) | |
return array(); | |
// All other entries | |
return $recordarr; | |
} |
Actually I just tested that file_put_contents approach and it works great.
Thank you! Using that info I solved it. Just had to change the match to a bit more fuzzy. The WP Rocket and Imagify ones append those keys to the end of their 'option', so they are all unique. But they all start with the same code:
// imagify
if ( 'settings' === $data_array['connector'] && isset( $data_array['meta']['option'] ) && strpos($data_array['meta']['option'], 'imagify_optimize_media_batch') !== false )
return array();
// WP Rocket
if ( 'settings' === $data_array['connector'] && isset( $data_array['meta']['option'] ) && strpos($data_array['meta']['option'], 'rocket_preload_batch') !== false )
return array();
You're welcome!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@greggh,
Do you have access to your database? That code basically reflects entries in the stream and stream_meta database tables.
'settings' === $recordarr['connector']
would be a more generic entry from the stream table, and, for example,
isset( $recordarr['meta']['option'] ) && 'jetpack_protect_blocked_attempts' === $recordarr['meta']['option']
would be a Jetpack related entry in the stream_meta table.
This didn't occur to me four years ago when I was working on this, but you could use file_put_contents in that filter callback function to write the Stream arrays into a log file so you can see better how to write your exclusion code. Something like this (untested) would work, I believe:
file_put_contents( dirname(__FILE__) . '/array-log.txt', print_r( $recordarr, true ), FILE_APPEND );