Skip to content

Instantly share code, notes, and snippets.

View trepmal's full-sized avatar
🍪

Kailey Lampert trepmal

🍪
View GitHub Profile
<?php
/**
* Plugin Name: Dev Plugins
*/
add_action( 'muplugins_loaded', function() {
// Plugins to activate automatically.
$auto_activate = [
'debug-bar/debug-bar.php',
'debug-bar-extender/debug-bar-extender.php',
<some-command> | tee some.log ; \
  ( [[ ${PIPESTATUS[0]} -eq 1 ]] \
  && (tail some.log | mail -s '<some-command> exited with error' you@example.com) \
  || (tail some.log | mail -s '<some-command> finished' you@example.com) )

breakdown:

| tee some.log;

#!/bin/bash
echo "mua hahah"
exit

# Uses an escape sequence to move the cursor up.
# So if you `cat` this file, it will hide the "bad" part
# But if you execute the file, the "bad" will be done.
# Try `cat -v` to expose the escape characters.
echo "gooooood file"
#!/bin/bash
#
# Back up my files and databases
#
#
# backup_static_if <fullpath> <shortname>
# use directory fingerprint to avoid unnecessary backups
#

Update core (and db), plugins, and themes, logging status to syslog. Ideal for running on a cronjob

Example of syslog

Apr 26 04:07:56 vvv vagrant: [WPAutoUpdate] Local WordPress Dev | http://local.wordpress.dev
Apr 26 04:08:27 vvv vagrant: [WPAutoUpdate] Core update: WordPress updated successfully to 4.5
Apr 26 04:08:28 vvv vagrant: [WPAutoUpdate] DB update: WordPress database already at latest db version 36686
<?php
// Plugin Name: Example. Change "Excerpt" meta box heading
namespace KDL\excerpt_change;
function filter_excerpt( $translations, $text, $domain ) {
if ( $text == 'Excerpt' ) {
return "New Excerpt";
}
@trepmal
trepmal / swap-admin-color.php
Last active September 18, 2016 03:26
WordPress plugin. Hot swap admin color scheme for probable local dev/stage sites
<?php
/**
* Plugin Name: Swap color scheme on local dev/stage
*/
/**
* Hotswap an alternate color scheme
*
* @param string $result Original value
* @param string $option Option name

create tarball of only end of 2015 and 2016

cd wp-content/uploads/sites/
find 5/ -regextype sed -regex ".*/\(2015/1\|2016\).*" | tar -czvf uploads.tar.gz --files-from -
<?php
if ( !defined( 'WP_CLI' ) ) return;
/**
* Migrate meta values to terms
*
* @package wp-cli
*/
class Meta_To_Term_Migration extends WP_CLI_Command {
@trepmal
trepmal / toggle-debug.php
Last active September 4, 2020 15:42
WordPress experiment. Toggle debug from admin bar
<?php
/*
Plugin Name: Toggle Debug
Description: Proof-of-concept for an admin-bar debug mode toggle. Needs some UX love.
*/
/*
// In wp-config.php, wrap debug constants in a cookie conditional
if ( isset( $_COOKIE['wp-debug'] ) && $_COOKIE['wp-debug'] == 'on' ) {
define('WP_DEBUG', true);
}