WooCommerce – Show different terms and conditions for different user roles

I’m setting up a WooCommerce shop and it will have two types of customer/user roles – a standard retail customer/user role and a wholesale customer/user role.

Here’s the snag that I’ve hit – when a Wholesale customer is logged in, I need the Terms and Conditions link on the checkout page to go to a different T&C’s page.

I’ve tried a couple of different functions in functions.php to replace the link text but they don’t work.

Does anyone out there have any suggestions that I can try??



Create an unprivilleged user in android

I want to create an account for android that cannot create another user or remove apps installed by the device owner.

I have looked at creating other accounts or logging as guest and that gives the user an opportunity to install and remove apps.

Does android enable one to have a none admin like account where a user cannot install or remove apps and cannot create accounts?

What’s the safest way to inform a new user of their password on my web site?

Hope this is the right forum for this.

I’m developing a web site where people will have accounts. However, unlike most web sites, user do not register, rather they are invited by the site admins. The site admins will create a new user profile, based on their email address, and then want the site to email them telling them that their profile is ready for use.

However, I’m not sure of the safest way to let people know of their password. In a normal registration, the user enters their password of choice, which is hashed and stored. All that remains is to send them a link to verify their email address.

In our case, they don’t register, so don’t supply a password. Whats the safest way to proceed?

This answer suggests sending them a link to a page where they can see their password, but I’m not sure if that has any benefits over sending them to a page where they can enter their own password. Actually, I think the latter suggestion is better, as if the password has already been set, the web page can inform them that the password has been set, and if this wasn’t them, to contact the admins immediately.

Anyone any suggestions or comments? Thanks

Online Game (Multi User Dungeon) – is it possible to avoid global data?

I need your precious advices 🙂

I am currently designing a Multi User Dungeon (MUD). For those who do not know what it is, they are the ancestors of MMORPGs. There is no graphics, everything is played in a console by typing commands. Players move into rooms, fight monsters, earn xp, and so on.

I am programming in C++ and use Boost. I am inspired by several examples of MUD that I found on the internet whose source code is available.

In each of the examples I found, global variables are often used: the list of players, the list of connected players, the list of rooms, etc. Indeed, these data are used absolutely everywhere in the program. They are at the heart of the game. 80% of the code consists in manipulating these data. I understand that others have been tempted to declare these data as global variables.

But I understand the danger of global variables and the problems that their use raises.

The problem is that I cannot imagine a viable solution that would prevent me from using global data.

I will try to give you a description of my architecture to illustrate my problem:

  • a class Server (linked to a list of sessions)
  • a class Session (linked to a connection instance)
  • a class Connection Instance (linked to a Player, a Session and a Context)
  • a class Player (linked to a Room)
  • a class Area (contains Rooms)
  • a class Room
  • a class Context (used to differentiate the different contexts: normal play, or when the player types his name and password, etc)
  • a class Command (for example, “kill a mob”)
  • many others…

I am not sure to know how I can have an access to every room/player/npc/object in the game in all these classes without passing everywhere a gigantic object containing the whole game as parameter.

For example, a player might have a “kill every player in the world” command. “KillEveryoneCommand” that would inherit “Command”. But where would this list of players be stored? How could it be accessed from the “Player” class or from the “KillEveryoneCommand” class?

Theoretically, a player could also have a command to ignite all the rooms of an area, or to communicate with another player from a distance… All these things are done without any problem with global data.

Would an online game with such central and shared data be a good exception for using global data?

I would love your opinions and your ideas because I am a little lost :p

Thank you!

Updating User Profile of Another User From SPFx Webpart using REST/JSOM?

Is there any way to update user profile of another user from SPFx webpart. Current logged in user is tenant admin and/or SharePoint admin.

Access is given to Azure AD app ‘SharePoint Online Client Extensibility Web Application Principal’ with User.ReadWrite.All

Still it throws ‘Access denied. You do not have permission to perform this action or access this resource.’ Same code works for current logged in user.

Below is using current site context

updateSingleUPValue() {     let apiUrl = this.context.pageContext.web.absoluteUrl + "/_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty";      let userData = {       'accountName': "i:0#.f|membership|" + "anotheruser@mytenant.com",       'propertyName': this.propertyName, //can also be used to set custom single value profile properties       'propertyValue': this.value     }     let httpClient: SPHttpClient = this.context.spHttpClient;        let spOpts = {       headers: {         'Accept': 'application/json;odata=nometadata',         'Content-type': 'application/json;odata=verbose',         'odata-version': '',       },       body: JSON.stringify(userData)     };      httpClient.post(apiUrl, SPHttpClient.configurations.v1, spOpts).then(response => {       alert("Updated");     });   } 

Read at couple of places that

updateSingleUPValue() {     apiUrl = "https://mytenant-admin.sharepoint.com" + "/_api/SP.UserProfiles.PeopleManager/SetSingleValueProfileProperty";     let userData = {       'accountName': "i:0#.f|membership|" + this.userdetails.loginName,       'propertyName': this.propertyName, //can also be used to set custom single value profile properties       'propertyValue': this.value     }     let httpClient: SPHttpClient = this.context.spHttpClient;        let spOpts = {       headers: {         'Accept': 'application/json;odata=nometadata',         'Content-type': 'application/json;odata=verbose',         'odata-version': '',       },       body: JSON.stringify(userData)     };      httpClient.post(apiUrl, SPHttpClient.configurations.v1, spOpts).then(response => {       alert("Updated");     });   } 

On above code first it is automatically trying to get context info – where itself it is failing and giving 403 forbidden

https://mytenant-admin.sharepoint.com/_api/contextinfo 403

any pointer/ideas – Basic Idea is to update user profile properties of another user, all required access can be given.

Why is this javascript/jquery not capturing user input?

I can’t figure out why the user input in the “Giphy search” box isn’t being captured. When I console log out “queryURL” the query from the input box is absent. See my code below:

<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta http-equiv="X-UA-Compatible" content="ie=edge">     <link rel="stylesheet"         href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" />     <title>Document</title>  </head>  <body>     <div class="container">         <h1>gifTastic!</h1>         <label for="search-field">Find a TV Show: </label>         <input type="text" id="search-field">         <input id="find-giphy" type="submit" value="giphy Search">     </div>      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>     <script type="text/javascript">         var baseURL = "http://api.giphy.com/v1/gifs/search?q="         var apiKey = "Yz4pO4lJDaMYGIX80M9gc2Mq7HKKS2or"         var input = $  ("#search-field").val();                  var queryURL = baseURL + input + "&api_key=" + apiKey + "&limit=10";         var testURL = "http://api.giphy.com/v1/gifs/search?q=ryan+gosling&api_key=YOUR_API_KEY&limit=5"          $  ("#find-giphy").on("click", function () {             $  .ajax({                 url: queryURL,                 method: "GET"             }).then(function (response) {                 console.log(response);                 console.log(queryURL);             })         })     </script> </body>  </html>

Having trouble printing out an encoded message with an offset entered by the user

I am creating a program to take in a simple string from the user and encode then decode the string. I have that part completed, however it just came to my attention we need to get an offset from the user as well and offset the encoded string. I am having trouble setting the offset and then printing the encoded string. Feel as though I am overthinking it. Any guidance would be greatly appreciated.

The trouble I am having is figuring out how to take in the byte[] string and add the int offset to each item in the string then print it. Below is what I have. I only put the main class and the encoder class since this is the part I’m having trouble with.

public class EncodeDecodeTester {      public static void main(String[] args) {         Scanner input = new Scanner(System.in);         System.out.println("Enter the message you want to encode: ");         String message = input.nextLine();         System.out.println("Enter the offset you would like: ");         int offset = input.nextInt();         Encoder encoder = new Encoder(message, offset);         System.out.println("Your encoded message is: " );         byte[] encoded = encoder.getEncodedMessage();          System.out.println(Arrays.toString(encoded));         System.out.println("Decoding your message. ");         Decoder decoder = new Decoder(encoded);         System.out.println("Your decoded message is: ");         String decoded = decoder.getDecodedMessage();         System.out.println(decoded);         }  }      public class Encoder {     public String message;     public int offset;     public Encoder() {         //this("Hello");     }     public Encoder(String message, int offset) {         this.message = message;         this.offset = offset;     }      public String getMessage() {         return message;     }     public void setMessage(String message) {         this.message = message;     }     public int getOffset() {         return offset;     }     public void setOffset(int offset) {         this.offset = offset;     }     public byte[] getEncodedMessage() {         String encodedMessage = message;         int offsetMessage = offset;         byte[] encoded = encodedMessage.getBytes();         for (byte i = 0; i < encoded.length; i++) {             encoded[i] = (int) offset + encoded;         }         return encoded;     }   } 

Keychain unique user

I want to be able to store and retrieve a unique user throughout the app. Multiple accounts are not used. The code I have written is stated below.

This is my first attempt using KeyChain. The test succeeds. I am wondering if anything if the code can be improved. Security issues perhaps?

import XCTest  class KeyChain {     struct User {         let identifier: Int64         let password: String     }      static func save(user: User) -> Bool {         let identifier = Data(from: user.identifier)         let password = user.password.data(using: .utf8)!         let query = [kSecClass as String : kSecClassGenericPassword as String,                      kSecAttrService as String : "comapp",                      kSecAttrAccount as String : identifier,                      kSecValueData as String : password]             as [String : Any]          let deleteStatus = SecItemDelete(query as CFDictionary)          if deleteStatus == noErr || deleteStatus == errSecItemNotFound {             return SecItemAdd(query as CFDictionary, nil) == noErr         }          return false     }      static func retrieveUser() -> User? {         let query = [kSecClass as String : kSecClassGenericPassword,                      kSecAttrService as String : "comapp",                      kSecReturnAttributes as String : kCFBooleanTrue!,                      kSecReturnData as String: kCFBooleanTrue!]             as [String : Any]          var result: AnyObject? = nil         let status = SecItemCopyMatching(query as CFDictionary, &result)          if status == noErr,             let dict = result as? [String: Any],             let passwordData = dict[String(kSecValueData)] as? Data,             let password = String(data: passwordData, encoding: .utf8),             let identifier = (dict[String(kSecAttrAccount)] as? Data)?.to(type: Int64.self) {              return User(identifier: identifier, password: password)         } else {             return nil         }     } }  private extension Data {     init<T>(from value: T) {         var value = value          self.init(buffer: UnsafeBufferPointer(start: &value, count: 1))     }      func to<T>(type: T.Type) -> T {         withUnsafeBytes { $  0.load(as: T.self) }     } }   class SecureStoreTests: XCTestCase {     func testUser() {         let user = KeyChain.User(identifier: 200, password: "somePassword")          let didAddedUser = KeyChain.save(user: user)          XCTAssertTrue(didAddedUser)          let retrievedUser = KeyChain.retrieveUser()!          XCTAssert(user.identifier == retrievedUser.identifier)         XCTAssert(user.password == retrievedUser.password)     } }