Skip to content

Instantly share code, notes, and snippets.

@adeel-raza
adeel-raza / functions.php
Created Dec 19, 2019
Add new tag to lessons/topics/quizzes inside LeanrDash course table which are updated within 30 days
View functions.php
<?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>";
}
}
@davewarfel
davewarfel / default-wordpress-blocks-sass.scss
Last active Jul 9, 2021
WordPress Blocks Styles - Cleaned Up, Commented & Sassified
View default-wordpress-blocks-sass.scss
/**
* WordPress Blocks
*
* Default block styling included with WordPress core.
* Provides a better starting point for WordPress theme developers,
* especially when using Sass.
*
* @link https://github.com/WordPress/WordPress/blob/master/wp-includes/css/dist/block-library/style.css
*
* Most styles from the above file are included.
@slushman
slushman / customizer-links.php
Last active Aug 30, 2021
How to link into the WordPress Customizer
View customizer-links.php
@devinsays
devinsays / tracking.js
Created Dec 21, 2015
Track JetPack Shares in Google Analytics
View tracking.js
/**
* Javacript for loading custom Google Analytics events
*
* @since 1.0.0
*/
(function($) {
// GA Docs for Social Interactions:
// https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions
@devinsays
devinsays / redirect-admin.php
Last active Feb 7, 2021
Redirects subscribers back to the home page if they attempt to access the dashboard.
View redirect-admin.php
<?php
/**
* Redirects subscribers back to the home page if they attempt to access the dashboard.
*/
function prefix_redirect_admin() {
if ( ! current_user_can( 'edit_posts' ) && ! defined( 'DOING_AJAX' ) ) {
wp_safe_redirect( home_url() );
exit;
}
}
@devinsays
devinsays / hide-admin-bar.php
Last active Feb 7, 2021
Disables the #wpadmin bar for users without "edit_posts" permissions.
View hide-admin-bar.php
<?php
/**
* Disables the #wpadmin bar for users without "edit_posts" permissions.
*/
function prefix_hide_admin_bar() {
if ( ! current_user_can( 'edit_posts' ) ) {
add_filter( 'show_admin_bar', '__return_false' );
}
}
add_action( 'after_setup_theme', 'prefix_hide_admin_bar' );
@devinsays
devinsays / authenticate-by-email.php
Last active Jan 4, 2016
Allows visitors to log in using e-mail address
View authenticate-by-email.php
<?php
/**
* Allows visitors to log in using e-mail address
*
* @param string username passed by reference
*/
function prefix_authenticate_by_email( &$username ) {
$user = get_user_by( 'email', $username );
View shortcode.css
.wp-video, video.wp-video-shortcode, .mejs-container, .mejs-overlay.load {
width: 100% !important;
height: 100% !important;
}
.mejs-container {
padding-top: 56.25%;
}
.wp-video, video.wp-video-shortcode {
max-width: 100% !important;
}
View gist:70fbf836b4254175429e
<?php
/**
* Generate the CSS in the <head> section using the Theme Customizer
* @since 0.1
*/
add_action('generate_head_css','generate_your_css');
if ( !function_exists( 'generate_your_css' ) ) :
function generate_advanced_css()
{
$your_option = get_option( 'your_saved_db_entry' );
@WebEndevSnippets
WebEndevSnippets / functions.php
Created Mar 3, 2014
Gravity Forms: Auto login to site after GF User Registration Form Submittal
View functions.php
add_action( 'gform_user_registered','we_autologin_gfregistration', 10, 4 );
/**
* Auto login to site after GF User Registration Form Submittal
*
*/
function we_autologin_gfregistration( $user_id, $config, $entry, $password ) {
wp_set_auth_cookie( $user_id, false, '' );
}