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 / add-to-wp-config.php
Created June 15, 2021 16:34
Add docker environment to WP
<?php
// Define a Docker environment constant with the value
define( 'WP_ENVIRONMENT_TYPE', getenv_docker('WORDPRESS_ENV', 'local') );
/*
* To use this, you should add a conditional
*
* ```
* if( wp_get_environment_type() === 'local' ) {
* // your code
@otakupahp
otakupahp / checkbox.html
Last active February 1, 2023 10:44
Nice Checkbox
<label for="check">Check</label>
<input
type="checkbox"
class="ui-toggle"
id="check"
name="check"
value="1"
>
@otakupahp
otakupahp / README.txt
Last active April 12, 2022 16:26
Plugin Header text to add Compatibility info
=== Plugin Name ===
.
.
.
Requires at least: 5.9
Tested up to: 5.9.3
Requires PHP: 8.0
WC requires at least: 6.0
WC tested up to: 6.0
License: GPLv2 or later
@otakupahp
otakupahp / wp-config.php
Created November 24, 2020 03:14
Deactivate Really Simple SSL with constants and SSL redirection
<?php
define('FORCE_SSL_ADMIN', false);
define('rsssl_no_wp_redirect', true);
define('rsssl_no_rest_api_redirect', true);
@otakupahp
otakupahp / autoloader.php
Last active August 24, 2022 10:09
Simple WordPress Autoloader
<?php
spl_autoload_register(function($required_file) {
# Transform file name from class based to file based
$fixed_name = strtolower( str_ireplace( '_', '-', $required_file ) );
$file_path = explode( '\\', $fixed_name );
$last_index = count( $file_path ) - 1;
$file_name = "class-{$file_path[$last_index]}.php";
# Get fully qualified path
@otakupahp
otakupahp / dynamic-shadow.js
Last active May 5, 2022 21:26
Add a shadow text with the desired content to a H2
// To add the text dynamically, use a class (overlay-title) in the h2 to catch the object and modify h2::before for "overlay-title-shadow"
(function( $ ) {
'use strict';
// Window loaded
$(window).on("load",function(){
const postTitleObj = $( '.overlay-title h2' );
if( 0 < postTitleObj.length ) {
postTitleObj.before( '<div class="overlay-title-shadow">' + postTitleObj.html() + '</div>' );
}
@otakupahp
otakupahp / file.php
Last active February 21, 2021 15:57
WordPress Ajax done correctly
<?php
# After enquequing the JS add this localization to add the nonce and other variables
$params = [
'action' => 'your_action',
'wp_nonce' => wp_create_nonce( 'wp_ajax_nonce' ),
'error' => __('There was an error with the Ajax call. Please try again later'),
];
wp_localize_script( 'custom_ajax_params', 'wp_globals', $params );
@otakupahp
otakupahp / getQueryParam.js
Last active September 24, 2021 16:00
Work with query param from URL
/** Get a value from the Query params */
function otkGetQueryParam(name, url = window.location.href) {
let objectURL = new URL( url );
let searchParams = new URLSearchParams( objectURL.search );
return searchParams.get(name);
}
/** Set a value to the Query params */
function otkSetQueryParam(name, url = window.location) {
const urlObj = new URL(url);
@otakupahp
otakupahp / activate_plugin.php
Last active July 12, 2021 22:51
Simple function to check a plugin activation
<?php
/**
* @since 1.0.0
*
* @param $plugin_name
*/
public static function activate($plugin_name) {
# Initialize variables
@otakupahp
otakupahp / jquery.js
Last active July 19, 2021 18:26
JQuery on ready
(function( $ ) {
'use strict';
// DOM ready
$(function() {
});
// Window loaded
$(window).on("load",function(){