Skip to content

Instantly share code, notes, and snippets.

View MikeNGarrett's full-sized avatar
🤘
Rocking this project.

Mike Garrett MikeNGarrett

🤘
Rocking this project.
View GitHub Profile
@MikeNGarrett
MikeNGarrett / functions.php
Created June 10, 2014 15:10
Grant Super Admin to WordPress user in theme's functions.php
<?php
include(ABSPATH . 'wp-admin/includes/ms.php');
$user = get_userdatabylogin('YOUR_USERNAME');
grant_super_admin($user->ID);
?>
@MikeNGarrett
MikeNGarrett / example.php
Created May 29, 2014 15:06
Stack trace anything
<?php
file_put_contents(__DIR__.'/stack.log', print_r(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT), true));
?>
@MikeNGarrett
MikeNGarrett / sanity.sh
Created May 7, 2014 03:54
Bring some sanity to a wget log. I'm pulling out all the files that are returning 404.
# Working with data like this:
# HTTP request sent, awaiting response... .--2014-05-06 16:41:58-- http://xxx.com/xxx.jpg
# Resolving xxx.com... 1.1.1.1
# Connecting to xxx.com|1.1.1.1|:80... ...............connected.
# HTTP request sent, awaiting response... .. .......... .... ....... .......--2014-05-06 16:41:58-- http://xxx.com/xxx.jpg
# Resolving xxx.com... .... .1.1.1.1
# Connecting to xxx.com|1.1.1.1|:80... .........404 Not Found
# 2014-05-06 16:41:58 ERROR 404: Not Found.
#
# .....200 OK
@MikeNGarrett
MikeNGarrett / bulk-resize-script
Created March 26, 2014 00:57
Imagemagick recursively reduce files to < 800x600 and 72ppi
# This is a bash script meant to be run on the command line. Requires imagemagick (apt-get install imagemagick)
## THIS WILL OVERWRITE YOUR FILES, uses sudo and may not require it.
for file in /path/to/files/*/*.jpg; do sudo convert $file -resize '800x600>' -density 72 $file; done
### another method using resolution (800*600)
for file in /path/to/files/*/*.jpg; do sudo convert $file -resize '480000@>' -density 72 $file; done
### example of *not* overwriting files
for file in /path/to/files/*/*.jpg; do sudo convert $file -resize '800x600>' -density 72 converted-$file; done
@MikeNGarrett
MikeNGarrett / redirect-wp-multisite-activation.php
Last active August 25, 2021 16:00
Redirect WordPress Multisite User Upon Activation
<?php
// add do_action('my_do_active_user_message_hook'); where you want the welcome message to display after redirect
add_action( 'activate_header', 'check_activation_key_redirect_to_page' );
/**
* Check the wp-activate key and redirect the user to the apply page
* based on http://www.vanbodevelops.com/tutorials/how-to-skip-the-activation-page-and-send-the-user-straight-to-the-home-page-for-wordpress-multisite
*/
function check_activation_key_redirect_to_page() {
// We check if the key is not empty
@MikeNGarrett
MikeNGarrett / gist:9405070
Last active February 12, 2023 17:58
Insert new user administrator account into WordPress via the database
# Grabbed for reference from http://www.wpbeginner.com/wp-tutorials/how-to-add-an-admin-user-to-the-wordpress-database-via-mysql/
# Check the table prefix
# Check the user_id to make sure it is the next in sequence
# Replace my name and email to your own
# Username will be demo and the password will be 1234
INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'mgarrett', MD5('1234'), 'Mike Garrett', '[email protected]', '', '2011-06-07 00:00:00', '', '0', 'Mike Garrett');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');
# Troubleshooting
@MikeNGarrett
MikeNGarrett / find-your-ip
Created February 18, 2014 15:03
Find your IP vis curl
//Find your IP vis curl
curl ipecho.net/plain
@MikeNGarrett
MikeNGarrett / wp_ajax_request
Created January 28, 2014 23:34
Simple WordPress ajax structure example
<?php
// in functions.php
add_action('wp_ajax_testing_axaj', 'ajax_function_to_execute', 1, 2);
add_action('wp_ajax_nopriv_testing_axaj', 'ajax_function_to_execute', 1, 2);
function ajax_function_to_execute() {
print_r($_REQUEST);
die();
@MikeNGarrett
MikeNGarrett / wp_schedule_task
Created January 27, 2014 20:37
Simple WordPress Scheduled Task Structure
<?php
add_action( 'wp', 'schedule_task' );
/* Let's schedule some tasks! */
function schedule_task() {
if ( ! wp_next_scheduled( 'task_hook' ) ) {
// Add scheduled daily task
wp_schedule_event( time(), 'daily', 'task_hook');
}
}
add_action( 'task_hook', 'function_to_run' );
@MikeNGarrett
MikeNGarrett / zendesk-ticket-export.php
Last active February 1, 2018 10:01
Zendesk ticket export for an organization without a premium account in PHP
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Money Morning Ticket Export</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.ticket-util').click( function(e) {
e.preventDefault();