| 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 |
function iwp_is_pro_disabled() |
| 17 |
{ |
| 18 |
return defined('IWP_PRO_VERSION') && version_compare(IWP_PRO_VERSION, IWP_CORE_MIN_PRO_VERSION, '<'); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* When updating ImportWP errors can arrise if the pro version has a different codebase |
| 23 |
* |
| 24 |
* Disable PRO functionality and alert user to reason. |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
function iwp_has_required_version_of_pro() |
| 29 |
{ |
| 30 |
if (iwp_is_pro_disabled()) { |
| 31 |
remove_action('plugins_loaded', 'iwp_pro_loaded'); |
| 32 |
|
| 33 |
// Display compatability message |
| 34 |
$message = '<strong>Import WP v' . IWP_VERSION . '</strong> requires <strong>Import WP PRO v' . IWP_CORE_MIN_PRO_VERSION . ' or greater</strong>, Download the lastest version of Import WP Pro or Rollback Import WP to a compatable version.'; |
| 35 |
add_action('admin_notices', function () use ($message) { |
| 36 |
|
| 37 |
global $pagenow; |
| 38 |
|
| 39 |
if (!in_array($pagenow, ['plugins.php', 'update-core.php', 'index.php'])) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
echo '<div class="notice notice-error is-dismissible"> |
| 44 |
<p>' . $message . '</p> |
| 45 |
</div>'; |
| 46 |
}); |
| 47 |
|
| 48 |
// display error message after plugin row |
| 49 |
$upgrade_mesasge = function () use ($message) { |
| 50 |
?> |
| 51 |
<tr class="iwp-upgrade-row-error iwp-invalid"> |
| 52 |
<td colspan="4"><?= $message; ?></td> |
| 53 |
</tr> |
| 54 |
<style> |
| 55 |
.iwp-upgrade-row-error td { |
| 56 |
-webkit-box-shadow: 0px -1px 0 rgba(255, 255, 255, 0.1), |
| 57 |
inset 0 -1px 0 rgba(0, 0, 0, 0.1); |
| 58 |
box-shadow: 0px -1px 0 rgba(255, 255, 255, 0.1), |
| 59 |
inset 0 -1px 0 rgba(0, 0, 0, 0.1); |
| 60 |
border-left: 4px solid #ffb900; |
| 61 |
background-color: #fff8e5; |
| 62 |
} |
| 63 |
|
| 64 |
.iwp-upgrade-row-error.iwp-invalid td { |
| 65 |
border-left: 4px solid #dc3232; |
| 66 |
background-color: #fef1f1; |
| 67 |
} |
| 68 |
|
| 69 |
.iwp-upgrade-row-error.iwp-valid td { |
| 70 |
border-left: 4px solid #00a0d2; |
| 71 |
background-color: #f7fcfe; |
| 72 |
} |
| 73 |
</style> |
| 74 |
<?php |
| 75 |
}; |
| 76 |
add_action('after_plugin_row_' . plugin_basename(dirname(__FILE__) . '/importwp-pro.php'), $upgrade_mesasge); |
| 77 |
add_action('after_plugin_row_' . plugin_basename(dirname(__FILE__) . '/jc-importer.php'), $upgrade_mesasge); |
| 78 |
|
| 79 |
add_filter('iwp/frontent/notices', function ($notices) use ($message) { |
| 80 |
$notices[] = ['type' => 'error', 'message' => strip_tags($message)]; |
| 81 |
return $notices; |
| 82 |
}); |
| 83 |
} |
| 84 |
} |
| 85 |
add_action('plugins_loaded', 'iwp_has_required_version_of_pro', 0); |
| 86 |
|
| 87 |
function iwp_loaded() |
| 88 |
{ |
| 89 |
if (function_exists('import_wp_pro') && !iwp_is_pro_disabled()) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
if (function_exists('import_wp')) { |
| 94 |
import_wp(); |
| 95 |
} |
| 96 |
} |
| 97 |
add_action('plugins_loaded', 'iwp_loaded'); |
| 98 |
|
| 99 |
/** |
| 100 |
* Register IWP Addon |
| 101 |
* |
| 102 |
* @param string $name |
| 103 |
* @param string $id |
| 104 |
* @param callable(AddonInterface) $callback |
| 105 |
* |
| 106 |
* @return ImportWP\Common\Addon\AddonInterface |
| 107 |
*/ |
| 108 |
function iwp_register_importer_addon($name, $id, $callback) |
| 109 |
{ |
| 110 |
return new ImportWP\Common\Addon\AddonBase($name, $id, $callback); |
| 111 |
} |
| 112 |
|