WordPress enqueue js script file in child theme — December 15, 2017

WordPress enqueue js script file in child theme

define( 'template_child_directory', dirname( get_bloginfo('stylesheet_url')));

function hermosa_child_enqueue_js() {
	wp_register_script('custom_js', template_child_directory . '/assets/js/custom.js', array( 'jquery' ),false,true);
	wp_enqueue_script( 'custom_js' );
//send any variable to script
    wp_localize_script( 'custom_js', 'custom', array(
        'ajax_url' => admin_url( 'admin-ajax.php' )
    ));
}
add_action('wp_enqueue_scripts', 'hermosa_child_enqueue_js');

For better explanation use wordpress documentation please.

Advertisements
ACF get Taxonomy Term meta — September 27, 2017
Codeigniter HMVC cross module call controller->method — September 13, 2017

Codeigniter HMVC cross module call controller->method

to call module01/controller01/method00:

//method 1 CORRECT:
$ctlObj = modules::load('module01/controller01/');
$ctlObj->method00();
//or you could use chaining:
modules::load('module01/controller01/')->method00();

//method 1 WRONG:
modules::load('module01/controller01/method00');  //this will only load contructor

---
//method 2 CORRECT:
modules::run('module01/controller01/method00');   //no trailing slash!

//method 2 WRONG:
modules::run('module01/controller01/method00/');  

---
//method 3 CORRECT:
$this->load->module('module01/controller01');
$this->controller01->method00();

if you want more information you can follow this thread.

acf_form() after form submit handler — September 4, 2017

acf_form() after form submit handler

Here is one filter which can help you

add_filter('acf/pre_save_post' , 'my_pre_save_post' );
function my_pre_save_post( $post_id ) {
    //do whatever u want to do here
    //dont forget to return $post_id
    return $post_id;
}

For better information check this link.

Also need to make it more selective otherwise this will work for all acf_forms

add_filter('acf/pre_save_post' , 'my_pre_save_post' );
function my_pre_save_post( $post_id ) {
        print_r($GLOBALS['acf_form']);	
	$current_user = wp_get_current_user();
	$user_id = $current_user->ID;
	if($GLOBALS['acf_form']['post_id'] == 'user_'.$user_id)
	{
		$GLOBALS['acf_form']['return'] = site_url().'/owners-add-new-property/?step=started';
		update_user_meta($user_id, "current_profile_step", 4);
	}
	return $post_id;
}

You can see some unique info in ‘$GLOBALS[‘acf_form’]’ which will be unique for this post request. If still u have question add comment , will try to reply :).

WordPress check if user meta exists with same value for any other user except current user —
WordPress not able to use variables in get_template_part() — September 3, 2017
WordPress Use Environment Variables for diff domains like local, staging or production — August 15, 2017

WordPress Use Environment Variables for diff domains like local, staging or production

I always use this. Put this in wp-config.php

//GET HOSTNAME INFO
$hostname = $_SERVER['SERVER_NAME']; 

//VERIFY WHICH ENVIRONMENT THE APP IS RUNNING
switch ($hostname) {
    case 'site.dev':
        define('WP_ENV', 'local');
        break;
    case 'staging.site.com':
        define('WP_ENV', 'staging');
        break;
    case 'site.com':
        define('WP_ENV', 'production');
        break;
    default:
        define('WP_ENV', 'local');
}