Skip to content

Instantly share code, notes, and snippets.

@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);
@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 / 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 / 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 / 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 / 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 / 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 / gist:a0911b3401d0a3cba778569c4ed8f675
Created February 19, 2019 23:30
Add PHP 5.2 to wp-local-docker v2 ( Mac )
https://github.com/10up/wp-local-docker-v2
Create new environment.
Edit docker-compose.yml
- set phpfpm image: 'liukaitj/php52'
- comment line
# - './config/php-fpm/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini'
Run 10updocker stop
Run 10updocker start
@lucymtc
lucymtc / Encrypt_Decrypt.php
Created December 13, 2018 14:13
Encrypt/Decrypt using WordPress constant SECURE_AUTH_KEY
<?php
// $this->_default_secure_auth_key defined in case SECURE_AUTH_KEY is not defined.
/**
* Encrypt code using OpenSSL
*
* @param string $code The code to encrypt.
*/
public function encrypt_code( $code ) {
if ( empty( $code ) ) {
@lucymtc
lucymtc / gist:7f02527ecd74ffa0408e36c8cf166d7b
Created November 23, 2018 12:34
Favourite Visual Code Extensions
Theme
https://marketplace.visualstudio.com/items?itemName=wesbos.theme-cobalt2
GitLens
https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens
Git History
https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory
PHP Debug