| @@ -6,8 +6,13 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace MainWP\Dashboard; |
| 9 | 9 | |
| 10 | +// Exit if accessed directly. | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit; | |
| 13 | +} | |
| 14 | + | |
| 10 | 15 | /** |
| 11 | 16 | * Class MainWP_Notification_Template |
| 12 | 17 | * |
| 13 | 18 | * @package MainWP\Dashboard |
| @@ -175,9 +180,9 @@ | ||
| 175 | 180 | * @since 4.1 |
| 176 | 181 | */ |
| 177 | 182 | do_action( 'mainwp_before_template_part', $template_name, $located, $args ); |
| 178 | 183 | |
| 179 | - include_once $located; // NOSONAR - WP compatible. | |
| 184 | + include $located; // NOSONAR - WP compatible. // `include` to fix loop load the template content. | |
| 180 | 185 | |
| 181 | 186 | /** |
| 182 | 187 | * Action: mainwp_after_template_part |
| 183 | 188 | * |
| @@ -299,8 +304,9 @@ | ||
| 299 | 304 | */ |
| 300 | 305 | public static function get_template_name_by_notification_type( $type = '' ) { |
| 301 | 306 | $types = array( |
| 302 | 307 | 'daily_digest' => 'emails/mainwp-daily-digest-email.php', |
| 308 | + 'auto_updates' => 'emails/mainwp-auto-updates-notification-email.php', | |
| 303 | 309 | 'uptime' => 'emails/mainwp-uptime-monitoring-email.php', |
| 304 | 310 | 'site_health' => 'emails/mainwp-site-health-monitoring-email.php', |
| 305 | 311 | 'http_check' => 'emails/mainwp-after-update-http-check-email.php', |
| 306 | 312 | 'deactivated_license_alert' => 'emails/mainwp-licenses-deactivated-alert-email.php', |
| @@ -359,10 +365,12 @@ | ||
| 359 | 365 | |
| 360 | 366 | if ( ! empty( $templ_base_name ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'save-email-template' ) ) { |
| 361 | 367 | $template_code = isset( $_POST[ 'edit_' . $type . '_code' ] ) ? wp_unslash( $_POST[ 'edit_' . $type . '_code' ] ) : ''; //phpcs:ignore -- saving template content. |
| 362 | 368 | $updated = $this->save_template( $template_code, $templ_base_name ); |
| 363 | - if ( $updated ) { | |
| 369 | + if ( true === $updated ) { | |
| 364 | 370 | $updated_templ = 3; |
| 371 | + } else { | |
| 372 | + $updated_templ = $updated; | |
| 365 | 373 | } |
| 366 | 374 | } |
| 367 | 375 | |
| 368 | 376 | return $updated_templ; |
| @@ -383,9 +391,14 @@ | ||
| 383 | 391 | * @param string $template_code Template code. |
| 384 | 392 | * @param string $template Template. |
| 385 | 393 | */ |
| 386 | 394 | public function save_template( $template_code, $template ) { |
| 387 | - if ( current_user_can( 'edit_themes' ) && ! empty( $template_code ) && ! empty( $template ) ) { | |
| 395 | + $failed = 31; | |
| 396 | + if ( empty( $template ) || empty( $template_code ) ) { | |
| 397 | + $failed = 34; | |
| 398 | + } elseif ( ! current_user_can( 'edit_themes' ) ) { | |
| 399 | + $failed = 35; | |
| 400 | + } else { | |
| 388 | 401 | $saved = false; |
| 389 | 402 | $file = $this->template_custom_path . $template; |
| 390 | 403 | $code = str_replace( PHP_EOL, '', $template_code ); // to fix issue create extra line breaks in custom template file. |
| 391 | 404 | |
| @@ -396,9 +409,13 @@ | ||
| 396 | 409 | if ( false !== $f ) { |
| 397 | 410 | fwrite( $f, $code ); |
| 398 | 411 | fclose( $f ); |
| 399 | 412 | $saved = true; |
| 413 | + } else { | |
| 414 | + $failed = 32; | |
| 400 | 415 | } |
| 416 | + } else { | |
| 417 | + $failed = 33; | |
| 401 | 418 | } |
| 402 | 419 | //phpcs:enable |
| 403 | 420 | |
| 404 | 421 | if ( $saved ) { |
| @@ -404,7 +421,8 @@ | ||
| 404 | 421 | if ( $saved ) { |
| 405 | 422 | return true; |
| 406 | 423 | } |
| 407 | 424 | } |
| 408 | - return false; | |
| 425 | + MainWP_Logger::instance()->debug( 'Saving email template failed :: [file=' . $this->template_custom_path . $template . ']' ); | |
| 426 | + return $failed; | |
| 409 | 427 | } |
| 410 | 428 | } |