PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.1
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / assets / src / js / utils / cookies.js

cookies.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.1, at assets/src/js/utils/cookies.js

63 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const Cookies = {
2 get: ( name, def, global ) => {
3 let ret;
4
5 if ( global ) {
6 ret = wpCookies.get( name );
7 } else {
8 let ck = wpCookies.get( 'LP' );
9 if ( ck ) {
10 ck = JSON.parse( ck );
11 ret = name ? ck[ name ] : ck;
12 }
13 }
14
15 if ( ! ret && ret !== def ) {
16 ret = def;
17 }
18
19 return ret;
20 },
21
22 set( name, value, expires, path, domain, secure ) {
23 if ( arguments.length > 2 ) {
24 wpCookies.set( name, value, expires, path, domain, secure );
25 } else if ( arguments.length == 2 ) {
26 let ck = wpCookies.get( 'LP' );
27
28 if ( ck ) {
29 ck = JSON.parse( ck );
30 } else {
31 ck = {};
32 }
33
34 ck[ name ] = value;
35
36 wpCookies.set( 'LP', JSON.stringify( ck ), '', '/' );
37 } else {
38 wpCookies.set( 'LP', JSON.stringify( name ), '', '/' );
39 }
40 },
41
42 remove( name ) {
43 const allCookies = Cookies.get();
44 const reg = new RegExp( name, 'g' );
45 const newCookies = {};
46 const useRegExp = name.match( /\*/ );
47
48 for ( const i in allCookies ) {
49 if ( useRegExp ) {
50 if ( ! i.match( reg ) ) {
51 newCookies[ i ] = allCookies[ i ];
52 }
53 } else if ( name != i ) {
54 newCookies[ i ] = allCookies[ i ];
55 }
56 }
57
58 Cookies.set( newCookies );
59 },
60 };
61
62 export default Cookies;
63