Skip to content

Instantly share code, notes, and snippets.

View coulterpeterson's full-sized avatar
🤓
Always learning

Coulter Peterson coulterpeterson

🤓
Always learning
View GitHub Profile
<?php
/**
* Drop this code into your main plugin file to hide plugin deactivation from the WordPress admin.
*/
add_filter( 'plugin_action_links', function ( $actions, $plugin_file ) {
if ( plugin_basename( __FILE__ ) === $plugin_file ) {
unset( $actions['deactivate'] );
}
@coulterpeterson
coulterpeterson / functions.php
Last active June 24, 2021 18:55
update_user_meta with better error handling
<?php
function better_update_user_meta( $user_id, $key, $newValue ) {
// Will return false if the previous value is the same as $new_value.
$updated = update_user_meta( $user_id, $key, $newValue );
// No error of any kind thrown, so return true
if($updated) {
return true;
@coulterpeterson
coulterpeterson / snippet.js
Created June 3, 2021 15:48
jQuery for fun and profit (various tricks that I find useful)
jQuery(document).ready(function($){
/* JQUERY BREAKPOINTS - THANKS TO https://stackoverflow.com/a/1974797 */
// Bind to the resize event of the window object
$(window).on("resize", function () {
// Do things with $(this).width(), which is the current viewport width
// Invoke the resize event immediately on page load
}).resize();
@coulterpeterson
coulterpeterson / procedure.md
Last active July 13, 2021 18:34
How to make an SVG stretchable/scalable like a PNG background in CSS

Source: https://stackoverflow.com/a/56459700

  • remove the width and height properties ex: width="375" height="137"
  • add this property preserveAspectRatio="none"
  • add the viewbox property (containing your original width and height that you just removed viewBox="0 0 375 137"

In your css file on the element that contains your svg background:

  • add the property: background-size: 100% 100%;
@coulterpeterson
coulterpeterson / functions.php
Created May 14, 2021 21:09
Add class to password protected pages in WordPress
<?php
/* Add class to body so we know it's a password protected site */
add_filter( 'body_class', 'add_password_protected_body_class' );
function add_password_protected_body_class( $classes ) {
// Thanks to https://wpsites.net/web-design/add-custom-class-to-style-password-protected-posts/
if ( post_password_required() )
$classes[] = 'password-protected';
return $classes;
@coulterpeterson
coulterpeterson / plugin.php
Last active June 24, 2021 16:43
#WordPress #Plugin options page
<?php
// .... various plugin code, then the options page gets added:
// Add settings link to plugins page listing
add_action('admin_menu', 'myplugin_register_options_page');
add_action('admin_init', 'myplugin_register_settings');
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'myplugin_add_settings_link');
// Settings link on plugin page
@coulterpeterson
coulterpeterson / terminal
Created May 4, 2021 23:46
#GIT Clean up files that were pushed that are now in the .gitignore
# https://www.codeblocq.com/2016/01/Untrack-files-already-added-to-git-repository-based-on-gitignore/
# First commit everything, including the .gitignore
git rm -r --cached .
git add .
git commit -m ".gitignore fix"
@coulterpeterson
coulterpeterson / howto.md
Created April 30, 2021 15:57
Debug Android Chrome from Mac/PC Desktop
@coulterpeterson
coulterpeterson / functions.php
Created April 28, 2021 19:06
Magical Function that Prioritizes the Enqueued Child Stylesheet Over the Parent in #WordPress
<?php
// enqueue parent styles
function ns_enqueue_styles() {
// thanks https://nickschaeferhoff.com/wordpress-child-theme/
$parent_style = 'parent-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
@coulterpeterson
coulterpeterson / .htaccess
Created April 12, 2021 18:37
301/302 Redirects in htaccess
# Redirects
Redirect 302 https://www.oldurl.com/staff/ https://www.newurl.com/about/
Redirect 302 https://www.oldurl.com/staff https://www.newurl.com/about/