-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrentfetch-sync.php
More file actions
132 lines (114 loc) · 3.82 KB
/
rentfetch-sync.php
File metadata and controls
132 lines (114 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/*
Plugin Name: Rent Fetch Sync
Plugin URI: https://github.com/jonschr/rentfetch-sync
Description: An addon for Rent Fetch that syncs properties, floorplans, and units
Version: 0.14.1
Author: Brindle Digital
Author URI: https://www.brindledigital.com/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/* Prevent direct access to the plugin */
if ( ! defined( 'ABSPATH' ) ) {
die( 'Sorry, you are not allowed to access this page directly.' );
}
// Define the version of the plugin.
define( 'RENTFETCHSYNC_VERSION', '0.14.1' );
// Plugin directory.
define( 'RENTFETCHSYNC_DIR', plugin_dir_path( __FILE__ ) );
define( 'RENTFETCHSYNC_PATH', plugin_dir_url( __FILE__ ) );
define( 'RENTFETCHSYNC_FILE', __FILE__ );
// Register deactivation hook.
register_deactivation_hook( __FILE__, 'rfs_deactivate_actions' );
/**
* Cancel all scheduled actions on deactivation.
*
* @return void.
*/
function rfs_deactivate_actions() {
as_unschedule_all_actions( 'rfs_do_sync' );
as_unschedule_all_actions( 'rfs_yardi_do_delete_orphans' );
}
// include action scheduler.
require_once plugin_dir_path( __FILE__ ) . 'vendor/action-scheduler/action-scheduler.php';
/**
* Include all files in a directory and its subdirectories.
*
* @param string $directory The path to the directory to load.
*
* @return void
*/
function rfs_require_files_recursive( $directory ) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $directory, RecursiveDirectoryIterator::SKIP_DOTS ),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ( $iterator as $file ) {
if ( $file->isFile() && $file->getExtension() === 'php' ) {
require_once $file->getPathname();
}
}
}
/**
* Check whether the base Rent Fetch plugin is loaded.
*
* @return bool
*/
function rfs_has_rentfetch_dependency() {
return defined( 'RENTFETCH_VERSION' );
}
/**
* Show an admin notice when Rent Fetch Sync is active without Rent Fetch.
*
* @return void
*/
function rfs_missing_rentfetch_notice() {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
?>
<div class="notice notice-error">
<p><?php esc_html_e( 'Rent Fetch Sync requires the Rent Fetch plugin to be active. Rent Fetch Sync has been loaded in safe mode and its sync features are disabled until Rent Fetch is available.', 'rentfetch-sync' ); ?></p>
</div>
<?php
}
/**
* Load Rent Fetch Sync only after plugin dependencies are available.
*
* @return void
*/
function rfs_boot_plugin() {
if ( ! rfs_has_rentfetch_dependency() ) {
add_action( 'admin_notices', 'rfs_missing_rentfetch_notice' );
return;
}
rfs_require_files_recursive( RENTFETCHSYNC_DIR . 'lib' );
}
add_action( 'plugins_loaded', 'rfs_boot_plugin', 20 );
// Add admin notice for sync success
add_action( 'admin_notices', 'rfs_sync_success_notice' );
function rfs_sync_success_notice() {
if ( isset( $_GET['sync_success'] ) && $_GET['sync_success'] == '1' ) {
?>
<div class="notice notice-success is-dismissible">
<p><?php esc_html_e( 'Property sync completed successfully!', 'rentfetch-sync' ); ?></p>
</div>
<?php
}
}
// Load Plugin Update Checker.
require RENTFETCHSYNC_DIR . 'vendor/plugin-update-checker/plugin-update-checker.php';
$update_checker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/BrindleDigital/rentfetch-sync',
__FILE__,
'rentfetch-sync'
);
// Optional: Set the branch that contains the stable release.
$update_checker->setBranch( 'main' );