1: <?php
2: /**
3: * Install Function
4: *
5: * @package EPL
6: * @subpackage Functions/Install
7: * @copyright Copyright (c) 2020, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 1.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: /**
18: * Get array of default settings
19: *
20: * @return array
21: * @since 3.3.5
22: * @since 3.6 Added the display_price_under_offer default.
23: * @since 3.6.1 display_price_under_offer defaults to no (hide the price), as before 3.6.
24: */
25: function epl_get_default_settings() {
26:
27: return array(
28:
29: 'currency' => 'AUD',
30: 'currency_position' => 'before',
31: 'currency_thousands_separator' => ',',
32: 'currency_decimal_separator' => '.',
33: 'admin_unique_id' => 0,
34: 'debug' => 0,
35: 'display_bond' => 0,
36: 'display_single_gallery' => 1,
37: 'display_gallery_n' => 4,
38: 'display_feature_columns' => 2,
39: 'display_excerpt_length' => 10,
40: 'display_archive_view_type' => 'list',
41: 'use_fancy_navigation' => 0,
42: 'label_bond' => __( 'Bond', 'easy-property-listings' ),
43: 'label_location' => __( 'Suburb', 'easy-property-listings' ),
44: 'label_suburb' => __( 'Suburb', 'easy-property-listings' ),
45: 'label_city' => __( 'City', 'easy-property-listings' ),
46: 'label_state' => __( 'State', 'easy-property-listings' ),
47: 'label_postcode' => __( 'Post Code', 'easy-property-listings' ),
48: 'label_home_open' => __( 'Home Open', 'easy-property-listings' ),
49: 'label_poa' => __( 'POA', 'easy-property-listings' ),
50: 'label_new' => __( 'New', 'easy-property-listings' ),
51: 'label_under_offer' => __( 'Under Offer', 'easy-property-listings' ),
52: 'display_price_under_offer' => 'no',
53: 'label_leased' => __( 'Leased', 'easy-property-listings' ),
54: 'label_sold' => __( 'Sold', 'easy-property-listings' ),
55: 'widget_label_all' => __( 'All', 'easy-property-listings' ),
56: 'widget_label_property' => __( 'Buy', 'easy-property-listings' ),
57: 'widget_label_land' => __( 'Land', 'easy-property-listings' ),
58: 'widget_label_rental' => __( 'Rent', 'easy-property-listings' ),
59: 'widget_label_rural' => __( 'Rural', 'easy-property-listings' ),
60: 'widget_label_business' => __( 'Business', 'easy-property-listings' ),
61: 'widget_label_commercial' => __( 'Commercial', 'easy-property-listings' ),
62: 'widget_label_commercial_land' => __( 'Commercial Land', 'easy-property-listings' ),
63: 'epl_max_graph_sales_price' => 2000000,
64: 'epl_max_graph_rent_price' => 2000,
65: 'sticker_new_range' => 7,
66: 'epl_admin_thumb_size' => 'admin-list-thumb',
67: 'epl_enable_city_field' => 'no',
68: 'epl_enable_country_field' => 'no',
69: 'epl_feeling_lucky' => 'off',
70: 'epl_lucky_disable_single_thumb' => 'off',
71: 'epl_lucky_disable_theme_single_thumb' => 'off',
72: 'epl_lucky_disable_archive_thumb' => 'off',
73: 'epl_lucky_disable_epl_archive_thumb' => 'off',
74: 'epl_use_core_css' => 'off', // Means Enable CSS.
75: 'epl_css_legacy' => 'off', // Legacy styles disabled by default.
76: 'epl_css_enhanced' => 'on', // Enhanced styles enabled for new installations by default.
77: 'epl_google_api_key' => '',
78: 'epl_disable_google_api' => 'on',
79: 'uninstall_on_delete' => 0,
80: 'inspection_date_format' => 'l, dS F',
81: 'inspection_time_format' => 'h:i a',
82: 'custom_inspection_date_format' => 'l, dS F',
83: 'custom_inspection_time_format' => 'h:i a',
84: 'epl_video_width' => 600,
85: 'min_contact_access' => 'level_10',
86: 'min_reports_access' => 'level_10',
87: 'activate_post_types' => array( 'property' ),
88: 'epl_default_country' => 'Australia',
89: 'epl_icons_svg_listings' => 'on',
90: 'epl_icons_svg_author' => 'on',
91: 'epl_plugin_mode' => 'production',
92: );
93: }
94:
95: /**
96: * Install
97: *
98: * Runs on plugin install by setting up the current version,
99: * flushing rewrite rules to initiate the new 'property' slug and also
100: * creates the plugin and populates the settings fields for those plugin
101: * pages. After successful install, the user is redirected to the EPL Welcome
102: * screen.
103: *
104: * @global $wpdb
105: * @global $epl_options
106: * @global $wp_version
107: * @return void
108: *
109: * @since 1.0
110: * @since 3.4.20 Altered order of flush permalinks function.
111: */
112: function epl_install() {
113: global $wpdb, $epl_options, $wp_version;
114:
115: // Add default EPL Settings.
116: $epl_settings = epl_settings();
117:
118: $new_fields_defaults = epl_get_default_settings();
119:
120: if ( ! empty( $epl_settings ) ) {
121:
122: // possible upgrade.
123: foreach ( $new_fields_defaults as $key => $value ) {
124: if ( ! isset( $epl_settings[ $key ] ) ) {
125: // sure upgrade, fields are not set lets set them for very first time.
126: $epl_settings[ $key ] = $value;
127: }
128: }
129: } else {
130: // first time install . load with default values.
131: $epl_settings = $new_fields_defaults;
132: }
133: update_option( 'epl_settings', $epl_settings );
134:
135: // Add Upgraded From Option.
136: $current_version = get_option( 'epl_version' );
137: if ( ! empty( $current_version ) ) {
138: update_option( 'epl_version_upgraded_from', $current_version );
139:
140: } else {
141: $epl_data = get_plugin_data( EPL_PLUGIN_PATH . '/easy-property-listings.php' );
142: update_option( 'epl_version', $epl_data['Version'] );
143: }
144:
145: $notice_display = get_transient( 'epl_admin_notices_display' );
146:
147: if ( ! $notice_display ) {
148: set_transient( 'epl_admin_notices_display', true, 60 * 60 * 24 * 14 );
149: }
150:
151: // Bail if activating from network, or bulk.
152: if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { //phpcs:ignore
153: return;
154: }
155: remove_role( 'epl_crm' );
156:
157: // Clear the permalinks.
158: flush_rewrite_rules();
159:
160: // Add the transient to redirect.
161: set_transient( '_epl_activation_redirect', true, 30 );
162: }
163: register_activation_hook( EPL_PLUGIN_FILE, 'epl_install' );
164:
165: /**
166: * Un-Install
167: *
168: * Runs on plugin un-install by setting up the current version, flushing rewrite rules
169: *
170: * @since 2.2
171: */
172: function epl_uninstall() {
173: update_option( 'epl_rewrite_rules', false );
174: flush_rewrite_rules();
175: }
176: register_deactivation_hook( EPL_PLUGIN_FILE, 'epl_uninstall' );
177:
178: /**
179: * Post-installation
180: *
181: * Runs just after plugin installation and exposes the
182: * epl_after_install hook.
183: *
184: * @since 1.0
185: * @return void
186: */
187: function epl_after_install() {
188:
189: if ( ! is_admin() ) {
190: return;
191: }
192:
193: $activation_pages = get_transient( '_epl_activation_pages' );
194:
195: // Exit if not in admin or the transient doesn't exist.
196: if ( false === $activation_pages ) {
197: return;
198: }
199:
200: // Delete the transient.
201: delete_transient( '_epl_activation_pages' );
202:
203: do_action( 'epl_after_install', $activation_pages );
204: }
205: add_action( 'admin_init', 'epl_after_install' );
206:
207: /**
208: * Apply new settings on update
209: *
210: * Runs just after plugin installation
211: *
212: * @since 1.0
213: * @since 3.6.1 Adds the 3.6.1 step: sites that had Under Offer Price Display on from 3.6 go back to hiding the price once, as NSW paused its underquoting rules.
214: * @return void
215: */
216: function epl_plugin_updates() {
217: $current_version = get_option( 'epl_version' );
218:
219: if ( version_compare( $current_version, '1.3', '<' ) ) {
220: include EPL_PATH_UPDATES . 'epl-1.3.1.php';
221: update_option( 'epl_version', '1.3' );
222: }
223: if ( version_compare( $current_version, '2.1', '<' ) ) {
224: include EPL_PATH_UPDATES . 'epl-2.1.php';
225: update_option( 'epl_version', '2.1' );
226: }
227: if ( version_compare( $current_version, '2.1.8', '<' ) ) {
228: include EPL_PATH_UPDATES . 'epl-2.1.8.php';
229: update_option( 'epl_version', '2.1.8' );
230: }
231: if ( version_compare( $current_version, '2.1.11', '<' ) ) {
232: include EPL_PATH_UPDATES . 'epl-2.1.11.php';
233: update_option( 'epl_version', '2.1.11' );
234: }
235: if ( version_compare( $current_version, '2.2', '<' ) ) {
236: include EPL_PATH_UPDATES . 'epl-2.2.php';
237: update_option( 'epl_version', '2.2' );
238: }
239: if ( version_compare( $current_version, '3.0', '<' ) ) {
240: include EPL_PATH_UPDATES . 'epl-3.0.php';
241: update_option( 'epl_version', '3.0' );
242: }
243: if ( version_compare( $current_version, '30', '==' ) ) { // Fix for 3.0 version number.
244: include EPL_PATH_UPDATES . 'epl-3.1.php';
245: update_option( 'epl_version', '3.1' );
246: }
247: if ( version_compare( $current_version, '3.1', '<' ) ) {
248: include EPL_PATH_UPDATES . 'epl-3.1.php';
249: update_option( 'epl_version', '3.1' );
250: }
251: if ( version_compare( $current_version, '3.1.16', '<' ) ) {
252: include EPL_PATH_UPDATES . 'epl-3.1.16.php';
253: update_option( 'epl_version', '3.1.16' );
254: }
255: if ( version_compare( $current_version, '3.2', '<' ) ) {
256: include EPL_PATH_UPDATES . 'epl-3.2.php';
257: update_option( 'epl_version', '3.2' );
258: }
259: if ( version_compare( $current_version, '3.2.2', '<' ) ) {
260: flush_rewrite_rules();
261: update_option( 'epl_version', '3.2.2' );
262: }
263: if ( version_compare( $current_version, '3.3', '<' ) ) {
264: include EPL_PATH_UPDATES . 'epl-3.3.php';
265: flush_rewrite_rules();
266: update_option( 'epl_version', '3.3' );
267: }
268: if ( version_compare( $current_version, '3.6.1', '<' ) ) {
269: include EPL_PATH_UPDATES . 'epl-3.6.1.php';
270: update_option( 'epl_version', '3.6.1' );
271: }
272: }
273: add_action( 'admin_init', 'epl_plugin_updates' );
274: