PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.1.7
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.1.7
4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / inc / CFF_Error_Reporter.php
custom-facebook-feed / inc Last commit date
Admin 3 years ago Builder 3 years ago Helpers 3 years ago CFF_Autolink.php 3 years ago CFF_Blocks.php 3 years ago CFF_Cache.php 3 years ago CFF_Education.php 3 years ago CFF_Elementor_Base.php 3 years ago CFF_Elementor_Widget.php 3 years ago CFF_Error_Reporter.php 3 years ago CFF_FB_Settings.php 3 years ago CFF_Feed_Elementor_Control.php 3 years ago CFF_Feed_Locator.php 3 years ago CFF_Feed_Pro.php 3 years ago CFF_GDPR_Integrations.php 3 years ago CFF_Group_Posts.php 3 years ago CFF_HTTP_Request.php 3 years ago CFF_Oembed.php 3 years ago CFF_Parse.php 3 years ago CFF_Resizer.php 3 years ago CFF_Response.php 3 years ago CFF_Shortcode.php 3 years ago CFF_Shortcode_Display.php 3 years ago CFF_SiteHealth.php 3 years ago CFF_Utils.php 3 years ago CFF_View.php 3 years ago Custom_Facebook_Feed.php 3 years ago SB_Facebook_Data_Encryption.php 3 years ago SB_Facebook_Data_Manager.php 3 years ago
CFF_Error_Reporter.php
760 lines
1 <?php
2 /**
3 * Class CFF_Error_Reporter
4 *
5 * Set as a global object to record and report errors
6 *
7 * @since
8 */
9
10 namespace CustomFacebookFeed;
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 die( '-1' );
15 }
16
17 class CFF_Error_Reporter
18 {
19 /**
20 * @var array
21 */
22 var $errors;
23
24 /**
25 * @var array
26 */
27 var $frontend_error;
28
29 /**
30 * @var string
31 */
32 var $reporter_key;
33
34 /**
35 * @var array
36 */
37 var $display_error;
38
39
40 /**
41 * CFF_Error_Reporter constructor.
42 */
43 public function __construct() {
44 $this->reporter_key = 'cff_error_reporter';
45 $this->errors = get_option( $this->reporter_key, [] );
46 if ( ! isset( $this->errors['connection'] ) ) {
47 $this->errors = array(
48 'connection' => [],
49 'resizing' => [],
50 'database_create' => [],
51 'upload_dir' => [],
52 'accounts' => [],
53 'error_log' => [],
54 'action_log' => []
55 );
56 }
57
58
59 $this->display_error = [];
60 $this->frontend_error = '';
61
62 add_action( 'cff_feed_issue_email', [ $this, 'maybe_trigger_report_email_send'] );
63 add_action( 'wp_ajax_cff_dismiss_critical_notice', [ $this, 'dismiss_critical_notice'] );
64 add_action( 'wp_footer', [ $this, 'critical_error_notice'] , 300 );
65 add_action( 'cff_admin_notices', [ $this, 'admin_error_notices'] );
66 }
67
68 /**
69 * @return array
70 *
71 * @since 2.0/4.0
72 */
73 public function get_errors() {
74 return $this->errors;
75 }
76
77 /**
78 * @param $type
79 * @param $message_array
80 *
81 * @since 2.0/4.0
82 */
83 public function add_error( $type, $args, $connected_account_term = false ) {
84 $connected_account = false;
85
86 $log_item = date( 'm-d H:i:s' ) . ' - ';
87
88 if( $connected_account_term !== false ){
89 if ( ! is_array( $connected_account_term ) ) {
90
91 } else {
92 $connected_account = $connected_account_term;
93 $log_item .= $args['error']['message'];
94 $this->add_connected_account_error( $connected_account, $type, $args );
95 }
96
97 }
98
99 //Access Token Error
100 if( $type === 'accesstoken' ){
101 $accesstoken_error_exists = false;
102 if ( isset( $this->errors['accounts'] ) ) {
103 foreach ($this->errors['accounts'] as $account ) {
104 if ( $args['accesstoken'] === $account['accesstoken'] ) {
105 $accesstoken_error_exists = true;
106 }
107 }
108 }
109 if ( !$accesstoken_error_exists ) {
110 $this->errors['accounts'][ $connected_account['id'] ][] = array(
111 'accesstoken' => $args['accesstoken'],
112 'post_id' => $args['post_id'],
113 'critical' => true,
114 'type' => $type,
115 'errorno' => $args['errorno']
116 );
117
118 }
119 }
120
121 //Connection Error API & WP REMOTE CALL
122 if( $type === 'api' || $type === 'wp_remote_get' ){
123 $connection_details = array(
124 'error_id' => ''
125 );
126 $connection_details['critical'] = false;
127
128 if( isset( $args['error']['code'] ) ){
129 $connection_details['error_id'] = $args['error']['code'];
130 if ( $this->is_critical_error( $args ) ) {
131 $connection_details['critical'] = true;
132 }
133
134 }elseif( isset( $args['response'] ) && is_wp_error( $args['response'] )){
135 foreach ( $args['response']->errors as $key => $item ) {
136 $connection_details['error_id'] = $key;
137 }
138 $connection_details['critical'] = true;
139 }
140
141 $connection_details['error_message'] = $this->generate_error_message( $args, $connected_account );
142 $log_item .= $connection_details['error_message']['admin_message'];
143 $this->errors['connection'] = $connection_details;
144 #var_dump($connection_details);
145 }
146
147 if ( $type === 'image_editor'
148 || $type === 'storage' ) {
149
150 $this->errors['resizing'] = $args;
151 $log_item .= $args;
152 }
153
154 if ( $type === 'database_create' ) {
155 $this->errors['database_create'] = $args;
156 $log_item .= $args;
157 }
158
159 if ( $type === 'upload_dir' ) {
160 $this->errors['upload_dir'] = $args;
161 $log_item .= $args;
162 }
163
164 $current_log = $this->errors['error_log'];
165 if ( is_array( $current_log ) && count( $current_log ) >= 10 ) {
166 reset( $current_log );
167 unset( $current_log[ key( $current_log ) ] );
168 }
169 $current_log[] = $log_item;
170 $this->errors['error_log'] = $current_log;
171 update_option( $this->reporter_key, $this->errors, false );
172
173 }
174
175
176 /**
177 * Stores information about an encountered error related to a connected account
178 *
179 * @param $connected_account array
180 * @param $error_type string
181 * @param $details mixed/array/string
182 *
183 * @since 2.19
184 */
185 public function add_connected_account_error( $connected_account, $error_type, $details ) {
186 $account_id = $connected_account['id'];
187 $this->errors['accounts'][ $account_id ][ $error_type ] = $details;
188
189 if ( $error_type === 'api' || $error_type === 'accesstoken' ) {
190 $this->errors['accounts'][ $account_id ][ $error_type ]['clear_time'] = time() + 60 * 3;
191 }
192
193 if ( isset( $details['error']['code'] )
194 && (int)$details['error']['code'] === 18 ) {
195 $this->errors['accounts'][ $account_id ][ $error_type ]['clear_time'] = time() + 60 * 15;
196 }
197
198 \CustomFacebookFeed\Builder\CFF_Source::add_error( $account_id, $details );
199 }
200
201 /**
202 * @return mixed
203 *
204 * @since 2.19
205 */
206 public function get_error_log() {
207 return $this->errors['error_log'];
208 }
209
210
211
212 /**
213 * Creates an array of information for easy display of API errors
214 *
215 * @param $response
216 * @param array $connected_account
217 *
218 * @return array
219 *
220 * @since 2.19
221 */
222 public function generate_error_message( $response, $connected_account = array( 'username' => '' ) ) {
223 $error_message_return = array(
224 'public_message' => '',
225 'admin_message' => '',
226 'frontend_directions' => '',
227 'backend_directions' => '',
228 'post_id' => get_the_ID(),
229 'errorno' => '',
230 'time' => time()
231 );
232
233 if( isset( $response['error']['code'] ) ){
234 $error_code = (int)$response['error']['code'];
235 if ( $error_code === 104 ) {
236 $error_code = 999;
237 $url = 'https://smashballoon.com/doc/error-999-access-token-could-not-be-decrypted/';
238
239 $response['error']['message'] = __( 'Your access token could not be decrypted on this website. Reconnect this account or go to our website to learn how to prevent this.', 'custom-facebook-feed' );
240 } else {
241 $url = 'https://smashballoon.com/doc/facebook-api-errors/';
242 }
243
244 $api_error_number_message = sprintf( __( 'API Error %s:', 'custom-facebook-feed' ), $error_code );
245 $error_message_return['public_message'] = __( 'Error connecting to the Facebook API.', 'custom-facebook-feed' ) . ' ' . $api_error_number_message;
246 $ppca_error = ( strpos($response['error']['message'], 'Public Content Access') !== false ) ? true : false;
247
248 $error_message_return['admin_message'] = ( $ppca_error)
249 ? '<B>PPCA Error:</b> Due to Facebook API changes it is no longer possible to display a feed from a Facebook Page you are not an admin of. Please use the button below for more information on how to fix this.'
250 : '<strong>' . $api_error_number_message . '</strong><br>' . $response['error']['message'];
251
252 $error_message_return['frontend_directions'] = ( $ppca_error )
253 ? '<p class="cff-error-directions"><a href="https://smashballoon.com/facebook-api-changes-september-4-2020/" target="_blank" rel="noopener">' . __( 'Directions on How to Resolve This Issue', 'custom-facebook-feed' ) . '</a></p>'
254 : '<p class="cff-error-directions"><a href="' . $url . '?facebook&utm_campaign=facebook-pro&utm_source=error-message&utm_medium=frontend#'. absint( $error_code ) .'" target="_blank" rel="noopener">' . __( 'Directions on How to Resolve This Issue', 'custom-facebook-feed' ) . '</a></p>';
255
256 $error_message_return['backend_directions'] = ( $ppca_error )
257 ? '<a class="cff-notice-btn cff-btn-blue" href="https://smashballoon.com/facebook-api-changes-september-4-2020/" target="_blank" rel="noopener">' . __( 'Directions on How to Resolve This Issue', 'custom-facebook-feed' ) . '</a>'
258 : '<a class="cff-notice-btn cff-btn-blue" href="' . $url . '?facebook&utm_campaign=facebook-pro&utm_source=error-message&utm_medium=frontend#'. absint( $error_code ) .'" target="_blank" rel="noopener">' . __( 'Directions on How to Resolve This Issue', 'custom-facebook-feed' ) . '</a>';
259
260 $error_message_return['errorno'] = $error_code;
261
262 }else{
263 $error_message_return['error_message'] = __( 'An unknown error has occurred.', 'custom-facebook-feed' );
264 $error_message_return['admin_message'] = json_encode( $response );
265 }
266
267 return $error_message_return;
268
269 }
270
271
272
273
274 /**
275 * Certain API errors are considered critical and will trigger
276 * the various notifications to users to correct them.
277 *
278 * @param $details
279 *
280 * @return bool
281 *
282 * @since 2.7/5.10
283 */
284 public function is_critical_error( $details ) {
285 $error_code = (int)$details['error']['code'];
286
287 $critical_codes = array(
288 10,
289 100,
290 200,
291 190,
292 104,
293 999
294 );
295
296 return in_array( $error_code, $critical_codes, true );
297 }
298
299 /**
300 * @param $type
301 *
302 * @since 2.19
303 */
304 public function remove_error( $type, $connected_account = false ) {
305 $update = false;
306 if ( ! empty( $this->errors[ $type ] ) ) {
307 $this->errors[ $type ] = array();
308 $this->add_action_log( 'Cleared ' . $type .' error.' );
309 $update = true;
310 }
311
312 if ( $update ) {
313 update_option( $this->reporter_key, $this->errors, false );
314 }
315
316 }
317
318 public function remove_all_errors() {
319 delete_option( $this->reporter_key );
320 }
321
322 public function reset_api_errors() {
323 $this->errors['connection'] = array();
324 $this->errors['accounts'] = array();
325 update_option( $this->reporter_key, $this->errors, false );
326 }
327
328 /**
329 * @param $type
330 * @param $message
331 *
332 * @since 2.0/5.0
333 */
334 public function add_frontend_error( $message, $directions ) {
335 $this->frontend_error = $message . $directions;
336 }
337
338 public function remove_frontend_error() {
339 $this->frontend_error = '';
340 }
341
342 /**
343 * @return string
344 *
345 * @since 2.0/5.0
346 */
347 public function get_frontend_error() {
348 return $this->frontend_error;
349 }
350
351 public function get_critical_errors() {
352 if ( ! $this->are_critical_errors() ) {
353 return '';
354 }
355 $error_message = $directions = false;
356 if ( isset( $this->errors['connection']['critical'] ) ) {
357 $errors = $this->get_errors();
358 $error = $errors['connection'];
359 $error_message_array = $error['error_message'];
360
361 $error_message = $error_message_array['admin_message'];
362
363 $directions = '<p class="cff-error-directions">';
364 $directions .= $error_message_array['backend_directions'];
365 $directions .= '<button data-url="'.get_the_permalink( $error_message_array['post_id'] ).'" class="cff-clear-errors-visit-page cff-space-left cff-btn cff-notice-btn cff-btn-grey">' . __( 'View Feed and Retry', 'custom-facebook-feed' ) . '</button>';
366 $directions .= '</p>';
367 }else{
368
369 }
370
371
372 return [
373 'error_message' => $error_message,
374 'directions' => $directions
375 ];
376 }
377
378 public function are_critical_errors() {
379 $are_errors = false;
380 $errors = $this->get_errors();
381 if( isset( $errors['connection']['critical'] ) && $errors['connection']['critical'] === true){
382 return true;
383 }else{
384 $connected_accounts = CFF_Utils::cff_get_connected_accounts();
385 foreach ( $connected_accounts as $connected_account ) {
386 $connected_account = (array)$connected_account;
387 if ( isset( $this->errors['accounts'][ $connected_account['id' ] ]['api'] ) ) {
388 if ( isset( $this->errors['accounts'][ $connected_account['id'] ]['api']['error'] ) ) {
389 return $this->is_critical_error( $this->errors['accounts'][ $connected_account['id'] ]['api'] );
390 }
391 }
392 }
393 }
394
395
396 return $are_errors;
397 }
398
399 /**
400 * Stores a time stamped string of information about
401 * actions that might lead to correcting an error
402 *
403 * @param string $log_item
404 *
405 * @since 2.19
406 */
407 public function add_action_log( $log_item ) {
408 $current_log = $this->errors['action_log'];
409
410 if ( is_array( $current_log ) && count( $current_log ) >= 10 ) {
411 reset( $current_log );
412 unset( $current_log[ key( $current_log ) ] );
413 }
414 $current_log[] = date( 'm-d H:i:s' ) . ' - ' . $log_item;
415
416 $this->errors['action_log'] = $current_log;
417 update_option( $this->reporter_key, $this->errors, false );
418 }
419
420 /**
421 * @return mixed
422 *
423 * @since 2.19
424 */
425 public function get_action_log() {
426 return $this->errors['action_log'];
427 }
428
429
430 /**
431 * Load the critical notice for logged in users.
432 */
433 function critical_error_notice() {
434 // Don't do anything for guests.
435 if ( ! is_user_logged_in() ) {
436 return;
437 }
438
439 // Only show this to users who are not tracked.
440 if ( ! current_user_can( 'edit_posts' ) ) {
441 return;
442 }
443
444 if ( ! $this->are_critical_errors() ) {
445 return;
446 }
447
448
449 // Don't show if already dismissed.
450 if ( get_option( 'cff_dismiss_critical_notice', false ) ) {
451 return;
452 }
453
454 /** TODO: Match real option */
455 $options = get_option('cff_settings' );
456 if ( isset( $options['disable_admin_notice'] ) && $options['disable_admin_notice'] === 'on' ) {
457 return;
458 }
459
460 ?>
461 <div class="cff-critical-notice cff-critical-notice-hide">
462 <div class="cff-critical-notice-icon">
463 <img src="<?php echo CFF_PLUGIN_URL . 'admin/assets/img/cff-icon.png'; ?>" width="45" alt="Custom Facebook Feed icon" />
464 </div>
465 <div class="cff-critical-notice-text">
466 <h3><?php esc_html_e( 'Facebook Feed Critical Issue', 'custom-facebook-feed' ); ?></h3>
467 <p>
468 <?php
469 $doc_url = admin_url() . 'admin.php?page=cff-settings';
470 // Translators: %s is the link to the article where more details about critical are listed.
471 printf( esc_html__( 'An issue is preventing your Custom Facebook Feeds from updating. %1$sResolve this issue%2$s.', 'custom-facebook-feed' ), '<a href="' . esc_url( $doc_url ) . '" target="_blank">', '</a>' );
472 ?>
473 </p>
474 </div>
475 <div class="cff-critical-notice-close">&times;</div>
476 </div>
477 <style type="text/css">
478 .cff-critical-notice {
479 position: fixed;
480 bottom: 20px;
481 right: 15px;
482 font-family: Arial, Helvetica, "Trebuchet MS", sans-serif;
483 background: #fff;
484 box-shadow: 0 0 10px 0 #dedede;
485 padding: 10px 10px;
486 display: flex;
487 align-items: center;
488 justify-content: center;
489 width: 325px;
490 max-width: calc( 100% - 30px );
491 border-radius: 6px;
492 transition: bottom 700ms ease;
493 z-index: 10000;
494 }
495
496 .cff-critical-notice h3 {
497 font-size: 13px;
498 color: #222;
499 font-weight: 700;
500 margin: 0 0 4px;
501 padding: 0;
502 line-height: 1;
503 border: none;
504 }
505
506 .cff-critical-notice p {
507 font-size: 12px;
508 color: #7f7f7f;
509 font-weight: 400;
510 margin: 0;
511 padding: 0;
512 line-height: 1.2;
513 border: none;
514 }
515
516 .cff-critical-notice p a {
517 color: #7f7f7f;
518 font-size: 12px;
519 line-height: 1.2;
520 margin: 0;
521 padding: 0;
522 text-decoration: underline;
523 font-weight: 400;
524 }
525
526 .cff-critical-notice p a:hover {
527 color: #666;
528 }
529
530 .cff-critical-notice-icon img {
531 height: auto;
532 display: block;
533 margin: 0;
534 }
535
536 .cff-critical-notice-icon {
537 padding: 0;
538 border-radius: 4px;
539 flex-grow: 0;
540 flex-shrink: 0;
541 margin-right: 12px;
542 overflow: hidden;
543 }
544
545 .cff-critical-notice-close {
546 padding: 10px;
547 margin: -12px -9px 0 0;
548 border: none;
549 box-shadow: none;
550 border-radius: 0;
551 color: #7f7f7f;
552 background: transparent;
553 line-height: 1;
554 align-self: flex-start;
555 cursor: pointer;
556 font-weight: 400;
557 }
558 .cff-critical-notice-close:hover,
559 .cff-critical-notice-close:focus{
560 color: #111;
561 }
562
563 .cff-critical-notice.cff-critical-notice-hide {
564 bottom: -200px;
565 }
566 </style>
567 <?php
568
569 if ( ! wp_script_is( 'jquery', 'queue' ) ) {
570 wp_enqueue_script( 'jquery' );
571 }
572 ?>
573 <script>
574 if ( 'undefined' !== typeof jQuery ) {
575 jQuery( document ).ready( function ( $ ) {
576 /* Don't show the notice if we don't have a way to hide it (no js, no jQuery). */
577 $( document.querySelector( '.cff-critical-notice' ) ).removeClass( 'cff-critical-notice-hide' );
578 $( document.querySelector( '.cff-critical-notice-close' ) ).on( 'click', function ( e ) {
579 e.preventDefault();
580 $( this ).closest( '.cff-critical-notice' ).addClass( 'cff-critical-notice-hide' );
581 $.ajax( {
582 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
583 method: 'POST',
584 data: {
585 action: 'cff_dismiss_critical_notice',
586 nonce: '<?php echo esc_js( wp_create_nonce( 'cff-critical-notice' ) ); ?>',
587 }
588 } );
589 } );
590 } );
591 }
592 </script>
593 <?php
594 }
595
596 /**
597 * Ajax handler to hide the critical notice.
598 */
599 public function dismiss_critical_notice() {
600
601 check_ajax_referer( 'cff-critical-notice', 'nonce' );
602 $cap = current_user_can( 'manage_custom_facebook_feed_options' ) ? 'manage_custom_facebook_feed_options' : 'manage_options';
603 $cap = apply_filters( 'cff_settings_pages_capability', $cap );
604 if ( ! current_user_can( $cap ) ) {
605 wp_send_json_error(); // This auto-dies.
606 }
607
608 update_option( 'cff_dismiss_critical_notice', 1, false );
609
610 wp_die();
611
612 }
613
614 public function send_report_email() {
615 $options = get_option( 'cff_style_settings', array() );
616
617 $to_string = ! empty( $options['email_notification_addresses'] ) ? str_replace( ' ', '', $options['email_notification_addresses'] ) : get_option( 'admin_email', '' );
618
619 $to_array_raw = explode( ',', $to_string );
620 $to_array = array();
621
622 foreach ( $to_array_raw as $email ) {
623 if ( is_email( $email ) ) {
624 $to_array[] = $email;
625 }
626 }
627
628 if ( empty( $to_array ) ) {
629 return false;
630 }
631 $from_name = esc_html( wp_specialchars_decode( get_bloginfo( 'name' ) ) );
632 $email_from = $from_name . ' <' . get_option( 'admin_email', $to_array[0] ) . '>';
633 $header_from = "From: " . $email_from;
634
635 $headers = array( 'Content-Type: text/html; charset=utf-8', $header_from );
636
637 $header_image = CFF_PLUGIN_URL . 'admin/assets/img/balloon-120.png';
638 $title = __( 'Custom Facebook Feed Report for ' . home_url() );
639 $link = admin_url( 'admin.php?page=cff-settings');
640 //&tab=customize-advanced
641 $footer_link = admin_url('admin.php?page=cff-style&tab=misc&flag=emails');
642 $bold = __( 'There\'s an Issue with a Facebook Feed on Your Website', 'custom-facebook-feed' );
643 $details = '<p>' . __( 'A Custom Facebook Feed on your website is currently unable to connect to Facebook to retrieve new posts. Don\'t worry, your feed is still being displayed using a cached version, but is no longer able to display new posts.', 'custom-facebook-feed' ) . '</p>';
644 $details .= '<p>' . sprintf( __( 'This is caused by an issue with your Facebook account connecting to the Facebook API. For information on the exact issue and directions on how to resolve it, please visit the %sCustom Facebook Feed settings page%s on your website.', 'custom-facebook-feed' ), '<a href="' . esc_url( $link ) . '">', '</a>' ). '</p>';
645 $message_content = '<h6 style="padding:0;word-wrap:normal;font-family:\'Helvetica Neue\',Helvetica,Arial,sans-serif;font-weight:bold;line-height:130%;font-size: 16px;color:#444444;text-align:inherit;margin:0 0 20px 0;Margin:0 0 20px 0;">' . $bold . '</h6>' . $details;
646 include_once CFF_PLUGIN_DIR . 'class-cff-education.php';
647 $educator = new CFF_Education();
648 $dyk_message = $educator->dyk_display();
649 ob_start();
650 include CFF_PLUGIN_DIR . 'email.php';
651 $email_body = ob_get_contents();
652 ob_get_clean();
653 $sent = wp_mail( $to_array, $title, $email_body, $headers );
654
655 return $sent;
656 }
657
658 public function maybe_trigger_report_email_send() {
659 if ( ! $this->are_critical_errors() ) {
660 return;
661 }
662 /** TODO: Match real option */
663 $options = get_option('cff_settings' );
664
665 if ( isset( $options['enable_email_report'] ) && empty( $options['enable_email_report'] ) ) {
666 return;
667 }
668
669 $this->send_report_email();
670 }
671
672 public function admin_error_notices() {
673
674 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'cff-settings' )) ) {
675 $errors = $this->get_errors();
676 if ( ! empty( $errors ) && (! empty( $errors['database_create'] ) || ! empty( $errors['upload_dir'] )) ) : ?>
677 <div class="cff-admin-notices cff-critical-error-notice">
678 <?php if ( ! empty( $errors['database_create'] ) ) echo '<p>' . $errors['database_create'] . '</p>'; ?>
679 <?php if ( ! empty( $errors['upload_dir'] ) ) echo '<p>' . $errors['upload_dir'] . '</p>'; ?>
680 <p><?php _e( sprintf( 'Visit our %s page for help', '<a href="https://smashballoon.com/custom-facebook-feed/faq/" class="cff-notice-btn cff-btn-grey" target="_blank">FAQ</a>' ), 'custom-facebook-feed' ); ?></p>
681 </div>
682
683 <?php endif;
684 $errors = $this->get_critical_errors();
685 if ( $this->are_critical_errors() && is_array( $errors ) && $errors['error_message'] !== false && $errors['directions'] !== false ) :
686 ?>
687 <div class="cff-admin-notices cff-critical-error-notice">
688 <span class="sb-notice-icon sb-error-icon">
689 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
690 <path d="M10 0C4.48 0 0 4.48 0 10C0 15.52 4.48 20 10 20C15.52 20 20 15.52 20 10C20 4.48 15.52 0 10 0ZM11 15H9V13H11V15ZM11 11H9V5H11V11Z" fill="#D72C2C"/>
691 </svg>
692 </span>
693 <div class="cff-notice-body">
694 <h3 class="sb-notice-title">
695 <?php echo esc_html__( 'Custom Facebook Feed is encountering an error and your feeds may not be updating due to the following reasons:', 'custom-facebook-feed') ; ?>
696 </h3>
697
698 <p><?php echo $errors['error_message']; ?></p>
699
700 <div class="license-action-btns">
701 <?php echo $errors['directions']; ?>
702 </div>
703 </div>
704 </div>
705 <?php
706 endif;
707
708 /*
709 $errors = $this->get_critical_errors();
710 if ( $this->are_critical_errors() && ! empty( $errors ) ) :
711 if ( isset( $errors['wp_remote_get'] ) ) {
712 $error = $errors['wp_remote_get'];
713 $error_message = $error['admin_message'];
714 $button = $error['backend_directions'];
715 $post_id = $error['post_id'];
716 $directions = '<p class="cff-error-directions">';
717 $directions .= $button;
718 $directions .= '<button data-url="'.get_the_permalink( $post_id ).'" class="cff-clear-errors-visit-page cff-space-left button button-secondary">' . __( 'View Feed and Retry', 'custom-facebook-feed' ) . '</button>';
719 $directions .= '</p>';
720 } elseif ( isset( $errors['api'] ) ) {
721 $error = $errors['api'];
722 $error_message = $error['admin_message'];
723 $button = $error['backend_directions'];
724 $post_id = $error['post_id'];
725 $directions = '<p class="cff-error-directions">';
726 $directions .= $button;
727 $directions .= '<button data-url="'.get_the_permalink( $post_id ).'" class="cff-clear-errors-visit-page cff-space-left button button-secondary">' . __( 'View Feed and Retry', 'custom-facebook-feed' ) . '</button>';
728 $directions .= '</p>';
729 } else {
730 $error = $errors['accesstoken'];
731
732 $tokens = array();
733 $post_id = false;
734 foreach ( $error as $token ) {
735 $tokens[] = $token['accesstoken'];
736 $post_id = $token['post_id'];
737 }
738 $error_message = sprintf( __( 'The access token %s is invalid or has expired.', 'custom-facebook-feed' ), implode( ', ', $tokens ) );
739 $directions = '<p class="cff-error-directions">';
740 $directions .= '<button class="button button-primary cff-reconnect">' . __( 'Reconnect Your Account', 'custom-facebook-feed' ) . '</button>';
741 $directions .= '<button data-url="'.get_the_permalink( $post_id ).'" class="cff-clear-errors-visit-page cff-space-left button button-secondary">' . __( 'View Feed and Retry', 'custom-facebook-feed' ) . '</button>';
742 $directions .= '</p>';
743 }
744 ?>
745 <div class="notice notice-warning is-dismissible cff-admin-notice">
746 <p><strong><?php echo esc_html__( 'Custom Facebook Feed is encountering an error and your feeds may not be updating due to the following reasons:', 'custom-facebook-feed') ; ?></strong></p>
747
748 <?php echo $error_message; ?>
749
750 <?php echo $directions; ?>
751 </div>
752 <?php endif;
753 */
754
755 }
756
757 }
758
759 }
760