Skip to content

Instantly share code, notes, and snippets.

@nrezane
nrezane / gravityform-australianumber-checker.php
Last active October 8, 2021 10:04
Gravity form - Check field if it is an Australian mobile number
//The field I use is a single line field and not phone field. Using a custom mask since client has specific format for phone. Add to functions.php of your child theme.
//for mobile
add_filter( 'gform_field_validation_4_6', 'validate_phone', 10, 4 ); // just replace / remove _4_6 since I am targetting a specific field
function validate_phone( $result, $value, $form, $field ) {
$pattern = "/^0(4)\d{8}$/"; //regex pattern that make sure it starts with "04" and must be total of 10 numbers only.
if (!preg_match( $pattern, $value ) ) {
$result['is_valid'] = false;
$result['message'] = 'Invalid mobile number.';
@nrezane
nrezane / yoast
Created December 10, 2020 08:14 — forked from aderaaij/yoast
Wordpress - Move yoast seo boxes to bottom of post/page
// Move Yoast to bottom
function yoasttobottom() {
return 'low';
}
add_filter( 'wpseo_metabox_prio', 'yoasttobottom');
//** *Enable upload for webp image files.*/
function webp_enable_mimes($existing_mimes) {
$existing_mimes['webp'] = 'image/webp';
return $existing_mimes;
}
add_filter('mime_types', 'webp_enable_mimes');
@nrezane
nrezane / woo.php
Created June 22, 2020 13:58
Get $product woocommerce data
// Get Product ID
$product->get_id(); (fixes the error: "Notice: id was called incorrectly. Product properties should not be accessed directly")
// Get Product General Info
$product->get_type();
$product->get_name();
$product->get_slug();
$product->get_date_created();
$product->get_date_modified();
$product->get_status();
$product->get_featured();
@nrezane
nrezane / style.css
Created June 22, 2020 13:57
Child theme wordpress with easy naming
/*
Theme Name: CHILD THEME NAME
Theme URI: https://nilrezane.net
Description: CHILD THEME NAME description
Author: John Doe
Author URI: https://nilrezane.net
Template: twentyfifteen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@nrezane
nrezane / repeatershortcode.php
Created June 22, 2020 13:54
Create WordPress shortcode using ACF repeater field.
function shortcodecustom_func() {
if ( have_rows( 'tabs_section' ) ):
    while ( have_rows( 'tabs_section' ) ): the_row();
      $content .= sprintf('<div class="classhere-1">
    <div class="containerclass-1">
      <div class="row">');
      $content .= sprintf('<div class="row">
        <div class="col-md-4">
          <h2 class="display-1 text-secondary">%s</h2></div>', get_sub_field( 'section_title' ));
      $content .= sprintf( '<div class="col-md-4">
@nrezane
nrezane / functions.php
Created June 22, 2020 13:52
Hide php error in Wordpress via functions.php
//add the code to your functions.php
ini_set('log_errors','On');
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);