| 1 |
<?php |
| 2 |
/** |
| 3 |
* PropertyHive Features Settings |
| 4 |
* |
| 5 |
* @author PropertyHive |
| 6 |
* @category Admin |
| 7 |
* @package PropertyHive/Admin |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly |
| 13 |
} |
| 14 |
|
| 15 |
if ( ! class_exists( 'PH_Settings_Features' ) ) : |
| 16 |
|
| 17 |
/** |
| 18 |
* PH_Settings_Features |
| 19 |
*/ |
| 20 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Settings_Features; preserving the existing PH_* class name is required for plugin and extension compatibility. |
| 21 |
class PH_Settings_Features extends PH_Settings_Page { |
| 22 |
|
| 23 |
/** |
| 24 |
* Constructor. |
| 25 |
*/ |
| 26 |
public function __construct() { |
| 27 |
$this->id = 'features'; |
| 28 |
$this->label = __( 'Features', 'propertyhive' ); |
| 29 |
|
| 30 |
add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
| 31 |
add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) ); |
| 32 |
add_action( 'propertyhive_admin_field_pro_features', array( $this, 'pro_features_setting' ) ); |
| 33 |
} |
| 34 |
|
| 35 |
public function get_settings() { |
| 36 |
|
| 37 |
$settings = array( |
| 38 |
|
| 39 |
array( 'title' => __( 'Active Features', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'pro_active_features_settings' ) |
| 40 |
|
| 41 |
); |
| 42 |
|
| 43 |
$settings[] = array( |
| 44 |
'type' => 'pro_features', |
| 45 |
); |
| 46 |
|
| 47 |
$settings[] = array( 'type' => 'sectionend', 'id' => 'pro_active_features_settings'); |
| 48 |
|
| 49 |
return $settings; |
| 50 |
} |
| 51 |
|
| 52 |
public function pro_features_setting() |
| 53 |
{ |
| 54 |
$features = get_ph_pro_features(); |
| 55 |
|
| 56 |
echo '<div class="pro-feature-settings">'; |
| 57 |
|
| 58 |
// filters |
| 59 |
$categories = array( |
| 60 |
'' => 'All', |
| 61 |
'import' => 'Property Import', |
| 62 |
'export' => 'Portal Feeds', |
| 63 |
'website' => 'Website Tools', |
| 64 |
'crm' => 'CRM Tools', |
| 65 |
'data-bridges' => 'Data Bridges', |
| 66 |
'free' => 'Free', |
| 67 |
); |
| 68 |
|
| 69 |
// Read-only category selection: no settings are changed by this query parameter. |
| 70 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Publicly linkable display filter only; no state mutation. |
| 71 |
$requested_category = isset( $_GET['profilter'] ) && is_string( $_GET['profilter'] ) ? sanitize_text_field( wp_unslash( $_GET['profilter'] ) ) : ''; |
| 72 |
$selected_category = array_key_exists( $requested_category, $categories ) ? $requested_category : ''; |
| 73 |
|
| 74 |
echo '<div class="pro-filters">'; |
| 75 |
echo '<ul>'; |
| 76 |
$i = 0; |
| 77 |
foreach ( $categories as $key => $value ) |
| 78 |
{ |
| 79 |
echo '<li ' . ( $selected_category == $key ? ' class="active"' : '' ) . '><a href="" data-filter="' . esc_attr($key) . '">' . esc_html($value) . '</a></li>'; |
| 80 |
++$i; |
| 81 |
} |
| 82 |
echo '</ul>'; |
| 83 |
echo '</div>'; |
| 84 |
|
| 85 |
// Check if AI Property Search is in list. If not, it can't have been launched yet and to show promo instead |
| 86 |
/*$ai_property_search_found = false; |
| 87 |
foreach ( $features as $feature ) |
| 88 |
{ |
| 89 |
$slug = explode("/", $feature['wordpress_plugin_file']); |
| 90 |
$slug = $slug[0]; |
| 91 |
|
| 92 |
if ( strpos($slug, 'propertyhive-ai-property-search') !== false ) |
| 93 |
{ |
| 94 |
$ai_property_search_found = true; |
| 95 |
break; |
| 96 |
} |
| 97 |
}*/ |
| 98 |
|
| 99 |
// list of features |
| 100 |
echo '<div class="pro-features">'; |
| 101 |
echo '<ul>'; |
| 102 |
$i = 0; |
| 103 |
foreach ( $features as $feature ) |
| 104 |
{ |
| 105 |
/*if ( $i == 0 && $ai_property_search_found === false ) |
| 106 |
{ |
| 107 |
// Show ad |
| 108 |
$feature_status = false; |
| 109 |
|
| 110 |
if ( is_dir( WP_PLUGIN_DIR . '/' . $slug ) ) |
| 111 |
{ |
| 112 |
$feature_status = 'installed'; |
| 113 |
} |
| 114 |
if ( is_plugin_active( $feature['wordpress_plugin_file'] ) ) |
| 115 |
{ |
| 116 |
$feature_status = 'active'; |
| 117 |
} |
| 118 |
|
| 119 |
echo '<li style="visibility:hidden" class="website"> |
| 120 |
<div class="inner" style="background:#0c2442; color:#FFF"> |
| 121 |
<h3><img src="' . esc_url(PH()->plugin_url() . '/assets/images/admin/settings/ai-property-search.png') . '" style="height:28px;" alt="AI Property Search - Coming Soon"></h3>'; |
| 122 |
|
| 123 |
$links = array(); |
| 124 |
|
| 125 |
$links[] = '<span style="color:#999;" class="help_tip" data-tip="' . esc_attr( __('Integrate with ai-property-search.com and add natural language search to your website.', 'propertyhive') ) . '"><span class="dashicons dashicons-info-outline"></span></span>'; |
| 126 |
|
| 127 |
$links[] = '<a href="https://ai-property-search.com/?src=plugin-feature-settings" target="_blank" style="text-decoration:none; color:#FFF;">' . esc_html(__( 'Coming Soon', 'propertyhive' )) . '</a>'; |
| 128 |
|
| 129 |
$links[] = '<a href="https://ai-property-search.com/?src=plugin-feature-settings" target="_blank" style="text-decoration:none; color:#FFF;">' . esc_html(__( 'More Info', 'propertyhive' )) . '</a>'; |
| 130 |
|
| 131 |
|
| 132 |
echo '<div style="float:right; padding-top:6px;">'; |
| 133 |
echo wp_kses_post( implode( " | ", $links ) ); |
| 134 |
echo '</div>'; |
| 135 |
|
| 136 |
echo '<label class="switch"> |
| 137 |
<input type="checkbox" name="" disabled value=""> |
| 138 |
<span class="slider round" style="pointer-events:none; opacity:0.5"></span> |
| 139 |
</label>'; |
| 140 |
|
| 141 |
echo '</div>'; |
| 142 |
echo '</li>'; |
| 143 |
|
| 144 |
++$i; |
| 145 |
}*/ |
| 146 |
|
| 147 |
$slug = explode("/", $feature['wordpress_plugin_file']); |
| 148 |
$slug = $slug[0]; |
| 149 |
|
| 150 |
if ( $slug == 'propertyhive-template-assistant' ) |
| 151 |
{ |
| 152 |
echo '<li style="visibility:hidden" class="'; |
| 153 |
if ( isset($feature['categories']) && is_array($feature['categories']) && !empty($feature['categories']) ) |
| 154 |
{ |
| 155 |
echo esc_attr(implode(" ", $feature['categories'])); |
| 156 |
} |
| 157 |
|
| 158 |
$pro = false; |
| 159 |
$can_use = true; |
| 160 |
|
| 161 |
echo '"> |
| 162 |
<div class="inner"' . ( !$can_use ? ' style="border:1px solid #900"' : '' ) . '> |
| 163 |
<h3>' . ( ( isset($feature['dashicon']) && !empty($feature['dashicon']) ) ? '<span class="dashicons ' . esc_attr($feature['dashicon']) . '"></span> ' : '' ) . esc_html($feature['name']) . '</h3> |
| 164 |
<span class="free"><span>FREE</span></span> |
| 165 |
'; |
| 166 |
|
| 167 |
$links = array(); |
| 168 |
$links[] = 'This feature has moved. <a href="https://wp-property-hive.com/template-assistant-is-now-part-of-property-hive-core-plugin?src=plugin-feature-settings" target="_blank" style="text-decoration:none">' . esc_html(__( 'Read More', 'propertyhive' )) . '</a>'; |
| 169 |
|
| 170 |
echo '<div style="float:right; padding-top:6px;">'; |
| 171 |
echo wp_kses_post( implode( " | ", $links ) ); |
| 172 |
echo '</div>'; |
| 173 |
|
| 174 |
echo '<label class="switch"> |
| 175 |
<input type="checkbox" name="" disabled value=""> |
| 176 |
<span class="slider round" style="pointer-events:none; opacity:0.5"></span> |
| 177 |
</label>'; |
| 178 |
|
| 179 |
echo '<div class="loading"><img src="' . esc_url(PH()->plugin_url() . '/assets/images/admin/loading.gif') . '" alt=""></div>'; |
| 180 |
|
| 181 |
echo '</div>'; |
| 182 |
echo '</li>'; |
| 183 |
|
| 184 |
continue; |
| 185 |
} |
| 186 |
|
| 187 |
$feature_status = false; |
| 188 |
|
| 189 |
if ( is_dir( WP_PLUGIN_DIR . '/' . $slug ) ) |
| 190 |
{ |
| 191 |
$feature_status = 'installed'; |
| 192 |
} |
| 193 |
if ( is_plugin_active( $feature['wordpress_plugin_file'] ) ) |
| 194 |
{ |
| 195 |
$feature_status = 'active'; |
| 196 |
} |
| 197 |
|
| 198 |
echo '<li style="visibility:hidden" class="'; |
| 199 |
if ( isset($feature['categories']) && is_array($feature['categories']) && !empty($feature['categories']) ) |
| 200 |
{ |
| 201 |
echo esc_attr(implode(" ", $feature['categories'])); |
| 202 |
} |
| 203 |
|
| 204 |
$pro = false; |
| 205 |
$plans = (isset($feature['plans']) && is_array($feature['plans'])) ? $feature['plans'] : array(); |
| 206 |
if ( !in_array('free', $plans) ) |
| 207 |
{ |
| 208 |
$pro = true; |
| 209 |
} |
| 210 |
|
| 211 |
$can_use = true; |
| 212 |
if ( $pro && $feature_status == 'active' && apply_filters( 'propertyhive_add_on_can_be_used', true, $slug ) === FALSE ) |
| 213 |
{ |
| 214 |
$can_use = false; |
| 215 |
} |
| 216 |
|
| 217 |
echo '"> |
| 218 |
<div class="inner"' . ( !$can_use ? ' style="border:1px solid #900"' : '' ) . '> |
| 219 |
<h3>' . ( ( isset($feature['dashicon']) && !empty($feature['dashicon']) ) ? '<span class="dashicons ' . esc_attr($feature['dashicon']) . '"></span> ' : '' ) . esc_html($feature['name']) . '</h3>' . |
| 220 |
( $pro ? '<span class="pro"><span><a href="https://wp-property-hive.com/pricing/?src=plugin-feature-settings" target="_blank">PRO</a></span></span>' : '' ) . |
| 221 |
( !$pro ? '<span class="free"><span>FREE</span></span>' : '' ) . ' |
| 222 |
'; |
| 223 |
|
| 224 |
$links = array(); |
| 225 |
if ( isset($feature['description']) && !empty($feature['description']) ) |
| 226 |
{ |
| 227 |
$links[] = '<span style="color:#999;" class="help_tip" data-tip="' . esc_attr($feature['description']) . '"><span class="dashicons dashicons-info-outline"></span></span>'; |
| 228 |
} |
| 229 |
if ( isset($feature['url']) && !empty($feature['url']) ) |
| 230 |
{ |
| 231 |
$links[] = '<a href="' . esc_url($feature['url']) . '" target="_blank" style="text-decoration:none">' . esc_html(__( 'Details', 'propertyhive' )) . '</a>'; |
| 232 |
} |
| 233 |
if ( isset($feature['docs_url']) && !empty($feature['docs_url']) ) |
| 234 |
{ |
| 235 |
$links[] = '<a href="' . esc_url($feature['docs_url']) . '" target="_blank" style="text-decoration:none">' . esc_html(__( 'Docs', 'propertyhive' )) . '</a>'; |
| 236 |
} |
| 237 |
if ( $feature_status == 'active' ) |
| 238 |
{ |
| 239 |
$transient = get_site_transient( 'update_plugins' ); |
| 240 |
if ( isset($transient->response) && is_array($transient->response) && isset($transient->response[$feature['wordpress_plugin_file']]) && isset($transient->response[$feature['wordpress_plugin_file']]->new_version) ) |
| 241 |
{ |
| 242 |
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $feature['wordpress_plugin_file'] ); |
| 243 |
|
| 244 |
if ( version_compare($plugin_data['Version'], $transient->response[$feature['wordpress_plugin_file']]->new_version, '<') ) |
| 245 |
{ |
| 246 |
$links[] = '<a href="' . esc_url(admin_url('plugins.php?plugin_status=upgrade')) . '" style="text-decoration:none"><span class="dashicons dashicons-update"></span> ' . esc_html(__( 'Update', 'propertyhive' )) . '</a>'; |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
echo '<div style="float:right; padding-top:6px;">'; |
| 252 |
echo wp_kses_post( implode( " | ", $links ) ); |
| 253 |
echo '</div>'; |
| 254 |
|
| 255 |
echo '<label class="switch"> |
| 256 |
<input type="checkbox" name="active_plugins[]" value="' . esc_attr($slug) . '"' . ( $feature_status == 'active' ? ' checked' : '' ) . '> |
| 257 |
<span class="slider round"></span> |
| 258 |
</label>'; |
| 259 |
|
| 260 |
echo '<div class="loading"><img src="' . esc_url(PH()->plugin_url() . '/assets/images/admin/loading.gif') . '" alt=""></div>'; |
| 261 |
|
| 262 |
if ( !$can_use ) |
| 263 |
{ |
| 264 |
echo '<div style="color:#900; font-size:0.9; margin-top:10px;">Disabled due to <a href="' . esc_url(admin_url('admin.php?page=ph-settings&tab=licensekey')) . '" style="color:inherit">invalid license</a></div>'; |
| 265 |
} |
| 266 |
|
| 267 |
echo '</div>'; |
| 268 |
echo '</li>'; |
| 269 |
|
| 270 |
++$i; |
| 271 |
} |
| 272 |
echo '</ul><div style="clear:both"></div></div>'; |
| 273 |
|
| 274 |
echo '</div>'; |
| 275 |
} |
| 276 |
|
| 277 |
/** |
| 278 |
* Output the settings |
| 279 |
*/ |
| 280 |
public function output() { |
| 281 |
global $current_section, $hide_save_button; |
| 282 |
|
| 283 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global. |
| 284 |
$hide_save_button = true; |
| 285 |
$settings = $this->get_settings(); |
| 286 |
|
| 287 |
PH_Admin_Settings::output_fields( $settings ); |
| 288 |
} |
| 289 |
|
| 290 |
} |
| 291 |
|
| 292 |
endif; |
| 293 |
|
| 294 |
return new PH_Settings_Features(); |
| 295 |
|