WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Шаблоны сайтов на русском

User Settings и wpCookies

JS Функции настроек пользователя (Cookies и Options)

JS функции из файла wp-includes/js/utils.js.

Функции для записи Куков в JS

window.wpCookies.getHash( name )
Get a multi-values cookie. Returns a JS object with the name: 'value' pairs.
window.wpCookies.setHash( name, values_obj, expires, path, domain, secure )
Set a multi-values cookie. 'values_obj' is the JS object that is stored. It is encoded as URI in wpCookies.set().
window.wpCookies.get( name )
Get a cookie.
window.wpCookies.set( name, value, expires, path, domain, secure )
Set a cookie. The 'expires' arg can be either a JS Date() object set to the expiration date (back-compat) or the number of seconds until expiration
window.wpCookies.remove( name, path, domain, secure )
Remove a cookie. This is done by setting it to an empty value and setting the expiration time in the past.

Функции опций юзера в JS

window.getUserSetting( name, def )
Returns the value as string. Second arg or empty string is returned when value is not set.
window.setUserSetting( name, value, _del )
Both name and value must be only ASCII letters, numbers or underscore and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text. The value is converted and stored as string.
window.deleteUserSetting( name )
Удаляет указанную опцию.
window.getAllUserSettings()
Returns all settings as js object.
window.getAllUserSettings()

/*
получим:
{
	align: "center"
	ed_size: "391"
	editor: "tinymce"
	editor_expand: "off"
	hidetb: "1"
	imgsize: "full"
	libraryContent: "browse"
	mfold: "o"
	posts_list_mode: "list"
	urlbutton: "file"
	wplink: "1"
}
*/

PHP функции настроек пользователя (options)

Также есть связанные с JS функциям PHP функции получения опций юзера

wp_user_settings()
-
get_user_setting( $name, $default = false )
-
set_user_setting( $name, $value )
-
delete_user_setting( $names )
-
get_all_user_settings()
-
wp_set_all_user_settings( $user_settings )
-
delete_all_user_settings()
-
print_r( get_all_user_settings() );

/*
получим:
Array
	[editor] => tinymce
	[wplink] => 1
	[editor_expand] => off
	[ed_size] => 391
	[posts_list_mode] => list
	[libraryContent] => browse
	[align] => center
	[imgsize] => full
	[urlbutton] => file
	[hidetb] => 1
	[mfold] => o
*/
Комментариев нет
    Здравствуйте, !     Войти . Зарегистрироваться