forked from openedx/openedx-wordpress-ecommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openedx-commerce.php
112 lines (98 loc) · 3.52 KB
/
openedx-commerce.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
<?php
/**
* Plugin Name: Open edX Commerce
* Plugin URI: https://github.com/openedx/openedx-wordpress-ecommerce
* Description: Easily connect your WooCommerce store to Open edX.
* Version: 2.0.7
* Author: Open edX Community
* Author URI: https://github.com/openedx/openedx-wordpress-ecommerce
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: openedx-commerce
* Domain Path: /languages
* Requires at least: 6.3
* Requires PHP: 8.0
*
* @package OpenedX_Commerce
*
* @wordpress-plugin
*/
use OpenedX_Commerce\Openedx_Commerce_Activator;
use OpenedX_Commerce\Openedx_Commerce_Deactivator;
use OpenedX_Commerce\Openedx_Commerce;
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'OPENEDX_COMMERCE_VERSION', '2.0.7' );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-openedx-commerce-activator.php
*/
function openedx_commerce_plugin_activate() {
include_once plugin_dir_path( __FILE__ ) . 'includes/class-openedx-commerce-activator.php';
Openedx_Commerce_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-openedx-commerce-deactivator.php
*/
function openedx_commerce_plugin_deactivate() {
include_once plugin_dir_path( __FILE__ ) . 'includes/class-openedx-commerce-deactivator.php';
Openedx_Commerce_Deactivator::deactivate();
}
/**
* Create the table for the logs on plugin activation
*/
function openedx_commerce_create_enrollment_logs_table() {
global $wpdb;
$logs_table = wp_cache_get( 'enrollment_logs_req_table', 'db' );
$logs_table_name = $wpdb->prefix . 'enrollment_logs_req_table';
if ( ! $logs_table ) {
if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $logs_table ) ) !== $logs_table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $logs_table_name (
id INT NOT NULL AUTO_INCREMENT,
post_id INT NOT NULL,
mod_date DATETIME NOT NULL,
user VARCHAR(255) NOT NULL,
action_name VARCHAR(255) NOT NULL,
object_before LONGTEXT NOT NULL,
object_after LONGTEXT NOT NULL,
object_status VARCHAR(255) NOT NULL,
api_response MEDIUMTEXT NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
}
wp_cache_set( 'enrollment_logs_req_table', $logs_table, 'db', 3600 );
}
}
register_activation_hook( __FILE__, 'openedx_commerce_plugin_activate' );
register_activation_hook( __FILE__, 'openedx_commerce_create_enrollment_logs_table' );
register_deactivation_hook( __FILE__, 'openedx_commerce_plugin_deactivate' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-openedx-commerce.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
function openedx_commerce_plugin_run() {
$plugin = new Openedx_Commerce();
$plugin->run();
}
openedx_commerce_plugin_run();