Skip to content

Instantly share code, notes, and snippets.

View adeel-raza's full-sized avatar

Adeel adeel-raza

View GitHub Profile
@adeel-raza
adeel-raza / functions.php
Last active July 11, 2019 03:26
Show content based on LearnDash course type
// Show content conditionally based on course type
add_shortcode( 'ld_display_course_content', 'ld_shortcode_display_course_content' );
function ld_shortcode_display_course_content( $atts , $content = null ) {
global $post;
if( is_admin() || !$post || !$post->post_type == 'sfwd-courses' || !isset( $atts['course_type'] ) ) {
return;
}
$course_meta = get_post_meta($post->ID, '_sfwd-courses', true);
@adeel-raza
adeel-raza / functions.php
Last active March 14, 2024 04:47
Personalize content for specific WordPress or LearnDash users using WordPress Shortcode
// Show personalized content to students
add_shortcode( 'sv_personalize', 'nt_student_specific_content' );
function nt_student_specific_content( $atts , $content = null ) {
if( !isset( $atts['values'] ) ) {
return $content;
}
$atts['values'] = preg_replace('/\s*,\s*/', ',', $atts['values']);
@adeel-raza
adeel-raza / run-multiple-redis-instances.md
Last active November 16, 2018 13:12 — forked from jarvys/run-multiple-redis-instances.md
run multiple redis instances on the same server for centos
  • create a new redis .conf file
$ cp /etc/redis.conf /etc/redis-xxx.conf
  • edit /etc/redis-xxx.conf, illustrated as below
...
@adeel-raza
adeel-raza / gist:6f2a2dcf6a338c4db97c0867cfff363d
Created November 2, 2018 12:29 — forked from sabarasaba/gist:1387550
Setting a timeout for the file_get_contents function
<?php
// Create the stream context
$context = stream_context_create(array(
'http' => array(
'timeout' => 3 // Timeout in seconds
)
));
// Fetch the URL's contents
$fileName = 'Billing-Summary.csv';
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$fileName}");
header("Expires: 0");
header("Pragma: public");
$fh = @fopen( 'php://output', 'w' );
@adeel-raza
adeel-raza / wp_mail_smtp.php
Created May 13, 2017 13:23 — forked from butlerblog/wp_config.php
Configure WordPress wp_mail function to send through SMTP server http://b.utler.co/Y3
/**
* This function will connect wp_mail to your authenticated
* SMTP server. This improves reliability of wp_mail, and
* avoids many potential problems.
*
* Author: Chad Butler
* Author URI: http://butlerblog.com
*
* For more information and instructions, see:
* http://b.utler.co/Y3
@adeel-raza
adeel-raza / date-comparison.php
Created May 13, 2017 08:05
Compare 2 dates and find the difference in days between them
<?php
$match_date = \DateTime::createFromFormat("Y-m-d H:i:s", $date_1);
$match_date->setTime( 0, 0, 0 ); // reset time part, to prevent partial comparison
$today = new \DateTime(); // This object represents current date/time
$today->setTime( 0, 0, 0 ); // reset time part, to prevent partial comparison
$diff = $today->diff( $match_date );
$diffDays = (integer)$diff->format( "%R%a" ); // Extract days count in interval
@adeel-raza
adeel-raza / parse-csv-as-associate-array.php
Created May 5, 2017 09:57
Parse a CSV as an associate array with column names as keys and row as values
$csv = array_map("str_getcsv", file("file1.csv",FILE_SKIP_EMPTY_LINES));
$keys = array_shift($csv);
foreach ($csv as $i=>$row) {
$csv[$i] = array_combine($keys, $row);
}
@adeel-raza
adeel-raza / textbox-range-limit.js
Created April 6, 2017 15:35
Limit the range of a numeric textbox with Jquery
jQuery("#textbox_id").on("keypress", function(e){
var currentChar = parseInt(String.fromCharCode(e.keyCode), 10);
if(!isNaN(currentChar)){
var nextValue = elem.val() + currentChar; //It's a string concatenation, not an addition
if(parseInt(nextValue, 10) <= 20) return true;
}
return false;
});
@adeel-raza
adeel-raza / check-if-on-backend-in-WP.php
Created October 19, 2016 15:23
Load content based on the condition that whether its the WP backend or frontend
<?php
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
// run Backend only code here
} else {
// Frontend code here, this will include the ajax calls
}