[{"data":1,"prerenderedAt":188},["ShallowReactive",2],{"post:override-login-messages-with-add-filter":3},{"id":4,"title":5,"body":6,"date":175,"description":176,"draft":177,"extension":178,"meta":179,"navigation":180,"path":181,"seo":182,"stem":183,"tags":184,"__hash__":187},"posts\u002Fposts\u002Foverride-login-messages-with-add-filter.md","TIL: Override Login Messages with `add_filter()`",{"type":7,"value":8,"toc":168},"minimark",[9,21,30,42,58,65,105,114,118,121,161,164],[10,11,12,13,20],"p",{},"Using the Wordpress ",[14,15,19],"a",{"href":16,"rel":17},"https:\u002F\u002Fwordpress.org\u002Fplugins\u002Ftheme-my-login\u002F",[18],"nofollow","\"Theme My Login\""," plugin to display a nice login form on a custom dashboard page. The form by default displays a \"Log In\" message, but what I'd like to see is \"Please log in to view your application status\".",[22,23,25,26],"h2",{"id":24},"what-is-apply_filters","What Is ",[27,28,29],"code",{},"apply_filters()",[10,31,32,37,38,41],{},[14,33,36],{"href":34,"rel":35},"https:\u002F\u002Fgithub.com\u002Fjfarthing84\u002Ftheme-my-login\u002Fblob\u002F6.4\u002Fincludes\u002Fclass-theme-my-login-template.php#L413",[18],"Under the hood",", the plugin uses ",[27,39,40],{},"apply_filters(...)"," to allow customizing the login message.",[43,44,49],"pre",{"className":45,"code":46,"language":47,"meta":48,"style":48},"language-php shiki shiki-themes github-light github-dark","return apply_filters('tml_action_template_message', $message, $action);\n","php","",[27,50,51],{"__ignoreMap":48},[52,53,56],"span",{"class":54,"line":55},"line",1,[52,57,46],{},[22,59,61,62],{"id":60},"using-add_filter","Using ",[27,63,64],{},"add_filter()",[10,66,67,68,71,72,75,76,79,80,83,84,87,88,91,92,95,96,101,102,104],{},"To modify it, one needs only call ",[27,69,70],{},"add_filter( $filter_name, $func_name, $priority, $arg_count )"," where ",[27,73,74],{},"$filter_name"," is ",[27,77,78],{},"tml_action_template_message"," and ",[27,81,82],{},"$func_name"," should be the name of a function which will return the new string for the login message. While ",[27,85,86],{},"$priority"," was not important in my case, for me it was important to pass ",[27,89,90],{},"2"," for the ",[27,93,94],{},"$arg_count"," or ",[14,97,100],{"href":98,"rel":99},"https:\u002F\u002Fstackoverflow.com\u002Fquestions\u002F24198086\u002Fmissing-argument-2-for-the-function-in-wordpress",[18],"else I wouldn't receive both arguments"," passed from the original ",[27,103,29],{}," call.",[43,106,108],{"className":45,"code":107,"language":47,"meta":48,"style":48},"add_filter( 'tml_action_template_message', 'custom_dashboard_login_message', 10, 2);\n",[27,109,110],{"__ignoreMap":48},[52,111,112],{"class":54,"line":55},[52,113,107],{},[22,115,117],{"id":116},"my-filter-function","My Filter Function",[10,119,120],{},"The function called needs only return a string. It could be the same string every time, or it could differ based on URL variables, time of day, various arguments, etc.",[43,122,124],{"className":45,"code":123,"language":47,"meta":48,"style":48},"function custom_dashboard_login_message( $message, $action = '' ) {\n    if ( $action === 'login' ) {\n        $message = 'Please log in to view your application status.';\n    }\n    return $message;\n}\n",[27,125,126,131,137,143,149,155],{"__ignoreMap":48},[52,127,128],{"class":54,"line":55},[52,129,130],{},"function custom_dashboard_login_message( $message, $action = '' ) {\n",[52,132,134],{"class":54,"line":133},2,[52,135,136],{},"    if ( $action === 'login' ) {\n",[52,138,140],{"class":54,"line":139},3,[52,141,142],{},"        $message = 'Please log in to view your application status.';\n",[52,144,146],{"class":54,"line":145},4,[52,147,148],{},"    }\n",[52,150,152],{"class":54,"line":151},5,[52,153,154],{},"    return $message;\n",[52,156,158],{"class":54,"line":157},6,[52,159,160],{},"}\n",[10,162,163],{},"This did the trick for me!",[165,166,167],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":48,"searchDepth":133,"depth":133,"links":169},[170,172,174],{"id":24,"depth":133,"text":171},"What Is apply_filters()",{"id":60,"depth":133,"text":173},"Using add_filter()",{"id":116,"depth":133,"text":117},"2018-04-24T08:51:01-04:00","Using the Wordpress \"Theme My Login\" plugin to display a nice login form on a custom dashboard page. The form by default displays a \"Log In\" message, but what I'd like to see is \"Please log in to view your application status\".",false,"md",{},true,"\u002Fposts\u002Foverride-login-messages-with-add-filter",{"title":5,"description":176},"posts\u002Foverride-login-messages-with-add-filter",[185,186],"wordpress","til","A2MOkuRrN8mSk4SpBWByJXqWf2e2fpuOzXhS5YrkPfA",1790471528283]