Disable new account email notification in WooCommerce - hook-woocommerce

I need to disable the default email sending of New Account to admin.
I have looked at the unhook_those_pesky_emails code but dont see it for New Accounts
The snippet of code probably start like
remove_action( 'woocommerce_created_customer_notification',

For people looking in the future, this is likely the code you need:
<?php
//Disable 'new user' notification for the site admin
function woo_disable_new_user_notifications() {
//Remove original emails
remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );
//Add new function to take over email creation
add_action( 'register_new_user', 'woo_send_new_user_notifications' );
add_action( 'edit_user_created_user', 'woo_send_new_user_notifications', 10, 2 );
}
function woo_send_new_user_notifications( $user_id, $notify = 'user' ) {
if ( empty($notify) || $notify == 'admin' ) {
return;
}elseif( $notify == 'both' ){
//Only send the new user an email, not the admin
$notify = 'user';
}
woo_send_new_user_notifications( $user_id, $notify );
}
add_action( 'init', 'woo_disable_new_user_notifications' );
This will disable WordPress notifications to the site admin regarding new user registrations.

Related

MSAL access token refreshing not working through AcquireTokenSilent

I am implementing MSAL authentication for our SPA. I've followed various official and unofficial guides and so far this is my auth implementation:
loginMicrosoft() {
myMSALObj
.loginPopup(msalConfig.loginRequest)
.then((response) => {
console.log(response);
this.username = response.account.userName;
this.account = response.account;
})
.catch((error) => {
console.error(error);
});
},
readEvents() {
this.getTokenPopup(msalConfig.tokenRequest)
.then((response) => {
console.log("silent token!: ", response);
this.callMSGraph(
graphConfig.graphConfig.graphGetCalendarEventsEndpoint,
response.accessToken
);
})
.catch((error) => {
console.error(error);
});
},
createEvent() {
this.getTokenPopup(msalConfig.tokenRequest)
.then((response) => {
this.callMSGraphCreateEvent(
graphConfig.graphConfig.graphCreateCalendarEventEndpoint,
response.accessToken
);
})
.catch((error) => {
console.error(error);
});
},
getTokenPopup(request) {
request.account = this.account;
console.log(request);
return myMSALObj.acquireTokenSilent(request).catch((error) => {
console.warn(
"silent token acquisition fails. acquiring token using popup : ",
error
);
if (error instanceof Msal.InteractionRequiredAuthError) {
// fallback to interaction when silent call fails
return myMSALObj
.acquireTokenPopup(request)
.then((tokenResponse) => {
console.log(tokenResponse);
return tokenResponse;
})
.catch((error) => {
console.error(error);
});
} else {
console.warn(error);
}
});
},
async callMSGraph(endpoint, token) {
console.log("request made to Graph API at: " + new Date().toString());
const resp = await axios.post("/api/microsoft/get-events", { endpoint, token });
this.calendarEvents = resp.data.value;
console.log("vaste: ", resp);
},
async callMSGraphCreateEvent(endpoint, token) {
console.log("request made to Graph API at: " + new Date().toString());
const resp = await axios.post("/api/microsoft/create-event", {
endpoint,
token,
});
this.calendarEvents = resp.data.value;
console.log("vaste: ", resp);
},
Everything works as intended, until the access token is reaching expiry.
If AcquireTokenSilent is called 5 minutes before the expiration of after the expiration of the access token, I would expect it to return a new access token, using the hidden refresh token in the MSAL cache. Instead, I get the following error:
silent token acquisition fails. acquiring token using popup :
InteractionRequiredAuthError: Silent authentication was denied. The
user must first sign in and if needed grant the client application
access to the scope 'User.Read Calendars.ReadWrite openid
profile'.
It doesn't seem to be normal to ask for user sign-in every hour, and I cant seem to find any resources on this issue..
Any help is greatly appreciated!
EDIT:
I tried adding offline_access to my token request scopes. My scopes setup is following:
export const loginRequest = {
scopes: ["User.Read", "Calendars.ReadWrite", "offline_access"],
};
export const tokenRequest = {
scopes: ["User.Read", "Calendars.ReadWrite", "offline_access"],
forceRefresh: false, // Set this to "true" to skip a cached token and go to the server to get a new token
};
Now im getting the login popup with the following error every time i try to call the api:
InteractionRequiredAuthError: Silent authentication was denied. The user must first sign in and if needed grant the client application access to the scope 'User.Read Calendars.ReadWrite offline_access openid profile'.
Probably your scopes (in your app registration or in your msal config, depending on where you define your config and if you are using .default scope) do not include the request for the offline_access scope. Please include it, it is required if you want to (auto-) refresh your tokens. If you don't get a new consent prompt after adding this scope (user must agree, i.e. give consent to this), just reset your app consents in azure portal, or consent manually.

Twilio Functions - Pass in parameters and format SMS body to include parameters

I am using Twilio to create an 'attendance line' where employees can provide information about why they will be absent and then Twilio will send separate, curated messages to supervisors and human resources.
To do this, I've created a Flow in Twilio Studio and I would like to use a Twilio Function to handle sending the mass SMS messages notifying users of a new absence.
I am passing parameters to the function like name, dept, shift, reason, etc with the intent to then share these values via SMS.
I am having the hardest time getting all of these different values properly into the body of the message.
exports.handler = function(context, event, callback) {
// Create a reference to the user notification service
const client = context.getTwilioClient();
const service = client.notify.services(
context.TWILIO_NOTIFICATION_SERVICE_SID
);
const notification = {
toBinding: JSON.stringify({
binding_type: 'sms', address: '+1XXXXXXXXXX',
binding_type: 'sms', address: '+1XXXXXXXXXX',
}),
body: 'New Attendance Notification',
event.question_name,
event.question_dept,
event.question_reason,
event.contactChannelAddress,
};
console.log(notification);
// Send a notification
return service.notifications.create(notification).then((message) => {
console.log('Notification Message',message);
callback(null, "Message sent.");
}).catch((error) => {
console.log(error);
callback(error,null);
});
};
Now I know the 'body' of the message above will not work but I'm a bit lost...
The text below is how I would like my SMS message to read out when sent.
New Attendance Notification
Name: event.Name
Dept: event.Dept
Reason: event.Reason
Contact: event.ContactChannelAddress
Is what I am trying to accomplish even possible?
Something like this...
exports.handler = function(context, event, callback) {
// Create a reference to the user notification service
const client = context.getTwilioClient();
const service = client.notify.services(
context.TWILIO_NOTIFICATION_SERVICE_SID
);
const bindings = [
'{ "binding_type": "sms", "address": "+14071234567" }',
'{ "binding_type": "sms", "address": "+18021234567" }'
];
const notice = `New Attendance Notification\nName: ${event.question_name}\nDept: ${event.question_dept} \nReason: ${event.question_reason}\nContact: ${event.contactChannelAddress} \n`;
// Send a notification
service.notifications.create({ toBinding: bindings, body: notice }).then((message) => {
console.log('Notification Message',message);
callback(null, "Message sent.");
})
.catch((error) => {
console.log(error);
callback(error,null);
});
};

In Twilio how can I access a menu after outgoing call is answered?

I'm trying to enable access to a menu after a call as been dialed and answered. For example, an agent dials a number, which uses the verb to place a call. During that call the person called asks to be transferred to a different agent, extension or queue. I have read about putting a call into a conference and using the hangupOnStar attribute to put the person called on hold and bring up a menu for the agent to further manipulate the call but have been unsuccessful. It seems that pressing the '*' button ends the call and therefore the DialCallSid belongs to a completed call which can't be updated.
I was originally going about this the wrong way. This is for an Outbound call, so I was able to successfully create a "on hold" conference, dial up a caller using the REST API, then add the caller to the conference. I was also able to harness the hangupOnStar attribute to enable leaving the conference and going to a menu.
Here is the code in my first function:
public function makeOutboundConference(Request $request) {
$sid = "ACxxxxxxxxxxxxxxxxxxxxxxxxx";
$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
$response = new Twiml();
$dial = $response->dial(
[
'hangupOnStar' => true,
'action' => 'url-to-incall-menu',
'method' => 'POST'
]
);
$dial->conference("On Hold",
[
'beep' => false,
]
);
$client = new Client($sid, $token);
try {
$call = $client->calls->create(
$to,
$callerId,
array('url' => 'fq-url-to-connect-caller')
);
} catch (Exception $e) {
error_log("Error: " . $e->getMessage());
}
return $response;
}
and my second function to add the person called to the conference:
public function showConnectCaller(Request $request) {
$response = new Twiml();
$dial = $response->dial();
$dial->conference(
"On Hold",
[
'record' => 'record-from-start',
'beep' => false,
'endConferenceOnExit' => true,
]
);
return $response;
}
Twilio: Can I make OUTBOUND Conference Calls? was very helpful.

hybridauth - can not restore google login

I have made login script with HybridAuth. I'm loged in my website with "providers" Facebook, Google, Twitter. When PHP sessions time out, I want to restore my connected "providers".
I use this code :
$connected_adapters_list = $hybridauth->getConnectedProviders();
if( count( $connected_adapters_list ) ){
foreach( $connected_adapters_list as $adapter_id ){
echo $adapter_id . "<br>";
}
}
HybridAuth can restore my Facebook and Twitter connection, but not Google. This is code error output. How to solve it ?
Ooophs, we got an error: User profile request failed! Google returned an invalid response:stdClass::__set_state(array( 'error' => stdClass::__set_state(array( 'errors' => array ( 0 => stdClass::__set_state(array( 'domain' => 'global', 'reason' => 'authError', 'message' => 'Invalid Credentials', 'locationType' => 'header', 'location' => 'Authorization', )), ), 'code' => 401, 'message' => 'Invalid Credentials', )), )) Error code: 6
I also has this problem,
it could be sloved by using "logoutAllProviders()" function
there is code :
try{
$hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "Google" );
$user_profile = $adapter->getUserProfile();
}
catch( Exception $e ){
$hybridauth->logoutAllProviders();
$hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "Google" );
$user_profile = $adapter->getUserProfile();
}
}
good luck for you !

Laravel 5 and Sentinel 2

I'm a complete starter using laravel 5.1. I was a PHP developer by 3 to 4 years and between those I was allways working with Java EE and I just came back to PHP environement and found a complete new list of frameworks.
After a little research, and using some surveys results, I found that Laravel is the ultimate one. Now I used Laragon to install it successfully and have my first fresh application running. I learning a little about how a route works and that's ok.
Now I need to use Sentinel 2.0 in order to apply the right roles/auth to my application and then add the socialize part.
So to do that, I need to know few things :
Is there any way to "completely" get rid of the Auth component beside removing the controller Auth folder and the route in routes.php ?
Is there any tutorial (as I can't find) telling how to REALLY include the sentinel means how to create a simple view with all what it needs (controller, vars, routes ....)
Thank you
Yes, you can. For example, this is my code for API rest with JWT and Sentinel. You can seed your database with Sentinel:
Create roles
Example EXA Role
$role = \Sentinel::getRoleRepository()->createModel()->create([
'name' => 'Example',
'slug' => 'EXA',
]);
$role->permissions = [
'servicio_dash' => true,
'servicio_widget' => true,
];
$role->save();
User Role USR
$role = \Sentinel::getRoleRepository()->createModel()->create([
'name' => 'User',
'slug' => 'USR',
]);
$role->permissions = [
'servicio_dash' => true,
'servicio_widget' =>false,
];
$role->save();
Create 50users and asignate EXA role(Using faker)
$usr_role = \Sentinel::findRoleBySlug('EXA');
factory(App\User::class, 50)->make()->each(function ($u) use ($usr_role) {
\Sentinel::registerAndActivate($u['attributes']);
});
Bonus Track: Factory example
$factory->define(App\User::class, function (Faker\Generator $faker) {
return [
'email' => $faker->safeEmail,
'password' => 'p4ssw0rd',
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'recycle' => false,
'phone' => $faker->phoneNumber,
'alt_email' => $faker->email
];
});
Only one user
$yo = factory(App\User::class)->make(['email' => 'jpaniorte#openmailbox.org']);
\Sentinel::registerAndActivate($yo['attributes']);
$jperez = User::where('email', 'jpaniorte#openmailbox.org')->firstOrFail();
$epa_role->users()->attach($jperez);
Authenticate Controller for API REST
public function authenticateCredentials(Request $request)
{
$credentials = $request->only('email', 'password');
$user = \Sentinel::authenticate($credentials);
return response()->json($user);
}
Authenticate with token (use JWT) and sentinel
public function authenticate(Request $request)
{
// grab credentials from the request
$credentials = $request->only('email', 'password');
try {
// attempt to verify the credentials and create a token for the user
if (!$token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(compact('token'));
}
Note: For this, you need configure JWT options with custom Auth provider, you can find this here
In any controller
public function hasPermission($type)
{
//$sentinel = \Sentinel::findById(\JWTAuth::parseToken()->authenticate()->id); //->this is for a token
$sentinel = \Sentinel::findById(1); //if you now the id
if($sentinel->hasAccess([$type]))
return response()->json(true, 200);
//yout custom handle for noAccess here
}

Resources