为什么这在全球范围内有效:
static int a;
static int a=0;
Run Code Online (Sandbox Code Playgroud)
但不在函数体内:
void foo()
{
static int b;
static int b=0; //error: Duplicate declaration of global variable 'b'
...
Run Code Online (Sandbox Code Playgroud)
使用clion 2017.3.1,C99,gcc5.4
.
WooCommerce 注册表中需要用户角色选择。用户应该有一个下拉菜单,可以在“客户”和“经销商”(ID)wordpress 角色之间进行选择。不幸的是,我组装代码的尝试失败了。
以下代码未分配所选角色,我被卡住了。尽管选择了“经销商”,但注册用户仍获得默认角色“客户”。
我已经更改了这个答案的代码(我不知道这段代码是否有效)
我做错了什么?
我正在使用的代码:
/* To add WooCommerce registration form custom fields. */
function WC_extra_registation_fields() {?>
<p class="form-row form-row-first">
<label for="reg_role"><?php _e( 'Privat or commercial?', 'woocommerce' ); ?></label>
<select class="input-text" name="role" id="reg_role">
<option <?php if ( ! empty( $_POST['role'] ) && $_POST['role'] == 'customer') esc_attr_e( 'selected' ); ?> value="customer">private</option>
<option <?php if ( ! empty( $_POST['role'] ) && $_POST['role'] == 'reseller') esc_attr_e( 'selected' ); ?> value="reseller">commercial</option>
</select>
</p>
<?php
}
add_action( 'woocommerce_register_form', 'WC_extra_registation_fields');
/* …Run Code Online (Sandbox Code Playgroud) c ×1
declaration ×1
duplicates ×1
global ×1
php ×1
user-roles ×1
variables ×1
woocommerce ×1
wordpress ×1