Skip to content

Instantly share code, notes, and snippets.

View otakupahp's full-sized avatar
🇪🇨
Latin Coder

Pablo Hernández (OtakuPahp) otakupahp

🇪🇨
Latin Coder
View GitHub Profile
@otakupahp
otakupahp / theme-filters.php
Created September 5, 2023 20:13
Add a body class if the content has a cover with an specific class
/**
* Check if the cover block has the hero class and set a global variable.
*
* @param string $content The block content about to be rendered.
*
* @return string
*/
function otk_cover_block( string $content ): string {
// The hero is the first block in the content, so we set it once.
@otakupahp
otakupahp / input.scss
Last active March 10, 2023 20:10
Add a new class on an specific position
// Desired output
// .woocommerce-page.single-product main .product_cat-intentional-pause form.cart #wc-stripe-payment-request-wrapper
.woocommerce-page.single-product {
main {
form.cart {
#wc-stripe-payment-request-wrapper {
$selector: nth(&,1); // Current element
$grandparent: nth($selector, -2); // Grandparent selector
@otakupahp
otakupahp / input.scss
Last active January 9, 2023 19:54
Add a class and use the direct parent as part of the child selector
// Desired output
// .content-section-about_this .wp-block-media-text.is-stacked-on-mobile .wp-block-media-text__content
.content-section-gift,
.content-section-about_this {
.wp-block-media-text {
$selector: nth(&,1);
$direct-parent: nth($selector, length($selector));
&.is-stacked-on-mobile #{selector-append($direct-parent, '__content')} {
@otakupahp
otakupahp / otk-security.php
Last active December 13, 2022 14:25
WP MU Misc Plugins
<?php
/*
Plugin Name: OtakuPahp Security Measures
Description: Some Wordpress Hacks to improve site security
Author: Pablo Hernandez (OtakuPahp)
Author URI: https://otakupahp.llc
Version: 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
@otakupahp
otakupahp / distance.php
Last active May 20, 2022 09:23
Calculate distance between 2 locations
<?php
/**
* Calculate the distance between the 2 locations
*
* @param array $point_a
* @param array $point_b
*
* @return float
*/
function calculate_distance( array $point_a, array $point_b ) : float {
@otakupahp
otakupahp / get_from_staging.sql
Last active September 21, 2022 09:18
Run Jetpack Instant Search locally
-- Replace table name as needed
SELECT * FROM `wp_options` WHERE `option_name` LIKE '%jetpack_search%' ORDER BY option_name ASC;
@otakupahp
otakupahp / post-receive
Last active January 29, 2022 01:49
Automatic deploy using GIT
#!/bin/bash
TARGET="/www/{site-folder}/public/wp-content/themes"
GIT_DIR="/www/{site-folder}/private/warp.git"
BRANCH="main"
while read oldrev newrev ref
do
# only checking out the master
if [[ $ref = refs/heads/$BRANCH ]];
then
@otakupahp
otakupahp / enqueue_script.php
Last active November 8, 2021 23:58
Adds support for 'integrity' and 'crossorigin' at enqueuing a script on WordPress
<?php
/**
* Adds support for 'integrity' and 'crossorigin'
*
* This relies on the function *wp_script_add_data* been called when enqueuing the script
*
* @param $tag
* @param $handle
*
@otakupahp
otakupahp / collection.php
Created July 31, 2021 23:30
Create an iterrator collection that could be accesed as an array
<?php
class Collection implements Iterator, ArrayAccess
{
private int $position;
private array $array = [];
public function __construct() {
$this->position = 0;
@otakupahp
otakupahp / loader.css
Last active June 30, 2022 22:01
Simple CSS Loader
.container {
height: 300px;
width: 300px;
margin: 0 auto;
display: flex;
justify-content: center;
align-content: center;
}
.loader {