Skip to content

Instantly share code, notes, and snippets.

@kwcjr
kwcjr / wp.snippet
Last active April 3, 2023 07:21
Redirect user if not logged in.
/**
* Snippet Action: Redirect user if not logged in.
* Snippet Author: Keith Crain ( MainWP.com )
*/
function custom_template_redirect_fn()
{
if( ! is_user_logged_in ) {
{
$loginUrl = wp_login_url();
@kwcjr
kwcjr / gist:8de4de4e5938046d8c9d0270db303a3e
Last active March 24, 2023 18:18
Get all users that are not Administrators
<?php
/**
* Snippet Action: Get all users that are not Administrators
* Snippet Type: Return info from Child Sites. ( IMPORTANT! This will make it run one time )
* Snippet Author: Keith Crain ( MainWP.com )
*
* Output:
* Total User Count: 5
* UserName1 : customer
@kwcjr
kwcjr / add-site-name.snippet
Last active May 15, 2023 15:53
Add site name to pdf report file.
/**
* Snippet Action: Add Site Name to pdf file.
* Snippet Type: MainWP Custom Dashboard CSS snippet.
* Snippet Author: Keith Crain ( MainWP.com )
*/
add_filter( 'mainwp_pro_reports_pdf_filename', 'mycustom_mainwp_pro_reports_pdf_filename', 10, 3 );
if ( !function_exists( 'mycustom_mainwp_pro_reports_pdf_filename' ) ) {
function mycustom_mainwp_pro_reports_pdf_filename( $filename, $report, $site_id ) {
$website = MainWP\Dashboard\MainWP_DB::instance()->get_website_by_id( $site_id );
@kwcjr
kwcjr / hide_update_all_button.snippet
Created March 3, 2023 22:35
Hide Update All Button
/**
* Snippet Action: Hide Update All Button on Updates Page.
* Snippet Type: MainWP Custom Dashboard CSS snippet.
* Snippet Author: Keith Crain ( MainWP.com )
*/
#mainwp-plugins-updates-table a:nth-child(3),
#plugins-updates-global a:nth-child(3) { display: none!important; }
@kwcjr
kwcjr / append_robots.snippet
Last active December 15, 2022 21:01
Append content to Robots.txt
<?php
/**
* Snippet Action: Append content to Robots.txt
* Snippet Type: Return info from Child Sites. ( IMPORTANT! This will make it run one time )
* Snippet Author: Keith Crain ( MainWP.com )
*/
// The string you want to add.
$txt = "
@kwcjr
kwcjr / wp-config.php
Created November 20, 2022 16:47
Set WordPress Timeout & cURL Timeout PHP Variables.
define( 'WP_MEMORY_LIMIT', '128M' );
ini_set("default_socket_timeout", 600);
/* That's all, stop editing! Happy blogging. */
@kwcjr
kwcjr / css.snippet
Created November 5, 2022 16:08
Change MainWP Logo
/**
* 1.) Upload your logo to WP Media Library
* 2.) Copy the URL from Media Library
* 3.) Paste on line 13
*/
/* Hide Original logo */
.mainwp-nav-wrap #mainwp-logo img {
display: none!important;
}
@kwcjr
kwcjr / Trigger-Elementor-DB-Update.snippet
Last active February 17, 2023 14:37
Trigger Elementor DB Update
<?php
/**
* Snippet Action: Trigger Elementor DB Update.
* Snippet Type: Return info from Child Sites. ( IMPORTANT! This will make it run one time )
* Snippet Author: Keith Crain ( Kronoslabs.io )
*/
add_action( 'plugins_loaded', 'klbs2345_trigger_elementor_db_update' );
function klbs2345_trigger_elementor_db_update() {
/**
* Snippet Action: Return Child Site Posts.
* Snippet Type: Return info from Child Sites.
*/
$posts = get_posts( array(
'post_type' => get_post_types(),
'post_status' => 'publish',
'numberposts' => -1,
) );
@kwcjr
kwcjr / gist:7ccb956346e924ca8d03819f75d8ea9d
Created July 26, 2022 22:24
List wp /upload directory file sizes.
$upload_dir = wp_upload_dir();
$folder = $upload_dir['basedir'];
$files = list_files( $folder );
foreach ( $files as $file ) {
if ( is_file( $file ) ) {
$filesize = size_format( filesize( $file ) );
$filename = basename( $file );
echo esc_html( $filename . " - (" . $filesize ) . ")<br />";
}