| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: WP All Export - User Export Add-On |
| 4 |
* Plugin URI: http://www.wpallimport.com/tour/export-wordpress-users/?utm_source=export-users-addon-free&utm_medium=wp-plugins-page&utm_campaign=upgrade-to-pro |
| 5 |
* Description: Export Users from WordPress. Requires WP All Export. |
| 6 |
* Version: 1.0.2 |
| 7 |
* Author: Soflyy |
| 8 |
* Text Domain: export-wp-users-xml-csv |
| 9 |
* License: GPL-2.0-or-later |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
/** |
| 15 |
* Plugin root dir with forward slashes as directory separator regardless of actuall DIRECTORY_SEPARATOR value |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
define('PMUE_ROOT_DIR', str_replace('\\', '/', dirname(__FILE__))); |
| 19 |
/** |
| 20 |
* Plugin root url for referencing static content |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
define('PMUE_ROOT_URL', rtrim(plugin_dir_url(__FILE__), '/')); |
| 24 |
/** |
| 25 |
* Plugin prefix for making names unique (be aware that this variable is used in conjuction with naming convention, |
| 26 |
* i.e. in order to change it one must not only modify this constant but also rename all constants, classes and functions which |
| 27 |
* names composed using this prefix) |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
define('PMUE_PREFIX', 'pmue_'); |
| 31 |
|
| 32 |
define('PMUE_VERSION', '1.0.2'); |
| 33 |
|
| 34 |
if ( class_exists('PMUE_Plugin') and PMUE_EDITION != "free"){ |
| 35 |
|
| 36 |
function pmue_notice(){ |
| 37 |
|
| 38 |
?> |
| 39 |
<div class="error"><p> |
| 40 |
<?php printf(esc_html__('Please de-activate and remove the free version of the User Add-On before activating the paid version.', 'export-wp-users-xml-csv')); |
| 41 |
?> |
| 42 |
</p></div> |
| 43 |
<?php |
| 44 |
|
| 45 |
deactivate_plugins(PMUE_ROOT_DIR . '/plugin.php'); |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
add_action('admin_notices', 'pmue_notice'); |
| 50 |
|
| 51 |
} |
| 52 |
else { |
| 53 |
|
| 54 |
define('PMUE_EDITION', 'free'); |
| 55 |
|
| 56 |
/** |
| 57 |
* Main plugin file, Introduces MVC pattern |
| 58 |
* |
| 59 |
* @singletone |
| 60 |
* @author Maksym Tsypliakov <maksym.tsypliakov@gmail.com> |
| 61 |
*/ |
| 62 |
|
| 63 |
final class PMUE_Plugin { |
| 64 |
/** |
| 65 |
* Singletone instance |
| 66 |
* @var PMUE_Plugin |
| 67 |
*/ |
| 68 |
protected static $instance; |
| 69 |
|
| 70 |
/** |
| 71 |
* Plugin root dir |
| 72 |
* @var string |
| 73 |
*/ |
| 74 |
const ROOT_DIR = PMUE_ROOT_DIR; |
| 75 |
/** |
| 76 |
* Plugin root URL |
| 77 |
* @var string |
| 78 |
*/ |
| 79 |
const ROOT_URL = PMUE_ROOT_URL; |
| 80 |
/** |
| 81 |
* Prefix used for names of shortcodes, action handlers, filter functions etc. |
| 82 |
* @var string |
| 83 |
*/ |
| 84 |
const PREFIX = PMUE_PREFIX; |
| 85 |
/** |
| 86 |
* Plugin file path |
| 87 |
* @var string |
| 88 |
*/ |
| 89 |
const FILE = __FILE__; |
| 90 |
|
| 91 |
/** |
| 92 |
* Return singletone instance |
| 93 |
* @return PMUE_Plugin |
| 94 |
*/ |
| 95 |
static public function getInstance() { |
| 96 |
if (self::$instance == NULL) { |
| 97 |
self::$instance = new self(); |
| 98 |
} |
| 99 |
return self::$instance; |
| 100 |
} |
| 101 |
|
| 102 |
static public function getEddName(){ |
| 103 |
return 'User Export Add-On'; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Common logic for requestin plugin info fields |
| 108 |
*/ |
| 109 |
public function __call($method, $args) { |
| 110 |
if (preg_match('%^get(.+)%i', $method, $mtch)) { |
| 111 |
$info = get_plugin_data(self::FILE); |
| 112 |
if (isset($info[$mtch[1]])) { |
| 113 |
return $info[$mtch[1]]; |
| 114 |
} |
| 115 |
} |
| 116 |
throw new Exception( esc_html( "Requested method " . get_class($this) . "::$method doesn't exist." ) ); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Get path to plagin dir relative to wordpress root |
| 121 |
* @param bool[optional] $noForwardSlash Whether path should be returned withot forwarding slash |
| 122 |
* @return string |
| 123 |
*/ |
| 124 |
public function getRelativePath($noForwardSlash = false) { |
| 125 |
$wp_root = str_replace('\\', '/', ABSPATH); |
| 126 |
return ($noForwardSlash ? '' : '/') . str_replace($wp_root, '', self::ROOT_DIR); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Check whether plugin is activated as network one |
| 131 |
* @return bool |
| 132 |
*/ |
| 133 |
public function isNetwork() { |
| 134 |
if ( !is_multisite() ) |
| 135 |
return false; |
| 136 |
|
| 137 |
$plugins = get_site_option('active_sitewide_plugins'); |
| 138 |
if (isset($plugins[plugin_basename(self::FILE)])) |
| 139 |
return true; |
| 140 |
|
| 141 |
return false; |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Class constructor containing dispatching logic |
| 146 |
* @param string $rootDir Plugin root dir |
| 147 |
* @param string $pluginFilePath Plugin main file |
| 148 |
*/ |
| 149 |
protected function __construct() { |
| 150 |
|
| 151 |
include_once 'src'.DIRECTORY_SEPARATOR.'Common'.DIRECTORY_SEPARATOR.'Bootstrap'.DIRECTORY_SEPARATOR.'Autoloader.php'; |
| 152 |
$autoloader = new \Pmue\Common\Bootstrap\Autoloader(self::ROOT_DIR, self::PREFIX); |
| 153 |
// create/update required database tables |
| 154 |
|
| 155 |
// register autoloading method |
| 156 |
spl_autoload_register(array($autoloader, 'autoload')); |
| 157 |
|
| 158 |
register_activation_hook(self::FILE, array($this, 'activation')); |
| 159 |
|
| 160 |
$autoloader->init(); |
| 161 |
|
| 162 |
// register admin page pre-dispatcher |
| 163 |
add_action('init', array($this, 'init')); |
| 164 |
|
| 165 |
} |
| 166 |
|
| 167 |
public function init(){ |
| 168 |
// Translations are automatically loaded by WordPress.org for hosted plugins |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Dispatch shorttag: create corresponding controller instance and call its index method |
| 173 |
* @param array $args Shortcode tag attributes |
| 174 |
* @param string $content Shortcode tag content |
| 175 |
* @param string $tag Shortcode tag name which is being dispatched |
| 176 |
* @return string |
| 177 |
*/ |
| 178 |
public function shortcodeDispatcher($args, $content, $tag) { |
| 179 |
|
| 180 |
$controllerName = self::PREFIX . preg_replace_callback('%(^|_).%', array($this, "replace_callback"), $tag);// capitalize first letters of class name parts and add prefix |
| 181 |
$controller = new $controllerName(); |
| 182 |
if ( ! $controller instanceof PMUE_Controller) { |
| 183 |
throw new Exception( esc_html( "Shortcode `$tag` matches to a wrong controller type." ) ); |
| 184 |
} |
| 185 |
ob_start(); |
| 186 |
$controller->index($args, $content); |
| 187 |
return ob_get_clean(); |
| 188 |
} |
| 189 |
|
| 190 |
public function replace_callback($matches){ |
| 191 |
return strtoupper($matches[0]); |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Plugin activation logic |
| 196 |
*/ |
| 197 |
public function activation() { |
| 198 |
// Uncaught exception doesn't prevent plugin from being activated, therefore replace it with fatal error so it does. |
| 199 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error, WordPress.Security.EscapeOutput.OutputNotEscaped -- Intentional fatal error for activation failures |
| 200 |
set_exception_handler(function($e){trigger_error($e->getMessage(), E_USER_ERROR);}); |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Method returns default import options, main utility of the method is to avoid warnings when new |
| 205 |
* option is introduced but already registered imports don't have it |
| 206 |
*/ |
| 207 |
public static function get_default_import_options() |
| 208 |
{ |
| 209 |
$importOptions = new \Pmue\Common\Bootstrap\DefaultImportOptions(); |
| 210 |
return $importOptions->getDefaultImportOptions(); |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
PMUE_Plugin::getInstance(); |
| 215 |
|
| 216 |
add_action('admin_notices', function(){ |
| 217 |
// notify user if history folder is not writable |
| 218 |
if ( ! class_exists( 'PMXE_Plugin' )) { |
| 219 |
?> |
| 220 |
<div class="error"><p> |
| 221 |
<?php |
| 222 |
echo wp_kses_post( sprintf( |
| 223 |
// translators: %s is the plugin name |
| 224 |
__('<b>%s Plugin</b>: WP All Export must be installed and activated. You can download it here <a href="https://wordpress.org/plugins/wp-all-export/" target="_blank">https://wordpress.org/plugins/wp-all-export/</a>', 'export-wp-users-xml-csv'), |
| 225 |
esc_html( PMUE_Plugin::getInstance()->getName() ) |
| 226 |
) ); |
| 227 |
?> |
| 228 |
</p></div> |
| 229 |
<?php |
| 230 |
|
| 231 |
deactivate_plugins(PMUE_ROOT_DIR . '/plugin.php'); |
| 232 |
|
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
if ( class_exists( 'PMXE_Plugin' ) && ( version_compare(PMXE_VERSION, '1.2.4') < 0 && PMXE_EDITION == 'free') ) { |
| 238 |
?> |
| 239 |
<div class="error"><p> |
| 240 |
<?php |
| 241 |
echo wp_kses_post( sprintf( |
| 242 |
// translators: %s is the plugin name |
| 243 |
__('<b>%s Plugin</b>: Please update WP All Export to the latest version', 'export-wp-users-xml-csv'), |
| 244 |
esc_html( PMUE_Plugin::getInstance()->getName() ) |
| 245 |
) ); |
| 246 |
?> |
| 247 |
</p></div> |
| 248 |
<?php |
| 249 |
|
| 250 |
deactivate_plugins(PMUE_ROOT_DIR . '/plugin.php'); |
| 251 |
} |
| 252 |
|
| 253 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin notice display |
| 254 |
$messages = isset($_GET['pmue_nt']) ? map_deep(wp_unslash($_GET['pmue_nt']), 'sanitize_text_field') : array(); |
| 255 |
if ($messages) { |
| 256 |
is_array($messages) or $messages = array($messages); |
| 257 |
foreach ($messages as $type => $m) { |
| 258 |
in_array((string)$type, array('updated', 'error')) or $type = 'updated'; |
| 259 |
?> |
| 260 |
<div class="<?php echo esc_attr($type) ?>"><p><?php echo esc_html($m) ?></p></div> |
| 261 |
<?php |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only check for menu highlighting, no data modification |
| 266 |
if ( ! empty($_GET['type']) and $_GET['type'] == 'user'){ |
| 267 |
?> |
| 268 |
<script type="text/javascript"> |
| 269 |
(function($){$(function () { |
| 270 |
$('#toplevel_page_pmxi-admin-home').find('.wp-submenu').find('li').removeClass('current'); |
| 271 |
$('#toplevel_page_pmxi-admin-home').find('.wp-submenu').find('a').removeClass('current'); |
| 272 |
$('#toplevel_page_pmxi-admin-home').find('.wp-submenu').find('li').eq(2).addClass('current').find('a').addClass('current'); |
| 273 |
});})(jQuery); |
| 274 |
</script> |
| 275 |
<?php |
| 276 |
} |
| 277 |
|
| 278 |
}); |
| 279 |
|
| 280 |
} |