Skip to content

Instantly share code, notes, and snippets.

View JoryHogeveen's full-sized avatar
👌
Coding

Jory Hogeveen JoryHogeveen

👌
Coding
View GitHub Profile
@JoryHogeveen
JoryHogeveen / cli-fix-charset-serialization.php
Created July 17, 2024 14:41
PHP CLI to fix charset collasion with serialized data support
#!/usr/bin/php
<?php
/**
* File edited by Jory Hogeveen <KERAWEB> to also convert table charsets and collasion.
* IMPORTANT: SQL file needs to be UTF8 format!
*
* Example usage:
*
* - php -d memory_limit=4G cli-fix-serialization-charset.php path_to_source.sql path_to_target.sql latin1_swedish_ci utf8mb4_unicode_520_ci
*
@JoryHogeveen
JoryHogeveen / wp_meta_image_url_to_id.sql
Created April 11, 2023 10:19
WP Metadata: Convert image URL to image ID
# Below SQL will convert an attachment URL to the attachment ID
# Useful when switching from Toolset to Pods or ACF.
UPDATE wp_postmeta m
LEFT JOIN wp_postmeta s
ON INSTR( m.meta_value, s.meta_value ) > 0
SET m.meta_value = s.post_id
WHERE
s.meta_key = '_wp_attached_file'
AND m.meta_key = 'YOUR_META_KEY'
@JoryHogeveen
JoryHogeveen / wp-add-admin-user.php
Created November 17, 2022 10:53
WP add admin user
<?php
$user = '';
$email = '';
$password = '';
$role = 'administrator';
$user = get_user_by( 'email', $email );
if ( ! $user ) {
wp_create_user( $user, $password, $email );
$user = get_user_by( 'email', $email );
@JoryHogeveen
JoryHogeveen / polylang-elementor-assets-url.php
Last active November 15, 2024 10:49
WP MU Plugin: Polylang multidomain Elementor assets URL
<?php
/**
* MU plugin. Need to be used together with regular plugin.
*
* Plugin Name: Polylang Elementor Cross Domain Assets URL
* Description: Fixes cross origin domain issues with Elementor and Polylang
* Version: 1.0
* Author: Jory Hogeveen
* Author URI: http://www.keraweb.nl/
*/
@JoryHogeveen
JoryHogeveen / load.php
Created September 28, 2017 18:19
WordPress mu-plugins loader
<?php
/**
* Load the mu-plugins just like regular plugins.
*/
$directory = scandir( WPMU_PLUGIN_DIR );
foreach ($directory as $dir) {
if ( $dir === '.' || $dir === '..' ) continue;
@JoryHogeveen
JoryHogeveen / wcssc-class-filters.php
Created August 21, 2017 12:37
Widget CSS Classes: Define your own classes through filters.
<?php
/**
* Plugin hooks:
* widget_css_classes_first
* widget_css_classes_last
* widget_css_classes_even
* widget_css_classes_odd
* widget_css_classes_number
*
@JoryHogeveen
JoryHogeveen / vaa-superior-admin.php
Last active July 10, 2017 14:55
Add this file in /wp-content/mu-plugins/ to securely set a superior admin.
<?php
/*
* Plugin Name: My View Admin As Superior Admin
* Description: Define a superior admin for View Admin As
* Version: 1.1
* Author: Jory Hogeveen
* Author URI: http://www.keraweb.nl/
*/
add_filter( 'view_admin_as_superior_admins', 'my_vaa_superior_admins', 99999 );
@JoryHogeveen
JoryHogeveen / movegfjstofooter.php
Last active August 21, 2018 10:29 — forked from eriteric/movegfjstofooter.php
Load gravity forms JS in footer
<?php
// GF method: http://www.gravityhelp.com/documentation/gravity-forms/extending-gravity-forms/hooks/filters/gform_init_scripts_footer/
add_filter( 'gform_init_scripts_footer', '__return_true' );
// solution to move remaining JS from https://bjornjohansen.no/load-gravity-forms-js-in-footer
// Force Gravity Forms to init scripts in the footer and ensure that the DOM is loaded before scripts are executed
add_filter( 'gform_cdata_open', 'wrap_gform_cdata_open', 1 );
function wrap_gform_cdata_open( $content = '' ) {
if ( ! wrap_gform_cdata() ) {
return $content;