-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmstore-api.php
More file actions
176 lines (149 loc) · 5.74 KB
/
mstore-api.php
File metadata and controls
176 lines (149 loc) · 5.74 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
* Plugin Name: Mstore API
* Plugin URI: https://github.com/inspireui/mstore-api
* Description: The MStore API Plugin which is used for the Mstore and FluxStore App
* Version: 1.4.0
* Author: InspireUI
* Author URI: http://inspireui.com
*
* Text Domain: MStore-Api
*/
defined('ABSPATH') or wp_die( 'No script kiddies please!' );
// use MStoreCheckout\Templates\MDetect;
include plugin_dir_path(__FILE__)."templates/class-mobile-detect.php";
include plugin_dir_path(__FILE__)."templates/class-rename-generate.php";
class MstoreCheckOut
{
public $version = '1.4.0';
public function __construct()
{
define('MSTORE_CHECKOUT_VERSION', $this->version);
define('MSTORE_PLUGIN_FILE', __FILE__);
include_once (ABSPATH . 'wp-admin/includes/plugin.php');
if (is_plugin_active('woocommerce/woocommerce.php') == false) {
return 0;
}
$path = get_template_directory()."/templates";
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
$templatePath = plugin_dir_path(__FILE__)."templates/mstore-api-template.php";
if (!copy($templatePath,$path."/mstore-api-template.php")) {
return 0;
}
$order = filter_has_var(INPUT_GET, 'order') && strlen(filter_input(INPUT_GET, 'order')) > 0 ? true : false;
if ($order) {
add_filter('woocommerce_is_checkout', '__return_true');
}
include_once plugin_dir_path(__FILE__)."controllers/MstoreDokan.php";
include_once plugin_dir_path(__FILE__)."controllers/MstoreHome.php";
/* Checkout Template*/
// require_once('templates/class-page-templater.php');
// add_action('plugins_loaded', array('PageTemplater', 'get_instance'));
// require_once __DIR__ . '/wp-templater/src/Templater.php';
// require_once __DIR__ . '/templates/class-mobile-detect.php';
add_action('wp_print_scripts', array($this, 'handle_received_order_page'));
}
public function handle_received_order_page()
{
// default return true for getting checkout library working
if (is_order_received_page()) {
$detect = new MDetect;
if ($detect->isMobile()) {
wp_register_style('mstore-order-custom-style', plugins_url('assets/css/mstore-order-style.css', MSTORE_PLUGIN_FILE));
wp_enqueue_style('mstore-order-custom-style');
}
}
}
}
$mstoreCheckOut = new MstoreCheckOut();
// use JO\Module\Templater\Templater;
include plugin_dir_path(__FILE__)."wp-templater/src/Templater.php";
add_action('plugins_loaded', 'load_mstore_templater');
function load_mstore_templater()
{
// add our new custom templates
$my_templater = new Templater(
array(
// YOUR_PLUGIN_DIR or plugin_dir_path(__FILE__)
'plugin_directory' => plugin_dir_path(__FILE__),
// should end with _ > prefix_
'plugin_prefix' => 'plugin_prefix_',
// templates directory inside your plugin
'plugin_template_directory' => 'templates',
)
);
$my_templater->add(
array(
'page' => array(
'mstore-api-template.php' => 'Page Custom Template',
),
)
)->register();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Define for the API User wrapper which is based on json api user plugin
///////////////////////////////////////////////////////////////////////////////////////////////////
if (!is_plugin_active('json-api/json-api.php') && !is_plugin_active('json-api-master/json-api.php')) {
// add_action('admin_notices', 'pim_draw_notice_json_api');
return;
}
add_filter('json_api_controllers', 'registerJsonApiController');
add_filter('json_api_mstore_user_controller_path', 'setMstoreUserControllerPath');
add_action('init', 'json_apiCheckAuthCookie', 100);
add_action( 'rest_api_init', 'my_register_route' );
function my_register_route() {
register_rest_route( 'order', 'verify', array(
'methods' => 'GET',
'callback' => 'check_payment'
)
);
}
function check_payment() {
return true;
}
add_action('admin_menu', 'mstore_plugin_setup_menu');
function mstore_plugin_setup_menu(){
add_menu_page( 'MStore Api', 'MStore Api', 'manage_options', 'mstore-plugin', 'mstore_init' );
}
function mstore_init(){
load_template( dirname( __FILE__ ) . '/templates/mstore-api-admin-page.php' );
}
function registerJsonApiController($aControllers)
{
$aControllers[] = 'Mstore_User';
return $aControllers;
}
function setMstoreUserControllerPath()
{
return plugin_dir_path(__FILE__) . '/controllers/MstoreUser.php';
}
function json_apiCheckAuthCookie()
{
global $json_api;
if ($json_api->query->cookie) {
$user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in');
if ($user_id) {
$user = get_userdata($user_id);
wp_set_current_user($user->ID, $user->user_login);
}
}
add_checkout_page();
}
function add_checkout_page() {
$page = get_page_by_title('Mstore Checkout');
if($page == null || strpos($page->post_name,"mstore-checkout") === false || $page->post_status != "publish") {
$my_post = array(
'post_type' => 'page',
'post_name' => 'mstore-checkout',
'post_title' => 'Mstore Checkout',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page'
);
// Insert the post into the database
$page_id = wp_insert_post( $my_post );
update_post_meta( $page_id, '_wp_page_template', 'templates/mstore-api-template.php' );
}
}