Skip to content

Instantly share code, notes, and snippets.

View dexit's full-sized avatar
🎯
Focusing

Rihards Mantejs dexit

🎯
Focusing
View GitHub Profile
@dexit
dexit / functions.php
Created June 12, 2024 13:49 — forked from pingram3541/functions.php
Elementor Form Validation - Block non-english bots
/**
* Checks form textarea content is english to reduce spam from non-english bots
**/
function elementor_form_message_field_validation( $field, $record, $ajax_handler ) {
// Let's check the message field only
if ( empty( $field ) || empty( $field['message'] ) ) {
return;
}
// Validate content format by language
$string = $field['message'];
add_action( 'elementor/query/myonmarketpropertyquery', 'elementor_query_on_market_only' );
function elementor_query_on_market_only( $query )
{
$meta_query = $query->get('meta_query');
$new_meta_query = $meta_query;
$new_meta_query[] = array(
'key' => '_on_market',
'value' => 'yes'
@dexit
dexit / elementor-tab-close.js
Created June 12, 2024 13:49 — forked from banarsiamin/elementor-tab-close.js
How to Set the Elementor Accordion Widget Closed by Default
jQuery(document).ready(function($) {
var delay = 100; setTimeout(function() {
$('.elementor-tab-title').removeClass('elementor-active');
$('.elementor-tab-content').css('display', 'none'); }, delay);
});
<?php
/**
* @credits https://jeroensormani.com/adding-a-custom-woocommerce-product-type/
*/
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
add_action('init' , 'wc_pm_load_product_type');
function wc_pm_load_product_type() {
<?php
$posts = maybeCache('remote_posts_data', 7200, function () {
return do_remote_get('https://jsonplaceholder.typicode.com/posts/');
});
foreach ($posts as $post) {
echo "<h2>{$post->title}</h2>";
}
@dexit
dexit / shortcode.php
Created April 11, 2024 09:11 — forked from igorbenic/shortcode.php
Conditional Enqueueing of scripts in WordPress
<?php
add_action('wp_enqueue_scripts', 'enqueue_if_shortcode');
function enqueue_if_shortcode(){
global $post;
if ( $post && has_shortcode( $post->post_content, 'your_shortcode_tag' ) {
// Enqueue
}
@dexit
dexit / functions.php
Created April 11, 2024 09:10 — forked from yanknudtskov/functions.php
Apparently SearchWP/Relevanss and Elementor doesn't play well together with Elementor, Searches and post grid. This is the outline of handling searching in post_meta.
<?php
// Modify the fields to search in
add_action( 'elementor/query/searched_query', function( $query ) {
$s = get_search_query();
if ( is_search() ) {
$query->set( 'post_type', 'leverandor' );
if( strlen($s) >= 3 ) {
@dexit
dexit / functions.php
Created April 11, 2024 09:09 — forked from yanknudtskov/functions.php
WooCommerce Add Custom Fields to Products
<?php
// For variations
add_action( 'woocommerce_variation_options_pricing', 'yanco_add_custom_field_to_variations', 10, 3 );
function yanco_add_custom_field_to_variations( $loop, $variation_data, $variation ) {
woocommerce_wp_text_input( array(
'id' => 'custom_field[' . $loop . ']',
'class' => 'short',
'label' => __( 'Custom Field', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, 'custom_field', true )
@dexit
dexit / functions.php
Created April 11, 2024 09:09 — forked from yanknudtskov/functions.php
Example on how to meta query ACF repeater fields
<?php
add_shortcode( 'user_company_link', 'yanco_user_company_link' );
function yanco_user_company_link() {
if( ! is_user_logged_in() ) {
return;
}
$html = '';
@dexit
dexit / functions.php
Created April 11, 2024 09:09 — forked from yanknudtskov/functions.php
Add query string if failed login with Elementor Pro Login Form
<?php
add_action( 'wp_login_failed', 'yanco_elementor_form_login_fail' );
function yanco_elementor_form_login_fail( $username ) {
// where did the post submission come from?
$referrer = $_SERVER['HTTP_REFERER'];
// if there's a valid referrer, and it's not the default log-in screen
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {