From ce02b8ac6b4b8f469c0e320e0437c7ede4e6b746 Mon Sep 17 00:00:00 2001 From: nikitasinelnikov Date: Fri, 28 Feb 2020 01:03:40 +0200 Subject: [PATCH] - added upgrade for myCRED balance fields; - fixed form_id PHP notice; --- .../admin/core/packages/2.1.5/functions.php | 95 +++++++++++++++++++ includes/admin/core/packages/2.1.5/hooks.php | 5 + includes/admin/core/packages/2.1.5/init.php | 30 ++++++ includes/um-short-functions.php | 2 +- readme.txt | 7 +- ultimate-member.php | 2 +- 6 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 includes/admin/core/packages/2.1.5/functions.php create mode 100644 includes/admin/core/packages/2.1.5/hooks.php create mode 100644 includes/admin/core/packages/2.1.5/init.php diff --git a/includes/admin/core/packages/2.1.5/functions.php b/includes/admin/core/packages/2.1.5/functions.php new file mode 100644 index 00000000..a6ef9140 --- /dev/null +++ b/includes/admin/core/packages/2.1.5/functions.php @@ -0,0 +1,95 @@ +admin()->check_ajax_nonce(); + + um_maybe_unset_time_limit(); + + global $wpdb; + + $point_type = defined( 'MYCRED_DEFAULT_TYPE_KEY' ) ? MYCRED_DEFAULT_TYPE_KEY : 'mycred_default'; + + // update default sorting + $wpdb->query( + "UPDATE {$wpdb->postmeta} + SET meta_value = IF( meta_value = 'most_mycred_points', 'most_mycred_default', IF( meta_value = 'least_mycred_points', 'least_mycred_default', meta_value ) ) + WHERE meta_key = '_um_sortby'" + ); + + // Update role_select and role_radio filters to role + $postmeta = $wpdb->get_results( "SELECT * FROM {$wpdb->postmeta} WHERE meta_key='_um_sorting_fields'", ARRAY_A ); + if ( ! empty( $postmeta ) ) { + foreach ( $postmeta as $row ) { + $meta_value = maybe_unserialize( $row['meta_value'] ); + + if ( is_array( $meta_value ) ) { + $update = false; + + if ( false !== ( $index = array_search( 'most_mycred_points', $meta_value ) ) ) { + $meta_value[ $index ] = 'most_mycred_default'; + $update = true; + } + + if ( false !== ( $index = array_search( 'least_mycred_points', $meta_value ) ) ) { + $meta_value[ $index ] = 'least_mycred_default'; + $update = true; + } + + if ( $update ) { + update_post_meta( $row['post_id'], '_um_sorting_fields', $meta_value ); + } + } + } + } + + + $custom_fields = get_option( 'um_fields', array() ); + + $forms_query = new WP_Query; + $forms = $forms_query->query( array( + 'post_type' => 'um_form', + 'posts_per_page' => -1, + 'fields' => 'ids' + ) ); + + $field_for_upgrade = array(); + + foreach ( $forms as $form_id ) { + $forms_fields = get_post_meta( $form_id, '_um_custom_fields', true ); + + foreach ( $forms_fields as $key => &$field ) { + + if ( isset( $field['metakey'] ) && $point_type == $field['metakey'] ) { + if ( empty( $field_for_upgrade ) ) { + $field_for_upgrade = array( + 'type' => 'mycred_balance', + 'title' => $field['title'], + 'metakey' => $field['metakey'], + 'label' => $field['label'], + 'public' => $field['public'], + 'visibility' => $field['visibility'], + ); + } + + $field['type'] = 'mycred_balance'; + } + + } + + update_post_meta( $form_id, '_um_custom_fields', $forms_fields ); + } + + if ( ! empty( $field_for_upgrade ) ) { + $custom_fields[ $point_type ] = $field_for_upgrade; + update_option( 'um_fields', $custom_fields ); + } + + update_option( 'um_last_version_upgrade', '2.1.5' ); + + if ( ! empty( $field_for_upgrade ) ) { + wp_send_json_success( array( 'message' => __( 'Balance fields were updated successfully', 'um-mycred' ) ) ); + } else { + wp_send_json_success( array( 'message' => __( 'Updated successfully', 'um-mycred' ) ) ); + } +} \ No newline at end of file diff --git a/includes/admin/core/packages/2.1.5/hooks.php b/includes/admin/core/packages/2.1.5/hooks.php new file mode 100644 index 00000000..e3b78b3c --- /dev/null +++ b/includes/admin/core/packages/2.1.5/hooks.php @@ -0,0 +1,5 @@ + 'balance_field215', +); \ No newline at end of file diff --git a/includes/admin/core/packages/2.1.5/init.php b/includes/admin/core/packages/2.1.5/init.php new file mode 100644 index 00000000..88c28a71 --- /dev/null +++ b/includes/admin/core/packages/2.1.5/init.php @@ -0,0 +1,30 @@ + + + + \ No newline at end of file diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php index 26a039cb..b0b723ec 100644 --- a/includes/um-short-functions.php +++ b/includes/um-short-functions.php @@ -939,7 +939,7 @@ function um_user_submitted_registration_formatted( $style = false ){ function um_user_submited_display( $k, $title, $data = array(), $style = true ) { $output = ''; - if ( 'form_id' == $k ) { + if ( 'form_id' == $k && ! empty( $data['form_id'] ) ) { $v = sprintf( __( '%s - Form ID#: %s', 'ultimate-member' ), get_the_title( $data['form_id'] ), $data['form_id'] ); } else { $v = um_user( $k ); diff --git a/readme.txt b/readme.txt index c8c7f78e..e9d1c799 100644 --- a/readme.txt +++ b/readme.txt @@ -146,7 +146,12 @@ The plugin works with popular caching plugins by automatically excluding Ultimat * To learn more about version 2.1 please see this [topic](https://wordpress.org/support/topic/version-2-1-4/) * UM2.1+ is a significant update to the Member Directories' code base from 2.0.x. Please make sure you take a full-site backup with restore point before updating the plugin -= 2.1.4: February 25, 2020 = += 2.1.5: March xx, 2020 = + +* Bugfixes: + - Fixed PHP notice 'form_id' on account submission + += 2.1.4: February 24, 2020 = * Enhancements: diff --git a/ultimate-member.php b/ultimate-member.php index e6194b9f..0c0cb832 100644 --- a/ultimate-member.php +++ b/ultimate-member.php @@ -3,7 +3,7 @@ Plugin Name: Ultimate Member Plugin URI: http://ultimatemember.com/ Description: The easiest way to create powerful online communities and beautiful user profiles with WordPress -Version: 2.1.4 +Version: 2.1.5-beta1 Author: Ultimate Member Author URI: http://ultimatemember.com/ Text Domain: ultimate-member