月下独思英 發表於 2023-5-31 00:00:00

详解WordPress中用于更新和获取用户选项数据的PHP函数

<p>
<strong>update_user_option()函数</strong></p>
<p>
update_user_option()函数作用利用全局博客权限更新用户选项。<br>
用户选项类似于用户元数据,唯一的不同之处在于用户选项支持全局博客选项。如果'global'参数为False(默认情况下),update_user_option会预先将WordPress表前缀改成选项名称。</p>
<p>
【函数使用】</p>
<div>
<div>
<div id="highlighter_589998">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>&lt;?php update_user_option( </code><code>$user_id</code><code>, </code><code>$option_name</code><code>, </code><code>$newvalue</code><code>, </code><code>$global</code> <code>) ?&gt;</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
【函数参数】</p>
<p>
$user_id<br>
(整数)(必需)用户ID<br>
默认值:None<br>
$option_name<br>
(字符串)(必需)用户选项名称<br>
默认值:0<br>
$newvalue<br>
(混合)(必需)用户选项值<br>
默认值:None<br>
$global<br>
(布尔值)(可选)选项名称是否博客特有<br>
默认值:false</p>
<p>
【返回值】</p>
<p>
(boolean)<br>
成功返回True,失败返回False</p>
<p>
【源文件】</p>
<p>
update_user_option())位于 wp-includes/user.php中。</p>
<p>
wordpress get_user_option()函数</p>
<p>
 </p>
<p>
<strong>get_user_option()函数</strong><br>
【函数介绍】</p>
<p>
检索用户选项,包括global、user或blog。<br>
如果未给出用户ID,使用当前用户ID。如果给出用户ID,检索该用户相关数据。函数结果的过滤器将原始选项名称和最终用户数据库对象作为第三个参数传递。<br>
该选项函数首先查找非全局名称,然后查找全局名称,如果仍然没有找到,函数会查找博客选项。可通过插件设置或修改选项。</p>
<p>
【函数用法】</p>
<div>
<div>
<div id="highlighter_199356">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
</td>
<td>
<div>
<div>
<code>&lt;?php get_user_option( </code><code>$option</code><code>, </code><code>$user</code><code>, </code><code>$check_blog_options</code> <code>) ?&gt; </code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
【参数介绍】</p>
<p>
$option<br>
(字符串)(必需)用户选项名称<br>
默认值:None<br>
$user<br>
(整数)(可选)用户ID<br>
默认值:0<br>
$check_blog_options<br>
(布尔值)(可选)如果之前的用户选项不存在,是否需要在选项表中查找一个选项<br>
默认值:true</p>
<p>
【返回值】</p>
<p>
(混合)<br>
成功返回选项的值,失败返回FALSE</p>
<p>
【函数实例】</p>
<div>
<div>
<div id="highlighter_651026">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
<div>
2</div>
<div>
3</div>
<div>
4</div>
<div>
5</div>
<div>
6</div>
<div>
7</div>
<div>
8</div>
</td>
<td>
<div>
<div>
<code>&lt;?php</code>
</div>
<div>
<code> </code><code>$bar</code> <code>= get_user_option( </code><code>'show_admin_bar_front'</code><code>, get_current_user_id() );</code>
</div>
<div>
<code> </code><code>if</code><code>( </code><code>$bar</code> <code>== </code><code>'true'</code> <code>) {</code>
</div>
<div>
<code> </code><code>echo</code> <code>'The admin bar is enabled'</code><code>;</code>
</div>
<div>
<code> </code><code>} </code><code>else</code> <code>{</code>
</div>
<div>
<code> </code><code>echo</code> <code>'The admin bar is disabled'</code><code>;</code>
</div>
<div>
<code> </code><code>}</code>
</div>
<div>
<code>?&gt;</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
【源文件】</p>
<p>
get_user_option() is located in wp-includes/user.php.</p>
頁: [1]
查看完整版本: 详解WordPress中用于更新和获取用户选项数据的PHP函数