forked from strangerstudios/pmpro-courses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pmpro-courses.php
155 lines (135 loc) · 5.81 KB
/
pmpro-courses.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* Plugin Name: Paid Memberships Pro - Courses for Membership Add On
* Plugin URI: https://www.paidmembershipspro.com/add-ons/pmpro-courses-lms-integration/
* Description: Create courses and lessons for members. Integrates LMS plugins with Paid Memberships Pro.
* Version: 1.2.5
* Author: Paid Memberships Pro
* Author URI: https://www.paidmembershipspro.com
* Text Domain: pmpro-courses
* Domain Path: /languages
*/
defined( 'ABSPATH' ) || die( 'File cannot be accessed directly' );
define( 'PMPRO_COURSES_VERSION', '1.2.5' );
define( 'PMPRO_COURSES_DIR', dirname( __FILE__ ) );
define( 'PMPRO_COURSES_BASENAME', plugin_basename( __FILE__ ) );
// Includes.
require_once PMPRO_COURSES_DIR . '/includes/common.php';
require_once PMPRO_COURSES_DIR . '/includes/admin.php';
require_once PMPRO_COURSES_DIR . '/includes/settings.php';
require_once PMPRO_COURSES_DIR . '/includes/blocks.php';
// Modules.
function pmpro_courses_setup_modules() {
require_once PMPRO_COURSES_DIR . '/includes/modules/default.php';
$default_module = new PMPro_Courses_Module();
require_once PMPRO_COURSES_DIR . '/includes/modules/lifterlms.php';
$lifterlms_module = new PMPro_Courses_LifterLMS();
require_once PMPRO_COURSES_DIR . '/includes/modules/learndash.php';
$learndash_module = new PMPro_Courses_LearnDash();
require_once PMPRO_COURSES_DIR . '/includes/modules/senseilms.php';
$senseilms_module = new PMPro_Courses_SenseiLMS();
require_once PMPRO_COURSES_DIR . '/includes/modules/tutorlms.php';
$tutorlms_module = new PMPro_Courses_TutorLMS();
}
add_action( 'plugins_loaded', 'pmpro_courses_setup_modules' );
/**
* Default settings on first load and updates.
*/
function pmpro_courses_admin_init() {
$db_version = get_option( 'pmpro_courses_db_version', '' );
if ( $db_version < 1 ) {
// Figure out which modules to enable.
$modules = array();
// Turn on LearnDash if it's already active.
if( defined( 'LEARNDASH_VERSION' ) ) {
$modules[] = 'learndash';
}
// If no other modules are active, install our core Courses and Lessons.
if ( empty( $modules ) ) {
$modules[] = 'default';
}
update_option( 'pmpro_courses_modules', $modules );
// Save DB version.
update_option( 'pmpro_courses_db_version', 1 );
}
}
add_action( 'admin_init', 'pmpro_courses_admin_init' );
/**
* Maybe flush rewrite rules.
* Fires on admin_init 5 to run after CPTs are set up,
* but before the settings are saved.
* @since 1.0
*/
function pmpro_courses_flush_rewrite_rules() {
$flush = get_transient( 'pmpro_courses_flush_rewrite_rules' );
if ( ! empty( $flush ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
$wp_rewrite->init();
delete_transient( 'pmpro_courses_flush_rewrite_rules' );
}
}
add_action( 'admin_init', 'pmpro_courses_flush_rewrite_rules', 5 );
/**
* Tie into GlotPress
*
* @return void
*/
function pmpro_courses_load_textdomain() {
load_plugin_textdomain( 'pmpro-courses', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
add_action( 'plugins_loaded', 'pmpro_courses_load_textdomain' );
/**
* Enqueue Admin Scripts and Styles
*/
function pmpro_courses_admin_styles( $hook ) {
$editing_course = in_array( $hook, array( 'post.php', 'post-new.php' ) ) && 'pmpro_course' == get_post_type();
$on_settings_page = ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] === 'pmpro-courses-settings';
if ( $editing_course || $on_settings_page ) {
wp_enqueue_style( 'pmpro-courses-admin', plugins_url( 'css/admin.css', __FILE__ ), '', PMPRO_COURSES_VERSION, 'screen' );
wp_enqueue_style( 'pmpro-courses-select2', plugins_url( 'css/select2.css', __FILE__ ), '', PMPRO_COURSES_VERSION, 'screen' );
wp_enqueue_script( 'pmpro-courses-select2', plugins_url( 'js/select2.js', __FILE__ ), array( 'jquery' ), PMPRO_COURSES_VERSION );
wp_register_script( 'pmpro_courses', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ), null, true );
if ( ! empty( $_GET['post'] ) ) {
$post_id = intval( $_GET['post'] );
} else {
$post_id = '';
}
$localize = array(
'editing_course' => $editing_course,
'on_settings_page' => $on_settings_page,
'course_id' => $post_id,
'save' => esc_html__( 'Save', 'pmpro-courses' ),
'saving' => esc_html__( 'Saving...', 'pmpro-courses' ),
'adding' => esc_html__( 'Adding...', 'pmpro-courses' ),
'saving_error_1' => esc_html__( 'Error saving lesson [1]', 'pmpro-courses' ),
'saving_error_2' => esc_html__( 'Error saving lesson [2]', 'pmpro-courses' ),
'remove_error_1' => esc_html__( 'Error removing lesson [1]', 'pmpro-courses' ),
'remove_error_2' => esc_html__( 'Error removing lesson [2]', 'pmpro-courses' ),
'nonce' => wp_create_nonce( 'pmpro_courses_admin_nonce' )
);
wp_localize_script( 'pmpro_courses', 'pmpro_courses', $localize );
wp_enqueue_script( 'pmpro_courses' );
}
}
add_action( 'admin_enqueue_scripts', 'pmpro_courses_admin_styles' );
/**
* Enqueue Frontend Scripts and Styles
*/
function pmpro_courses_frontend_styles(){
global $post;
if(
is_singular( array( 'pmpro_course', 'pmpro_lesson' ) ) ||
( $post && has_shortcode( $post->post_content, 'pmpro_all_courses' ) ) ||
( $post && has_shortcode( $post->post_content, 'pmpro_my_courses' ) )
){
wp_enqueue_script( 'jquery' );
wp_enqueue_style( 'dashicons' );
wp_enqueue_style( 'pmpro-courses-styles', plugins_url( 'css/frontend.css', __FILE__ ) );
wp_enqueue_script( 'pmpro-courses-scripts', plugins_url( 'js/frontend.js', __FILE__ ), array( 'jquery' ) );
wp_localize_script( 'pmpro-courses-scripts', 'pmpro_courses', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
wp_enqueue_script( 'pmpro-courses-loading-bar-js', plugins_url( 'js/loading-bar.js', __FILE__ ) );
wp_enqueue_style( 'pmpro-courses-loading-bar-css', plugins_url( 'css/loading-bar.css', __FILE__ ) );
}
}
add_action( 'wp_enqueue_scripts', 'pmpro_courses_frontend_styles' );