wp_new_user_notification not triggered - php

I am testing a simple function, to get the wp_new_user_notification email to send, but the standard ordpress function is not triggering.
I'm not trying to change the function, I just want to trigger it.
Any ideas of what I'm doing wrong?
My code:
function test_new_user_email() {
wp_new_user_notification ( '2', null, 'both' );
}
...which is as per:
https://developer.wordpress.org/reference/functions/wp_new_user_notification/
In this case, I'm testing the sending of the email to an existing User ID = 2
As far as I can tell, it doesn't look like there are any dependencies on this standard function, unless I'm missing something here.

Here's a modified version of the core file for "Import Users from CSV": import-users-from-csv.php.
Note that it's not a full upgrade; I modified it just to make sure it's warnings-free (i.e. it passes WP_DEBUG "on" mode); and secondly, I've tested the "Send to new users" option (which uses the wp_new_user_notification() function), and it worked well.
In line 354, you can, if you want, set the 3rd argument to both:
if ( $new_user_notification )
wp_new_user_notification( $user_id, null, 'user' );
Try that new file — download and upload it to wp-content/plugins/import-users-from-csv/ — and just let me know if you need further assistance.

Related

PHP Active Session Warning in wordpress

I know this question is frequently asked on this forum, but none of the proposed solutions has worked for me, basically, I am a WordPress plugin developer and developing a plugin whose session starts in the init file but close when the client closes his/her browser, and it is necessary to keep the session open. In this case, how can I get rid of this warning? Maybe I should use something other than the session or what you suggest.
Till now there are different proposed solutions like Use
if ( !session_id() ) {
session_start( [
'read_and_close' => true,
] );
}
but with this technique, I can never be able to use sessions in my plugin, and the whole functionality goes on the ground.
Any help in this regard would be much appreciated.
thanks
WordPress plugin or theme developers cannot use php's session subsystem as you have discovered.
If you need to save some kind of global context for your plugin to work, use WordPress's add_option() function to save it at the end of each operation. You can retrieve your context using get_option().
If you need per-user context, use add_user_meta() to save it and get_user_meta() to retrieve it. Like this:
$id = get_current_user_id();
$myContext = get_user_meta( $id, 'my_plugins_meta_tag_name' );
...
add_user_meta( $id, 'my_plugins_meta_tag_name', $myContext);
WordPress uses a database table to store these sorts of options. Some sites put an object cache in front of the table. But these APIs are how you do what you want to do.
In your plugin's deactivation hook, please consider calling delete_option() to clean up that storage. And, if you use per-user context, please consider using delete_user_meta() to remove your user_meta item from all of them.
$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach($users as $user){
delete_user_meta ( $user->ID, 'my_plugins_meta_tag_name' );
}
As for sensitive information, WordPress offers no other place to put it. And, if you were using sessions, php would need to put it somewhere as well. By default, php puts session data in the filesystem of the server. That's why WordPress hashes user passwords before storing them.

using setTransactionSettings in the Authorize.net PHP API

I am trying to set the duplicateWindow time using:
$transactionRequestType->setTransactionSettings();
I found this in the PHP SDK code,
public function setTransactionSettings(array $transactionSettings) {...}
That tells me this method accepts an array, but I'm not sure how to format the data I send.
I found the XML version:
<transactionSettings>
<setting>
<settingName>duplicateWindow</settingName>
<settingValue>0</settingValue>
</setting>
</transactionSettings>
But I'm not sure how to translate that into a PHP array.
Thanks,
D
This works if you only want to set a single setting.
I'm still trying to figure out how to set multiple settings (you get duplicate key issues if you try to set more than one).
$transactionSettings = array(
'setting' => array(
'settingName' => 'duplicateWindow',
'settingValue' => 0
)
);
Here is the solution I ended up using and it works fine.
$duplicateWindowSetting = new AnetAPI\SettingType();
$duplicateWindowSetting->setSettingName("duplicateWindow");
$duplicateWindowSetting->setSettingValue("120");
$transactionRequestType->addToTransactionSettings($duplicateWindowSetting);
To add multiple new settings, it would be pretty similar, just making a new instance of class SettingType() for each different setting you wanted.
Something like:
//add the values for each setting
$duplicateWindowSetting = new AnetAPI\SettingType();
$duplicateWindowSetting->setSettingName("duplicateWindow");
$duplicateWindowSetting->setSettingValue("600");
$allowPartialAuthSetting = new AnetAPI\SettingType();
$allowPartialAuthSetting->setSettingName("allowPartialAuth");
$allowPartialAuthSetting->setSettingValue("true");
and so on, then adding each transaction setting to the transaction request by doing something like:
$transactionRequestType->addToTransactionSettings($duplicateWindowSetting);
$transactionRequestType->addToTransactionSettings($allowPartialAuthSetting);

Typo3 - Typoscript set FE username as a constant

I am currently trying to add the username of the currently logged in FE user as a constant. I have tried the following but it does not seem to work.
Username = TSFE:fe_user|user|username
I am using this as a starting point
I would like to know how get the FE username into a constant so I can call it when ever I need for the rest of my typoscript.
This is the bit of typoscript that I am trying to get the username into, at the moment it just adds the company name which is defined as a constant else where, but I would like to add int he username also. I have tried adding the global variable for the username but no joy.
[usergroup = *]
config.tx_we_google_analytics {
_setCustomVar = 1, 'Client', '{$companyName} - {TSFE:fe_user|user|username}',2
}
[end]
Many Thanks in Advance
Bob
I wouldn't recommend using an extension to insert something as basic as a Google Analytics Snippet. Each extension slows down the system and makes it less maintainable.
I don't know what your customVar does, but you might try something like
temp.analytics = COA
temp.analytics {
10 = TEXT
10.value (
first part of GA snippet
)
20 = TEXT
20.data = TSFE:fe_user|user|username
30 = TEXT
30.value (
rest of GA Snippet
)
}
Then insert your snippet where you want, e.g. headerData.99 < temp.analyticsand you're done.
Or even try with a wrap and insertData=1.
As Artur says, if data doesn't render in .wrap, always try stdWrap.wrap - it tends to add functionality (although afaik there have been efforts to pass every wrap through stdWrap by default, but I don't think it's fully implemented).
You can use the appropriate global variable inside TypoScript setup directly, there is no need for a constant I think. The example you provided is the global variable I am talking about, which you can use in any getText context inside typoscript setup.
e.g.
temp.userName = TEXT
temp.userName.data = TSFE:fe_user|user|username
TypoScript constants allow only direct value assignment, it is not possible to assign any other "variable" to a constant IMHO.
Try this. If you are lucky it could work.
[usergroup = *]
config.tx_we_google_analytics {
_setCustomVar.cObject = TEXT
_setCustomVar.cObject.value = 1, 'Client', '{$companyName} - {TSFE:fe_user|user|username}',2
_setCustomVar.cObject.insertData = 1
}
[end]
If it doesn't, you will have to modify the plugin code to process the config value by stdWrap. Thsi code works from within the plugin controller
$configValue = $this->cObj->stdWrap('',$GLOBALS['TSFE']->tmpl->setup['config.']['tx_we_google_analytics.']['_setCustomVar.']);
or simpler (stil within the controller)
$configValue = $this->cObj->stdWrap('',$this->conf['_setCustomVar.']);

Record the time/date of a post meta field change WordPress

So I have a post meta field that has two values, true or false. It is defaulted at false, and it'll automatically change to true when an event occurs.
Anyway, is it possible to create another meta field that records the exact time that this change occurs? If so, how would I go about doing this?
Well without modifying wordpress core or overriding the update_field() function in your theme functions.php you cant get in a smooth way the time when a record has been added to the database.
But what can i advice to you:
1) If your application highly depends on seconds:milliseconds when post_meta has been modified, you should use advanced technique: database transactions.
2) If your application are fine with a small delay between writing up 1st meta and the second just add it with add_post_meta() right below the update_field() performed
p.s If you think that overriding the function with functions.php is the way you prefer just ping me a comment, i'll try to help you with by editing the post.
Cheers!
EDIT
Right after your manipulation with allready_aired field performed
$alreadyAired = get_field('already_aired', $episodeID);
if (get_field('already_aired', $episodeID) == "no") {
update_field('field_28', "yes", $episodeID);
}
you can use add_post_meta($post_id, $meta_key, $meta_value, $unique) function in a way like this:
$alreadyAired = get_field('already_aired', $episodeID);
if (get_field('already_aired', $episodeID) == "no") {
update_field('field_28', "yes", $episodeID);
}
add_post_meta($episodeID, 'NEW_TIMESTAMP_FIELD', time(), true);
Then, you can call this NEW_TIMESTAMP_FIELD and use in a way you like (echo formatted date-string, compare 2 dates, etc.
Please note the 4th parameter of add_post_meta function. This one tell you that this field is unique and considering that app_post_meta does not affect "Update" actions, this bundle wont let this field get modified in the second time.

json return null from ipage hoster

I have a code that works well on localhost(xampp kit).
I am using php-oop static classes to generate forms, instead of write html code.
When I use it on iPage server it returns null, for the variable divResposta (html code that will geneate a form - as told above). pkUser,pagOrigem,pagAtual all ok.When I check on inspect elements(chrome)>networks>xhr I see divResposta=null.
Note I use ajax-jQuery to retrive this information.
Any clue will be good.
Thanks
elseif($ObjEvn==="link_criarIndicador"){
$divResposta=D3BI::Div_Indicador_Criar($idioma,$pkUser);
$pagOrigem=$pagAtual;
$pagAtual="criarIndicadorPage";
$data=array(
array(
"divResposta"=>"$divResposta",
"pkUser"=>"$pkUser",
"pagOrigem"=>"$pagOrigem",
"pagAtual"=>"$pagAtual"
)
);
$strJson=json_encode($data);
echo $strJson;
}

Categories