Skip to content

Instantly share code, notes, and snippets.

@ethanpil
ethanpil / wordpress-custom-admin-menu.php
Created December 26, 2022 20:50
Re-Order and Hide Wordpress Admin Menu Items
<?php
/* How to Rearrange/Hide WordPress Admin Menu Links
Source: https://www.digital.ink/blog/wordpress-rearrange-admin-menu/
1) Find the URL slug of relevant menu items (everything past the /wp-admin/)
2) Re-order as in the first function.
3) Add separators as necessary.
NOTE: If you don’t add an item to your custom menu order, and don’t remove it completely,
it will fall in line below your custom order. So if you only want to re-order the first few
@ethanpil
ethanpil / mark.sh
Created March 12, 2023 18:10
Shell Bookmark Directories
# https://news.ycombinator.com/item?id=35122780#35123388
# http://karolis.koncevicius.lt/posts/fast_navigation_in_the_command_line/
<<USAGE
mark @name # add bookmark called @name for the current directory
cd @name # jump to the bookmarked location
cd @<tab> # list all available bookmarks
USAGE
export CDPATH=.:~/.marks/
function mark {
@ethanpil
ethanpil / wc_make_processing_orders_editable.php
Created March 21, 2023 01:13
Make WooCommerce order status Processing editable
<?php
//https://nicolamustone.blog/2015/05/14/how-to-edit-processing-orders/
add_filter( 'wc_order_is_editable', 'wc_make_processing_orders_editable', 10, 2 );
function wc_make_processing_orders_editable( $is_editable, $order ) {
if ( $order->get_status() == 'processing' ) {
$is_editable = true;
}
return $is_editable;
@ethanpil
ethanpil / jwt_request.php
Created July 28, 2023 15:03
PHP JWT OAuth2 Request Boilerplate
<?php
//https://stackoverflow.com/a/48896992/933782
function jwt_request($token, $post) {
header('Content-Type: application/json'); // Specify the type of data
$ch = curl_init('https://APPURL.com/api/json.php'); // Initialise cURL
$post = json_encode($post); // Encode the data array into a JSON string
$authorization = "Authorization: Bearer ".$token; // Prepare the authorisation token
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization )); // Inject the token into the header
@ethanpil
ethanpil / mopidy-play-stream-cli.sh
Created July 30, 2023 21:50
Mopidy Play Web Stream from Shell CLI
#!/bin/sh
#How to play a web stream on mopidy from command line (Linux) using CURL.
#Can also adjust moplidy playback volume if needed
#Clear current tracklist. Will also stop playback
curl -X POST -H Content-Type:application/json -d '{
"method": "core.tracklist.clear",
"jsonrpc": "2.0",
"id": 1
}' http://localhost:6680/mopidy/rpc
@ethanpil
ethanpil / gist:621cbd8a13e2eb0e5baa6a07d8cfccaa
Created August 14, 2023 23:37
Imagemagic convert transparent png to white background
convert image.png -background white -alpha remove -alpha off new-image.png
@ethanpil
ethanpil / woocommerce-filter-on-sale.php
Last active August 15, 2023 18:01
Woocommerce Filter by On Sale
<?php
/*
* Plugin Name: On Sale Filter for WooCommerce Admin
* Description: Filter the products list in WooCommerce admin to show items on sale.
* Version: 1.0
* Requires at least: 5.2
* Requires PHP: 7.2
*/
@ethanpil
ethanpil / wordpress-cleaning-commands.sh
Last active September 4, 2023 22:33
Hacked Wordpress Command Line Tools
# Find suspicious php files
find . -type f -name '*.php' | xargs egrep -i "(mail|fsockopen|pfsockopen|stream\_socket\_client|exec|system|passthru|eval|base64_decode) *("
# Find suspicious images
find wp-content/uploads -type f -iname '*.jpg' | xargs grep -i php
#Find iframes
find . -type f -name '*.php'| grep -i '<iframe'
#Find files modified in last 3 days
@ethanpil
ethanpil / wp-plugin.php
Created September 10, 2023 18:51
Wordpress Function Boilerplate
<?php
* Plugin Name: WordPress Plugin Boilerplate
* Plugin URI: http://example.com/plugin-name-uri/
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
* Version: 1.0.0
* Author: Your Name or Your Company
* Author URI: http://example.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@ethanpil
ethanpil / log-all-db-to-file.php
Last active September 10, 2023 19:44
WordPress Log All DB Queries To File
<?php
/*
* Plugin Name: WordPress Log All DB Queries To File
* Plugin URI: http://example.com/plugin-name-uri/
* Description: All database queries will be logged to uploads/sql_log.txt activated.
* Version: 1.0.0
* Author: Ethan Piliavin
* Author URI: http://piliavin.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt