-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstawp-connect.php
157 lines (128 loc) · 6.35 KB
/
instawp-connect.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
156
<?php
/**
* @link https://instawp.com/
* @since 0.0.1
* @package instawp
*
* @wordpress-plugin
* Plugin Name: InstaWP Connect
* Description: 1-click WordPress plugin for Staging, Migrations, Management, Sync and Companion plugin for InstaWP.
* Version: 0.1.0.80
* Author: InstaWP Team
* Author URI: https://instawp.com/
* License: GPL-3.0+
* License URI: http://www.gnu.org/copyleft/gpl.html
* Text Domain: instawp-connect
* Domain Path: /languages
*/
use InstaWP\Connect\Helpers\Curl;
use InstaWP\Connect\Helpers\Helper;
use InstaWP\Connect\Helpers\Option;
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
global $wpdb;
defined( 'INSTAWP_PLUGIN_VERSION' ) || define( 'INSTAWP_PLUGIN_VERSION', '0.1.0.80' );
defined( 'INSTAWP_API_DOMAIN_PROD' ) || define( 'INSTAWP_API_DOMAIN_PROD', 'https://app.instawp.io' );
$wp_plugin_url = WP_PLUGIN_URL . '/' . plugin_basename( __DIR__ ) . '/';
$parsed_site_url = wp_parse_url( site_url() );
if ( isset( $parsed_site_url['scheme'] ) && strtolower( $parsed_site_url['scheme'] ) === 'http' ) {
$is_protocol_https = ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) || ( ! empty( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] === 443 );
if ( ! $is_protocol_https ) {
$is_protocol_https = ( ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && strtolower( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) ) === 'https' );
}
if ( $is_protocol_https ) {
$wp_plugin_url = str_replace( 'http://', 'https://', $wp_plugin_url );
}
}
defined( 'INSTAWP_PLUGIN_URL' ) || define( 'INSTAWP_PLUGIN_URL', $wp_plugin_url );
defined( 'INSTAWP_PLUGIN_DIR' ) || define( 'INSTAWP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
defined( 'INSTAWP_PLUGIN_FILE' ) || define( 'INSTAWP_PLUGIN_FILE', plugin_basename( __FILE__ ) );
defined( 'INSTAWP_DEFAULT_BACKUP_DIR' ) || define( 'INSTAWP_DEFAULT_BACKUP_DIR', 'instawpbackups' );
defined( 'INSTAWP_BACKUP_DIR' ) || define( 'INSTAWP_BACKUP_DIR', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . INSTAWP_DEFAULT_BACKUP_DIR . DIRECTORY_SEPARATOR );
defined( 'INSTAWP_DOCS_URL_PLUGIN' ) || define( 'INSTAWP_DOCS_URL_PLUGIN', esc_url( 'https://instawp.to/docs/plugin-errors' ) );
defined( 'INSTAWP_PLUGIN_SLUG' ) || define( 'INSTAWP_PLUGIN_SLUG', 'instawp-connect' );
defined( 'INSTAWP_PLUGIN_NAME' ) || define( 'INSTAWP_PLUGIN_NAME', plugin_basename( __FILE__ ) );
defined( 'INSTAWP_DB_TABLE_EVENTS' ) || define( 'INSTAWP_DB_TABLE_EVENTS', $wpdb->prefix . 'instawp_events' );
defined( 'INSTAWP_DB_TABLE_SYNC_HISTORY' ) || define( 'INSTAWP_DB_TABLE_SYNC_HISTORY', $wpdb->prefix . 'instawp_sync_history' );
defined( 'INSTAWP_DB_TABLE_EVENT_SITES' ) || define( 'INSTAWP_DB_TABLE_EVENT_SITES', $wpdb->prefix . 'instawp_event_sites' );
defined( 'INSTAWP_DB_TABLE_EVENT_SYNC_LOGS' ) || define( 'INSTAWP_DB_TABLE_EVENT_SYNC_LOGS', $wpdb->prefix . 'instawp_event_sync_logs' );
defined( 'INSTAWP_DB_TABLE_ACTIVITY_LOGS' ) || define( 'INSTAWP_DB_TABLE_ACTIVITY_LOGS', $wpdb->prefix . 'instawp_activity_logs' );
defined( 'INSTAWP_DEFAULT_MAX_FILE_SIZE_ALLOWED' ) || define( 'INSTAWP_DEFAULT_MAX_FILE_SIZE_ALLOWED', 50 );
defined( 'INSTAWP_EVENTS_SYNC_PER_PAGE' ) || define( 'INSTAWP_EVENTS_SYNC_PER_PAGE', 5 );
defined( 'INSTAWP_API_URL' ) || define( 'INSTAWP_API_URL', '/api/v1' );
defined( 'INSTAWP_CONNECT_PLAN_ID' ) || define( 'INSTAWP_CONNECT_PLAN_ID', 1 );
defined( 'INSTAWP_CONNECT_PLAN_EXPIRE_DAYS' ) || define( 'INSTAWP_CONNECT_PLAN_EXPIRE_DAYS', 0 );
/**
* @global instaWP $instawp_plugin
*/
global $instawp_plugin;
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/class-instawp.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/functions.php';
function instawp_plugin_activate() {
InstaWP_Tools::instawp_reset_permalink();
do_action( 'instawp_prepare_large_files_list' );
//set default user for sync settings if user empty
$default_user = Option::get_option( 'instawp_default_user' );
if ( empty( $default_user ) ) {
Option::update_option( 'instawp_default_user', get_current_user_id() );
}
$instawp_sync_tab_roles = Option::get_option( 'instawp_sync_tab_roles' );
if ( empty( $instawp_sync_tab_roles ) ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
Option::update_option( 'instawp_sync_tab_roles', $roles );
}
$connect_id = instawp_get_connect_id();
if ( ! empty( $connect_id ) ) {
$response = Curl::do_curl( "connects/{$connect_id}/restore", array( 'url' => Helper::wp_site_url() ) );
if ( empty( $response['success'] ) ) {
Option::delete_option( 'instawp_api_options' );
}
}
$default_plan_id = INSTAWP_CONNECT_PLAN_ID;
$default_plan_expire_days = INSTAWP_CONNECT_PLAN_EXPIRE_DAYS;
if ( defined( 'CONNECT_WHITELABEL' ) && CONNECT_WHITELABEL && defined( 'CONNECT_WHITELABEL_PLAN_DETAILS' ) && is_array( CONNECT_WHITELABEL_PLAN_DETAILS ) ) {
$default_plan = array_filter( CONNECT_WHITELABEL_PLAN_DETAILS, function ( $plan ) {
return $plan['default'] === true;
} );
if ( ! empty( $default_plan ) ) {
$default_plan_id = $default_plan[0]['plan_id'];
$default_plan_expire_days = $default_plan[0]['trial'];
}
}
Option::update_option( 'instawp_connect_plan_id', $default_plan_id );
Option::update_option( 'instawp_connect_plan_expire_days', $default_plan_expire_days );
}
/*Deactivate Hook Handle*/
function instawp_plugin_deactivate() {
InstaWP_Tools::instawp_reset_permalink();
Option::delete_option( 'instawp_last_heartbeat_sent' );
$connect_id = instawp_get_connect_id();
if ( ! empty( $connect_id ) ) {
Curl::do_curl( "connects/{$connect_id}/delete", array(), array(), 'DELETE' );
}
}
register_activation_hook( __FILE__, 'instawp_plugin_activate' );
register_deactivation_hook( __FILE__, 'instawp_plugin_deactivate' );
/**
* 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
*/
if ( isset( $instawp_plugin ) && is_a( $instawp_plugin, 'instaWP' ) ) {
return;
}
function run_instawp() {
$instawp_plugin = new instaWP();
$GLOBALS['instawp_plugin'] = $instawp_plugin;
$GLOBALS['instawp'] = $instawp_plugin;
}
add_filter( 'got_rewrite', '__return_true' );
run_instawp();