%s', AP_BASENAME, __('Settings') ) ); } return $links; } // end plugin_action() /* ---------------------------------------------------------------------*/ function ap_options_panel() { // if (!check_admin_referer('apers')) die; if (isset($_REQUEST['uninstall']) OR isset($_REQUEST['reallyuninstall'])) { /* */ amr_personalise_uninstall(); return; } else { $ifnoname = get_option('ap-ifnoname'); if (!($ifnoname)) $ifnoname = ''; $fromaddr = get_option('ap-fromaddr'); $fromname = get_option('ap-fromname'); $enable = get_option('ap-enable-senderchange'); if (empty($enable)) $enable=false; if ((isset($_POST['action'])) and ($_POST['action'] == "save")) {/* Validate the input and save */ if (isset($_POST['ifnoname'])) { $ifnoname = $_POST['ifnoname']; update_option('ap-ifnoname', $ifnoname); } if (isset($_POST['fromaddr'])) { $fromaddr = $_POST['fromaddr']; update_option('ap-fromaddr', $fromaddr); } if (isset($_POST['fromname'])) { $fromname = $_POST['fromname']; update_option('ap-fromname', $fromname); } if (isset($_POST['enable'])) { if ($_POST['enable'] === 'true') $enable = true; else $enable = false; update_option('ap-enable-senderchange', $enable); } else {$enable = false; update_option('ap-enable-senderchange', false); } }?>

'.AMR_NL; ?>

  • />
user_firstname)) return (ucwords($user->user_firstname)); else if (!empty ($user->display_name)) return (ucwords($user->display_name)); else if (!empty ($user->user_nicename)) return (ucwords($user->user_nicename)); else if (!empty ($user->user_login)) return (ucwords($user->user_login)); else if (!empty ($user->user_email)) return (ucwords($user->user_email)); else { $ifnoname = get_option('ap-ifnoname'); if (!is_null($ifnoname)) return ($ifnoname); else return(''); } } /* -------------------------------------------------------------------------*/ function amr_format_datetime ($dt_string) { /* expects a string ala 2009-06-01 03:52:48 */ global $df, $tf, $tz; return( date_i18n( $df.' '.$tf, strtotime($dt_string))); } /* -------------------------------------------------------------------------*/ function amr_personalise ($user, $metakey) { /* look for metafield and echo */ if (!is_object ($user)) { if ($metakey==='display_name') { $ifnoname = get_option('ap-ifnoname'); If (!is_null($ifnoname)) return ('No user object'.$ifnoname); } else return('No user object'); } if ($metakey === 'display_name') return amr_firstname ($user); else if ($metakey === 'user_registered') { if (isset ($user->$metakey)) { return amr_format_datetime ($user->$metakey);} else return ('user_registered'); } if (stristr($metakey,'capabilities')) { if (is_array ($user->$metakey)) { $text = ''; foreach ($user->$metakey as $c => $tf) { if ($tf == '1') $text = $text.','.$c; } return (trim( $text,',')); } else return ($metakey); } if (!empty ($user->$metakey)) { if (is_array ($user->$metakey)) return (implode(',', $user->$metakey)); else return ($user->$metakey); } else return ($metakey); } /* ---------------------------------------------------------------------*/ /* insert the specific user parameters into the message at the place holders */ function a_personalised_message($user_info, $text, $atts) { /* EG: You registered on %s with user name %s */ $c = substr_count($text, '%s'); foreach ($atts as $i => $v) { if (!($atts[$i] = amr_personalise($user_info, $v))) unset ($atts[$i]); else if ($atts[$i] === $v) unset ($atts[$i]); } if (($c < count($atts)) or empty($atts)) { return(''); } else return (vsprintf ($text, $atts)); } /* -------------------------------------------------------------------------*/ function ap_user_shortcode ($atts, $otherargs='') { /* If no atts, then just display name if have else user default */ /* shortcode can be any of the values from the user or user meta tables user_login, user_nicename, user_email, user_url, display_name Shortcode usage: [user] or [user display_name]- will give display name or default from settings [user user_email] will give email address if it exists */ global $current_user; if ((isset($_REQUEST['ID'])) and (is_numeric ($_REQUEST['ID']))) $user_info = get_userdata($_REQUEST['ID']); else { get_currentuserinfo(); $user_info = $current_user; } /* allow for potentially a request for more than one value */ if (!is_array($atts)) { return( amr_firstname ($user_info)); } else { if (!empty($atts['message'])) { $text = $atts['message']; unset ($atts['message']); if (function_exists('a_personalised_message')) return (a_personalised_message($user_info, $text, $atts)); } $result = ''; foreach ($atts as $i => $v) { if (!empty($result)) $result .= ' '; $result .= amr_personalise($user_info, $v); } } return ($result); } /* -------------------------------------------------------------------------------------------------------------*/ function ap_admin_menu() { /* parent, page title, menu title, access level, file, function */ $plugin_page = add_submenu_page('options-general.php', 'AmR Personalise', 'AmR Personalise', 8, __FILE__, 'ap_options_panel'); // add_action( 'admin_head-'. $plugin_page, 'ap_admin_header' ); add_action('admin_print_styles-'. $plugin_page, 'ap_stylesheet'); } /* -------------------------------------------------------------------------------------------------------------*/ function ap_mail_from (&$atts) { $name = get_option('ap-fromaddr'); if (isset($name)) return ($name); else return ($atts); } /* -------------------------------------------------------------------------------------------------------------*/ function ap_mail_from_name (&$atts) { $name = get_option('ap-fromname'); if (isset($name)) return ($name); else return ($atts); } /* -------------------------------------------------------------------------------------------------------------*/ function ap_user_mailfilter (&$atts) { /* apply the shortcode functionality to outgoing email messages */ if (isset ($atts ['to'])) { if ( $user = get_user_by('email',$atts['to'] )) { $name = amr_firstname ($user); } else $name = get_option('ap-ifnoname'); if (isset($atts['message'])) $atts['message'] = do_shortcode($atts['message']); if (isset ($atts['subject'])) $atts ['subject'] = do_shortcode($atts['subject']); } return ($atts); } /* -------------------------------------------------------------------------------------------------------------*/ if (is_admin() ) { load_plugin_textdomain('apers', false , basename(dirname(__FILE__)) ); add_action('admin_menu', 'ap_admin_menu'); add_filter('plugin_action_links', 'ap_plugin_action', -10, 2); } else add_filter('widget_text', 'do_shortcode', 11 /*SHORTCODE_PRIORITY*/); /* Need priority to get the filter to load early */ /* does apply filters apply the shortcodes too */ add_shortcode('user', 'ap_user_shortcode'); add_filter('wp_mail','ap_user_mailfilter'); If ($enable = get_option('ap-enable-senderchange')) { add_filter('wp_mail_from','ap_mail_from'); add_filter('wp_mail_from_name','ap_mail_from_name'); } ?>