generated from washingtonstateuniversity/wsuwp-plugin-hrs-courses
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhrswp-sqlsrv-db.php
90 lines (81 loc) · 2.15 KB
/
hrswp-sqlsrv-db.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
<?php
/**
* Plugin Name: HRSWP Sqlsrv DB
* Version: 0.11.6
* Description: A WSU HRS WordPress plugin to connect to and query external Microsoft SQL Server databases.
* Author: Adam Turner, washingtonstateuniversity
* Author URI: https://hrs.wsu.edu/
* Plugin URI: https://github.com/washingtonstateuniversity/hrswp-plugin-sqlsrv-db
* Update URI: https://api.github.com/repos/washingtonstateuniversity/hrswp-plugin-sqlsrv-db/releases/latest
* Text Domain: hrswp-sqlsrv-db
* Requires at least: 5.0
* Tested up to: 6.5.2
* Requires PHP: 7.4
*
* @package HRSWP_Sqlsrv_DB
*/
namespace HRSWP\SQLSRV;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Activates the plugin.
*
* @since 0.11.0
*/
register_activation_hook(
__FILE__,
function (): void {
// Delete legacy option.
delete_option( 'hrswp_sqlsrv_db_plugin-status' );
}
);
// Load plugin classes.
require_once __DIR__ . '/includes/classes/class-sqlsrv-db.php';
require_once __DIR__ . '/includes/classes/class-sqlsrv-query.php';
/**
* Uninstalls the plugin.
*
* @since 0.11.0
*/
function uninstall(): void {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
// Delete plugin options.
delete_option( 'hrswp_sqlsrv_db_plugin-status' );
}
register_uninstall_hook( __FILE__, __NAMESPACE__ . '\uninstall' );
/**
* Verifies plugin dependencies.
*
* @since 0.11.0
*
* @return bool True if dependencies are met, false if not.
*/
function verify_plugin_dependencies(): bool {
// Check for the HRSWP Sqlsrv configuration file.
if (
! file_exists( ABSPATH . 'hrswp-sqlsrv-config.php' ) &&
! file_exists( dirname( ABSPATH ) . '/hrswp-sqlsrv-config.php' )
) {
return false;
}
return true;
}
add_action(
'plugins_loaded',
function (): void {
if ( ! verify_plugin_dependencies() ) {
add_action(
'admin_notices',
function (): void {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
esc_html__( 'ERROR: There doesn\'t seem to be a', 'hrswp-sqlsrv-db' ) . '<code>hrswp-sqlsrv-config.php</code>' . esc_html__( 'file. This is required for the HRSWP Sqlsrv DB plugin to work.', 'hrswp-sqlsrv-db' )
);
}
);
}
}
);