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
Created December 19, 2019 00:15
Add new tag to lessons/topics/quizzes inside LeanrDash course table which are updated within 30 days
<?php
add_action( 'learndash-lesson-row-title-after', 'learndash_add_tag_to_new_lessons', 10, 3);
function learndash_add_tag_to_new_lessons( $lesson_id, $course_id, $user_id ) {
$lesson = get_post( $lesson_id );
if ( strtotime( $lesson->post_modified ) > strtotime( '-30 days' ) ) {
echo "<span class='ld-content-new-tag'>" . __( "(New)", 'sfwd-lms' ) . "</span>";
}
}
@adeel-raza
adeel-raza / functions.php
Created September 20, 2019 13:27
Creates a custom myCRED hook to award creds on Restrict content pro subscription renewal
<?php
add_filter( 'mycred_setup_hooks', 'custom_hook_renew_rcpro_subscription' );
function custom_hook_renew_rcpro_subscription( $installed )
{
$installed['hook_rcpro_renew_subs'] = array(
'title' => __( '%_plural% for RCP Subscription renewal', 'mycred' ),
'description' => __( 'Award %_plural% when RCP subscription is renewed', 'mycred' ),
'callback' => [ 'myCRED_Hook_Rcpro_Renew' ]
);
@adeel-raza
adeel-raza / functions.php
Last active August 16, 2021 01:06
Get LearnDash next lesson link or first lesson link if course not started
function ld_next_lesson_link() {
global $post;
$course_id = learndash_get_course_id( $post );
$user = _wp_get_current_user();
if( $course_id && isset( $user->ID ) ) {
$lessons = learndash_get_lesson_list( $course_id );
if( $lessons ) {
$first_lesson = reset($lessons);
@adeel-raza
adeel-raza / .htaccess
Created July 26, 2019 15:35
Prevent image hotlinking in WordPress using .htaccess
#Prevent image hotlinking in WordPress
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourwebsite.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?facebook.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?twitter.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?other-websites-go-here.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [F]
@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