| 1 |
<?php |
| 2 |
/** |
| 3 |
* PropertyHive Updates |
| 4 |
* |
| 5 |
* Functions for updating data during an update. |
| 6 |
* |
| 7 |
* @author PropertyHive |
| 8 |
* @category Core |
| 9 |
* @package PropertyHive/Functions |
| 10 |
* @version 1.0.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
|
| 15 |
/** |
| 16 |
* Update on_market_change_dates for 1.4.68 |
| 17 |
* |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
function propertyhive_update_1468_on_market_change_dates() { |
| 21 |
global $wpdb; |
| 22 |
|
| 23 |
$args = array( |
| 24 |
'post_type' => 'property', |
| 25 |
'fields' => 'ids', |
| 26 |
'post_status' => 'publish', |
| 27 |
'meta_query' => array( |
| 28 |
array( |
| 29 |
'key' => '_on_market', |
| 30 |
'value' => 'yes' |
| 31 |
), |
| 32 |
array( |
| 33 |
'key' => '_on_market_change_date', |
| 34 |
'compare' => 'NOT EXISTS' |
| 35 |
) |
| 36 |
), |
| 37 |
'nopaging' => true, |
| 38 |
'suppress_filters' => true, |
| 39 |
); |
| 40 |
$property_query = new WP_Query($args); |
| 41 |
|
| 42 |
if ( $property_query->have_posts() ) |
| 43 |
{ |
| 44 |
while ( $property_query->have_posts() ) |
| 45 |
{ |
| 46 |
$property_query->the_post(); |
| 47 |
|
| 48 |
$date_post_written = get_the_date( 'Y-m-d H:i:s' ); |
| 49 |
add_post_meta( get_the_ID(), '_on_market_change_date', $date_post_written ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
wp_reset_postdata(); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Record the fact we've updated to version 2 from an older version and which add ons were installed at the time of update |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
function propertyhive_update_200_pre_pro_record_installed_plugins() |
| 62 |
{ |
| 63 |
$installed_plugins = array(); |
| 64 |
|
| 65 |
$features = get_ph_pro_features(); |
| 66 |
|
| 67 |
foreach ( $features as $feature ) |
| 68 |
{ |
| 69 |
$slug = explode("/", $feature['wordpress_plugin_file']); |
| 70 |
$slug = $slug[0]; |
| 71 |
|
| 72 |
if ( is_dir( WP_PLUGIN_DIR . '/' . $slug ) ) |
| 73 |
{ |
| 74 |
$installed_plugins[] = array( |
| 75 |
'slug' => $slug, |
| 76 |
'plugin' => $feature['wordpress_plugin_file'] |
| 77 |
); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
update_option( 'propertyhive_pre_pro_add_ons', $installed_plugins ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Deactivate Template Assistant add on after moving it's functionality into core |
| 86 |
* |
| 87 |
* @return void |
| 88 |
*/ |
| 89 |
function propertyhive_deactivate_template_assistant() |
| 90 |
{ |
| 91 |
if ( ! function_exists( 'is_plugin_active' ) ) |
| 92 |
{ |
| 93 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 94 |
} |
| 95 |
|
| 96 |
$ta_plugin = 'propertyhive-template-assistant/propertyhive-template-assistant.php'; |
| 97 |
|
| 98 |
// Single site. |
| 99 |
if ( ! is_multisite() ) |
| 100 |
{ |
| 101 |
if ( is_plugin_active( $ta_plugin ) ) |
| 102 |
{ |
| 103 |
deactivate_plugins( $ta_plugin, true, false ); |
| 104 |
|
| 105 |
$auto_deactivated = get_option( 'propertyhive_template_assistant_auto_deactivated', null ); |
| 106 |
|
| 107 |
if ( null === $auto_deactivated ) |
| 108 |
{ |
| 109 |
update_option( |
| 110 |
'propertyhive_template_assistant_auto_deactivated', |
| 111 |
current_time( 'mysql' ), |
| 112 |
false |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
$existing_ta_settings = get_option( 'propertyhive_template_assistant', null ); |
| 117 |
$existing_ta_settings_backup = get_option( 'propertyhive_template_assistant_backup', null ); |
| 118 |
|
| 119 |
if ( null !== $existing_ta_settings && null === $existing_ta_settings_backup ) |
| 120 |
{ |
| 121 |
update_option( |
| 122 |
'propertyhive_template_assistant_backup', |
| 123 |
array( |
| 124 |
'backed_up_at' => current_time( 'mysql' ), |
| 125 |
'settings' => $existing_ta_settings, |
| 126 |
), |
| 127 |
false |
| 128 |
); |
| 129 |
} |
| 130 |
} |
| 131 |
else |
| 132 |
{ |
| 133 |
// TA plugin not active. Take backup of settings if exists and empty current settings |
| 134 |
$existing_ta_settings = get_option( 'propertyhive_template_assistant', null ); |
| 135 |
$existing_ta_settings_backup = get_option( 'propertyhive_template_assistant_backup', null ); |
| 136 |
|
| 137 |
if ( null !== $existing_ta_settings && null === $existing_ta_settings_backup ) |
| 138 |
{ |
| 139 |
update_option( |
| 140 |
'propertyhive_template_assistant_backup', |
| 141 |
array( |
| 142 |
'backed_up_at' => current_time( 'mysql' ), |
| 143 |
'settings' => $existing_ta_settings, |
| 144 |
), |
| 145 |
false |
| 146 |
); |
| 147 |
|
| 148 |
delete_option( 'propertyhive_template_assistant' ); |
| 149 |
} |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
return; |
| 154 |
} |
| 155 |
|
| 156 |
$was_network_active = false; |
| 157 |
|
| 158 |
// Multisite: handle network-active first. |
| 159 |
if ( is_plugin_active_for_network( $ta_plugin ) ) |
| 160 |
{ |
| 161 |
$was_network_active = true; |
| 162 |
|
| 163 |
deactivate_plugins( $ta_plugin, true, true ); |
| 164 |
|
| 165 |
$auto_deactivated = get_site_option( 'propertyhive_template_assistant_auto_deactivated', null ); |
| 166 |
|
| 167 |
if ( null === $auto_deactivated ) |
| 168 |
{ |
| 169 |
update_site_option( |
| 170 |
'propertyhive_template_assistant_auto_deactivated', |
| 171 |
current_time( 'mysql' ) |
| 172 |
); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
// Multisite: handle each site individually. |
| 177 |
$sites = get_sites( |
| 178 |
array( |
| 179 |
'fields' => 'ids', |
| 180 |
'number' => 0, |
| 181 |
) |
| 182 |
); |
| 183 |
|
| 184 |
foreach ( $sites as $blog_id ) |
| 185 |
{ |
| 186 |
switch_to_blog( $blog_id ); |
| 187 |
|
| 188 |
if ( $was_network_active || is_plugin_active( $ta_plugin ) ) |
| 189 |
{ |
| 190 |
deactivate_plugins( $ta_plugin, true, false ); |
| 191 |
|
| 192 |
$auto_deactivated = get_option( 'propertyhive_template_assistant_auto_deactivated', null ); |
| 193 |
|
| 194 |
if ( null === $auto_deactivated ) |
| 195 |
{ |
| 196 |
update_option( |
| 197 |
'propertyhive_template_assistant_auto_deactivated', |
| 198 |
current_time( 'mysql' ), |
| 199 |
false |
| 200 |
); |
| 201 |
} |
| 202 |
|
| 203 |
$existing_ta_settings = get_option( 'propertyhive_template_assistant', null ); |
| 204 |
$existing_ta_settings_backup = get_option( 'propertyhive_template_assistant_backup', null ); |
| 205 |
|
| 206 |
if ( null !== $existing_ta_settings && null === $existing_ta_settings_backup ) { |
| 207 |
update_option( |
| 208 |
'propertyhive_template_assistant_backup', |
| 209 |
array( |
| 210 |
'backed_up_at' => current_time( 'mysql' ), |
| 211 |
'settings' => $existing_ta_settings, |
| 212 |
), |
| 213 |
false |
| 214 |
); |
| 215 |
} |
| 216 |
} |
| 217 |
else |
| 218 |
{ |
| 219 |
// TA plugin not active. Take backup of settings if exists and empty current settings |
| 220 |
$existing_ta_settings = get_option( 'propertyhive_template_assistant', null ); |
| 221 |
$existing_ta_settings_backup = get_option( 'propertyhive_template_assistant_backup', null ); |
| 222 |
|
| 223 |
if ( null !== $existing_ta_settings && null === $existing_ta_settings_backup ) |
| 224 |
{ |
| 225 |
update_option( |
| 226 |
'propertyhive_template_assistant_backup', |
| 227 |
array( |
| 228 |
'backed_up_at' => current_time( 'mysql' ), |
| 229 |
'settings' => $existing_ta_settings, |
| 230 |
), |
| 231 |
false |
| 232 |
); |
| 233 |
|
| 234 |
delete_option( 'propertyhive_template_assistant' ); |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
restore_current_blog(); |
| 239 |
} |
| 240 |
} |