| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: AppMySite |
| 4 |
* Plugin URI: https://www.appmysite.com |
| 5 |
* Description: This plugin enables WordPress & WooCommerce users to sync their websites with native iOS and Android apps, created on <a href="https://www.appmysite.com/"><strong>www.appmysite.com</strong></a> |
| 6 |
* Version: 3.15.4 |
| 7 |
* Author: AppMySite |
| 8 |
* Text Domain: appmysite |
| 9 |
* Author URI: https://www.appmysite.com |
| 10 |
* Requires PHP: 7.4 |
| 11 |
* Tested up to: 7.0 |
| 12 |
* WC tested up to: 10.7.0 |
| 13 |
* WC requires at least: 7.4 |
| 14 |
* License: GPL v2 or later |
| 15 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 16 |
**/ |
| 17 |
|
| 18 |
// If this file is called directly, abort. |
| 19 |
if ( ! defined( 'WPINC' ) ) { |
| 20 |
die( 'No script kiddies please!' ); |
| 21 |
} |
| 22 |
|
| 23 |
if ( ! defined( 'AMS_PLUGIN_DIR' ) ) { |
| 24 |
define( 'AMS_PLUGIN_DIR', __FILE__ ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Returns the slug of an installed default WordPress theme, or null if none. |
| 29 |
* |
| 30 |
* @return string|null |
| 31 |
*/ |
| 32 |
function ams_get_default_theme_slug() { |
| 33 |
if ( defined( 'WP_DEFAULT_THEME' ) ) { |
| 34 |
$default_theme = wp_get_theme( WP_DEFAULT_THEME ); |
| 35 |
if ( $default_theme->exists() ) { |
| 36 |
return WP_DEFAULT_THEME; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
$fallback_slugs = array( |
| 41 |
'twentytwentyfive', |
| 42 |
'twentytwentyfour', |
| 43 |
'twentytwentythree', |
| 44 |
'twentytwentytwo', |
| 45 |
'twentytwentyone', |
| 46 |
'twentytwenty', |
| 47 |
'twentynineteen', |
| 48 |
'twentyeighteen', |
| 49 |
'twentyseventeen', |
| 50 |
'twentysixteen', |
| 51 |
'twentyfifteen', |
| 52 |
'twentyfourteen', |
| 53 |
'twentythirteen', |
| 54 |
'twentytwelve', |
| 55 |
'twentyeleven', |
| 56 |
'twentyten', |
| 57 |
); |
| 58 |
|
| 59 |
$themes = wp_get_themes(); |
| 60 |
foreach ( $fallback_slugs as $slug ) { |
| 61 |
if ( array_key_exists( $slug, $themes ) ) { |
| 62 |
return $slug; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
return null; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Whether a default WordPress theme is available for safe mode. |
| 71 |
* |
| 72 |
* @return bool |
| 73 |
*/ |
| 74 |
function ams_has_default_theme() { |
| 75 |
return null !== ams_get_default_theme_slug(); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Current safe mode value from wp-config, or off when not defined. |
| 80 |
* |
| 81 |
* @return string 'on' or 'off' |
| 82 |
*/ |
| 83 |
function ams_get_safe_mode_value() { |
| 84 |
if ( defined( 'AMS_SAFE_MODE' ) ) { |
| 85 |
return AMS_SAFE_MODE; |
| 86 |
} |
| 87 |
|
| 88 |
return 'off'; |
| 89 |
} |
| 90 |
|
| 91 |
/******************************************************************************* |
| 92 |
* Show warning to all where WordPress version is below minimum requirement. |
| 93 |
*/ |
| 94 |
|
| 95 |
global $wp_version; |
| 96 |
if ( $wp_version <= 4.9 ) { |
| 97 |
function wo_incompatibility_with_wp_version() { |
| 98 |
?> |
| 99 |
<div class="notice notice-error"> |
| 100 |
<p><?php esc_html_e( 'AppMySite requires that WordPress 4.9 or greater be used. Update to the latest WordPress version.', 'appmysite' ); ?> |
| 101 |
<a href="<?php echo esc_url( admin_url( 'update-core.php' ) ); ?>"><?php esc_html_e( 'Update Now', 'appmysite' ); ?></a></p> |
| 102 |
</div> |
| 103 |
<?php |
| 104 |
} |
| 105 |
|
| 106 |
add_action( 'admin_notices', 'wo_incompatibility_with_wp_version' ); |
| 107 |
} |
| 108 |
|
| 109 |
register_activation_hook(__FILE__, 'ams_activate'); |
| 110 |
register_deactivation_hook(__FILE__, 'ams_deactivate'); |
| 111 |
|
| 112 |
//load |
| 113 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 114 |
// Include the main AMS_Rest_Routes class. |
| 115 |
if ( ! class_exists( 'AMS_Rest_Routes', false ) ) { |
| 116 |
include_once dirname( AMS_PLUGIN_DIR ) . '/includes/class-ams-rest-routes.php'; |
| 117 |
new AMS_Rest_Routes(); |
| 118 |
} |
| 119 |
|
| 120 |
// Include the main AMS_Register_Rest_Fields class. |
| 121 |
if ( ! class_exists( 'AMS_Register_Rest_Fields', false ) ) { |
| 122 |
include_once dirname( AMS_PLUGIN_DIR ) . '/includes/class-ams-rest-register-fields.php'; |
| 123 |
new AMS_Register_Rest_Fields(); |
| 124 |
} |
| 125 |
|
| 126 |
// Include the main AMS_Filters class. |
| 127 |
if ( ! class_exists( 'AMS_Filters', false ) ) { |
| 128 |
include_once dirname( AMS_PLUGIN_DIR ) . '/includes/class-ams-filters.php'; |
| 129 |
new AMS_Filters(); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
// Include the main AMS_Admin_Functions class. |
| 134 |
if ( ! class_exists( 'AMS_Admin_Functions', false ) ) { |
| 135 |
include_once dirname( AMS_PLUGIN_DIR ) . '/includes/class-ams-admin-functions.php'; |
| 136 |
new AMS_Admin_Functions(); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
// Include the main AMS_Admin_Scripts class. |
| 141 |
if ( ! class_exists( 'AMS_Admin_Scripts', false ) ) { |
| 142 |
include_once dirname( AMS_PLUGIN_DIR ) . '/includes/class-ams-admin-scripts.php'; |
| 143 |
new AMS_Admin_Scripts(); |
| 144 |
} |
| 145 |
|
| 146 |
add_action( 'before_woocommerce_init', function() { |
| 147 |
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { |
| 148 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); |
| 149 |
} |
| 150 |
} ); |
| 151 |
|
| 152 |
function ams_activate() |
| 153 |
{ |
| 154 |
// This plugin works by the somewhat hidden feature of WordPress called MU-plugins (that's short for 'must use', not the old abbreviation for multisite). |
| 155 |
// So basically we'll make sure the folder exists and copy a file to that folder. |
| 156 |
|
| 157 |
/* |
| 158 |
if(!file_exists(WP_CONTENT_DIR . '/mu-plugins/')) |
| 159 |
@mkdir(WP_CONTENT_DIR . '/mu-plugins/'); |
| 160 |
|
| 161 |
if(file_exists(WP_CONTENT_DIR . '/mu-plugins/safe-mode-loader.php')) |
| 162 |
@unlink(WP_CONTENT_DIR . '/mu-plugins/safe-mode-loader.php'); |
| 163 |
|
| 164 |
if(file_exists(WP_PLUGIN_DIR . '/' . plugin_basename(dirname(__FILE__)) . '/includes/safe-mode-loader.php')) |
| 165 |
@copy(WP_PLUGIN_DIR . '/' . plugin_basename(dirname(__FILE__)) . '/includes/safe-mode-loader.php', WP_CONTENT_DIR . '/mu-plugins/safe-mode-loader.php'); |
| 166 |
*/ |
| 167 |
try { |
| 168 |
$config_transformer = new WPConfigTransformer( get_config_path() ); |
| 169 |
//initialize AMS_SAFE_MODE with default off. |
| 170 |
$config_transformer->update( 'constant', 'AMS_SAFE_MODE', "off", array( 'normalize' => true ) ); //'raw' => true |
| 171 |
|
| 172 |
} catch ( \Exception $e ) { |
| 173 |
$messsage = 'Unable to update AMS_SAFE_MODE in wp-config. ' . $e->getMessage(); |
| 174 |
wp_die( esc_html( $messsage ) ); |
| 175 |
} |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
function ams_deactivate() |
| 180 |
{ |
| 181 |
try { |
| 182 |
$config_transformer = new WPConfigTransformer( get_config_path() ); |
| 183 |
|
| 184 |
if ( $config_transformer->exists( 'constant', 'AMS_SAFE_MODE' ) ) { |
| 185 |
// update constant |
| 186 |
$config_transformer->remove( 'constant', 'AMS_SAFE_MODE', array( 'normalize' => true ) ); //'raw' => true |
| 187 |
} |
| 188 |
|
| 189 |
} catch ( \Exception $e ) { |
| 190 |
$messsage = 'Unable to update AMS_SAFE_MODE in wp-config. - ' . $e->getMessage(); |
| 191 |
wp_die( esc_html( $messsage ) ); |
| 192 |
} |
| 193 |
if(file_exists(WP_CONTENT_DIR . '/mu-plugins/safe-mode-loader.php')) |
| 194 |
@unlink(WP_CONTENT_DIR . '/mu-plugins/safe-mode-loader.php'); |
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
function get_config_path() { |
| 199 |
$config_path = ABSPATH . 'wp-config.php'; |
| 200 |
|
| 201 |
if ( ! file_exists( $config_path ) ) { |
| 202 |
if ( @file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! @file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) { |
| 203 |
$config_path = dirname( ABSPATH ) . '/wp-config.php'; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
return apply_filters( 'wp_debugging_config_path', $config_path ); |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|