| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: AyeCode Connect |
| 4 |
* Plugin URI: https://ayecode.io/ |
| 5 |
* Description: A service plugin letting users connect AyeCode Services to their site. |
| 6 |
* Version: 1.4.22 |
| 7 |
* Author: AyeCode |
| 8 |
* Author URI: https://ayecode.io |
| 9 |
* Requires at least: 6.0 |
| 10 |
* Tested up to: 7.1 |
| 11 |
* |
| 12 |
* Text Domain: ayecode-connect |
| 13 |
* Domain Path: /languages/ |
| 14 |
* |
| 15 |
*/ |
| 16 |
|
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit; // Exit if accessed directly. |
| 19 |
} |
| 20 |
|
| 21 |
if ( !defined( 'AYECODE_CONNECT_VERSION' ) ) { |
| 22 |
define( 'AYECODE_CONNECT_VERSION', '1.4.22' ); |
| 23 |
} |
| 24 |
|
| 25 |
if ( !defined( 'AYECODE_CONNECT_SSL_VERIFY' ) ) { |
| 26 |
define( 'AYECODE_CONNECT_SSL_VERIFY', true ); |
| 27 |
} |
| 28 |
|
| 29 |
if ( !defined( 'AYECODE_CONNECT_PLUGIN_DIR' ) ) { |
| 30 |
define( 'AYECODE_CONNECT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 31 |
} |
| 32 |
|
| 33 |
add_action( 'plugins_loaded', 'ayecode_connect' ); |
| 34 |
|
| 35 |
/** |
| 36 |
* Sets up the client |
| 37 |
*/ |
| 38 |
function ayecode_connect() { |
| 39 |
global $ayecode_connect; |
| 40 |
|
| 41 |
/** |
| 42 |
* The libraries required. |
| 43 |
*/ |
| 44 |
require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload.php'; |
| 45 |
|
| 46 |
// Include the client connection class |
| 47 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ayecode-connect.php'; |
| 48 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ayecode-connect-settings.php'; |
| 49 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ayecode-connect-turnstile-settings.php'; |
| 50 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-ayecode-connect-turnstile.php'; |
| 51 |
|
| 52 |
// Prepare client args |
| 53 |
$args = ayecode_connect_args(); |
| 54 |
|
| 55 |
$ayecode_connect = new AyeCode_Connect( $args ); |
| 56 |
|
| 57 |
// Call the init method to register routes. This should be called exactly once per client (Preferably before the init hook). |
| 58 |
$ayecode_connect->init(); |
| 59 |
|
| 60 |
// Determines the current locale. |
| 61 |
$locale = determine_locale(); |
| 62 |
|
| 63 |
$locale = apply_filters( 'plugin_locale', $locale, 'ayecode-connect' ); |
| 64 |
|
| 65 |
unload_textdomain( 'ayecode-connect', true ); |
| 66 |
load_textdomain( 'ayecode-connect', WP_LANG_DIR . '/ayecode-connect/ayecode-connect-' . $locale . '.mo' ); |
| 67 |
load_plugin_textdomain( 'ayecode-connect', false, basename( dirname( __FILE__ ) ) . '/languages/' ); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* The AyeCode Connect arguments. |
| 72 |
* |
| 73 |
* @return array |
| 74 |
*/ |
| 75 |
function ayecode_connect_args() { |
| 76 |
$base_url = 'https://ayecode.io'; |
| 77 |
|
| 78 |
return array( |
| 79 |
'remote_url' => $base_url, //URL to the WP site containing the WP_Service_Provider class |
| 80 |
'connection_url' => $base_url . '/connect', //This should be a custom page the authinticates a user the calls the WP_Service_Provider::connect_site() method |
| 81 |
'api_url' => $base_url . '/wp-json/', //Might be different for you |
| 82 |
'api_namespace' => 'ayecode/v1', |
| 83 |
'local_api_namespace' => 'ayecode-connect/v1', //Should be unique for each client implementation |
| 84 |
'prefix' => 'ayecode_connect', //A unique prefix for things (accepts alphanumerics and underscores). Each client on a given site should have it's own unique prefix |
| 85 |
'textdomain' => 'ayecode-connect', |
| 86 |
'version' => AYECODE_CONNECT_VERSION, |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Add settings link to plugins page. |
| 92 |
* |
| 93 |
* @param $links |
| 94 |
* |
| 95 |
* @return mixed |
| 96 |
*/ |
| 97 |
function ayecode_connect_settings_link( $links ) { |
| 98 |
$settings_link = '<a href="admin.php?page=ayecode-connect">' . __( 'Settings','ayecode-connect' ) . '</a>'; |
| 99 |
array_push( $links, $settings_link ); |
| 100 |
return $links; |
| 101 |
} |
| 102 |
$plugin = plugin_basename( __FILE__ ); |
| 103 |
|
| 104 |
add_filter( "plugin_action_links_{$plugin}", 'ayecode_connect_settings_link' ); |
| 105 |
|
| 106 |
/** |
| 107 |
* Remove wp cron on deactivation if set. |
| 108 |
*/ |
| 109 |
register_deactivation_hook( __FILE__, 'ayecode_connect_deactivation' ); |
| 110 |
|
| 111 |
function ayecode_connect_deactivation() { |
| 112 |
$args = ayecode_connect_args(); |
| 113 |
$prefix = $args['prefix']; |
| 114 |
wp_clear_scheduled_hook( $prefix.'_callback' ); |
| 115 |
|
| 116 |
// destroy support user |
| 117 |
$support_user = get_user_by( 'login', 'ayecode_connect_support_user' ); |
| 118 |
if ( ! empty( $support_user ) && isset( $support_user->ID ) && ! empty( $support_user->ID ) ) { |
| 119 |
require_once(ABSPATH.'wp-admin/includes/user.php'); |
| 120 |
$user_id = absint($support_user->ID); |
| 121 |
// get all sessions for user with ID $user_id |
| 122 |
$sessions = WP_Session_Tokens::get_instance($user_id); |
| 123 |
// we have got the sessions, destroy them all! |
| 124 |
$sessions->destroy_all(); |
| 125 |
$reassign = user_can( 1, 'manage_options' ) ? 1 : null; |
| 126 |
wp_delete_user( $user_id, $reassign ); |
| 127 |
if ( is_multisite() ) { |
| 128 |
if ( ! function_exists( 'wpmu_delete_user' ) ) { |
| 129 |
require_once( ABSPATH . 'wp-admin/includes/ms.php' ); |
| 130 |
} |
| 131 |
revoke_super_admin( $user_id ); |
| 132 |
wpmu_delete_user( $user_id ); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
// Try to remove the must use plugin. This should fail silently even if file is missing. |
| 137 |
wp_delete_file( WPMU_PLUGIN_DIR."/ayecode-connect-filter-fix.php" ); |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Sync licenses if connected. |
| 142 |
*/ |
| 143 |
function ayecode_connect_sync_licenses() { |
| 144 |
global $ayecode_connect; |
| 145 |
|
| 146 |
if(method_exists($ayecode_connect,'sync_licences')){ |
| 147 |
$ayecode_connect->sync_licences(); |
| 148 |
} |
| 149 |
} |
| 150 |
add_action( 'ayecode_connect_sync_licenses', 'ayecode_connect_sync_licenses' ); |
| 151 |
|
| 152 |
function ayecode_connect_demo_import_redirect( $plugin ){ |
| 153 |
if ( $plugin == plugin_basename( __FILE__ ) && !empty( $_SERVER['HTTP_REFERER'] ) ) { |
| 154 |
$parts = parse_url($_SERVER['HTTP_REFERER']); |
| 155 |
|
| 156 |
if ( ! empty( $parts['query'] ) ) { |
| 157 |
parse_str( $parts['query'], $query ); |
| 158 |
} else { |
| 159 |
$query = array(); |
| 160 |
} |
| 161 |
|
| 162 |
if(!empty($query['ac-demo-import'])){ |
| 163 |
$demo = sanitize_title_with_dashes($query['ac-demo-import']); |
| 164 |
wp_redirect(admin_url( "admin.php?page=ayecode-demo-content&ac-demo-import=".esc_attr($demo) )); |
| 165 |
exit; |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
//register_activation_hook( __FILE__, 'ayecode_connect_demo_import_redirect' ); |
| 170 |
add_action( 'activated_plugin', 'ayecode_connect_demo_import_redirect' ); |