Skip to content

Instantly share code, notes, and snippets.

`
### wp-core ###
version: 6.7.1
site_language: en_US
user_language: en_US
timezone: America/Indiana/Indianapolis
permalink: /%postname%/
https_status: true
multisite: false
@Anshu-wwc
Anshu-wwc / learnpress-enroll-status.php
Created August 30, 2022 06:06 — forked from wpacademy/learnpress-enroll-status.php
Check if user has enrolled into any course at your LearnPress website.
<?php
/*
* Function to check if given user is enrolled into any course.
*/
function wpac_check_enrolled_user($user_id){
if (is_numeric($user_id)) {
//Global WordPress DB object
global $wpdb;
<?php
$certs = LLMS()->certificates(); // our certs class
$cert_id = 123; // this should be the WP Post ID of the certificate you created on the admin panel via LLMS
$related_post_id = 456; // this is really for record keeping only at the moment
// should be the WP post id of the course, lesson, or section which
// the student has completed to earn the certificate
$students = new WP_User_Query(); // get your students however you see fit
if ( ! empty( $students->results ) ) {
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
* Engagments Class
*
* Finds and triggers the appropriate engagement
*/
class LLMS_Engagements {
<?php
add_action( 'init', 'my_manual_achievement' );
function my_manual_achievement() {
$user_id = 123; // WP User ID of the user you want to award an achievement to
$achievement_id = 456; // WP Post ID of the LifterLMS Achievement Post you want to award to the user
$post_id = 5202; // The Releated WP Post ID that triggered the awarding of this achievement. This could be a Course, Lesson, Section, or Quiz ID
$achievements = LLMS()->achievements();
$achievements->trigger_engagement( $user_id, $achievement_id, $post_id );
<?php
function my_llms_builder_custom_fields( $fields ) {
$fields['lesson']['my_custom_group'] = array(
// Optional field group title
'title' => __( 'My Custom Field Group', 'my-text-domain' ),
// if the group can be toggled open/closed
'toggleable' => true,
<?php // don't copy this line to your functions.php file!
/**
* Add custom dashboard tabs / urls to the dashboard navigation
* @param array $tabs existing tabs
* @return array
*/
function my_custom_dashboard_tabs( $tabs ) {
// save the signout tab
$signout = $tabs['signout'];
<?php // Do not copy this line
// Copy from under this line and paste into your child theme's functions.php
add_filter( 'llms_certificate_merge_codes', 'llms_certificate_grade_merge_code', 10, 2 );
function llms_certificate_grade_merge_code( $merge_codes_array, $certificate_object ) {
// add custom certificate title merge code to existing ones. See https://github.com/gocodebox/lifterlms/blob/a1a6833c6e6bab57bf4356739463220e51f89408/includes/certificates/class.llms.certificate.user.php#L132
<?php // Do not copy this line
// copy from below this line
/**
* Generates sequential serial numbers for a given post type
*/
class LLMS_Serial_Number_Generator {
private $post_type = '';
@Anshu-wwc
Anshu-wwc / update-start-end-time-learnpress.php
Last active March 30, 2022 03:53
Update Course/Lesson Start/End Time Learnpress
<?php
$user_id = !empty( $_POST['user_id']) ? $_POST['user_id']: '';
$course_id = !empty( $_POST['course_id'] ) ? $_POST['course_id'] : '';
$complete_date = !empty( $_POST['com_date'] ) ? $_POST['com_date'] : '';
// change date format
$com_date = DateTime::createFromFormat('Y-m-d\TH:i:s', $complete_date);
$dt = $com_date->format('Y-m-d H:i:s');