From 59ce02ab475661cd85fc19618aacd422e5a4e642 Mon Sep 17 00:00:00 2001 From: Mykyta Synelnikov Date: Wed, 8 May 2024 13:53:13 +0300 Subject: [PATCH] - fixed PHP errors while update from 1.3.x version; --- ...mail_templates.php => email-templates.php} | 98 +++++++++---------- .../core/packages/2.0-beta1/functions.php | 4 +- .../2.0-beta1/{um_cpt.php => um-cpt.php} | 50 +++++----- 3 files changed, 75 insertions(+), 77 deletions(-) rename includes/admin/core/packages/2.0-beta1/{email_templates.php => email-templates.php} (63%) rename includes/admin/core/packages/2.0-beta1/{um_cpt.php => um-cpt.php} (57%) diff --git a/includes/admin/core/packages/2.0-beta1/email_templates.php b/includes/admin/core/packages/2.0-beta1/email-templates.php similarity index 63% rename from includes/admin/core/packages/2.0-beta1/email_templates.php rename to includes/admin/core/packages/2.0-beta1/email-templates.php index e7f3bcc8..1c05738b 100644 --- a/includes/admin/core/packages/2.0-beta1/email_templates.php +++ b/includes/admin/core/packages/2.0-beta1/email-templates.php @@ -1,16 +1,15 @@ mail()->get_template_filename( $template_name ); - $ext = ! $html ? '.php' : '.html'; + $ext = ! $html ? '.php' : '.html'; $blog_id = ''; if ( ! $html ) { @@ -18,14 +17,15 @@ function um_upgrade20beta1_template_in_theme( $template_name, $html = false ) { } // check if there is template at theme folder - $template = locate_template( array( - trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name_file . $ext - ) ); + $template = locate_template( + array( + trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name_file . $ext, + ) + ); // Return what we found. - return ! $template ? false : true; + return (bool) $template; } - /** * Method returns expected path for template * @@ -36,28 +36,26 @@ function um_upgrade20beta1_template_in_theme( $template_name, $html = false ) { * @return string */ function um_upgrade20beta1_get_template_file( $location, $template_name, $html = false ) { - $template_path = ''; + $template_path = ''; $template_name_file = UM()->mail()->get_template_filename( $template_name ); - $ext = ! $html ? '.php' : '.html'; - switch( $location ) { + $ext = ! $html ? '.php' : '.html'; + switch ( $location ) { case 'theme': - $blog_id = ''; if ( ! $html ) { $blog_id = UM()->mail()->get_blog_id(); } - - $template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' . $blog_id ). $template_name_file . $ext; + $template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' . $blog_id ) . $template_name_file . $ext; break; + case 'plugin': - $path = ! empty( UM()->mail()->path_by_slug[ $template_name ] ) ? UM()->mail()->path_by_slug[ $template_name ] : UM_PATH . 'templates/email'; + $path = ! empty( UM()->mail()->path_by_slug[ $template_name ] ) ? UM()->mail()->path_by_slug[ $template_name ] : UM_PATH . 'templates/email'; $template_path = trailingslashit( $path ) . $template_name . $ext; break; } return $template_path; } - /** * Ajax copy template to the theme * @@ -70,28 +68,23 @@ function um_upgrade20beta1_copy_email_template( $template ) { return false; } $plugin_template_path = um_upgrade20beta1_get_template_file( 'plugin', $template ); - $theme_template_path = um_upgrade20beta1_get_template_file( 'theme', $template ); - $temp_path = str_replace( trailingslashit( get_stylesheet_directory() ), '', $theme_template_path ); - $temp_path = str_replace( '/', DIRECTORY_SEPARATOR, $temp_path ); - $folders = explode( DIRECTORY_SEPARATOR, $temp_path ); - $folders = array_splice( $folders, 0, count( $folders ) - 1 ); - $cur_folder = ''; - $theme_dir = trailingslashit( get_stylesheet_directory() ); + $theme_template_path = um_upgrade20beta1_get_template_file( 'theme', $template ); + $temp_path = str_replace( trailingslashit( get_stylesheet_directory() ), '', $theme_template_path ); + $temp_path = str_replace( '/', DIRECTORY_SEPARATOR, $temp_path ); + $folders = explode( DIRECTORY_SEPARATOR, $temp_path ); + $folders = array_splice( $folders, 0, count( $folders ) - 1 ); + $cur_folder = ''; + $theme_dir = trailingslashit( get_stylesheet_directory() ); foreach ( $folders as $folder ) { - $prev_dir = $cur_folder; + $prev_dir = $cur_folder; $cur_folder .= $folder . DIRECTORY_SEPARATOR; if ( ! is_dir( $theme_dir . $cur_folder ) && wp_is_writable( $theme_dir . $prev_dir ) ) { mkdir( $theme_dir . $cur_folder, 0777 ); } } - if ( file_exists( $plugin_template_path ) && copy( $plugin_template_path, $theme_template_path ) ) { - return true; - } else { - return false; - } + return ( file_exists( $plugin_template_path ) && copy( $plugin_template_path, $theme_template_path ) ); } - /** * Insert email template content to file * @@ -99,21 +92,22 @@ function um_upgrade20beta1_copy_email_template( $template ) { * @param string $content Email template content */ function um_upgrade20beta1_insert_content( $path, $content ) { - $fp = @fopen( $path, "w" ); - @fputs( $fp, $content ); - @fclose( $fp ); + if ( file_exists( $path ) ) { + $fp = @fopen( $path, "w" ); + @fputs( $fp, $content ); + @fclose( $fp ); + } } - /** * Transferring email templates to new logic */ function um_upgrade20beta1_email_templates_process() { $templates_in_theme = 0; - $emails = UM()->config()->email_notifications; + $emails = UM()->config()->email_notifications; foreach ( $emails as $email_key => $value ) { - $in_theme = um_upgrade20beta1_template_in_theme( $email_key, true ); + $in_theme = um_upgrade20beta1_template_in_theme( $email_key, true ); $theme_template_path = um_upgrade20beta1_get_template_file( 'theme', $email_key ); if ( ! $in_theme ) { @@ -138,23 +132,22 @@ function um_upgrade20beta1_email_templates_process() { um_upgrade20beta1_insert_content( $theme_template_path, $setting_value ); } - } else { //there is HTML email template in a theme's folder $theme_template_path_html = um_upgrade20beta1_get_template_file( 'theme', $email_key, true ); - $setting_value = preg_replace( '/<\/body>|<\/head>||<\/html>||/' , '', file_get_contents( $theme_template_path_html ) ); + $setting_value = preg_replace( '/<\/body>|<\/head>||<\/html>||/', '', file_get_contents( $theme_template_path_html ) ); if ( file_exists( $theme_template_path_html ) ) { - $temp_path = str_replace( trailingslashit( get_stylesheet_directory() ), '', $theme_template_path ); - $temp_path = str_replace( '/', DIRECTORY_SEPARATOR, $temp_path ); - $folders = explode( DIRECTORY_SEPARATOR, $temp_path ); - $folders = array_splice( $folders, 0, count( $folders ) - 1 ); + $temp_path = str_replace( trailingslashit( get_stylesheet_directory() ), '', $theme_template_path ); + $temp_path = str_replace( '/', DIRECTORY_SEPARATOR, $temp_path ); + $folders = explode( DIRECTORY_SEPARATOR, $temp_path ); + $folders = array_splice( $folders, 0, count( $folders ) - 1 ); $cur_folder = ''; - $theme_dir = trailingslashit( get_stylesheet_directory() ); + $theme_dir = trailingslashit( get_stylesheet_directory() ); foreach ( $folders as $folder ) { - $prev_dir = $cur_folder; + $prev_dir = $cur_folder; $cur_folder .= $folder . DIRECTORY_SEPARATOR; if ( ! is_dir( $theme_dir . $cur_folder ) && wp_is_writable( $theme_dir . $prev_dir ) ) { mkdir( $theme_dir . $cur_folder, 0777 ); @@ -168,26 +161,25 @@ function um_upgrade20beta1_email_templates_process() { $templates_in_theme++; } - } - } } - $email_html = ( $templates_in_theme > 0 ) ? true : false; + $email_html = $templates_in_theme > 0; UM()->options()->update( 'email_html', $email_html ); } - if ( is_multisite() ) { $start_blog_id = get_current_blog_id(); - $blog_ids = get_sites( array( - 'fields' => 'ids', - ) ); + $blog_ids = get_sites( + array( + 'fields' => 'ids', + ) + ); - foreach ( $blog_ids as $blog_id ) { - switch_to_blog( $blog_id ); + foreach ( $blog_ids as $b_id ) { + switch_to_blog( $b_id ); um_upgrade20beta1_email_templates_process(); } diff --git a/includes/admin/core/packages/2.0-beta1/functions.php b/includes/admin/core/packages/2.0-beta1/functions.php index 830b6fdc..f3ec400d 100644 --- a/includes/admin/core/packages/2.0-beta1/functions.php +++ b/includes/admin/core/packages/2.0-beta1/functions.php @@ -150,7 +150,7 @@ function um_upgrade_cpt20beta1() { um_maybe_unset_time_limit(); - include 'um_cpt.php'; + include 'um-cpt.php'; wp_send_json_success( array( 'message' => __( 'UM Custom Posts was upgraded successfully', 'ultimate-member' ) ) ); } @@ -318,7 +318,7 @@ function um_upgrade_email_templates20beta1() { um_maybe_unset_time_limit(); - include 'email_templates.php'; + include 'email-templates.php'; update_option( 'um_last_version_upgrade', '2.0-beta1' ); delete_option( 'um_roles_associations' ); diff --git a/includes/admin/core/packages/2.0-beta1/um_cpt.php b/includes/admin/core/packages/2.0-beta1/um-cpt.php similarity index 57% rename from includes/admin/core/packages/2.0-beta1/um_cpt.php rename to includes/admin/core/packages/2.0-beta1/um-cpt.php index 8ff13119..6c073707 100644 --- a/includes/admin/core/packages/2.0-beta1/um_cpt.php +++ b/includes/admin/core/packages/2.0-beta1/um-cpt.php @@ -5,57 +5,63 @@ $roles_associations = get_option( 'um_roles_associations' ); //"use_global" meta change to "_use_custom_settings" //also update for forms metadata where "member" or "admin" -$forms_query = new WP_Query; -$forms = $forms_query->query( array( - 'post_type' => 'um_form', - 'posts_per_page' => -1, - 'fields' => 'ids' -) ); +$forms_query = new WP_Query(); +$forms = $forms_query->query( + array( + 'post_type' => 'um_form', + 'posts_per_page' => -1, + 'fields' => 'ids', + ) +); foreach ( $forms as $form_id ) { $form_type = get_post_meta( $form_id, '_um_mode', true ); if ( ! empty( $form_type ) ) { - $use_globals = get_post_meta( $form_id, "_um_{$form_type}_use_globals", true ); - $use_custom_settings = empty( $use_globals ) ? true : false; + $use_globals = get_post_meta( $form_id, "_um_{$form_type}_use_globals", true ); + $use_custom_settings = empty( $use_globals ); update_post_meta( $form_id, "_um_{$form_type}_use_custom_settings", $use_custom_settings ); delete_post_meta( $form_id, "_um_{$form_type}_use_globals" ); - $role = get_post_meta( $form_id, "_um_{$form_type}_role", true ); - if ( $role ) { - update_post_meta( $form_id, "_um_{$form_type}_role", $roles_associations[ $role ] ); + $role_slug = get_post_meta( $form_id, "_um_{$form_type}_role", true ); + if ( $role_slug && array_key_exists( $role_slug, $roles_associations ) ) { + update_post_meta( $form_id, "_um_{$form_type}_role", $roles_associations[ $role_slug ] ); } } } //for metadata for all UM Member Directories //also update for forms metadata where "member" or "admin" -$forms_query = new WP_Query; -$member_directories = $forms_query->query( array( - 'post_type' => 'um_directory', - 'posts_per_page' => -1, - 'fields' => 'ids' -) ); +$forms_query = new WP_Query(); +$member_directories = $forms_query->query( + array( + 'post_type' => 'um_directory', + 'posts_per_page' => -1, + 'fields' => 'ids', + ) +); foreach ( $member_directories as $directory_id ) { $directory_roles = get_post_meta( $directory_id, '_um_roles', true ); - if ( ! empty( $directory_roles ) ) { foreach ( $directory_roles as $i => $role_k ) { - $directory_roles[ $i ] = $roles_associations[ $role_k ]; + if ( array_key_exists( $role_k, $roles_associations ) ) { + $directory_roles[ $i ] = $roles_associations[ $role_k ]; + } } update_post_meta( $directory_id, '_um_roles', $directory_roles ); } $um_roles_can_search = get_post_meta( $directory_id, '_um_roles_can_search', true ); - if ( ! empty( $um_roles_can_search ) ) { foreach ( $um_roles_can_search as $i => $role_k ) { - $um_roles_can_search[ $i ] = $roles_associations[ $role_k ]; + if ( array_key_exists( $role_k, $roles_associations ) ) { + $um_roles_can_search[ $i ] = $roles_associations[ $role_k ]; + } } update_post_meta( $directory_id, '_um_roles_can_search', $um_roles_can_search ); } -} \ No newline at end of file +}