Completed
Push — master ( 643987...ab0124 )
by Daryl
01:58
created

component-google-maps.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 5 and the first side effect is on line 74.

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
namespace Clubdeuce\WPLib\Components;
3
4
5
class Google_Maps extends \WPLib_Module_Base {
6
7
    const INSTANCE_CLASS = 'Clubdeuce\WPLib\Components\GoogleMaps\Map';
8
9
    /**
10
     * @var string
11
     */
12
    protected static $_api_key = '';
13
14
    /**
15
     * These conditions will be used to determine whether to enqueue the Google Maps JS.
16
     *
17
     * @var array
18
     */
19
    protected static $_script_conditions = array();
20
21
22
    static function on_load() {
23
24
        self::add_class_action( 'wp_enqueue_scripts', 9 );
25
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    static function api_key() {
32
33
        return static::$_api_key;
34
35
    }
36
37
    /**
38
     * @param string $key
39
     */
40
    static function register_api_key( $key ) {
41
42
        static::$_api_key = filter_var( $key, FILTER_SANITIZE_STRING );
43
44
    }
45
46
    /**
47
     * @param callable $condition
48
     */
49
    static function register_script_condition( $condition ) {
50
51
        static::$_script_conditions[] = $condition;
52
53
    }
54
55
    static function _wp_enqueue_scripts_9() {
56
57
        $key = static::api_key();
58
59
        wp_register_script('google-maps', "https://maps.google.com/maps/api/js?key={$key}", false, '3.0', true );
60
        wp_register_script('map-control', home_url( '/vendor/clubdeuce/wplib-olm-google-maps/assets/maps.js' ), array( 'jquery', 'google-maps' ), '0.1', true );
61
62
        array_walk(static::$_script_conditions, function( $function ) {
63
            return is_callable( $function ) ? call_user_func( $function ) : $function;
64
        } );
65
66
        if ( in_array( true, static::$_script_conditions ) ) {
67
            wp_enqueue_script( 'map-control' );
68
        }
69
70
    }
71
72
}
73
74
Google_Maps::on_load();
75