Skip to content

Commit

Permalink
Setting "Freeze locale"
Browse files Browse the repository at this point in the history
Fixes #21
  • Loading branch information
JoryHogeveen committed Nov 9, 2016
1 parent 3ff1cd4 commit 2e0f799
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions assets/js/view-admin-as.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ if ( 'undefined' == typeof VAA_View_Admin_As ) {
}
VAA_View_Admin_As.ajax( viewAs, false );
});

// Enable freeze locale
$(document).on('change', VAA_View_Admin_As.prefix+root+'-freeze-locale input#' + prefix + '-freeze-locale', function( e ) {
e.preventDefault();
var viewAs = { user_setting : { freeze_locale : "no" } };
if ( this.checked ) {
viewAs = { user_setting : { freeze_locale : "yes" } };
}
var reload = false;
if ( typeof VAA_View_Admin_As.view_as == 'object' && typeof VAA_View_Admin_As.view_as.user != 'undefined' ) {
reload = true;
}
VAA_View_Admin_As.ajax( viewAs, reload );
});
};


Expand Down
2 changes: 2 additions & 0 deletions includes/class-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ final class VAA_View_Admin_As_Store
'admin_menu_location' => 'top-secondary',
'force_group_users' => 'no',
'hide_front' => 'no',
'freeze_locale' => 'no',
);

/**
Expand All @@ -98,6 +99,7 @@ final class VAA_View_Admin_As_Store
'admin_menu_location' => array( 'top-secondary', 'my-account' ),
'force_group_users' => array( 'yes', 'no' ),
'hide_front' => array( 'yes', 'no' ),
'freeze_locale' => array( 'yes', 'no' ),
);

/**
Expand Down
1 change: 1 addition & 0 deletions includes/class-vaa.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ public function enqueue_scripts() {
'__no_users_found' => esc_html__( 'No users found.', 'view-admin-as' ),
'__success' => esc_html__( 'Success', 'view-admin-as' ),
'__confirm' => esc_html__( 'Are you sure?', 'view-admin-as' ),
'view_as' => $this->store->get_viewAs(),
'settings' => $this->store->get_settings(),
'settings_user' => $this->store->get_userSettings()
);
Expand Down
22 changes: 22 additions & 0 deletions includes/class-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public function init() {
// Change the capabilities (map_meta_cap is better for compatibility with network admins)
add_filter( 'map_meta_cap', array( $this, 'map_meta_cap' ), 999999999, 4 );
}

// @since 1.6.1 Force own locale on view
if ( 'yes' == $this->store->get_userSettings('freeze_locale') ) {
add_action( 'init', array( $this, 'freeze_locale' ) );
}
}

}
Expand Down Expand Up @@ -507,6 +512,23 @@ public function validate_view_as_data( $view_as ) {
return false;
}

/**
* Set the locale for the current view
*
* @since 1.6.1
* @access public
*/
public function freeze_locale() {
if ( function_exists( 'get_user_locale' ) && function_exists( 'switch_to_locale' ) ) {
$locale = get_user_locale( $this->store->get_curUser()->ID );
if ( $locale != get_locale() ) {
switch_to_locale( $locale );
}
return true;
}
return false;
}

/**
* Main Instance.
*
Expand Down
12 changes: 12 additions & 0 deletions ui/class-admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,18 @@ public function admin_bar_menu_settings( $admin_bar ) {
),
) );

$admin_bar->add_node( array(
'id' => $root . '-freeze-locale',
'parent' => $root,
'title' => '<input type="checkbox" value="1" class="checkbox ' . $root . '-freeze-locale" id="' . $root . '-freeze-locale" name="vaa_settings_freeze_locale" ' . checked( $this->get_userSettings('freeze_locale'), 'yes', false ) . '>
<label for="' . $root . '-freeze-locale">' . __('Freeze locale', 'view-admin-as') . '</label>
<p class="description ab-item">' . __('Force your own locale setting to the current view', 'view-admin-as') . '</p>',
'href' => false,
'meta' => array(
'class' => 'auto-height',
),
) );

/**
* force_group_users setting
* @since 1.5.2
Expand Down

0 comments on commit 2e0f799

Please sign in to comment.