WordPress adds contact fields such as Sina Tencent Weibo to users. The following code adds three contact methods: Sina Weibo, Tencent Weibo, and iMessage. You can also modify or add the fields you need. Paste the following code to the functions. php file of the current topic. After saving the code, you can see the effect in the contact information in the background> user> my personal data.
The code is as follows: |
Copy code |
Add_filter ('User _ contactmethods ', 'My _ user_contactmethods '); Function my_user_contactmethods ($ user_contactmethods ){ $ User_contactmethods ['Weibo '] = 'sina weibo '; $ User_contactmethods ['T-QQ'] = 'Tencent Weibo '; $ User_contactmethods ['imessage'] = 'imessage '; Return $ user_contactmethods; } |
If you want to add more information, you can add it in the form of $ user_contactmethods ['qq-weibo '] = 'Tencent weibo. Qq-weibo is a character segment and must be unique. Tencent Weibo is the name of this option.
Synchronous recommendation of Sina, Tencent, Weibo, NetEase Weibo and Douban plug-ins
1. Check that the comment template contains <? Php do_action ('comment _ form', $ post-> ID);?> Code. If not, add it.
2. wordpress version> 3.0.
3. to synchronize comments to Weibo, a = confirmation field is required, that is, the "synchronize to XXX" option selected after login, when submitting your ajax comments, you must also extract and submit the value of this field. The method is as follows:
PHP
// Native javascript method
The code is as follows: |
Copy code |
If (document. getElementById ('post _ to_socialmedias ') & amp; document. getElementById ('post _ to_socialmedias'). checked ){
// Here, field information is appended to the end of the original submission string, and submit_str is the assumption that the original submission string Submit_str + = '& amp; post_to_socialmedias =' + document. getElementById ('post _ to_socialmedias '). value; } |
PHP
1 // jQuery method
The code is as follows: |
Copy code |
If ($ ('# post_to_socialmedias'). length & gt; 0 ){
Submit_str + = '& amp; post_to_socialmedias =' + $ ('# post_to_socialmedias: checked'). val ();
}
|
4. to modify an article, synchronize it to Weibo again, find the "force sync to Weibo" option at the bottom of the article editing page, and select "synchronize ", when you modify an article, the modified information is synchronized to Weibo.