-fixed formated code

This commit is contained in:
Denis Baranov
2018-02-12 15:37:10 +02:00
parent 4d9ba51afe
commit 7bdc82ef4a
3 changed files with 60 additions and 23 deletions
+5 -5
View File
@@ -23,7 +23,7 @@ if ( ! class_exists( 'Permalinks' ) ) {
add_action( 'wp_head', array( &$this, 'um_rel_canonical_' ), 9 );
add_filter( 'um_user_pre_updating_profile_array', array( &$this, 'um_user_pre_updating_profile_array') );
add_filter( 'um_user_pre_updating_profile_array', array( &$this, 'um_user_updating_profile_need_change_permalink') );
}
@@ -305,7 +305,6 @@ if ( ! class_exists( 'Permalinks' ) ) {
if ( in_array( $permalink_base, $full_name_permalinks ) ) {
$separated = array('name' => '.','name_dash' =>'-','name_plus'=>'+');
$separate = $separated[$permalink_base];
$opt_display_name = UM()->options()->get( 'display_name' );
$first_name = um_user( 'first_name' );
$last_name = um_user( 'last_name' );
$full_name = sprintf('%s %s',$first_name,$last_name);
@@ -329,7 +328,6 @@ if ( ! class_exists( 'Permalinks' ) ) {
}
$user_in_url = $this->profile_slug( $username, $first_name, $last_name );
error_log('<pre>'.print_r($user_in_url,true).'</pre>');
}
update_user_meta( um_user('ID'), "um_user_profile_url_slug_{$permalink_base}", $user_in_url );
@@ -509,9 +507,11 @@ error_log('<pre>'.print_r($user_in_url,true).'</pre>');
}
/**
* @param $to_update
* Adds the "need_change_permalink" parameter to recreate the user's permanent link
* @param array $to_update
* @return array $to_update
*/
function um_user_pre_updating_profile_array( $to_update ) {
function um_user_updating_profile_need_change_permalink( $to_update ) {
if ( um_user( 'first_name' ) != $to_update['first_name'] ||
um_user( 'last_name' ) != $to_update['last_name'] ) {
+51 -13
View File
@@ -183,7 +183,31 @@ function um_submit_account_errors_hook( $args ) {
delete_user_meta( um_user('ID'), 'hide_in_members' );
unset( $changes['hide_in_members'] );
}
/**
* UM hook
*
* @type filter
* @title um_account_pre_updating_profile_array
* @description Contains all data from which are transmitted when updating information page "account". This filter is used before changing data in the database
* @inpust_vars {
* "(array) $changes": 'Contains all data from which are transmitted when updating information page "account"'
* }
*
* @example
* add_filter( 'um_account_pre_updating_profile_array', 'um_account_pre_updating_profile_need_change_permalink' );
* function um_account_pre_updating_profile_need_change_permalink( $to_update ) {
*
* if ( um_user( 'first_name' ) != $to_update['first_name'] ||
* um_user( 'last_name' ) != $to_update['last_name'] ) {
* $to_update['need_change_permalink'] = true;
* }
*
* return $to_update;
* }
*/
$changes = apply_filters( 'um_account_pre_updating_profile_array', $changes );
// fired on account page, just before updating profile
do_action('um_account_pre_update_profile', $changes, um_user('ID') );
@@ -262,17 +286,31 @@ function um_submit_account_errors_hook( $args ) {
update_user_meta( um_user('ID'), 'um_account_secure_fields', $secure_fields );
}
add_filter( 'um_account_pre_updating_profile_array','um_account_pre_updating_profile_array_1' );
function um_account_pre_updating_profile_array_1( $to_update ) {
if ( um_user( 'first_name' ) != $to_update['first_name'] ||
um_user( 'last_name' ) != $to_update['last_name'] ) {
$to_update['need_change_permalink'] = true;
}
return $to_update;
}
add_action('um_after_user_account_updated','um_after_user_account_updated_1',10,2);
function um_after_user_account_updated_1($user_id,$changed){
/**
* Adds the "need_change_permalink" parameter to recreate the user's permanent link
* @param array $to_update
* @return array $to_update
*/
function um_account_pre_updating_profile_need_change_permalink( $to_update ) {
if ( um_user( 'first_name' ) != $to_update['first_name'] ||
um_user( 'last_name' ) != $to_update['last_name'] ) {
$to_update['need_change_permalink'] = true;
}
return $to_update;
}
add_filter( 'um_account_pre_updating_profile_array', 'um_account_pre_updating_profile_need_change_permalink' );
/**
*
* @param $user_id
* @param $changed
*
*/
function um_after_user_account_updated_permalink($user_id,$changed){
UM()->permalinks()->profile_url($changed);
}
}
add_action('um_after_user_account_updated','um_after_user_account_updated_permalink',10,2);
+4 -5
View File
@@ -186,12 +186,12 @@ if ( ! defined( 'ABSPATH' ) ) exit;
return $changes;
}
add_filter('insert_user_meta','um_user_edit_after_updating_profile_array',10,3);
function um_user_edit_after_updating_profile_array($meta, $user, $update){
add_filter('insert_user_meta','um_user_edit_check_change_first_name_and_last_name',10,1);
function um_user_edit_check_change_first_name_and_last_name($meta){
if (!empty($_POST['user_id'])){
if(get_user_meta( $_POST['user_id'],'first_name',true ) != $meta['first_name'] ||
get_user_meta( $_POST['user_id'],'last_name',true ) != $meta['last_name']){
add_filter( 'um_user_edit_after_updating_profile_array','um_user_edit_after_updating_profile_array_1' );
add_filter( 'um_user_edit_after_updating_profile_array','um_user_edit_after_updating_profile_need_change_permalink' );
}
}
@@ -199,8 +199,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
return $meta;
}
function um_user_edit_after_updating_profile_array_1( $to_update ) {
function um_user_edit_after_updating_profile_need_change_permalink( $to_update ) {
$to_update['need_change_permalink'] = true;
return $to_update;
}