Skip to content

Instantly share code, notes, and snippets.

View hamadadonis12's full-sized avatar

hamadadonis12

View GitHub Profile
<?php
/**
* Task 2 - Average product price.
*
* Returns the average of an array of numeric prices, rounded to 2 decimals.
* If the array is empty (or has no valid numbers), returns 0.
*/
function average_price( array $prices ) {
// Filter to numeric values only so a stray null/string doesn't blow things up.
<?php
/**
* Task 1 - Add a "Company Name" custom field to the WP user profile,
* save it on update, and show it on the admin dashboard.
*
* Drop this in a small plugin file or paste into functions.php of the
* active theme. Tested on WP 6.x.
*/
// 1) Render the field on the profile screens.