Skip to content

Instantly share code, notes, and snippets.

@rfmeier
Last active January 20, 2016 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfmeier/7ec5e9283b2a333fcc71 to your computer and use it in GitHub Desktop.
Save rfmeier/7ec5e9283b2a333fcc71 to your computer and use it in GitHub Desktop.
Authenticate callback for WordPress register_meta() function.
<?php //* do not include php tag
/**
* Callback for WordPress register_meta() sanitize parameter.
*
* Determine if the current meta key and value should be visible within the
* WordPress post editor Custom Fields meta box.
*
* @see https://codex.wordpress.org/Function_Reference/register_meta
*
* @uses current_user_can()
* @see https://codex.wordpress.org/Function_Reference/current_user_can
*
* @param boolean $allowed True if allowed to view the meta field by default, false if else.
* @param string $meta_key The meta key.
* @param integer $post_ID The post ojbect ID.
* @param integer $user_id The user ID.
* @param string $cap The meta capability.
* @param array $caps An array of capabilities.
* @return boolean True if allowed to view the meta field by default, false if else.
*/
function auth_sample_count_meta( $allowed, $meta_key, $post_ID, $user_id, $cap, $caps ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
$allowed = false;
}
return $allowed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment