This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In your wp_enqueue_scripts, just declare it when you localise your script or include it in your ajax array | |
add_action( 'wp_enqueue_scripts', 'wp_enqueue_child_scripts' ); | |
function wp_enqueue_child_scripts() { | |
// Globalize post variable to get current post data | |
global $post; | |
// Enqueue child script used | |
wp_enqueue_script( 'custom-name', get_stylesheet_directory_uri() . '/js/script.js', array( 'jquery' ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'template_redirect', 'page_redirection' ); | |
function page_redirection() { | |
global $current_user; | |
$user_id = $current_user->ID; | |
$user_info = get_userdata($user_id); | |
$user_role = $user_info->roles[0]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_enqueue_scripts', 'my_custom_enqueue' ); | |
function my_custom_enqueue() { | |
// Custom scipt | |
------------------------// | |
// Child theme's function.php | |
wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/path/to/script.js' ); | |
// In your plugin's function.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
$('.my-posts').change(function(){ | |
var post_id = $('.my-posts').val(); | |
$.ajax({ | |
url : my_ajax_object.ajaxurl, | |
type : 'post', | |
data : { | |
action : 'get_data', | |
post_id : post_id, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$new_data = array( | |
'id' => 4, | |
'name' => 'Magic', | |
'email' => 'user_email_4', | |
'birth_date' => '10-11-2019' | |
); | |
$current_data = array ( | |
array( | |
'id' => 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Number of months after/before | |
$num = 3; | |
// Months before | |
$now = new DateTime(); | |
$lastMonth = $now->sub(new DateInterval('P'. $num . 'M')); | |
// displays month/s before | |
echo $lastMonth->format('Y M'); | |
// quick and short way | |
echo date('M', strtotime("-". $num . " month")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// **** For simple array | |
// Delete value 2 in the array | |
$id = 2; | |
$simple_array = array(1, 2, 3); | |
$key = array_search($id, $array); | |
unset($array[$key]); | |
// We are expecting to remove id #2. To check: | |
print_r($array); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Uinique id to point on a certain data | |
$id = 3; | |
// New value | |
$name = 'Michael'; | |
// We are trying to change the name that matches the id | |
$array_values = array ( | |
array( | |
'id' => 1, | |
'name' => 'Kobe', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Paste html in your header | |
<div class="loader-wrap"> | |
<div class="loader-wrap-inner"> | |
<div class="loader-holder"> | |
<img src="your-loader.gif" alt="pre-loader-img" /> | |
</div> | |
</div> | |
</div> | |
// Preloader style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In this example im going to get certain fields that the user put in in the first page | |
// then make them choices on the second page | |
// You can paste this in your child's functions.php | |
add_filter('gform_pre_render_1', 'select_username_callback'); //only get data form form id 1 | |
function select_username_callback($form) { | |
// To get what page you are on | |
$current_page = GFFormDisplay::get_current_page($form["id"]); | |
if ($current_page == 2) { | |
// Get values from previous form |
OlderNewer