mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-19 22:54:03 +09:00
- removed Google+, VKonakte but leaves these custom fields as just URL type with Website URL validation;
- added 2.6.0 version upgrade script for changing 'vk_url', 'google_url', 'googleplus_url' just to 'url' validate value; - close #1145;
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function um_upgrade_social_fields260() {
|
||||
UM()->admin()->check_ajax_nonce();
|
||||
|
||||
um_maybe_unset_time_limit();
|
||||
|
||||
$fields_for_upgrade = array();
|
||||
|
||||
$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 ) {
|
||||
$forms_fields = get_post_meta( $form_id, '_um_custom_fields', true );
|
||||
if ( ! is_array( $forms_fields ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$need_update = false;
|
||||
foreach ( $forms_fields as $key => &$field ) {
|
||||
if ( array_key_exists( 'validate', $field ) && in_array( $field['validate'], array( 'google_url', 'googleplus_url', 'vk_url' ), true ) ) { // Looks like googleplus_url is old legacy value.
|
||||
$field['validate'] = 'url';
|
||||
$need_update = true;
|
||||
|
||||
$fields_for_upgrade[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $need_update ) {
|
||||
update_post_meta( $form_id, '_um_custom_fields', $forms_fields );
|
||||
}
|
||||
}
|
||||
|
||||
$need_update = false;
|
||||
$custom_fields = get_option( 'um_fields', array() );
|
||||
foreach ( $custom_fields as &$field ) {
|
||||
if ( array_key_exists( 'validate', $field ) && in_array( $field['validate'], array( 'google_url', 'googleplus_url', 'vk_url' ), true ) ) { // Looks like googleplus_url is old legacy value.
|
||||
$field['validate'] = 'url';
|
||||
$need_update = true;
|
||||
|
||||
$fields_for_upgrade[] = $field['metakey'];
|
||||
}
|
||||
}
|
||||
if ( $need_update ) {
|
||||
update_option( 'um_fields', $custom_fields );
|
||||
}
|
||||
|
||||
$fields_for_upgrade = array_unique( $fields_for_upgrade );
|
||||
|
||||
// delete temporarily option for fields upgrade
|
||||
update_option( 'um_last_version_upgrade', '2.6.0' );
|
||||
|
||||
if ( ! empty( $fields_for_upgrade ) ) {
|
||||
wp_send_json_success( array( 'message' => __( 'Social URLs fields have been successfully updated.', 'ultimate-member' ) ) );
|
||||
} else {
|
||||
wp_send_json_success( array( 'message' => __( 'Database has been updated successfully', 'ultimate-member' ) ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
return array(
|
||||
'social_fields260' => 'social_fields260',
|
||||
);
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
jQuery( document ).ready( function() {
|
||||
um_add_upgrade_log( '<?php echo esc_js( __( 'Updated social URLs fields in the UM Forms fields...', 'ultimate-member' ) ) ?>' );
|
||||
|
||||
jQuery.ajax({
|
||||
url: wp.ajax.settings.url,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'um_social_fields260',
|
||||
nonce: um_admin_scripts.nonce
|
||||
},
|
||||
success: function( response ) {
|
||||
if ( typeof response.data.message != 'undefined' ) {
|
||||
um_add_upgrade_log( response.data.message );
|
||||
//switch to the next package
|
||||
um_run_upgrade();
|
||||
} else {
|
||||
um_wrong_ajax();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
um_something_wrong();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user