Skip to content

Instantly share code, notes, and snippets.

Avatar

Olaf Lederer finalwebsites

View GitHub Profile
@finalwebsites
finalwebsites / redirect_user_add.php
Last active May 6, 2022
This snippet will redirect the WordPress admin to the user profile page after a new user was added.
View redirect_user_add.php
<?php
// place this code snippet to the functions.php file from your WordPress child theme
add_action("current_screen", "redirect_user_add");
function redirect_user_add() {
if (!empty($_GET['id'])) {
$currentScreen = get_current_screen();
if ($currentScreen->id == "users") {
wp_redirect( admin_url("/user-edit.php?user_id=".(int)$_GET['id']) );
@finalwebsites
finalwebsites / uitverkocht-uitschakelen.php
Created Feb 20, 2022
WooCommerce product variaties uitschakelen wanneer deze zijn uitverkocht
View uitverkocht-uitschakelen.php
<?php
// plaats deze code in het functions.php bestand van je child thema
add_filter( 'woocommerce_variation_is_active', 'fws_disable_variations_out_of_stock', 10, 2 );
function fws_disable_variations_out_of_stock( $is_active, $variation ) {
if ( ! $variation->is_in_stock() ) return false;
return $is_active;
}
@finalwebsites
finalwebsites / Admin_columns_variation_name.php
Created Jan 31, 2022
Admin Columns: Add variation name to column
View Admin_columns_variation_name.php
<?php
function ac_column_value_usage( $col_value, $id, AC\Column $column ) {
if ('column-wc-product_details' == $column->get_type()) {
$order = wc_get_order( $id );
foreach ( $order->get_items() as $item_id => $item ) {
if ( $item->get_variation_id() ) {
$product = $item->get_product();
foreach ( $product->get_attributes() as $attribute => $value ) {
$name = term_exists( $value, $attribute ) ? get_term_by( 'slug', $value, $attribute )->name : $value;
$col_value = $col_value .'<br>' . $name;
@finalwebsites
finalwebsites / functions.php
Created Jul 12, 2021
reCaptacha for HTML Forms
View functions.php
<?php
function fws_enqueue_recaptcha() {
$sitekey = mysitekey';
wp_enqueue_script( 'fws-recaptcha', '//www.google.com/recaptcha/api.js?render=' . $sitekey, null, null, true );
}
add_action( 'wp_enqueue_scripts', 'oceanwp_child_enqueue_parent_style' );
@finalwebsites
finalwebsites / check-email-list.php
Created Jul 6, 2021
Check your email list with the email validation service from mailboxlayer
View check-email-list.php
<?php
set_time_limit(0);
ini_set('memory_limit', '2048M'); // if your list is very long
$api_key = 'PLACE HERE YOUR API';
$fp = fopen('emailchecked.csv', 'w');
fputcsv($fp, array('Email address', 'Valid MX', 'Valid SMTP', 'Score'));
$count = 0;
@finalwebsites
finalwebsites / wordpress-instellingen-afbeeldingen.php
Last active May 31, 2021
"Overbodige" afbeeldingsafmetingen in WordPress uitschakelen
View wordpress-instellingen-afbeeldingen.php
<?php
// disable the generation of large image sizes
function fws_disable_image_sizes($sizes) {
unset($sizes['medium_large']);
unset($sizes['1536x1536']); // 2x medium-large size
unset($sizes['2048x2048']); // 2x large size
return $sizes;
}
add_action('intermediate_image_sizes_advanced', 'fws_disable_image_sizes');
@finalwebsites
finalwebsites / form-checkout.php
Created Jan 24, 2021
WooCommerce afrekenpagina met twee kolommen voor de klant- en ordergegevens
View form-checkout.php
<?php
/**
* Checkout Form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-checkout.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@finalwebsites
finalwebsites / wp_add_modified_date_column.php
Created Dec 12, 2020
Add a modified date column to your posts & pages list in WordPress
View wp_add_modified_date_column.php
<?php
// Register Modified Date Column for both posts & pages
function modified_column_register( $columns ) {
$columns['Modified'] = __( 'Modified Date', 'show_modified_date_in_admin_lists' );
return $columns;
}
add_filter( 'manage_posts_columns', 'modified_column_register' );
add_filter( 'manage_pages_columns', 'modified_column_register' );
function modified_column_display( $column_name, $post_id ) {
@finalwebsites
finalwebsites / categories_with_childs.php
Created Aug 23, 2020
Hierarchical categories for the plugin WooCommerce Google Product feed
View categories_with_childs.php
<?php
add_filter( 'woocommerce_gpf_elements_google', function ( $elements, $product_id, $variation_id ) {
$elements['product_type'] = array_map( function ( $item ) {
if ( empty( $item->parent ) ) {
return $item->name;
}
$parent_list = array_reverse( get_ancestors( $item->term_id, 'product_cat', 'taxonomy' ) );
$parent_list = array_map( function ( $term_id ) {
$term = get_term( $term_id, 'product_cat' );
@finalwebsites
finalwebsites / cf7_recaptcha.php
Created Aug 23, 2020
Dequeue cf7 JavaScript and reCaptcha scripts and preventing them from loading everywhere.
View cf7_recaptcha.php
<?php
function my_register_cf7_js() {
// Dequeue cf7 and recaptcha scripts, preventing them from loading everywhere
add_filter( 'wpcf7_load_js', '__return_false' ); // Might as well use their filter
wp_dequeue_script( 'google-recaptcha' );
// If current post has cf7 shortcode, enqueue!
global $post;
if ( isset( $post->post_content ) AND has_shortcode( $post->post_content, 'contact-form-7' ) ) {