Advertisement
mbis

Mailster support

Jan 27th, 2020
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. function pm_extra_mailster_endpoints($endpoints) {
  2.     if(function_exists('mailster_option')) {
  3.         $slugs = implode('|', (array) mailster_option('slugs', array('confirm', 'subscribe', 'unsubscribe', 'profile')));
  4.         $endpoints .= "|{$slugs}";
  5.     }
  6.  
  7.     return $endpoints;
  8. }
  9. add_filter('permalink_manager_endpoints', 'pm_extra_mailster_endpoints');
  10.  
  11. function pm_detect_mailster_urls() {
  12.     global $pm_query, $wp_query;
  13.  
  14.     if(!function_exists('mailster_option') || empty($pm_query['endpoint'])) {
  15.         return;
  16.     }
  17.  
  18.     // Get list of Mailster endpoints
  19.     $slugs = (array) mailster_option('slugs', array('confirm', 'subscribe', 'unsubscribe', 'profile'));
  20.  
  21.     if(in_array($pm_query['endpoint'], $slugs)) {
  22.         $wp_query->query_vars['_mailster_page'] = $pm_query['endpoint'];
  23.  
  24.         // Detect hash & extra parameter
  25.         preg_match('/([a-f0-9]{32})?\/?([a-z0-9\/]*)/', $pm_query['endpoint_value'], $parts);
  26.         $wp_query->query_vars['_mailster_hash'] = $parts[1];
  27.  
  28.         if(!empty($parts[2])) {
  29.             $wp_query->query_vars['_mailster_extra'] = $parts[2];
  30.         }
  31.     }
  32. }
  33. add_action('wp', 'pm_detect_mailster_urls', 99);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement