0

I am using a custom code to make certain plugin's functionality available only with particular capabilities.

Here is the code:

<?php
// Check if User can Edit
// Set permission to false = 'not allowed'
$current_user_is_allowed_to_edit = false;
// Get the ID of the user who watches this post
$user_ID = get_current_user_id();
// Get the ID of the Post-Writer
$post_author_ID = the_author_meta('ID');

//   Check if User has role 'Editor' and higher  OR is the Post-Writer
if ( current_user_can('edit_others_posts') ||  get_post(filter_input(INPUT_POST, 'post_id'))->post_author == get_current_user_id() ) {

    // Set permission to true = 'allowed'
    $current_user_is_allowed_to_edit = true;
}
?>

I want $post_author_ID = the_author_meta('ID'); only to set the capability to access particular content { live_edit('post_title, myfield2'); } and not to publish the id. But it publishes some number on every post which I don't want. Here is the complate template

Also let me know If I am not using the correct way to restrict access to particular content- { live_edit('post_title, myfield2'); }

1 Answer 1

2

the_author_meta displays the data. That is, it echos the data to the screen. From the Codex entry for that function:

NOTE: Use get_the_author_meta() if you need to return (not display) the information.

So, use get_the_author_meta() instead.

There is a somewhat reliable pattern in WordPress function naming whereby functions starting with the_ echo data to the screen; functions starting with get_ return the data.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.