1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Real Estate Pro |
4
|
|
|
* |
5
|
|
|
* @package re-pro |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/* |
9
|
|
|
------------------------------------------------------------------------------- |
10
|
|
|
Plugin Name: Real Estate Pro |
11
|
|
|
Plugin URI: https://www.imforza.com |
12
|
|
|
Description: A WordPress plugin for Real Estate websites, offering tools such as widgets and badges. Built by <a href="https://www.imforza.com">imFORZA</a>. |
13
|
|
|
Version: 1.0.4 |
14
|
|
|
Author: imFORZA |
15
|
|
|
Contributors: imforza, bhubbard, sfgarza, matoledo |
16
|
|
|
Text Domain: re-pro |
17
|
|
|
Author URI: https://www.imforza.com |
18
|
|
|
License: GPLv3 or later |
19
|
|
|
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html |
20
|
|
|
------------------------------------------------------------------------------ |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/* Exit if accessed directly. */ |
24
|
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; } |
25
|
|
|
|
26
|
|
|
/** Instantiate the plugin. */ |
27
|
|
|
new RePro(); |
28
|
|
|
require_once( 'settings.php'); |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* RePro class. |
33
|
|
|
*/ |
34
|
|
|
class RePro { |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor. |
38
|
|
|
* |
39
|
|
|
* @access public |
40
|
|
|
* @return void |
|
|
|
|
41
|
|
|
*/ |
42
|
|
|
public function __construct() { |
43
|
|
|
/* Define Constants */ |
44
|
|
|
define( 'REPRO_BASE_NAME', plugin_basename( __FILE__ ) ); |
45
|
|
|
define( 'REPRO_BASE_DIR', plugin_dir_path( __FILE__ ) ); |
46
|
|
|
define( 'REPRO_PLUGIN_FILE', REPRO_BASE_DIR . 're-pro.php' ); |
47
|
|
|
|
48
|
|
|
/* Include dependencies */ |
49
|
|
|
require_once( 'includes.php' ); |
50
|
|
|
|
51
|
|
|
$this->init(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Init. |
57
|
|
|
* |
58
|
|
|
* @access private |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
private function init() { |
62
|
|
|
$this->general_settings = get_option('re_pro_settings'); |
|
|
|
|
63
|
|
|
|
64
|
|
|
/* Language Support. */ |
65
|
|
|
load_plugin_textdomain( 're-pro', false, dirname( REPRO_BASE_NAME ) . '/languages' ); |
66
|
|
|
|
67
|
|
|
/* Plugin Activation/De-Activation. */ |
68
|
|
|
register_activation_hook( REPRO_PLUGIN_FILE, array( $this, 'activate' ) ); |
69
|
|
|
register_deactivation_hook( REPRO_PLUGIN_FILE, array( $this, 'deactivate' ) ); |
70
|
|
|
|
71
|
|
|
/* Set menu page. */ |
72
|
|
|
add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
73
|
|
|
|
74
|
|
|
/** Enqueue css and js files. */ |
75
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
76
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'widget_styles' ) ); |
77
|
|
|
|
78
|
|
|
/* Add link to settings in plugins admin page. */ |
79
|
|
|
add_filter( 'plugin_action_links_' . REPRO_BASE_NAME , array( $this, 'plugin_links' ) ); |
80
|
|
|
|
81
|
|
|
add_filter( 'wpapi_google_map_data', array( $this, 'gmap_style' ), 1 ); |
82
|
|
|
|
83
|
|
|
$this->init_modules(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private function init_modules(){ |
87
|
|
|
$gmaps_key = isset( $this->general_settings['gmaps_key'] ) ? $this->general_settings['gmaps_key'] : null; |
88
|
|
|
|
89
|
|
|
if ( isset( $this->general_settings['gmaps_active'] ) && isset( $gmaps_key ) ) { |
90
|
|
|
new WPAPI_GOOGLE_MAPS( $gmaps_key ); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function gmap_style( $map_data ){ |
95
|
|
|
// Grab style option. |
96
|
|
|
$map_json = ( isset( $this->general_settings['gmaps_style'] ) ) ? $this->general_settings['gmaps_style'] : '[]'; |
97
|
|
|
|
98
|
|
|
// Validate JSON. |
99
|
|
|
json_decode($map_json); |
100
|
|
|
$json_valid = json_last_error(); |
101
|
|
|
|
102
|
|
|
// Set style to map_data. |
103
|
|
|
$map_data['style'] = ( $json_valid === JSON_ERROR_NONE ) ? $map_json : '[]'; |
104
|
|
|
|
105
|
|
|
return $map_data; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Method that runs on admin_menu hook. |
110
|
|
|
*/ |
111
|
|
|
public function admin_menu() { |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Enqueue CSS. |
117
|
|
|
*/ |
118
|
|
|
public function admin_scripts() { |
119
|
|
|
if ( ! is_admin() ) { |
120
|
|
|
wp_register_style( 're-pro', plugins_url( 'assets/css/re-pro-min.css', REPRO_PLUGIN_FILE ) ); |
121
|
|
|
// wp_enqueue_style( 're-pro' ); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Register Widget CSS. |
127
|
|
|
*/ |
128
|
|
|
public function widget_styles() { |
129
|
|
|
wp_register_style( 're-pro-widgets', plugins_url( 'assets/css/re-pro-widgets.min.css', REPRO_PLUGIN_FILE ) ); |
130
|
|
|
wp_enqueue_style( 're-pro-widgets' ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Method that executes on plugin activation. |
135
|
|
|
*/ |
136
|
|
|
public function activate() { |
137
|
|
|
flush_rewrite_rules(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Method that executes on plugin de-activation. |
142
|
|
|
*/ |
143
|
|
|
public function deactivate() { |
144
|
|
|
flush_rewrite_rules(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Add Tools link on plugin page. |
149
|
|
|
* |
150
|
|
|
* @param [Array] $links : Array of links on plugin page. |
|
|
|
|
151
|
|
|
* @return [Array] : Array of links on plugin page. |
|
|
|
|
152
|
|
|
*/ |
153
|
|
|
public function plugin_links( $links ) { |
154
|
|
|
$settings_link = '<a href="options-general.php?page=re-pro-settings">Settings</a>'; |
155
|
|
|
array_unshift( $links, $settings_link ); |
156
|
|
|
return $links; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.