{"id":9805,"date":"2013-04-20T05:38:22","date_gmt":"2013-04-20T05:38:22","guid":{"rendered":"http:\/\/musilda.cz\/?p=151"},"modified":"2013-04-20T05:38:22","modified_gmt":"2013-04-20T05:38:22","slug":"jak-pridat-pole-pro-heslo-do-registracniho-formulare-bez-pouziti-pluginu","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-pridat-pole-pro-heslo-do-registracniho-formulare-bez-pouziti-pluginu\/","title":{"rendered":"Jak p\u0159idat pole pro heslo do registra\u010dn\u00edho formul\u00e1\u0159e bez pou\u017eit\u00ed pluginu"},"content":{"rendered":"

P\u0159i registraci do blogu be\u017e\u00edc\u00edm na redak\u010dn\u00edm syst\u00e9mu WordPress, je nutn\u00e9 nejprve zadat u\u017eivatelsk\u00e9 jm\u00e9no a email, n\u00e1hodn\u011b vygenerovan\u00e9 heslo n\u00e1m pak automaticky p\u0159ijde na zadan\u00fd email. Heslo si pak m\u016f\u017eeme zm\u011bnit v profilu u\u017eivatele.<\/p>\n

Jak postupovat, pokud chceme u\u017eivatel\u016fm umo\u017enit zadat sv\u00e9 heslo ji\u017e p\u0159i registraci a vynechat tak mezikrok s nutnost\u00ed kop\u00edrov\u00e1n\u00ed vygenerovan\u00e9ho hesla a jeho zm\u011bn\u011b v nastaven\u00ed \u00fa\u010dtu.<\/p>\n

P\u016fvodn\u00ed formul\u00e1\u0159 vypad\u00e1 takto:<\/p>\n

\"\"<\/a><\/p>\n

My budeme cht\u00edt p\u0159idat dv\u011b pole pro heslo a potvrzen\u00ed hesla. Do functions.php vlo\u017e\u00edme n\u00e1sleduj\u00edc\u00ed funkci:<\/p>\n

function vm_extra_fields(){\necho '\n

\n

\n

T\u00edm jsme vytvo\u0159ili dv\u011b pole pro heslo a potvrzen\u00ed hesla, je\u0161t\u011b je p\u0159id\u00e1me do formul\u00e1\u0159e pomoc\u00ed add_action a hooku register_form:<\/p>\n

add_action( 'register_form', 'vm_extra_fields' );<\/pre>\n

V\u00fdsledek:
\n
\"\"<\/a>
\nNa formul\u00e1\u0159i je vid\u011bt, \u017ee jako podm\u00ednku jsme si stanovili, \u017ee heslo mus\u00ed b\u00fdt dlouh\u00e9 minim\u00e1ln\u011b 8 znak\u016f a mus\u00edme tedy prov\u00e9st kontrolu:<\/p>\n

function vm_check_register_fields($login, $email, $errors) {\n  if ( $_POST['password'] !== $_POST['repeat_password'] ) {\n  $errors->add( 'passwords_not_matched', \"ERROR<\/strong>:\n  Passwords must match\" );\n  }\n  if ( strlen( $_POST['password'] ) add( 'password_too_short', \"ERROR<\/strong>:\n  Passwords must be at least eight characters long\" );\n  }\n}\n\nadd_action( 'register_post', 'vm_check_register_fields', 10, 3 );<\/pre>\n

Ur\u010dit\u011b jste si tak\u00e9 v\u0161imli, \u017ee se na formul\u00e1\u0159i ji\u017e nezobrazuje upozorn\u011bn\u00ed, \u017ee heslo bude zasl\u00e1no emailem. To nyn\u00ed postr\u00e1d\u00e1 smysl a proto jej odstran\u00edme. Bohu\u017eel se mi nepoda\u0159ilo p\u0159ij\u00edt na zp\u016fsob, kter\u00fd by fungoval univerz\u00e1ln\u011b pro jak\u00fdkoliv jazyk, proto jsem vytvo\u0159il filtr pro angli\u010dtinu a \u010de\u0161tinu. P\u0159i pou\u017eit\u00ed jin\u00e9ho jazyka je nutn\u00e9 zm\u011bnit podm\u00ednku:<\/p>\n

function vm_edit_password_email_text ( $text ) {\n\tif ( $text == 'A password will be e-mailed to you.' ) {\n\t\t$text = '';\n\t}\n\treturn $text;\n}\nadd_filter( 'gettext', 'vm_edit_password_email_text' );<\/pre>\n

Jako posledn\u00ed krok ulo\u017e\u00edme zadan\u00e9 heslo do datab\u00e1ze:<\/p>\n

function vm_register_extra_fields( $user_id ){\n\t$userdata = array();\n\n\t$userdata['ID'] = $user_id;\n\tif ( $_POST['password'] !== '' ) {\n\t\t$userdata['user_pass'] = $_POST['password'];\n\t}\n\t$new_user_id = wp_update_user( $userdata );\n}\nadd_action( 'user_register', 'vm_register_extra_fields', 100 );<\/pre>\n

Samoz\u0159ejm\u011b, \u017ee by bylo fajn p\u0159idat je\u0161t\u011b kontrolu t\u0159eba pomoc\u00ed CAPTCHA, ale to nen\u00ed sou\u010d\u00e1st\u00ed tohoto \u010dl\u00e1nku.
\nV n\u011bkter\u00e9m z dal\u0161\u00edch \u010dl\u00e1nk\u016f pop\u00ed\u0161i zp\u016fsob, jak vytvo\u0159it widget s p\u0159ihla\u0161ovac\u00edm formul\u00e1\u0159em pro um\u00edst\u011bn\u00ed do sidebaru.<\/p>\n","protected":false},"excerpt":{"rendered":"

P\u0159i registraci do blogu be\u017e\u00edc\u00edm na redak\u010dn\u00edm syst\u00e9mu WordPress, je nutn\u00e9 nejprve zadat u\u017eivatelsk\u00e9 jm\u00e9no a email, n\u00e1hodn\u011b vygenerovan\u00e9 heslo n\u00e1m pak automaticky p\u0159ijde na zadan\u00fd email. Heslo si pak m\u016f\u017eeme zm\u011bnit v profilu u\u017eivatele. Jak postupovat, pokud chceme u\u017eivatel\u016fm umo\u017enit zadat sv\u00e9 heslo ji\u017e p\u0159i registraci a vynechat tak mezikrok s nutnost\u00ed kop\u00edrov\u00e1n\u00ed vygenerovan\u00e9ho<\/p>\n","protected":false},"author":1,"featured_media":8624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,30],"tags":[257,319,320],"class_list":["post-9805","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-navody","category-wordpress","tag-navod-wordpress","tag-registrace-wordpress","tag-registracni-formular"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/9805"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=9805"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/9805\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8624"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=9805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=9805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=9805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}