@@ -25,9 +25,10 @@ class AWPP_Init {
25
25
26
26
27
27
public function __construct (){
28
- // Admin menu
29
- add_action ('admin_init ' , array ( 'AWPP_Settings ' , 'admin_init ' ));
30
- add_action ('admin_menu ' , array ( 'AWPP_Settings ' , 'add_menu ' ));
28
+ // Admin menu id built and populated in AWPP_Settings
29
+ $ awpps = new AWPP_Settings ();
30
+ add_action ('admin_init ' , array ( $ awpps , 'admin_init ' ));
31
+ add_action ('admin_menu ' , array ( $ awpps , 'add_menu ' ));
31
32
32
33
// Always? Cf. callback function comment
33
34
//add_action('wp_enqueue_scripts', array( &$this, 'loadResources'), 11); // that action doesn't seem to work
@@ -94,15 +95,18 @@ public function loadResources() {
94
95
class AWPP_Shortcode {
95
96
96
97
const PREFIX = 'awpp ' ;
98
+ private $ _options ;
99
+ private $ _debug ;
97
100
98
101
public function __construct (){
102
+ $ this ->_options = get_option ('awpp_options ' );
103
+ $ this ->_debug = $ this ->_options ['debug_enable ' ];
99
104
100
105
}
101
106
/*
102
107
* [annuaire-map] shortcode with region, type and content parameters
103
108
*/
104
109
public function create_annuaire_map ( $ attributes ){
105
- $ options = get_option ('awpp_options ' );
106
110
$ geoData = null ;
107
111
108
112
extract (
@@ -111,9 +115,9 @@ public function create_annuaire_map( $attributes ){
111
115
'region ' => 'north ' ,
112
116
'type ' => 1 ,
113
117
'content ' => 'structure ' ,
114
- 'width ' => $ options ['map_width ' ],
115
- 'height ' => $ options ['map_height ' ],
116
- 'center ' => $ options ['map_center ' ]
118
+ 'width ' => $ this -> _options ['map_width ' ],
119
+ 'height ' => $ this -> _options ['map_height ' ],
120
+ 'center ' => $ this -> _options ['map_center ' ]
117
121
),
118
122
$ attributes )
119
123
);
@@ -134,7 +138,6 @@ public function create_annuaire_map( $attributes ){
134
138
* [annuaire] shortcode with region, type and content parameters
135
139
*/
136
140
public function create_annuaire_list ( $ attributes ){
137
- $ options = get_option ('awpp_options ' );
138
141
$ geoData = null ;
139
142
140
143
extract (
@@ -144,9 +147,9 @@ public function create_annuaire_list( $attributes ){
144
147
'type ' => 1 ,
145
148
'content ' => 'structure ' ,
146
149
'map ' => false ,
147
- 'width ' => $ options ['map_width ' ],
148
- 'height ' => $ options ['map_height ' ],
149
- 'center ' => $ options ['map_center ' ],
150
+ 'width ' => $ this -> _options ['map_width ' ],
151
+ 'height ' => $ this -> _options ['map_height ' ],
152
+ 'center ' => $ this -> _options ['map_center ' ],
150
153
'photos ' => true ,
151
154
'limit ' => 100
152
155
),
@@ -242,7 +245,7 @@ private function _encodeAddress( $name, $data ) {
242
245
* Embedd the DOM element that will be replaced by the actual map
243
246
*/
244
247
private function _displayMap ( $ geoData , $ center , $ width , $ height ){
245
- if ( empty ( $ geoData ) ) {
248
+ if ( $ this -> _debug && empty ( $ geoData ) ) {
246
249
return sprintf ('Something went incredibly wrong: No geodata received ' );
247
250
}
248
251
@@ -306,10 +309,10 @@ private function _googleGeocode( $address ) {
306
309
str_replace ( ' ' , '+ ' , $ address )
307
310
)
308
311
);
309
- if ( is_wp_error ( $ geocodeResponse )) {
312
+ if ( $ this -> _debug && is_wp_error ( $ geocodeResponse )) {
310
313
print ('Something went wrong: ' . $ geocodeResponse ->get_error_message ());
311
314
}
312
- if ( $ geocodeResponse [ 'response ' ][ 'code ' ] != 200 ) {
315
+ if ( $ this -> _debug && $ geocodeResponse [ 'response ' ][ 'code ' ] != 200 ) {
313
316
printf (
314
317
__ ( '<p>%s geocode error: %d %s</p> <p>Response: %s</p> ' , self ::PREFIX ),
315
318
self ::PREFIX ,
@@ -322,17 +325,21 @@ private function _googleGeocode( $address ) {
322
325
323
326
// Else decode response and handle geocoding related errors
324
327
$ coordinates = json_decode ( $ geocodeResponse ['body ' ] );
325
- if ( json_last_error () != JSON_ERROR_NONE ) {
328
+ if ( $ this -> _debug && json_last_error () != JSON_ERROR_NONE ) {
326
329
print ('Did not get valid json response ' );
327
330
}
328
331
329
- if ( isset ( $ coordinates ->status ) && $ coordinates ->status == 'REQUEST_DENIED ' ) {
332
+ if ( $ this -> _debug && isset ( $ coordinates ->status ) && $ coordinates ->status == 'REQUEST_DENIED ' ) {
330
333
printf ( __ ( '%s geocode error: Request Denied. ' , self ::PREFIX ), self ::PREFIX );
331
334
return false ;
332
335
}
333
336
334
- if ( !isset ( $ coordinates ->results ) || empty ( $ coordinates ->results ) ) {
335
- print ( __ ( "That address couldn't be geocoded, please make sure that it's correct. " , self ::PREFIX ) );
337
+ if ( ( $ this ->_debug && !isset ( $ coordinates ->results ) ) || ($ this ->_debug && empty ( $ coordinates ->results ) ) ) {
338
+ printf (
339
+ __ ( "%s geocode error: The address (%s) couldn't be geocoded, please make sure that it's correct. " ),
340
+ self ::PREFIX ,
341
+ $ address
342
+ );
336
343
return false ;
337
344
}
338
345
0 commit comments