Im trying to get the email stored udner 'settings' in wordpress. I know there was an old function for this: get_settings but this is depreciated. I can't find a replacement - is there a reason for this? What is the best practice method for returning the settings email in wordpress?
Instead of using get_settings(), use get_option().
Example:
$email = get_option('admin_email');
Related
I am trying to create a function that matches user's that have the same expertise as a custom post custom field. So if a custom author meta has an expertise of 'Ninja' and the custom post type has a custom field that also has 'Ninja', my email will go out to all those matching user's.
I have the following bit of wp_mail code and can also create user queries using get_users but cannot get the two to work as i need. Any ideas?
add_action('future_to_publish', 'send_emails_on_new_event');
add_action('new_to_publish', 'send_emails_on_new_event');
add_action('draft_to_publish', 'send_emails_on_new_event');
add_action('auto-draft_to_publish', 'send_emails_on_new_event');
function send_emails_on_new_event($post) {
global $post;
$expertise = get_field('expertise', $postid);
$emails = MATCHING USER EMAIL ADDRESSES TO GO HERE;
$message = '<p>Email content will go here ...</p>';
if (get_post_type($post->ID) === 'custom_post_type') {
wp_mail($emails, "Email title will go here ...", $message);
}
}
Have you tried using SQL query actually to get matching emails from database??
something like
$sql = SELECT user.email FROM user WHERE user.expertise = $postExpertise;
$email = database->getRecords($sql); //getRecords() is just general function placeholder, build your own db processor class
...
function send_emails_on_new_event($post) {
...
}
You have to understand, WP is just a tool written in PHP with common functionality, if you want custom functionality, either build it yourself or if you are lucky, find plugin already created with similiar functionality. But you will not always find the plugin you want.
Hence why WP is good only for low-budget websites built by not so great web developers. Because if you can build custom functionality on top of WP, you should already consider if using WP is even good idea in first place
I'm using the notify_entity module for Drupal 8 and want to change the mail address used for the from value.
I'm trying to do it using hook_mail_alt r but it doesn't work, Drupal still send mail with the default administrator mail address... Am I doing something wrong? Or there is another way to do this?
Thanks.
/**
* Implements hook_mail_alter()
*/
function notify_entity_mail_alter(&$message){
$from = "foo#bar.com";
$message['from'] = $from;
}
They should be changed like this
$message['headers']['Return-Path'] = 'user#email.com';
$message['headers']['Sender'] = 'user#email.com';
$message['headers']['From'] = 'Site name';
$message['headers']['Reply-to'] = 'user#email.com';
Also note it seems you are modifying (hacking) the notify_entity module right ? You should not do that! If you update it or someone else updates this drupal installation in the future you might end up losing the changes and not realize it ...
You should create your own module and implement the hook_mail_alter and name your function MYMODULE_mail_alter()
Just today I had to do this and stumbled upon your question here it is a very simple module that does exactly what you want https://github.com/GiorgosK/mail_alter_headers.
NOTE: you have to modify the .module file with your own details or comment out // the ones you don't want to modify.
I' creating a moodle local plugin
I created a language file in local/myplugin/lang/en/local_usercertlist.php with some keys:
I created a language file in local/myplugin/lang/en/local_myplugin.php with some keys:
<?php
$string['pluginname']="My Plug-in";
$string['testkey']="Test Val";
in lib.php I use get_string like this:
get_string('testkey','local_myplugin')
But I get [[testkey]] instead of Test Val !
why? what is the problem?
local/myplugin/lang/en/local_usercertlist.php
Should be
local/usercertlist/lang/en/local_usercertlist.php
and
get_string('testkey','local_myplugin')
should be
get_string('testkey','local_usercertlist')
I just needed to increase plugin version & update moodle database;
If I want to link to a cms page from a template with smarty, I currently use something like this:
{$link->getPageLink('cms',null,null,'id_cms=4')}
But that is going to generate a regular url (with query string), so if I activate pretty urls (url rewrite), it won't work. I analized the Link class but I can't find a way to generate a proper rewritten url. In fact, THERE IS a simple way:
{$link->getCMSLink(4)}
BUT, taking a look into Link::getCMSLink notes, I read that using an ID instead of a CMS object is deprecated. But from a template I don't have the cms object available.
Anyone had the same problem?
I found it really by "let's try if this one works".....
In PS1.6 you can get CMS object like:
$myCMS = new CMS( YOUR_CMS_ID );
If you want to use it in tpl, you have to define it in your controller e.g.:
$this->context->smarty->assign( "myCMS", $myCMS );
This is my solution. I recently tested it for Prestashop v1.6 and v1.7
This code utilizes the method getCMSLink of the Link class. It is necessary to know the id_cms of the CMS Page, to create the object model.
$link = new Link();
$cmsPageObject = new CMS(
$id_cms,
$id_lang
);
// $cmsLink has the URL string.
$cmsLink = $link->getCMSLink(
$cmsPageObject,
null,
Configuration::get("PS_SSL_ENABLED") === "1",
$id_lang,
null,
null
);
I'd like to know which is the cleanest way to insert an url in an email sent by Moodle module.
So far I'm using this formula, what IMHO I don't think is the cleanest way:
$url = $CFG->wwwroot.'/mod/<mymodulename>/view.php?id='.$cm->id;
The things I don't like here are:
Using $CFG->wwwroot
/mod/<mymodulename> needs to be provided always. (Assume here that I'm using a constant instead of a hardcoded string).
I expected Moodle to have a function to provide this out of the box just when providing module script. I've tried moodle_url but this function doesn't provide the path to the php script when used this way:
new moodle_url('view.php?id='.$cm->id);
I just get:
view.php?id=XX
Thanks in advance.
I would do it like this
$url = new moodle_url('/mod/<mymodulename>/view.php', array('id' => $cm->id));
echo html_writer::link($url, get_string('linktitle', 'mod_mymodulename'));
You can use following statement:
This is Absolute path of file
$url = new moodle_url($CFG->wwwroot.'/mod//view.php', array('id' => $cm->id));