mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- Skype field code review;
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
|
||||
function um_upgrade_skype_id226() {
|
||||
UM()->admin()->check_ajax_nonce();
|
||||
|
||||
um_maybe_unset_time_limit();
|
||||
|
||||
$forms_query = new WP_Query;
|
||||
$forms = $forms_query->query( array(
|
||||
'post_type' => 'um_form',
|
||||
'posts_per_page' => -1,
|
||||
'fields' => 'ids'
|
||||
) );
|
||||
|
||||
$fields_for_upgrade = array();
|
||||
|
||||
foreach ( $forms as $form_id ) {
|
||||
$forms_fields = get_post_meta( $form_id, '_um_custom_fields', true );
|
||||
|
||||
$changed = false;
|
||||
foreach ( $forms_fields as $key => &$field ) {
|
||||
if ( isset( $field['validate'] ) && 'skype' === $field['validate'] ) {
|
||||
if ( isset( $field['type'] ) && 'url' === $field['type'] ) {
|
||||
$field['type'] = 'text';
|
||||
$changed = true;
|
||||
|
||||
$fields_for_upgrade[] = $field['metakey'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $changed ) {
|
||||
update_post_meta( $form_id, '_um_custom_fields', $forms_fields );
|
||||
}
|
||||
}
|
||||
|
||||
$changed = false;
|
||||
$custom_fields = get_option( 'um_fields', array() );
|
||||
foreach ( $custom_fields as &$custom_field ) {
|
||||
if ( isset( $custom_field['validate'] ) && 'skype' === $custom_field['validate'] ) {
|
||||
if ( isset( $custom_field['type'] ) && 'url' === $custom_field['type'] ) {
|
||||
$custom_field['type'] = 'text';
|
||||
$changed = true;
|
||||
|
||||
$fields_for_upgrade[] = $custom_field['metakey'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $changed ) {
|
||||
update_option( 'um_fields', $custom_fields );
|
||||
}
|
||||
|
||||
$fields_for_upgrade = array_unique( $fields_for_upgrade );
|
||||
|
||||
// avoid 'https://', 'http://' at the start of the Skype field is there is nickname but not https://join.skype.com/
|
||||
// change only links with nickname skip https://join.skype.com/
|
||||
if ( ! empty( $fields_for_upgrade ) ) {
|
||||
global $wpdb;
|
||||
$usermetas = $wpdb->get_results( "SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta} WHERE meta_key IN( '" . implode( "','", $fields_for_upgrade ) . "' )", ARRAY_A );
|
||||
if ( ! empty( $usermetas ) ) {
|
||||
foreach ( $usermetas as $usermeta ) {
|
||||
if ( false !== strstr( $usermeta['meta_value'], 'https://' ) || false !== strstr( $usermeta['meta_value'], 'http://' ) ) {
|
||||
if ( false === strstr( $usermeta['meta_value'], 'join.skype.com/' ) ) {
|
||||
$usermeta['meta_value'] = str_replace( array( 'https://', 'http://' ), '', $usermeta['meta_value'] );
|
||||
update_user_meta( $usermeta['user_id'], $usermeta['meta_key'], $usermeta['meta_value'] );
|
||||
|
||||
delete_option( "um_cache_userdata_{$usermeta['user_id']}" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'um_last_version_upgrade', '2.2.6' );
|
||||
|
||||
if ( ! empty( $fields_for_upgrade ) ) {
|
||||
wp_send_json_success( array( 'message' => __( 'SkypeID fields have been updated successfully', '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(
|
||||
'skype_id226' => 'skype_id226',
|
||||
);
|
||||
+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( __( 'Upgrade SkypeID fields...', 'ultimate-member' ) ) ?>' );
|
||||
|
||||
jQuery.ajax({
|
||||
url: wp.ajax.settings.url,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'um_skype_id226',
|
||||
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