Completed
Push — master ( 325fc8...6772ac )
by Brandon
03:10
created

RePro   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 125
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B init() 0 24 1
A init_modules() 0 7 4
A gmap_style() 0 13 3
A admin_menu() 0 3 1
A admin_scripts() 0 6 2
A widget_styles() 0 4 1
A activate() 0 3 1
A deactivate() 0 3 1
A plugin_links() 0 5 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 34 and the first side effect is on line 24.

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.

Loading history...
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 {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
35
36
	/**
37
	 * Constructor.
38
	 *
39
	 * @access public
40
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
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');
0 ignored issues
show
Bug introduced by
The property general_settings does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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.
0 ignored issues
show
Documentation introduced by
The doc-type [Array] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
151
	 * @return [Array]        : Array of links on plugin page.
0 ignored issues
show
Documentation introduced by
The doc-type [Array] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
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