Created
May 4, 2018 14:46
-
-
Save danilosong/2f49c077ac18857b80d2280d27119abb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Controle de posts para usuários inferior a role "administrator" | |
* Função para setar o post_status para "revisão pendente" caso o usuário não seja o | |
* Administrator(root). | |
* | |
* @author Danilo Song <danilosong@outlook.com> | |
* @since 03-05-2018 | |
* @version 1.0 | |
* | |
* @param WP_Post $post Current post object. | |
* | |
*/ | |
function alter_post_status($post){ | |
$user = wp_get_current_user(); | |
$role = $user->roles[0]; | |
if($role != "administrator"){ | |
$post->post_status = "pending"; | |
}else{ | |
$post->post_status = "publish"; | |
} | |
} | |
add_action('post_submitbox_minor_actions', 'alter_post_status', 10, 1); | |
/** | |
* Função referente ao buttom entrar com a funcionalidade da função alter_post_status() | |
* Altera o name do botão de publicação do post caso o usuário for diferente do nivel | |
* administrator | |
* | |
* @since 04-05-2018 | |
* @author Danilo Song <danilosong@outlook.com> | |
* @version 1.0 | |
* | |
* @param WP_Post $post Current post object. | |
* | |
*/ | |
function alter_button_publish($post){ | |
$user = wp_get_current_user(); | |
$role = $user->roles[0]; | |
?> | |
<script> | |
$(function(){ | |
var $role = "<?= $role; ?>"; | |
if($role != "administrator"){ | |
$('#publish').attr('name', 'save'); | |
} | |
}); | |
</script> | |
<?php | |
} | |
add_action('post_submitbox_start', 'alter_button_publish', 10, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment