Skip to content

Commit

Permalink
Use WP_filesystem; fix return value if not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Jan 7, 2025
1 parent 6b168b5 commit 60d0342
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/my-calendar-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,11 @@ function mc_import_settings() {
if ( $nonce ) {
$size = isset( $_FILES['mc-import-settings']['size'] ) ? absint( $_FILES['mc-import-settings']['size'] ) : 0;
$name = isset( $_FILES['mc-import-settings']['tmp_name'] ) ? sanitize_text_field( $_FILES['mc-import-settings']['tmp_name'] ) : '';
$settings = ( 0 !== $size ) ? file_get_contents( $name ) : false;
global $wp_filesystem;
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();

$settings = ( 0 !== $size ) ? $wp_filesystem->get_contents( $name ) : false;
if ( ! $settings ) {
$return = __( 'No settings file provided.', 'my-calendar' );
} else {
Expand Down Expand Up @@ -555,8 +559,8 @@ function mc_import_settings() {
$return = __( 'My Calendar settings have been replaced with the imported values.', 'my-calendar' );
}
}
return $return;
}
return $return;
}
}
return '';
Expand Down
6 changes: 5 additions & 1 deletion src/my-calendar-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ function mc_setup_template( $template, $default_template ) {
// allow reference by file to external template.
$template = ( 'default' === $template ) ? '' : $template;
if ( '' !== $template && mc_file_exists( $template ) ) {
$template = file_get_contents( mc_get_file( $template ) );
global $wp_filesystem;
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();

$template = $wp_filesystem->get_contents( mc_get_file( $template ) );
}
if ( mc_key_exists( $template ) ) {
$template = mc_get_custom_template( $template );
Expand Down

0 comments on commit 60d0342

Please sign in to comment.