Skip to content

Instantly share code, notes, and snippets.

View dingo-d's full-sized avatar
🏠
Working from home

Denis Žoljom dingo-d

🏠
Working from home
View GitHub Profile
@dingo-d
dingo-d / search-modification.php
Last active April 22, 2024 10:58
WordPress search modification. Read the description!
<?php
/**
* Modification of the default WordPress search
*
* By default, the WordPress search is very rigid. It checks the post table's
* title, content and excerpt with a '%LIKE%' keyword. So the search is very
* limited.
* This will modify the search clause and do a fulltext search. For more information
* about fulltext you can read about it here: https://www.digitalocean.com/community/tutorials/how-to-improve-database-searches-with-full-text-search-in-mysql-5-6-on-ubuntu-16-04
*
@dingo-d
dingo-d / conf.phperrorlog
Last active March 26, 2024 21:40
Config examples for debug, and error logs with grc: https://github.com/garabik/grc
# Highlight time
regexp=^\[\d\d-[A-Z][a-z][a-z]-\d\d\d\d \d\d:\d\d:\d\d [A-Z]{3}\]
colour=dark
count=once
-
# Highlight file paths with lines at end
regexp=(/[A-z0-9-]+)+.php:[\d]+
colour=green
count=more
-
@dingo-d
dingo-d / page-metabox.php
Last active May 23, 2023 15:05
A page metabox with a color picker option
<?php
add_action( 'admin_enqueue_scripts', 'mytheme_backend_scripts');
if ( ! function_exists( 'mytheme_backend_scripts' ) ){
function mytheme_backend_scripts($hook) {
wp_enqueue_media();
wp_enqueue_style( 'wp-color-picker');
wp_enqueue_script( 'wp-color-picker');
}
@dingo-d
dingo-d / function.sh
Created September 19, 2022 19:21
Scripts to quickly create wp site using wpcli
#!/bin/zsh
# WP-CLI site setup for Windows
# Usage create-site {folder name} {database name} {site title}
create-site () {
if [ $1 ]
then
mkdir $1 && cd $1
wp core download --skip-content;
wp config create --dbname=$2 --dbuser=root;
@dingo-d
dingo-d / BookCptOOPTest.php
Last active May 16, 2022 12:29
Example of WP unit tests with Pest. Doesn't include the entire setup, for that you can check https://github.com/dingo-d/wp-pest-integration-test-setup
<?php
use TestPlugin\Cpt;
// Unit test with OOP code.
it('checks that the hook is registered for custom post type registration', function() {
$this->stubTranslationFunctions();
(new RegisterBookCpt())->register();
@dingo-d
dingo-d / validate-acf-wysiwyg.php
Created August 30, 2018 08:45
Validate WYSIWYG character limit
<?php
/**
* Validate WYSIWYG field so that it outputs only 250 characters
*
* Targets the overview field in the documentation only.
*
* @param bool $valid Check the validity of the field.
* @param string $value The field value.
* @param array $field Array with the field details.
@dingo-d
dingo-d / application-blocks-editor.js
Created July 14, 2021 06:34
Color picker meta that adds inline css variable using ACF color palette
// Only run if ACF is active.
if (typeof acf !== 'undefined') {
acf.add_filter('color_picker_args', function (args, $field) {
// Add predefined color palette.
args.palettes = ['#5D2BFF', '#FFE194', '#E45353', '#96DFFF', '#FFBDA7', '#8CEAB7', '#ECA7C8'];
return args;
});
}
@dingo-d
dingo-d / wsl2-dns-fix.md
Created June 12, 2021 12:58
Fixing the valet and DNS resolving in WSL2

If the local sites aren't working, or some services, these are possible fixes.

Check the /etc/resolv.conf file, it should look like this

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
generateResolvConf = false
nameserver 172.17.48.1
@dingo-d
dingo-d / docker-composer.yaml
Created May 22, 2021 13:16
Example of docker compose file with WP and WP-CLI (allowed root). Note to self: when specifying command parameter in the compose file you'll need to add the default entrypoint and commands that are running on the default image you're pulling info from.
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
@dingo-d
dingo-d / .zshrc
Created May 22, 2021 06:26
My default .zshrc config
# If you come from bash you might have to change your $PATH.
ZSH_DISABLE_COMPFIX=true
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="agnoster"