Skip to content

Instantly share code, notes, and snippets.

@lucymtc
lucymtc / preview.php
Last active March 3, 2021 13:40
WordPress preview trashed posts
<?php
class Preview {
/**
* Register WordPress hooks and filters
*
* @return void
*/
public function register() {
@lucymtc
lucymtc / util-strings.js
Created January 30, 2020 05:58
Javascript rtrim, ltrim, trim helpers
export const ltrim = (str, char) => {
let message = str;
if (typeof message !== 'undefined') {
while (message[0] === char) {
message = message.substring(1);
}
}
return message;
};
@lucymtc
lucymtc / DomNodeInsertAfter.php
Last active February 16, 2020 11:48
helper DOMNode::insertAfter
<?php
/**
* Helper function to insert node after another node.
*
* @param DOMNode $newNode Node to be appended.
* @param DOMNode $refNode Node required to have new node appended after it.
*/
function insertAfter ( $newNode, $refNode ) {
if( $refNode->nextSibling ){
$refNode->parentNode->insertBefore( $newNode, $refNode->nextSibling );
@lucymtc
lucymtc / gist:bb8cf05a4423e44d4f568ee3c1bcb41a
Last active May 11, 2023 16:07
RN iOS clean and reinstall pods
cd ios
pod cache clean --all
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
@lucymtc
lucymtc / cli-process-in-batches.php
Last active March 30, 2022 08:09
wp cli process something in batches
/**
* Start point for CLI command to process some posts in batches
*
* ## EXAMPLES
*
* wp mycommand
*
* @subcommand process-posts
*
* @param array $args Positional arguments for the command.
@lucymtc
lucymtc / is_tax_rest_request.php
Last active December 21, 2023 08:50
is_tax_rest_request() The WordPress REST API workaround for is_tax()
/**
* Determine if it's a REST API request.
*
* @return boolean True if rest request.
*/
function is_rest() {
return defined( 'REST_REQUEST' ) && REST_REQUEST;
}
/**
@lucymtc
lucymtc / cors-error-headless-wp.php
Created February 21, 2024 10:23
resolve CORS error headless WP
WP headers api for for POST from localhost:3000:
<?php
// init hook as will be global. send_headers hook doesn't work on rest api.
add_action( 'init', [ $this, 'security_headers' ] );
// DEBUG_MODE_CLIENT_URL = http://localhost:3000
public function security_headers() {
if ( defined( 'DEBUG_MODE_CLIENT_URL' ) ) {
header("Access-Control-Allow-Origin: " . DEBUG_MODE_CLIENT_URL);