Skip to content

Instantly share code, notes, and snippets.

View kbcarte's full-sized avatar

K.B. Carte kbcarte

View GitHub Profile
@kbcarte
kbcarte / mount-example.md
Created November 18, 2021 19:13
Mount remote sftp server to local dir

Mounting be explicit with file paths

sshfs <USERNAME>@<SERVER>:/ /home/<PATH TO LOCAL>/ -p 2222

Unmount no trailing slash

fusermount -u ~/

@kbcarte
kbcarte / wp_export_db.php
Last active March 16, 2022 16:59
WordPress wp-admin download db backup
<?php
/**
* Checks that the filename has correct extensions
*/
function validate_export( $filename ){
$ext = explode(".", $filename);
if( $ext[1] && $ext[1] != "sql" ){
return false;
}
if( $ext[2] && $ext[2] != "gz" ){
@kbcarte
kbcarte / query_wp.php
Last active March 16, 2022 16:58
Example of querying wordpress posts, pages, and custom post types, then update the posts
<?php
// this will probably take a while to run
// so don't refresh the page, if the browser complains
// continue to wait
// -1 posts per page will give ALL
// will default to 10 if blank
// default blog posts
$blog_args = array(
@kbcarte
kbcarte / cookie-example.html
Created January 19, 2022 18:41
cookieconsent banner
@kbcarte
kbcarte / sushi-tips.md
Last active February 14, 2022 18:29
general sushi tips

General Tips

  • Use short grain rice, helps more if label for sushi
    • can be medium grain only if you can't find short grain
  • wash rice in COLD water, do not rub or crush rice just gently move around
    • drain and wash again usually 4-5 times, water need to run mostly clear
    • again, COLD water and be gentle
  • use a rice cooker, it will be 200% easier and better in every way
    • let rice cool to room temp or just above, do not work with hot ingredients
    • store bought sushi vinegar or "seasonsed rice vinegar" is fine, no need to do your own or add sugar
  • cucumbers should ALWAYS be english cucumbers, they are used for the really low moisture content.
@kbcarte
kbcarte / wp_allow_svg.php
Created March 16, 2022 16:56
Allow svg upload per WPEngine
<?php
// Allow svg: https://wpengine.com/resources/enable-svg-wordpress/
add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
global $wp_version;
if ( $wp_version !== '4.7.1' ) {
return $data;
}
$filetype = wp_check_filetype( $filename, $mimes );
return [
'ext' => $filetype['ext'],
@kbcarte
kbcarte / remove_vc_shortcodes.php
Last active March 21, 2022 20:01
PHP Removes the old "[vc_]" shortcodes found in post_content during migrations. If other shortcodes not specific to vc_* are preset, the regex pattern will need to be updated.
<?php
// Add to functions.php
// Remove the "[vc_*]" shortcodes usually found during migrations
// Add this shortcode to a debug/test page and visit it
// The page will render and dump all new post/pages to the screen
// This can take a long time if there are a lot of pages/posts
add_shortcode('remove-vc-shortcodes', 'remove_vc_shortcodes');
function remove_vc_shortcodes() {
$pattern = '/\[\/?vc_.*\]?/i';
@kbcarte
kbcarte / remove_vc_shortcodes.py
Created March 21, 2022 20:03
Python Removes the old "[vc_]" shortcodes found in the db during migrations. If other shortcodes not specific to vc_* are preset, the regex pattern will need to be updated.
# Python script to find-replace an exported DB
# For use when the php version timeout's or exceeding memory limits
# export db you want to update, rename it to backup.sql
# place backup in same dir as this script
# run script
# import the out.sql file
import re
from pprint import pprint
@kbcarte
kbcarte / security_headers.md
Last active June 2, 2022 17:26
Security Headers .htaccess Example
<IfModule mod_headers.c>
    Header set X-Frame-Options SAMEORIGIN
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Content-Type-Options "nosniff"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
    Header set Strict-Transport-Security "max-age=86400; includeSubDomains;" env=HTTPS
    Header set Permission-Policy "accelerometer=Origin(), autoplay=(), camera=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), publickey-credentials-get=(), usb=()"
    Header always unset X-Powered-By
 Header always unset server
@kbcarte
kbcarte / find-gravity-forms.md
Last active April 4, 2022 15:52
Find all posts and pages in WordPress containing gravity forms

For ALL gravity forms

SELECT `guid`, `post_title` FROM `wp_posts` WHERE `post_content` LIKE '%[gravityform%'

For gravity form by ID

Replace <ID HERE> with the id number found in wp-admin

SELECT `guid`, `post_title` FROM `wp_posts` WHERE `post_content` LIKE '%[gravityform id="<ID HERE>"%'