| 1 |
<?php |
| 2 |
/** |
| 3 |
* Meta boxes |
| 4 |
* |
| 5 |
* Functions related to meta-box management. |
| 6 |
* |
| 7 |
* @package simple-embed-code |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly. |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Remove Custom Fields |
| 18 |
* |
| 19 |
* Remove the custom field meta boxes if the user doesn't have the unfiltered HTML permissions. |
| 20 |
* |
| 21 |
* @param string $post_id Post ID. |
| 22 |
* @param string $post Post object. |
| 23 |
* @param boolean $update Whether this is an existing post being updated. |
| 24 |
*/ |
| 25 |
function sec_check_post_fields( $post_id, $post, $update ) { |
| 26 |
|
| 27 |
$options = get_option( 'artiss_code_embed' ); |
| 28 |
|
| 29 |
// Check if it's an autosave or if the current user has the 'unfiltered_html' capability. |
| 30 |
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( current_user_can( 'unfiltered_html' ) ) ) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
// Fetch all post meta (custom fields) associated with the post. |
| 35 |
$custom_fields = get_post_meta( $post_id ); |
| 36 |
|
| 37 |
// If there are custom fields, read through them. |
| 38 |
if ( ! empty( $custom_fields ) ) { |
| 39 |
|
| 40 |
foreach ( $custom_fields as $key => $value ) { |
| 41 |
|
| 42 |
// Check to see if any begining with this plugin's prefix. |
| 43 |
if ( substr( $key, 0, strlen( $options['keyword_ident'] ) ) === $options['keyword_ident'] ) { |
| 44 |
|
| 45 |
// Filter the meta value. |
| 46 |
$new_value = wp_kses_post( $value[0] ); |
| 47 |
|
| 48 |
// Now write out the new value. |
| 49 |
update_post_meta( $post_id, $key, $new_value ); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
add_action( 'save_post', 'sec_check_post_fields', 10, 3 ); |
| 56 |
|