Skip to content

Instantly share code, notes, and snippets.

View devlamconstructie's full-sized avatar

Willem de Vlam devlamconstructie

View GitHub Profile
@devlamconstructie
devlamconstructie / wp_page_debloater.php
Last active December 7, 2022 10:25
REMOVE Gutenberg Styles and gradient svg's added by wordpress.
/**
* REMOVE Gutenberg Styles auto added by wordpress.
*
*/
if(! is_admin())
add_action ( 'init', 'remove_wp_block_library_css', PHP_INT_MAX );
function remove_wp_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
@devlamconstructie
devlamconstructie / storyloop.php
Last active September 22, 2022 23:36
custom loop in custom post type.
<?php
/*
code is broken.
Either wordpress completely discards the paging request variables, or sends a 404.
*/
function get_story_loop(){
global $wp_query;
$post_query = $wp_query;
@devlamconstructie
devlamconstructie / get_meta_values.php
Created September 20, 2022 23:05 — forked from tybruffy/get_meta_values.php
Get all distinct values of a meta field in Wordpress
function _get_all_meta_values($key) {
global $wpdb;
$result = $wpdb->get_col(
$wpdb->prepare( "
SELECT DISTINCT pm.meta_value FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
WHERE pm.meta_key = '%s'
AND p.post_status = 'publish'
ORDER BY pm.meta_value",
$key
@devlamconstructie
devlamconstructie / index.js
Created September 5, 2022 19:34 — forked from skokenes/index.js
SVG Path Generator for Rounded Rectangles
function createRoundedRectPath(x, y, width, height, radius) {
return (
// Move to position, offset by radius in x direction
"M" +(x + radius) + "," + y
// Draw a horizontal line to the top right curve start
+ "h" + (width - 2 * radius)
// Draw the top right corner curve
+ "a" + radius + "," + radius + " 0 0 1 " + radius + "," + radius
// Draw a vertical line to the bottom right corner
+ "v" + (height - 2 * radius)
@devlamconstructie
devlamconstructie / disable_wp_user_passwordfields.php
Last active July 14, 2022 09:50
disable wordpress user password fields for anyone other than admins
<?php
/**
* prevent anyone other than admins from editing other user's passwords.
* disable password change fields for anyone other than admins.
* @since 0.0.2 removed part about editing own profile, because the password fields don't show there anyway.
* @see https://developer.wordpress.org/reference/hooks/show_password_fields/ show_password_fields hook documentation
* @param bool $default the current setting; default = true.
* @param object $profileuser, the user currently being edited.
*/
add_filter('show_password_fields', function($default, $profileuser){
@devlamconstructie
devlamconstructie / disable_complianz_in_o2.php
Last active April 25, 2022 14:51
disable complianz in oxygen builder
<?php
/**
* Disables loading of complianz cookie banner and blocking of cookies
* while in Oxygen Builder. Uses early-firing compliance hook.
* simply checks the request for the ct_builder query var.
* */
add_filter(
'cmplz_site_needs_cookiewarning',
function ( $cookiewarning_required) {
<?php
/**
* In the Stripe Gravity Forms Addon, the api test-mode is all-or-nothing.
* sometimes you need more granular control; eg testing a form on a production site,
* while leaving other forms operational.
* This function allows you to set the api to test mode for specific user capabilities.
* you can also specify a form you want to test, while leaving all other forms live.
* @param integer $formID
* @param string the user cap. default 'manage_options'
* @example stripe_api_mode_to_test(); //admin will be able to use all forms in test mode.
@devlamconstructie
devlamconstructie / wordpress-upload-base64.php
Created January 30, 2021 20:47 — forked from cyberwani/wordpress-upload-base64.php
Upload a base64 string as image to the WordPress media library
<?php
/**
* Save the image on the server.
*/
function save_image( $base64_img, $title ) {
// Upload dir.
$upload_dir = wp_upload_dir();
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
@devlamconstructie
devlamconstructie / save_upload_field_to_custom_field.php
Created January 30, 2021 17:24 — forked from saltnpixels/save_upload_field_to_custom_field.php
gravity form upload file to media library and use attachment ID in custom field
add_action( 'gform_after_create_post', 'gf_add_to_media_library', 10, 3 );
/**
* Save file upload fields under custom post field to the library
*
* @param $post_id The post identifier
* @param $entry The entry
* @param $form The form
*/
@devlamconstructie
devlamconstructie / gw-gravity-forms-map-fields-to-field.php
Created December 21, 2020 14:38 — forked from spivurno/gw-gravity-forms-map-fields-to-field.php
Gravity Wiz // Gravity Forms // Map Submitted Field Values to Another Field
<?php
/**
* Gravity Wiz // Gravity Forms // Map Submitted Field Values to Another Field
*
* Usage
*
* 1 - Enable "Allow field to be populated dynamically" option on field which should be populated.
* 2 - In the "Parameter Name" input, enter the merge tag (or merge tags) of the field whose value whould be populated into this field.
*
* Basic Fields