| 1 |
<?php |
| 2 |
namespace WGMSRM\Traits; |
| 3 |
|
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
/** |
| 8 |
* Trait CommonFunctions |
| 9 |
*/ |
| 10 |
trait CommonFunctions |
| 11 |
{ |
| 12 |
|
| 13 |
/** |
| 14 |
* Update post meta |
| 15 |
* |
| 16 |
* @param int $post_id |
| 17 |
* @param string $field_name |
| 18 |
* @param string $value |
| 19 |
*/ |
| 20 |
public function wgm_update_post_meta($post_id, $field_name, $value = '') |
| 21 |
{ |
| 22 |
// Sanitize and validate input before updating post meta |
| 23 |
$post_id = intval($post_id); |
| 24 |
$field_name = sanitize_key($field_name); |
| 25 |
// $value should be sanitized/validated before calling this function, or sanitize here if generic |
| 26 |
if (!get_post_meta($post_id, $field_name)) { |
| 27 |
add_post_meta($post_id, $field_name, $value); |
| 28 |
} else { |
| 29 |
update_post_meta($post_id, $field_name, $value); |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|