Last active
September 29, 2022 14:24
-
-
Save lelandf/a05391f193bc0dbc35207567273c1d32 to your computer and use it in GitHub Desktop.
[TEC] Replace plugin icon image on /wp-admin/update-core.php
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 | |
add_action( 'admin_print_footer_scripts-update-core.php', function() { | |
?> | |
<script> | |
( () => { | |
// saving this plugin row class because we'll be using it in multiple places | |
const ROW_CLASS = 'plugin-title'; | |
// collecting names of all plugins with updates available | |
const plugins = document.querySelectorAll( `.${ ROW_CLASS } strong` ); | |
// if no updates available, then we stop here | |
if ( ! plugins ) { | |
return; | |
} | |
// plugins have updates available, prepare for TEC | |
const PLUGINS_URL = <?php echo wp_json_encode( plugins_url() ); ?>; | |
const IMAGE_PATH = 'the-events-calendar/common/src/resources/images/logo/the-events-calendar.svg'; | |
// Replace the image, only invoked if seeker found a match | |
const replacer = plugin => { | |
const row = plugin.closest( `.${ ROW_CLASS }` ); | |
const img = row.querySelector( 'img' ); | |
img.setAttribute( 'src', `${ PLUGINS_URL }/${ IMAGE_PATH }` ); | |
}; | |
// Seeking function that seeks out "The Events Calendar" | |
const seeker = plugin => { | |
const { innerText: text } = plugin; | |
if ( 'The Events Calendar' === text ) { | |
replacer( plugin ); | |
} | |
}; | |
// Call the seeker function on each plugin | |
plugins.forEach( seeker ); | |
} )(); | |
</script> | |
<?php | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment