| 1 |
<?php |
| 2 |
|
| 3 |
function import_wp() |
| 4 |
{ |
| 5 |
global $iwp; |
| 6 |
|
| 7 |
if (!is_null($iwp)) { |
| 8 |
return $iwp; |
| 9 |
} |
| 10 |
|
| 11 |
$iwp = new ImportWP\Free\ImportWPFree(); |
| 12 |
$iwp->register(); |
| 13 |
return $iwp; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* @return \ImportWP\ImportWP |
| 18 |
*/ |
| 19 |
function iwp() |
| 20 |
{ |
| 21 |
global $iwp; |
| 22 |
return $iwp; |
| 23 |
} |
| 24 |
|
| 25 |
function iwp_is_pro_disabled() |
| 26 |
{ |
| 27 |
return defined('IWP_PRO_VERSION') && version_compare(IWP_PRO_VERSION, IWP_CORE_MIN_PRO_VERSION, '<'); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* When updating ImportWP errors can arrise if the pro version has a different codebase |
| 32 |
* |
| 33 |
* Disable PRO functionality and alert user to reason. |
| 34 |
* |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
function iwp_has_required_version_of_pro() |
| 38 |
{ |
| 39 |
if (iwp_is_pro_disabled()) { |
| 40 |
remove_action('plugins_loaded', 'iwp_pro_loaded'); |
| 41 |
|
| 42 |
// Display compatability message |
| 43 |
$message = sprintf(__('ImportWP v%s requires ImportWP PRO v%s or greater, Download the lastest version of Import WP Pro or Rollback Import WP to a compatable version.', 'jc-importer'), IWP_VERSION, IWP_CORE_MIN_PRO_VERSION); |
| 44 |
add_action('admin_notices', function () use ($message) { |
| 45 |
|
| 46 |
global $pagenow; |
| 47 |
|
| 48 |
if (!in_array($pagenow, ['plugins.php', 'update-core.php', 'index.php'])) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
echo '<div class="notice notice-error is-dismissible"> |
| 53 |
<p>' . $message . '</p> |
| 54 |
</div>'; |
| 55 |
}); |
| 56 |
|
| 57 |
// display error message after plugin row |
| 58 |
$upgrade_mesasge = function () use ($message) { |
| 59 |
?> |
| 60 |
<tr class="iwp-upgrade-row-error iwp-invalid"> |
| 61 |
<td colspan="4"><?= $message; ?></td> |
| 62 |
</tr> |
| 63 |
<style> |
| 64 |
.iwp-upgrade-row-error td { |
| 65 |
-webkit-box-shadow: 0px -1px 0 rgba(255, 255, 255, 0.1), |
| 66 |
inset 0 -1px 0 rgba(0, 0, 0, 0.1); |
| 67 |
box-shadow: 0px -1px 0 rgba(255, 255, 255, 0.1), |
| 68 |
inset 0 -1px 0 rgba(0, 0, 0, 0.1); |
| 69 |
border-left: 4px solid #ffb900; |
| 70 |
background-color: #fff8e5; |
| 71 |
} |
| 72 |
|
| 73 |
.iwp-upgrade-row-error.iwp-invalid td { |
| 74 |
border-left: 4px solid #dc3232; |
| 75 |
background-color: #fef1f1; |
| 76 |
} |
| 77 |
|
| 78 |
.iwp-upgrade-row-error.iwp-valid td { |
| 79 |
border-left: 4px solid #00a0d2; |
| 80 |
background-color: #f7fcfe; |
| 81 |
} |
| 82 |
</style> |
| 83 |
<?php |
| 84 |
}; |
| 85 |
add_action('after_plugin_row_' . plugin_basename(dirname(__FILE__) . '/importwp-pro.php'), $upgrade_mesasge); |
| 86 |
add_action('after_plugin_row_' . plugin_basename(dirname(__FILE__) . '/jc-importer.php'), $upgrade_mesasge); |
| 87 |
|
| 88 |
add_filter('iwp/frontent/notices', function ($notices) use ($message) { |
| 89 |
$notices[] = ['type' => 'error', 'message' => strip_tags($message)]; |
| 90 |
return $notices; |
| 91 |
}); |
| 92 |
} |
| 93 |
} |
| 94 |
add_action('plugins_loaded', 'iwp_has_required_version_of_pro', 0); |
| 95 |
|
| 96 |
|
| 97 |
function iwp_check_installed_plugins() |
| 98 |
{ |
| 99 |
|
| 100 |
// Check and disable loading of zip archive plugin |
| 101 |
if (function_exists('iwp_zip_archive_setup') && has_filter('plugins_loaded', 'iwp_zip_archive_setup')) { |
| 102 |
remove_action('plugins_loaded', 'iwp_zip_archive_setup', 9); |
| 103 |
|
| 104 |
$upgrade_mesasge = function () { |
| 105 |
?> |
| 106 |
<tr class="iwp-zip-remove-row-error iwp-invalid"> |
| 107 |
<td colspan="4"><?php _e('Import WP - Zip Archive Importer Addon is now included in ImportWP, please deactivate and remove this plugin.', 'jc-importer'); ?></td> |
| 108 |
</tr> |
| 109 |
<style> |
| 110 |
.iwp-zip-remove-row-error td { |
| 111 |
-webkit-box-shadow: 0px -1px 0 rgba(255, 255, 255, 0.1), |
| 112 |
inset 0 -1px 0 rgba(0, 0, 0, 0.1); |
| 113 |
box-shadow: 0px -1px 0 rgba(255, 255, 255, 0.1), |
| 114 |
inset 0 -1px 0 rgba(0, 0, 0, 0.1); |
| 115 |
border-left: 4px solid #ffb900; |
| 116 |
background-color: #fff8e5; |
| 117 |
} |
| 118 |
|
| 119 |
.iwp-zip-remove-row-error.iwp-invalid td { |
| 120 |
border-left: 4px solid #dc3232; |
| 121 |
background-color: #fef1f1; |
| 122 |
} |
| 123 |
|
| 124 |
.iwp-zip-remove-row-error.iwp-valid td { |
| 125 |
border-left: 4px solid #00a0d2; |
| 126 |
background-color: #f7fcfe; |
| 127 |
} |
| 128 |
</style> |
| 129 |
<?php |
| 130 |
}; |
| 131 |
add_action('after_plugin_row_importwp-zip-archive/zip-archive.php', $upgrade_mesasge); |
| 132 |
} |
| 133 |
} |
| 134 |
add_action('plugins_loaded', 'iwp_check_installed_plugins', 0); |
| 135 |
|
| 136 |
function iwp_loaded() |
| 137 |
{ |
| 138 |
if (function_exists('import_wp_pro') && !iwp_is_pro_disabled()) { |
| 139 |
return; |
| 140 |
} |
| 141 |
|
| 142 |
if (function_exists('import_wp')) { |
| 143 |
import_wp(); |
| 144 |
} |
| 145 |
} |
| 146 |
add_action('plugins_loaded', 'iwp_loaded'); |
| 147 |
|
| 148 |
/** |
| 149 |
* Register IWP Addon |
| 150 |
* |
| 151 |
* @param string $name |
| 152 |
* @param string $id |
| 153 |
* @param callable(AddonInterface) $callback |
| 154 |
* @deprecated 2.14.0 |
| 155 |
* |
| 156 |
* @return ImportWP\Common\Addon\AddonInterface |
| 157 |
*/ |
| 158 |
function iwp_register_importer_addon($name, $id, $callback) |
| 159 |
{ |
| 160 |
return new ImportWP\Common\Addon\AddonBase($name, $id, $callback); |
| 161 |
} |
| 162 |
|
| 163 |
function iwp_register_muplugin_uninstall() |
| 164 |
{ |
| 165 |
do_action('iwp/compat/register_muplugin_uninstall'); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
add_action('init', function () { |
| 170 |
load_plugin_textdomain('jc-importer', false, basename(dirname(__FILE__)) . '/languages/'); |
| 171 |
}); |
| 172 |
|