Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am kwcjr on github.
* I am kwcjr (https://keybase.io/kwcjr) on keybase.
* I have a public key whose fingerprint is B2ED 100D 4C1F 4EDF 6E4F 461C 4E1A CB3A 3C62 3911
To claim this, I am signing this object:
@kwcjr
kwcjr / Remote WP Admin Notice
Created October 17, 2021 02:56
This gist will create a persistent WP admin notice.
add_filter( 'admin_notices', 'my_remote_admin_notice' );
add_filter( 'network_admin_notices', 'my_remote_admin_notice' );
function my_remote_admin_notice() {
$notice_url = 'INSERT_URL_HERE';
$message = json_decode( wp_remote_retrieve_body( wp_remote_get( $notice_url ) ), true)['content']['rendered'];
if( is_wp_error( $message ) ) {
return false;
@kwcjr
kwcjr / gist:01f3ba3c187bb112cb5ef30282688613
Created October 17, 2021 10:12
Woocommerce admin notices
function my_woocommerce_admin_notices()
{
// Test to see if WooCommerce is active (including network activated).
$plugin_path = trailingslashit( WP_PLUGIN_DIR ) . 'woocommerce/woocommerce.php';
if (
in_array( $plugin_path, wp_get_active_and_valid_plugins() )
|| in_array( $plugin_path, wp_get_active_network_plugins() )
) {
do_action( 'admin_notices' );
@kwcjr
kwcjr / gist:c2cf1a053eb28215c4a8dbb2a4d95661
Created October 17, 2021 13:48
Check for a woocommerce notice highlighting bad template files.
ob_start(); // start capturing output.
WC_Admin_Notices::template_file_check_notice(); // Check for a notice highlighting bad template files.
$notice = ob_get_contents(); // the actions output will now be stored in the variable as a string!
ob_end_clean(); // never forget this or you will keep capturing output.
echo $notice; // output to screen or do something else with it.
@kwcjr
kwcjr / Custom MainWP Menu
Last active November 7, 2021 20:35
Create custom MainWP menu items.
/**
* MainWP Custom Menu.
* Add a custom menu/submenu to the MainWP Dashboard main menu.
*
* Filter Hook: mainwp_main_menu
* Source: https://mainwp.dev/hooks/mainwp_main_menu/
*
* Filter Hook: mainwp_main_menu_submenu
* Source: https://mainwp.dev/hooks/mainwp_main_menu_submenu/
**/
@kwcjr
kwcjr / hide-plugin.php
Last active November 13, 2021 06:29
Hide a defined plugin from the WP admin area.
/**
* Hide plugin from WordPress Admin.
*
* @howto:
* - Change plugin slug to what you want within `$hidearr` separated by comma.
* eg. $hidearr = array('seo-by-rank-math/rank-math.php', users.php );
*
* - Change `$submenu['plugin-slug'][0]` to correct plugin slug.
*/
@kwcjr
kwcjr / after_wp_updates.php
Last active December 8, 2021 16:47
After WP Plugin update Hook
/**
* Purge LiteSpeed Cache after updates.
*
* This snippet will check if LS plugin is activated & then Purge all Cache
* after any Core, Theme or Plugin Installation, Update or rollback. Then it
* will email the results to the given address on line 35. Disable by commenting out
* line 39.
*
* @howto: Update line 35 with your email address and save the code snippet to Execute on Child Sites.
*
@kwcjr
kwcjr / purge-ls-after-updates.php
Created November 25, 2021 11:47
Purge LiteSpeed cache after updates.
/**
* Purge LiteSpeed Cache after updates.
*
* This snippet will check if LS plugin is activated & then Purge all Cache
* after any Core, Theme or Plugin Installation, Update or rollback.
*
* @snippetType: Execute on Child Sites
*/
function my_upgrade_function( $upgrader_object, $options ) {
// Purge all LS Cache.
@kwcjr
kwcjr / delete-wp-readme.php
Created November 27, 2021 00:53
Delete WP readme.html
/**
* Delete WP readme.html file remotely.
*
* This snippet will delete the readme.html file from your Child Site root dir.
*
* @snippetType: Return info from Child Site.
*/
// Load in WP Core files we need.
include_once(ABSPATH . WPINC . '/functions.php');
include_once(ABSPATH . WPINC . '/plugins.php');
@kwcjr
kwcjr / mainwp-pro-report-template.php
Created January 16, 2022 22:46
MainWP Pro Reports WordFence Table.
<!-- WordFence Data -->
<div class="page-break"></div>
<div style="padding:30px;">
<div style="padding:30px;">
<h2><?php echo __( 'WordFence', 'mainwp-pro-reports-extension' ); ?></h2>
<h3><?php echo __( 'Total Scan Count: ', 'mainwp-pro-reports-extension' ); ?>[wordfence.scan.count]</h3>
<table>
<thead>
<tr>
<th><?php echo __( 'Scanned on', 'mainwp-pro-reports-extension' ); ?></th>