我目前正在尝试为我的Wordpress用户添加一些自定义用户配置文件字段.
我已将以下代码添加到我的functions.php中但由于某种原因输入的数据未保存...
//** CUSTOM USER META **//
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="club">Club You Support</label></th>
<td>
<input type="text" name="club" id="club" value="<?php echo esc_attr( get_the_author_meta( 'club', $user->ID ) ); ?>" class="regular-text" /><br />
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
update_usermeta( $user_id, 'club', sanitize_text_field( $_POST['club']) );
}
Run Code Online (Sandbox Code Playgroud)
关于为什么这些数据不坚持的任何想法?
我试图在我的Laravel网站上计算一些统计数据...但是当我执行以下代码时,它给了我一个'除以零错误'
我理解为什么因为没有记录所以计算是0除0
有没有办法,如果它eqauls零回显'0'而不是抛出该错误
Controlller
private function getAverageOddsForLastMonth()
{
$firstDayOfLastMonth = new Carbon('first day of last month');
$lastDayOfLastMonth = new Carbon('last day of last month');
$tipslastmonth = Tip::whereBetween('tip_date',
[
$firstDayOfLastMonth,
$lastDayOfLastMonth
]
)->count();
$sumOfTheOddsLastMonth = Tip::whereBetween('tip_date',
[
$firstDayOfLastMonth,
$lastDayOfLastMonth
]
)->sum('odds');
return ($sumOfTheOddsLastMonth / $tipslastmonth);
}
Run Code Online (Sandbox Code Playgroud)