PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.1.2
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.1.2
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 4 years ago Builder 4 years ago Helpers 4 years ago CFF_Autolink.php 4 years ago CFF_Blocks.php 4 years ago CFF_Cache.php 4 years ago CFF_Education.php 4 years ago CFF_Elementor_Base.php 4 years ago CFF_Elementor_Widget.php 4 years ago CFF_Error_Reporter.php 4 years ago CFF_FB_Settings.php 4 years ago CFF_Feed_Elementor_Control.php 4 years ago CFF_Feed_Locator.php 4 years ago CFF_Feed_Pro.php 4 years ago CFF_GDPR_Integrations.php 4 years ago CFF_Group_Posts.php 4 years ago CFF_HTTP_Request.php 4 years ago CFF_Oembed.php 4 years ago CFF_Parse.php 4 years ago CFF_Resizer.php 4 years ago CFF_Response.php 4 years ago CFF_Shortcode.php 4 years ago CFF_Shortcode_Display.php 4 years ago CFF_SiteHealth.php 4 years ago CFF_Utils.php 4 years ago CFF_View.php 4 years ago Custom_Facebook_Feed.php 4 years ago SB_Facebook_Data_Encryption.php 4 years ago SB_Facebook_Data_Manager.php 4 years ago
CFF_Error_Reporter.php
748 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 $connected_account = CFF_Utils::cff_get_account( $connected_account_term );
91 } else {
92 $connected_account = $connected_account_term;
93 }
94 $log_item .= $args['error']['message'];
95 $this->add_connected_account_error( $connected_account, $type, $args );
96 }
97
98 //Access Token Error
99 if( $type === 'accesstoken' ){
100 $accesstoken_error_exists = false;
101 if ( isset( $this->errors['accounts'] ) ) {
102 foreach ($this->errors['accounts'] as $account ) {
103 if ( $args['accesstoken'] === $account['accesstoken'] ) {
104 $accesstoken_error_exists = true;
105 }
106 }
107 }
108 if ( !$accesstoken_error_exists ) {
109 $this->errors['accounts'][ $connected_account['id'] ][] = array(
110 'accesstoken' => $args['accesstoken'],
111 'post_id' => $args['post_id'],
112 'critical' => true,
113 'type' => $type,
114 'errorno' => $args['errorno']
115 );
116
117 }
118 }
119
120 //Connection Error API & WP REMOTE CALL
121 if( $type === 'api' || $type === 'wp_remote_get' ){
122 $connection_details = array(
123 'error_id' => ''
124 );
125 $connection_details['critical'] = false;
126
127 if( isset( $args['error']['code'] ) ){
128 $connection_details['error_id'] = $args['error']['code'];
129 if ( $this->is_critical_error( $args ) ) {
130 $connection_details['critical'] = true;
131 }
132
133 }elseif( isset( $args['response'] ) && is_wp_error( $args['response'] )){
134 foreach ( $args['response']->errors as $key => $item ) {
135 $connection_details['error_id'] = $key;
136 }
137 $connection_details['critical'] = true;
138 }
139
140 $connection_details['error_message'] = $this->generate_error_message( $args, $connected_account );
141 $log_item .= $connection_details['error_message']['admin_message'];
142 $this->errors['connection'] = $connection_details;
143 #var_dump($connection_details);
144 }
145
146 if ( $type === 'image_editor'
147 || $type === 'storage' ) {
148
149 $this->errors['resizing'] = $args;
150 $log_item .= $args;
151 }
152
153 if ( $type === 'database_create' ) {
154 $this->errors['database_create'] = $args;
155 $log_item .= $args;
156 }
157
158 if ( $type === 'upload_dir' ) {
159 $this->errors['upload_dir'] = $args;
160 $log_item .= $args;
161 }
162
163 $current_log = $this->errors['error_log'];
164 if ( is_array( $current_log ) && count( $current_log ) >= 10 ) {
165 reset( $current_log );
166 unset( $current_log[ key( $current_log ) ] );
167 }
168 $current_log[] = $log_item;
169 $this->errors['error_log'] = $current_log;
170 update_option( $this->reporter_key, $this->errors, false );
171
172 }
173
174
175 /**
176 * Stores information about an encountered error related to a connected account
177 *
178 * @param $connected_account array
179 * @param $error_type string
180 * @param $details mixed/array/string
181 *
182 * @since 2.19
183 */
184 public function add_connected_account_error( $connected_account, $error_type, $details ) {
185 $account_id = $connected_account['id'];
186 $this->errors['accounts'][ $account_id ][ $error_type ] = $details;
187
188 if ( $error_type === 'api' || $error_type === 'accesstoken' ) {
189 $this->errors['accounts'][ $account_id ][ $error_type ]['clear_time'] = time() + 60 * 3;
190 }
191
192 if ( isset( $details['error']['code'] )
193 && (int)$details['error']['code'] === 18 ) {
194 $this->errors['accounts'][ $account_id ][ $error_type ]['clear_time'] = time() + 60 * 15;
195 }
196
197 \CustomFacebookFeed\Builder\CFF_Source::add_error( $account_id, $details );
198 }
199
200 /**
201 * @return mixed
202 *
203 * @since 2.19
204 */
205 public function get_error_log() {
206 return $this->errors['error_log'];
207 }
208
209
210
211 /**
212 * Creates an array of information for easy display of API errors
213 *
214 * @param $response
215 * @param array $connected_account
216 *
217 * @return array
218 *
219 * @since 2.19
220 */
221 public function generate_error_message( $response, $connected_account = array( 'username' => '' ) ) {
222 $error_message_return = array(
223 'public_message' => '',
224 'admin_message' => '',
225 'frontend_directions' => '',
226 'backend_directions' => '',
227 'post_id' => get_the_ID(),
228 'errorno' => '',
229 'time' => time()
230 );
231
232 if( isset( $response['error']['code'] ) ){
233 $error_code = (int)$response['error']['code'];
234 $api_error_number_message = sprintf( __( 'API Error %s:', 'custom-facebook-feed' ), $error_code );
235 $error_message_return['public_message'] = __( 'Error connecting to the Facebook API.', 'custom-facebook-feed' ) . ' ' . $api_error_number_message;
236 $ppca_error = ( strpos($response['error']['message'], 'Public Content Access') !== false ) ? true : false;
237
238 $error_message_return['admin_message'] = ( $ppca_error)
239 ? '<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.'
240 : '<strong>' . $api_error_number_message . '</strong><br>' . $response['error']['message'];
241
242 $error_message_return['frontend_directions'] = ( $ppca_error )
243 ? '<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>'
244 : '<p class="cff-error-directions"><a href="https://smashballoon.com/custom-facebook-feed/docs/errors/" target="_blank" rel="noopener">' . __( 'Directions on How to Resolve This Issue', 'custom-facebook-feed' ) . '</a></p>';
245
246 $error_message_return['backend_directions'] = ( $ppca_error )
247 ? '<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>'
248 : '<a class="cff-notice-btn cff-btn-blue" href="https://smashballoon.com/custom-facebook-feed/docs/errors/" target="_blank" rel="noopener">' . __( 'Directions on How to Resolve This Issue', 'custom-facebook-feed' ) . '</a>';
249
250 $error_message_return['errorno'] = $error_code;
251
252 }else{
253 $error_message_return['error_message'] = __( 'An unknown error has occurred.', 'custom-facebook-feed' );
254 $error_message_return['admin_message'] = json_encode( $response );
255 }
256
257 return $error_message_return;
258
259 }
260
261
262
263
264 /**
265 * Certain API errors are considered critical and will trigger
266 * the various notifications to users to correct them.
267 *
268 * @param $details
269 *
270 * @return bool
271 *
272 * @since 2.7/5.10
273 */
274 public function is_critical_error( $details ) {
275 $error_code = (int)$details['error']['code'];
276
277 $critical_codes = array(
278 10,
279 100,
280 200,
281 190,
282 104
283 );
284
285 return in_array( $error_code, $critical_codes, true );
286 }
287
288 /**
289 * @param $type
290 *
291 * @since 2.19
292 */
293 public function remove_error( $type, $connected_account = false ) {
294 $update = false;
295 if ( ! empty( $this->errors[ $type ] ) ) {
296 $this->errors[ $type ] = array();
297 $this->add_action_log( 'Cleared ' . $type .' error.' );
298 $update = true;
299 }
300
301 if ( $update ) {
302 update_option( $this->reporter_key, $this->errors, false );
303 }
304
305 }
306
307 public function remove_all_errors() {
308 delete_option( $this->reporter_key );
309 }
310
311 public function reset_api_errors() {
312 $this->errors['connection'] = array();
313 $this->errors['accounts'] = array();
314 update_option( $this->reporter_key, $this->errors, false );
315 }
316
317 /**
318 * @param $type
319 * @param $message
320 *
321 * @since 2.0/5.0
322 */
323 public function add_frontend_error( $message, $directions ) {
324 $this->frontend_error = $message . $directions;
325 }
326
327 public function remove_frontend_error() {
328 $this->frontend_error = '';
329 }
330
331 /**
332 * @return string
333 *
334 * @since 2.0/5.0
335 */
336 public function get_frontend_error() {
337 return $this->frontend_error;
338 }
339
340 public function get_critical_errors() {
341 if ( ! $this->are_critical_errors() ) {
342 return '';
343 }
344 $error_message = $directions = false;
345 if ( isset( $this->errors['connection']['critical'] ) ) {
346 $errors = $this->get_errors();
347 $error = $errors['connection'];
348 $error_message_array = $error['error_message'];
349
350 $error_message = $error_message_array['admin_message'];
351
352 $directions = '<p class="cff-error-directions">';
353 $directions .= $error_message_array['backend_directions'];
354 $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>';
355 $directions .= '</p>';
356 }else{
357
358 }
359
360
361 return [
362 'error_message' => $error_message,
363 'directions' => $directions
364 ];
365 }
366
367 public function are_critical_errors() {
368 $are_errors = false;
369 $errors = $this->get_errors();
370 if( isset( $errors['connection']['critical'] ) && $errors['connection']['critical'] === true){
371 return true;
372 }else{
373 $connected_accounts = CFF_Utils::cff_get_connected_accounts();
374 foreach ( $connected_accounts as $connected_account ) {
375 $connected_account = (array)$connected_account;
376 if ( isset( $this->errors['accounts'][ $connected_account['id' ] ]['api'] ) ) {
377 if ( isset( $this->errors['accounts'][ $connected_account['id'] ]['api']['error'] ) ) {
378 return $this->is_critical_error( $this->errors['accounts'][ $connected_account['id'] ]['api'] );
379 }
380 }
381 }
382 }
383
384
385 return $are_errors;
386 }
387
388 /**
389 * Stores a time stamped string of information about
390 * actions that might lead to correcting an error
391 *
392 * @param string $log_item
393 *
394 * @since 2.19
395 */
396 public function add_action_log( $log_item ) {
397 $current_log = $this->errors['action_log'];
398
399 if ( is_array( $current_log ) && count( $current_log ) >= 10 ) {
400 reset( $current_log );
401 unset( $current_log[ key( $current_log ) ] );
402 }
403 $current_log[] = date( 'm-d H:i:s' ) . ' - ' . $log_item;
404
405 $this->errors['action_log'] = $current_log;
406 update_option( $this->reporter_key, $this->errors, false );
407 }
408
409 /**
410 * @return mixed
411 *
412 * @since 2.19
413 */
414 public function get_action_log() {
415 return $this->errors['action_log'];
416 }
417
418
419 /**
420 * Load the critical notice for logged in users.
421 */
422 function critical_error_notice() {
423 // Don't do anything for guests.
424 if ( ! is_user_logged_in() ) {
425 return;
426 }
427
428 // Only show this to users who are not tracked.
429 if ( ! current_user_can( 'edit_posts' ) ) {
430 return;
431 }
432
433 if ( ! $this->are_critical_errors() ) {
434 return;
435 }
436
437
438 // Don't show if already dismissed.
439 if ( get_option( 'cff_dismiss_critical_notice', false ) ) {
440 return;
441 }
442
443 /** TODO: Match real option */
444 $options = get_option('cff_settings' );
445 if ( isset( $options['disable_admin_notice'] ) && $options['disable_admin_notice'] === 'on' ) {
446 return;
447 }
448
449 ?>
450 <div class="cff-critical-notice cff-critical-notice-hide">
451 <div class="cff-critical-notice-icon">
452 <img src="<?php echo CFF_PLUGIN_URL . 'admin/assets/img/cff-icon.png'; ?>" width="45" alt="Custom Facebook Feed icon" />
453 </div>
454 <div class="cff-critical-notice-text">
455 <h3><?php esc_html_e( 'Facebook Feed Critical Issue', 'custom-facebook-feed' ); ?></h3>
456 <p>
457 <?php
458 $doc_url = admin_url() . 'admin.php?page=cff-settings';
459 // Translators: %s is the link to the article where more details about critical are listed.
460 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>' );
461 ?>
462 </p>
463 </div>
464 <div class="cff-critical-notice-close">&times;</div>
465 </div>
466 <style type="text/css">
467 .cff-critical-notice {
468 position: fixed;
469 bottom: 20px;
470 right: 15px;
471 font-family: Arial, Helvetica, "Trebuchet MS", sans-serif;
472 background: #fff;
473 box-shadow: 0 0 10px 0 #dedede;
474 padding: 10px 10px;
475 display: flex;
476 align-items: center;
477 justify-content: center;
478 width: 325px;
479 max-width: calc( 100% - 30px );
480 border-radius: 6px;
481 transition: bottom 700ms ease;
482 z-index: 10000;
483 }
484
485 .cff-critical-notice h3 {
486 font-size: 13px;
487 color: #222;
488 font-weight: 700;
489 margin: 0 0 4px;
490 padding: 0;
491 line-height: 1;
492 border: none;
493 }
494
495 .cff-critical-notice p {
496 font-size: 12px;
497 color: #7f7f7f;
498 font-weight: 400;
499 margin: 0;
500 padding: 0;
501 line-height: 1.2;
502 border: none;
503 }
504
505 .cff-critical-notice p a {
506 color: #7f7f7f;
507 font-size: 12px;
508 line-height: 1.2;
509 margin: 0;
510 padding: 0;
511 text-decoration: underline;
512 font-weight: 400;
513 }
514
515 .cff-critical-notice p a:hover {
516 color: #666;
517 }
518
519 .cff-critical-notice-icon img {
520 height: auto;
521 display: block;
522 margin: 0;
523 }
524
525 .cff-critical-notice-icon {
526 padding: 0;
527 border-radius: 4px;
528 flex-grow: 0;
529 flex-shrink: 0;
530 margin-right: 12px;
531 overflow: hidden;
532 }
533
534 .cff-critical-notice-close {
535 padding: 10px;
536 margin: -12px -9px 0 0;
537 border: none;
538 box-shadow: none;
539 border-radius: 0;
540 color: #7f7f7f;
541 background: transparent;
542 line-height: 1;
543 align-self: flex-start;
544 cursor: pointer;
545 font-weight: 400;
546 }
547 .cff-critical-notice-close:hover,
548 .cff-critical-notice-close:focus{
549 color: #111;
550 }
551
552 .cff-critical-notice.cff-critical-notice-hide {
553 bottom: -200px;
554 }
555 </style>
556 <?php
557
558 if ( ! wp_script_is( 'jquery', 'queue' ) ) {
559 wp_enqueue_script( 'jquery' );
560 }
561 ?>
562 <script>
563 if ( 'undefined' !== typeof jQuery ) {
564 jQuery( document ).ready( function ( $ ) {
565 /* Don't show the notice if we don't have a way to hide it (no js, no jQuery). */
566 $( document.querySelector( '.cff-critical-notice' ) ).removeClass( 'cff-critical-notice-hide' );
567 $( document.querySelector( '.cff-critical-notice-close' ) ).on( 'click', function ( e ) {
568 e.preventDefault();
569 $( this ).closest( '.cff-critical-notice' ).addClass( 'cff-critical-notice-hide' );
570 $.ajax( {
571 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
572 method: 'POST',
573 data: {
574 action: 'cff_dismiss_critical_notice',
575 nonce: '<?php echo esc_js( wp_create_nonce( 'cff-critical-notice' ) ); ?>',
576 }
577 } );
578 } );
579 } );
580 }
581 </script>
582 <?php
583 }
584
585 /**
586 * Ajax handler to hide the critical notice.
587 */
588 public function dismiss_critical_notice() {
589
590 check_ajax_referer( 'cff-critical-notice', 'nonce' );
591 $cap = current_user_can( 'manage_custom_facebook_feed_options' ) ? 'manage_custom_facebook_feed_options' : 'manage_options';
592 $cap = apply_filters( 'cff_settings_pages_capability', $cap );
593 if ( ! current_user_can( $cap ) ) {
594 wp_send_json_error(); // This auto-dies.
595 }
596
597 update_option( 'cff_dismiss_critical_notice', 1, false );
598
599 wp_die();
600
601 }
602
603 public function send_report_email() {
604 $options = get_option( 'cff_style_settings', array() );
605
606 $to_string = ! empty( $options['email_notification_addresses'] ) ? str_replace( ' ', '', $options['email_notification_addresses'] ) : get_option( 'admin_email', '' );
607
608 $to_array_raw = explode( ',', $to_string );
609 $to_array = array();
610
611 foreach ( $to_array_raw as $email ) {
612 if ( is_email( $email ) ) {
613 $to_array[] = $email;
614 }
615 }
616
617 if ( empty( $to_array ) ) {
618 return false;
619 }
620 $from_name = esc_html( wp_specialchars_decode( get_bloginfo( 'name' ) ) );
621 $email_from = $from_name . ' <' . get_option( 'admin_email', $to_array[0] ) . '>';
622 $header_from = "From: " . $email_from;
623
624 $headers = array( 'Content-Type: text/html; charset=utf-8', $header_from );
625
626 $header_image = CFF_PLUGIN_URL . 'admin/assets/img/balloon-120.png';
627 $title = __( 'Custom Facebook Feed Report for ' . home_url() );
628 $link = admin_url( 'admin.php?page=cff-settings');
629 //&tab=customize-advanced
630 $footer_link = admin_url('admin.php?page=cff-style&tab=misc&flag=emails');
631 $bold = __( 'There\'s an Issue with a Facebook Feed on Your Website', 'custom-facebook-feed' );
632 $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>';
633 $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>';
634 $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;
635 include_once CFF_PLUGIN_DIR . 'class-cff-education.php';
636 $educator = new CFF_Education();
637 $dyk_message = $educator->dyk_display();
638 ob_start();
639 include CFF_PLUGIN_DIR . 'email.php';
640 $email_body = ob_get_contents();
641 ob_get_clean();
642 $sent = wp_mail( $to_array, $title, $email_body, $headers );
643
644 return $sent;
645 }
646
647 public function maybe_trigger_report_email_send() {
648 if ( ! $this->are_critical_errors() ) {
649 return;
650 }
651 /** TODO: Match real option */
652 $options = get_option('cff_settings' );
653
654 if ( isset( $options['enable_email_report'] ) && empty( $options['enable_email_report'] ) ) {
655 return;
656 }
657
658 $this->send_report_email();
659 }
660
661 public function admin_error_notices() {
662
663 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'cff-settings' )) ) {
664 $errors = $this->get_errors();
665 if ( ! empty( $errors ) && (! empty( $errors['database_create'] ) || ! empty( $errors['upload_dir'] )) ) : ?>
666 <div class="cff-admin-notices cff-critical-error-notice">
667 <?php if ( ! empty( $errors['database_create'] ) ) echo '<p>' . $errors['database_create'] . '</p>'; ?>
668 <?php if ( ! empty( $errors['upload_dir'] ) ) echo '<p>' . $errors['upload_dir'] . '</p>'; ?>
669 <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>
670 </div>
671
672 <?php endif;
673 $errors = $this->get_critical_errors();
674 if ( $this->are_critical_errors() && is_array( $errors ) && $errors['error_message'] !== false && $errors['directions'] !== false ) :
675 ?>
676 <div class="cff-admin-notices cff-critical-error-notice">
677 <span class="sb-notice-icon sb-error-icon">
678 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
679 <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"/>
680 </svg>
681 </span>
682 <div class="cff-notice-body">
683 <h3 class="sb-notice-title">
684 <?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') ; ?>
685 </h3>
686
687 <p><?php echo $errors['error_message']; ?></p>
688
689 <div class="license-action-btns">
690 <?php echo $errors['directions']; ?>
691 </div>
692 </div>
693 </div>
694 <?php
695 endif;
696
697 /*
698 $errors = $this->get_critical_errors();
699 if ( $this->are_critical_errors() && ! empty( $errors ) ) :
700 if ( isset( $errors['wp_remote_get'] ) ) {
701 $error = $errors['wp_remote_get'];
702 $error_message = $error['admin_message'];
703 $button = $error['backend_directions'];
704 $post_id = $error['post_id'];
705 $directions = '<p class="cff-error-directions">';
706 $directions .= $button;
707 $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>';
708 $directions .= '</p>';
709 } elseif ( isset( $errors['api'] ) ) {
710 $error = $errors['api'];
711 $error_message = $error['admin_message'];
712 $button = $error['backend_directions'];
713 $post_id = $error['post_id'];
714 $directions = '<p class="cff-error-directions">';
715 $directions .= $button;
716 $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>';
717 $directions .= '</p>';
718 } else {
719 $error = $errors['accesstoken'];
720
721 $tokens = array();
722 $post_id = false;
723 foreach ( $error as $token ) {
724 $tokens[] = $token['accesstoken'];
725 $post_id = $token['post_id'];
726 }
727 $error_message = sprintf( __( 'The access token %s is invalid or has expired.', 'custom-facebook-feed' ), implode( ', ', $tokens ) );
728 $directions = '<p class="cff-error-directions">';
729 $directions .= '<button class="button button-primary cff-reconnect">' . __( 'Reconnect Your Account', 'custom-facebook-feed' ) . '</button>';
730 $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>';
731 $directions .= '</p>';
732 }
733 ?>
734 <div class="notice notice-warning is-dismissible cff-admin-notice">
735 <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>
736
737 <?php echo $error_message; ?>
738
739 <?php echo $directions; ?>
740 </div>
741 <?php endif;
742 */
743
744 }
745
746 }
747
748 }