Skip to content

Instantly share code, notes, and snippets.

View erikyo's full-sized avatar

Erik Golinelli erikyo

View GitHub Profile
@erikyo
erikyo / replacevar-script.js
Last active April 8, 2026 20:43
Adds to Yoast an additional replacement variable both in frontend and snippet preview (backend)
/* inspired from https://github.com/Yoast/wpseo-woocommerce/blob/trunk/js/src/yoastseo-woo-replacevars.js */
/* global jQuery, YoastSEO, app, globals YoastACFAnalysisConfig */
var pluginName = "additionalVariablePlugin";
var ReplaceVar = window.YoastReplaceVarPlugin && window.YoastReplaceVarPlugin.ReplaceVar;
var placeholders = {};
var modifiableFields = [
"content",
"title",
@erikyo
erikyo / wp_mail_test.php
Last active February 13, 2023 19:30
WordPress mail function test
<?php
if ( !get_transient( 'wpcf7_test_mail' ) ) {
set_transient( 'wpcf7_test_mail', 'sent', 600 ); // no more than 1 mail every 10 Minutes
add_action( 'wp_footer', 'send_test_mail' ); // execute my function on the desired hook.
add_action( 'phpmailer_init', 'phpmailer_conf' ); // tests the php mailer (not needed)
}
function send_test_mail() {
@erikyo
erikyo / cf7-abort-send-mail.js
Created June 22, 2021 21:43
contact form 7 wait before send mail and optionally abort like gmail
var delay = 2000; // set the preferred delay before send email
var interval = null; // don't touch this
jQuery(function ($) {
// displays the button in active state
function sendDisplayON(btn) {
btn.val('Abort?');
btn.addClass('submitting');
$(btn).siblings('.ajax-loader').css('visibility','visible');
@erikyo
erikyo / woo_inject_sku_into_search_query.php
Created June 25, 2021 10:17
Adds products found by sku and gtin to wp search query (WooCommerce)
<?php
/**
* Returns an array of product ids similar to the given sku / gtin
* @param $sku - the search key
* @param int $limit - maximum number of returned items
*
* @return array|bool
*/
function prefix_get_product_arr_by_sku( $sku, $limit = 10 ) {
global $wpdb;
@erikyo
erikyo / wpcf7_replace_posted_data.php
Last active January 14, 2022 13:20
Contact Form 7 - replace mail content / posted data (in this example replace the email appending the support email domain)
<?php
function prefix_replace_email( $posted_data ) {
$posted_data[ 'your-email-backup' ] = $posted_data[ 'your-email' ] ;
$posted_data[ 'your-email' ] = str_replace('@', 'A', $posted_data[ 'your-email' ]) . '@mysupport.com' ;
return $posted_data;
}
add_filter( 'wpcf7_posted_data', 'prefix_replace_email' );

CF7 TROUBLESHOOTING

Please follow this steps in order to identify the issue. Please copy and paste into forum.

Mail not sent

  • The wp_mail() function is working. Tested with (my smtp plugin|a custom function) and i'm sure i can deliver a email messages
  • The page and form have well formed html, even the form is set up with the correct "to:" and "from:" and no warnings in the cf7 backend.
  • I have disabled plugins that are not necessary for my site (if there are some you just can't disable list here)
  • I have disabled all the caching plugins (mandatory)
  • Tried to switch theme without success. (if you can't or with the default template cf7 works, you need to check your template functions that hooks to wpcf7 or wp_mail). Activating wp_debug will help you to deal with this
  • cf7 works in [ajax mode](https://contactform7.com/why-isnt-my-ajax-contact-form-working-corr
@erikyo
erikyo / woocommerce_switch_tab_via_url.php
Last active August 11, 2021 19:03 — forked from corsonr/gist:0e0a4dfaacf59fdca314
WooCommerce: activate product tabs from URL (support with history states, share link to tab with hash)
<?php
/**
* wc_direct_link_to_product_tabs
*
* Allows you to create custom URLs to activate product tabs by default, directly from the URL.
* ex: http://mysite.com/my-product-name#reviews
* this fork add history.pushState and each tab will be treated as a page
* so you can use browser history back / forward to move along tabs
*/
add_action( 'wp_footer', function () {
@erikyo
erikyo / cf7.scss
Created August 23, 2021 18:06
contact form 7 sass style
// the default palette
$wpcf7-white: #fff !default; // Blue
$wpcf7-light-gray: #505b66 !default; // Light Gray
$wpcf7-dark-gray: #23282d !default; // Dark Gray
$wpcf7-blue: #00a0d2 !default; // Blue
$wpcf7-green: #46b450 !default; // Green
$wpcf7-red: #dc3232 !default; // Red
$wpcf7-orange: #f56e28 !default; // Orange
$wpcf7-yellow: #ffb900 !default; // Yellow
@erikyo
erikyo / dequeue_gutenberg_custom_var.php
Created August 31, 2021 12:03
Dequeue global wordpress style (dequeue custom vars)
<?php
/**
* Dequeue global wordpress style
*/
if ( ! function_exists( 'my_remove_global_style' ) ) :
function my_remove_global_style() {
wp_deregister_style( 'global-styles' );
wp_dequeue_style( 'global-styles' );
}
endif;
@erikyo
erikyo / explode_accept_language.php
Last active September 12, 2021 11:34
Returns an array of 2 digit languages codes from the user $_SERVER['HTTP_ACCEPT_LANGUAGE']
<?php
// a modified version of https://stackoverflow.com/a/33748742/5735847
function get_accept_language_array( $languages ) {
return array_values(
array_reduce(
explode(',', str_replace(' ', '', $languages) ),
function ($res, $el) {
if (strlen($el) === 5) {
$l = explode('-', $el);