%s', AP_BASENAME, __('Settings') ) ); } return $links; } // end plugin_action() add_filter('plugin_action_links', 'ap_plugin_action', -10, 2); /* ---------------------------------------------------------------------*/ function ap_options_panel() { // if (!check_admin_referer('apers')) die; if (isset($_REQUEST['uninstall']) OR isset($_REQUEST['reallyuninstall'])) { /* */ // echo 'Not Yet Implemented. Please delete options in DB manually ' amr_personalise_uninstall(); return; } else { // wait till works ap_version(); $ifnoname = get_option('ap-ifnoname'); if (!($ifnoname)) $ifnoname = ''; $fromaddr = get_option('ap-fromaddr'); $fromname = get_option('ap-fromname'); if($_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); } } echo '

'.__('AmR Personalise ', 'apers').AMR_PERSONALISE_VERSION.'

'.AMR_NL; ?>
user_firstname)) return (ucwords($user->user_firstname)); else if (isset ($user->display_name)) return (ucwords($user->display_name)); else if (isset ($user->user_nicename)) return (ucwords($user->user_nicename)); else if (isset ($user->user_login)) return (ucwords($user->user_login)); else if (isset ($user->user_email)) return (ucwords($user->user_email)); else { $ifnoname = get_option('ap-ifnoname'); if (!is_null($ifnoname)) return ($ifnoname); else return(''); } } /* -------------------------------------------------------------------------*/ 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 (isset ($user->$metakey)) return ($user->$metakey); /* later on, with 'plus' can extract other fields */ else return ; /* we may want to expand this to extract data from within meta values, or for other meta keys*/ } } /* -------------------------------------------------------------------------*/ 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; get_currentuserinfo(); /* allow for potentially a request for more than one value */ if (!is_array($atts)) { return( amr_firstname ($current_user)); } else { foreach ($atts as $i => $v) { if (isset ($result)) $result .= ' '; else $result = ''; $result .= amr_personalise ($current_user, $v); } return ($result); } } /* -------------------------------------------------------------------------------------------------------------*/ /* Internationalization functionality */ function ap_load_text() { /* $textdomain, path from abspath, path from plugins folder */ load_plugin_textdomain('apers', false , basename(dirname(__FILE__)) ); } /* -------------------------------------------------------------------------------------------------------------*/ 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' ); } /* -------------------------------------------------------------------------------------------------------------*/ function ap_mail_from (&$atts) { $name = get_option('ap-fromaddr'); if (isset($name) and (strlen($name)>1)) return ($name); else return ($atts); } /* -------------------------------------------------------------------------------------------------------------*/ function ap_mail_from_name (&$atts) { $name = get_option('ap-fromname'); if (isset($name) and (strlen($name)>1)) return ($name); else return ($atts); } /* -------------------------------------------------------------------------------------------------------------*/ function ap_user_mailfilter (&$atts) { /* Since shortcodes don't seem to work in wp_mail filters, we have to manually deal with the text */ /* so look for [user .... ] and deal with it - urg more regex ? */ /* for now just do the basic - first name */ /* atts should contain the "to" */ 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'] = str_replace("[user]",$name, $atts['message']); if (isset ($atts['subject'])) $atts ['subject'] = str_replace ('[user]',$name, $atts['subject']); } return ($atts); } /* -------------------------------------------------------------------------------------------------------------*/ if (is_admin() ) { add_action('admin_menu', 'ap_admin_menu'); } /* does apply filters apply the shortcodes too */ add_shortcode('user', 'ap_user_shortcode'); add_filter('wp_mail','ap_user_mailfilter'); add_filter('wp_mail_from','ap_mail_from'); add_filter('wp_mail_from_name','ap_mail_from_name'); ?>