Skip to content

Instantly share code, notes, and snippets.

@joshhartman
joshhartman / randomPassphrase.php
Last active August 15, 2023 13:29
Memorable Passphrase Generator (Requires PHP 7.1+)
<?php
function randomPassphrase( $numwords = 3, $minlength = 16, $ucfirst = true, $spchar = true )
{
if ( $numwords < 3 ) {
$numwords = 3;
} elseif ( $numwords > 6 ) {
$numwords = 6;
}
if ( $minlength < $numwords * 4.5 ) {
$minlength = $numwords * 5;
@joshhartman
joshhartman / functions.php
Last active July 5, 2022 21:23
Disable specific WordPress shortcodes when editing with Beaver Builder
<?php
// Disable specific WordPress shortcodes when editing with Beaver Builder
function shortcode_compatibility_bb_fix() {
if ( FLBuilderModel::is_builder_active() ) {
remove_shortcode( 'gravityform' );
remove_shortcode( 'fl_builder_insert_layout' );
}
}
add_action( 'wp', 'shortcode_compatibility_bb_fix' );
@joshhartman
joshhartman / functions.php
Created December 14, 2021 04:14
Add a Custom WordPress Image Size and Register for Use with UABB and Other Plugins
<?php
// Add new image size for mini gallery
add_action( 'after_setup_theme', 'custom_theme_setup' );
function custom_theme_setup(){
add_image_size( 'mini-thumb', 75, 75, array( 'center', 'center' ) );
}
// Register image size for plugins to use
add_filter( 'image_size_names_choose', 'custom_image_sizes' );
add_filter( 'uabb_photo_gallery_image_sizes', 'custom_image_sizes' );
@joshhartman
joshhartman / gzip_mime_types.txt
Created October 11, 2021 21:15
GZIP MIME Types List for use with cPanel's "Optimize Website" Module
Navigate to cPanel > Optimize Website.
Choose "Compress the specified MIME types."
Clear the contents of the "Mime Types" text input field and paste in the following space-separated list of MIME types:
text/css text/html text/javascript text/plain text/xml application/javascript application/rss+xml application/vnd.ms-fontobject application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/opentype font/otf font/ttf image/svg+xml image/x-icon
Click "Update Settings" button to save your changes.
@joshhartman
joshhartman / functions.php
Created October 2, 2021 03:44
Defer Loading CSS in WordPress to Prevent Render-Blocking
<?php
// Defer Loading CSS in WordPress to Prevent Render-Blocking
function custom_defer_css( $tag, $handle ) {
$css_to_defer = array( 'style-handle-one', 'style-handle-two' );
if ( in_array( $handle, $css_to_defer ) ) {
return str_replace( "media='all'", "media='print' onload=\"this.media='all';\"", $tag );
}
return $tag;
@joshhartman
joshhartman / sysinfo.php
Last active January 7, 2022 08:29
cPanel Linux Server System Info Summary
<?php
function sys_uptime(){
$uptime = '';
if(is_readable('/proc/uptime')){
$str = @file_get_contents('/proc/uptime');
$num = floatval($str);
$secs = $num % 60;
$num = (int)($num / 60);
$mins = $num % 60;
@joshhartman
joshhartman / gist:fce56971dcac1438f56b14ea9f8ac4d9
Created January 11, 2021 18:37
Windows Icon Resource EXE/DLLs for use with shortcuts, etc.
C:\Windows\Explorer.Exe
C:\Windows\System32\AccessibilityCpl.Dll
C:\Windows\System32\compstui.dll
C:\Windows\System32\Ddores.Dll
C:\Windows\System32\DDORes.dll
C:\Windows\System32\GameUx.Dll
C:\Windows\System32\imageres.dll
C:\Windows\System32\mmcndmgr.dll
C:\Windows\System32\mmRes.Dll
C:\Windows\System32\MorIcons.Dll
@joshhartman
joshhartman / functions.php
Created August 13, 2020 21:26
Override FreeSSL WordPress plugin domain exclusion list
<?php
// Override FreeSSL plugin domain exclusion list
add_filter('option_exclude_domains_auto_install_free_ssl', function ($data) {
$custom_data = array('domains_to_exclude' => array('mail.mydomain.com'));
if(isset($data['domains_to_exclude'])){
$data['domains_to_exclude'] = array_merge($data['domains_to_exclude'], $custom_data['domains_to_exclude']);
return $data;
}
return $custom_data;
});
@joshhartman
joshhartman / functions.php
Last active August 3, 2020 20:11
Disable specific WordPress shortcodes when editing with Beaver Builder
<?php
function shortcode_compatibility_bb_fix() {
if ( FLBuilderModel::is_builder_active() ) {
remove_shortcode( 'team-members' );
}
}
add_action( 'wp', 'shortcode_compatibility_bb_fix' );
@joshhartman
joshhartman / functions.php
Created March 13, 2020 20:17
WordPress Admin Login Custom Styling
<?php
function my_custom_login_styles() { ?>
<style type="text/css">
body.login {
background-color: #114892 !important;
}
body.login div#login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri() ?>/images/site-login-logo.png);
padding-bottom: 15px;