-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtutor-lms-migration-tool.php
152 lines (125 loc) · 3.49 KB
/
tutor-lms-migration-tool.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
<?php
/**
* Plugin Name: Tutor LMS - Migration Tool
* Plugin URI: https://www.themeum.com/
* Description: A migration toolkit that allows you to migrate data from other LMS platforms to Tutor LMS.
* Author: Themeum
* Version: 2.2.1
* Author URI: http://themeum.com
* Requires at least: 5.3
* Tested up to: 6.6
* Requires PHP: 7.4
* License: GPLv2 or later
* Text Domain: tutor-lms-migration-tool
*
* @package TutorLMSMigrationTool
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require 'classes/Dependency.php';
use TutorLMSMigrationTool\TLMT\Dependency;
/**
* Defining Constant
*
* @since v.1.0.0
*/
define( 'TLMT_VERSION', '2.2.1' );
define( 'TLMT_FILE', __FILE__ );
define( 'TLMT_PATH', plugin_dir_path( TLMT_FILE ) );
define( 'TLMT_URL', plugin_dir_url( TLMT_FILE ) );
define( 'TLMT_BASENAME', plugin_basename( TLMT_FILE ) );
define( 'TLMT_PLUGIN_NAME', 'Tutor LMS - Migration Tool' );
define( 'TLMT_TUTOR_CORE_REQ_VERSION', '2.0.10' );
define( 'TLMT_TUTOR_CORE_LATEST_VERSION', 'v2.0.10' );
register_activation_hook( __FILE__, 'tutor_migration_tool_activate' );
/**
* On plugin activation
*
* @return void
*/
function tutor_migration_tool_activate() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$schema = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}tutor_migration` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`migration_type` varchar(48) NOT NULL DEFAULT '',
`migration_vendor` varchar(48) NOT NULL DEFAULT '',
`created_by` bigint(20) unsigned NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) $charset_collate";
if ( ! function_exists( 'dbDelta' ) ) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
}
dbDelta( $schema );
}
/**
* On plugin uninstall
*
* @return void
*/
function tutor_migration_tool_deleted() {
global $wpdb;
$table_name = $wpdb->prefix . 'tutor_migration';
$query = "DROP TABLE IF EXISTS {$table_name}";
$wpdb->query( $query ); //phpcs:ignore
}
register_uninstall_hook( __FILE__, 'tutor_migration_tool_deleted' );
if ( ! class_exists( 'TutorLMSMigrationTool' ) ) {
$dependency = new Dependency();
if ( ! $dependency->is_tutor_core_has_req_verion() ) {
add_action( 'admin_notices', array( $dependency, 'show_admin_notice' ) );
return;
}
include_once 'classes/TutorLMSMigrationTool.php';
TutorLMSMigrationTool::instance();
}
if ( is_plugin_active( 'tutor/tutor.php' ) ) {
$utils = new Utils();
// Migrate Learndash Instructor to Tutor Instructor.
$ld_migration_history = $utils->fetch_history( 'ld' );
if ( count( $ld_migration_history ) ) {
add_action(
'wp_login',
function( $user_login, $user ) {
// We want $user.
if ( in_array( 'wdm_instructor', $user->roles ) ) {
$user->set_role( 'tutor_instructor' );
}
},
10,
2
);
}
// Migrate Learnpress Instructor to Tutor Instructor.
$lp_migration_history = $utils->fetch_history( 'lp' );
if ( count( $lp_migration_history ) ) {
add_action(
'wp_login',
function( $user_login, $user ) {
// We want $user.
if ( in_array( 'lp_teacher', $user->roles ) ) {
$user->set_role( 'tutor_instructor' );
}
},
10,
2
);
}
// Migrate Lifter Instructor to Tutor Instructor.
$lifter_migration_history = $utils->fetch_history( 'lif' );
if ( count( $lifter_migration_history ) ) {
add_action(
'wp_login',
function( $user_login, $user ) {
// We want $user .
if ( in_array( 'instructor', $user->roles ) ) {
$user->set_role( 'tutor_instructor' );
}
},
10,
2
);
}
}