Running SMTP Conditionally

I’m working on developing a support website and I’m using Gravity Forms to handle the support ticket form. I have the form notification configured so that the "From" shows my client’s email address instead of the email address from the SMTP.

I need it to do this because I have another plugin that pipes emails sent to a specific inbox. That plugin handles the actual help desk. I’m explaining this part to give some background into what I’m trying to accomplish.

Any SMTP plugin that I use will force all emails coming from the website to use the "From" email set up within the plugin. Gravity Forms won’t override the "From" email notification. I want SMTP to work all the time EXCEPCT for when an email is getting sent out with a different "From".

I found some code to execute from my functions.php file that will change the default wp_mail() if the "From" email doesn’t match. Exactly what I want..:

add_filter('wp_mail_from', 'doEmailFilter'); add_filter('wp_mail_from_name', 'doEmailNameFilter');  function doEmailFilter($  email_address){ if($  email_address === "")     return ''; else     return $  email_address; } function doEmailNameFilter($  email_from){ if($  email_from === "WordPress")     return 'Site Admin'; else     return $  email_from; } 

I also found code that will run SMTP from functions.php:

add_action( 'phpmailer_init', 'send_smtp_email' ); function send_smtp_email( $  phpmailer ) {     $  phpmailer->isSMTP();     $  phpmailer->Host       = SMTP_HOST;     $  phpmailer->SMTPAuth   = SMTP_AUTH;     $  phpmailer->Port       = SMTP_PORT;     $  phpmailer->Username   = SMTP_USER;     $  phpmailer->Password   = SMTP_PASS;     $  phpmailer->SMTPSecure = SMTP_SECURE;     $  phpmailer->From       = SMTP_FROM;     $  phpmailer->FromName   = SMTP_NAME; } 

How would I go about combining these two pieces of code so that the SMTP would run and process the the desired "From" email ONLY if the "From" email doesn’t match? Is such a thing possible? Thank you!

Conditionally open nested, product sub category menus based on is_product_category( ) – Woocommerce

I have a complex product category menu in my woo shop sidebar with lots of sub menus. When the current category is one of the parent menu items, the menu item changes style. But when the current category is one of the nested, sub categories, the menu is closed, hiding the active menu item.

How can I force the menu to open to the current sub category and inherit the active menu item styles?

Conditionally enqueue a stylesheet based off of a javascript click event

I would like to use a different ccs file based on a javascript click event. The user will have a choice of color themes by clicking one of the colored buttons on the screen. I originally have it working by providing the linked css with an id that can be targeted with javascript. The link is in the HTML head tag of course. In WordPress though we enqueue the css file in the functions.php file and so I am not sure how to give the css file an ID to target it with the javascript. If anyone can help me out or point me in the right direction I will really appreciate it. I am open to all possibilities and I thank you all in advance. if you need me to elaborate more feel free to let me know.

Conditionally check if page is using template from plugin directory

I am having trouble loading the script conditionally in my plugin.

I have a DataTables page and want to load datatables scripts only for that page. So I made a page template called datatables-template.php and loading dynamically so can set the template in page attribute.

The template path is my-plugin/public/templates/datatables-template.php

So far so all is working fine. However, when I try to load script explicit fore that template using is_page_template()

When I have checked with get_page_template() that returning theme current page template which is page.php in my case.

Note: is_page working fine, of course, since it will check the current page, that would work. I have also checked my path using file_exists and that returns true. That means I am giving a correct path for the template. So no idea how to check it.

Additionally: I have tried with global $ template which returns the correct plugin template but that doesn’t work in conditional check in my plugin file.

global $  template;  if('datatables-template.php' == $  template){     //load script } 

Question: How can I check if the page has set the specific page template in page attributes, in my case datatables-template.php and load script explicit for that page?

Conditionally returning a constant if function returns Undefined

Often times functions might return Undefined in Mathematica, e.g. when the Volume@RegionIntersection is called for 2 objects which have no overlapping volume. A simple If statement checking if the return has been indeed Undefined does not seem to work. For example, a=Undefined; If[a == Undefined, Print["yes"]] ends up printing the command itself.

  • How can we check if a variable (or a function return) such as a has been assigned as Undefined and assign a different value to it in that case?

How to set a shortcut that alternate it’s function conditionally?

I want to set a unique hotkey to be able to alternate the system sound between analog and HDMI outputs. How can I do this?

This behavior could be observed in play shortcut (from that play and pause the media alternatively.

As answered here, the commands to set the sound-output are:

pactl set-card-profile 0 output:hdmi-stereo  pactl set-card-profile 0 output:analog-stereo 

How can I use JQuery to conditionally require the people picker field on edit form?

Environment: SharePoint 2013 foundation

I’d like to make/validate the People Picker field required conditionally in the edit form of a task list. If the task status is changed to Completed, I want the people picker field to be required.

I tried using PreSaveAction to make this happen, but my code is not working properly. It continues to give an alert even when the people picker field is populated. My people picker field is named Assigned To.

What am I missing in this code? I’ve searched endlessly, but cannot make this happen.

<script type="text/javascript" src="https://mysiteurl/Scripts/jquery-2.1.4.min.js"></script> <script type="text/javascript" language="javascript">  function PreSaveAction() {  drop = $  ("select[title='Task Status']").val(); assigned = $  ().SPServices.SPFindPeoplePicker({  peoplePickerDisplayName: "Assigned To",  checkNames: true  });     if (drop ==="Completed" && assigned===""){         alert("Please assign this item to yourself.");         return false;     }             return true; } 

How to conditionally alter search api relevance score?

I must be missing some core concept of search API somehow, but I am stuck. The goal is to alter search API results depending on a flag, like Give flagged products in search API a higher search score? however this time without SOLR, but with database backend instead.

I can see all flagged fields properly indexed, so there is a line that associates the content entity id with the user who flagged, and now I want to increase the relevance score of the results, so that items flagged by the current user are always shown first.

I have hijacked the SearchApiDbService class and I did add the following line in postQuery (I also wonder why this hook does not exist, but that is not relevant for now):

drupal_alter('search_api_db_query_results', $  results, $  query); 

This should allow me to alter the search results right before search_api_db hands them over to the search API right?

So now I use the alter hook as follows:

function mymodule_search_api_db_query_results_alter(&$  results, SearchApiQueryInterface $  query) {   global $  user;   $  uid = $  user->uid;    // Fetch a list of content entities that the user has flagged.   $  drupal_db_q = db_select('search_api_db_MY_FLAG_FIELD_TABLE', 'f')     ->fields('f')     ->condition('value', $  uid);   $  items = $  drupal_db_q->execute()->fetchCol();    // Iterate over results and multiply score of flagged items.   foreach ($  results['results'] as $  key => &$  result) {     if (in_array($  key, $  items)) {       $  result['score'] *= 10;     }   }  dpm($  results);  } 

In $ results I can see that the scores have changed, but the order of the items on my views results page has not, even though I am sorting by relevance.

It has to be something simple, or I am completely misunderstanding how the score value works somehow?

p.s. Since this is conditionally I don’t think altering the search api query directly makes sense because I found no way to boost any field scores there. Directions on how to achieve that are welcome too.

How to conditionally map two identical variables in nginx?

I would like to set the variable $ sub conditionally dependent on $ request_uri and $ host.

map $  request_uri $  sub {     default       front;     ~^/api/.*     api;     ~^/rest/.*    rest; }  map $  host $  sub {     hostnames;      #default    $  sub; # Tried, no success      ping.*     ping;     admin.*    admin; }  server {     listen 80;     server_name _;      root /usr/share/nginx/html;      location / {         add_header X-Sub $  sub;         try_files $  uri $  uri/ /index.html;     } } 

I thought nginx will not overwrite $ sub in map $ host $ sub if the hostname is not in the list, but unfortunatly it just blanks out $ sub.

So basically it should be like if $ host is “ping” or “admin” set $ sub accordingly. If hostname did not match, check for $ request_uri.

Any idea how to archive that statement?