Commit a1d6bb9a authored by Rafael Chaves Freitas's avatar Rafael Chaves Freitas

remove admin GET parameter

parent 8df18d08
......@@ -12,5 +12,4 @@ require 'library/functions.php';
require 'library/images.php';
require 'library/related-posts.php';
require 'library/authors.php';
require 'library/admin.php';
require 'pagebuilder-components/index.php';
\ No newline at end of file
<?php
namespace guaraci;
add_action( 'admin_init', function(){
add_settings_field(
'admin_qs__use',
__('Parâmetro GET para aditores', 'guaraci'),
function(){
?>
<p>
<em><?php _e('Esta opção adiciona um parâmetro GET nas urls de posts, categorias e home_url quando o acesso é de um usuário logado que tenha permissão de editar posts. Isto ajuda a resolver conflitos do cache de borda com a utilização da barra do admin do WP.', 'guaraci') ?></em>
</p>
<p>
<label>
<input name="admin_qs__use" id="admin_qs__use" type="checkbox" value="1" class="code" <?= checked( 1, get_option( 'admin_qs__use' ), false ) ?> /> <?php _e('Adicionar parâmetro GET nas urls para os editores.', 'guaraci') ?>
</label>
</p>
<?php
},
'general',
);
register_setting( 'general', 'admin_qs__use' );
});
add_action('wp', function (){
if(current_user_can('edit_posts')){
$post_types = get_post_types(['public' => true]);
unset($post_types['attachment']);
$param = base_convert (time() - strtotime (date('Y-m-d')), 10, 36);
add_filter('post_link', function($link, $post) use ($post_types, $param) {
$link = urldecode($link);
if($post->post_status != 'publish'){
return $link;
}
if(!in_array($post->post_type, $post_types)){
return $link;
}
if(substr($link, -1) != '/'){
return $link;
}
if(strpos($link, "?{$param}") > 0){
return $link;
} else {
return $link . "?{$param}";
}
},10000 , 2);
add_filter('term_link', function($link) use ($param) {
$link = urldecode($link);
if(strpos($link, "?{$param}") > 0) {
return $link;
} else {
return $link . "?{$param}";
}
},10000);
add_filter('home_url', function($link) use ($param) {
$link = urldecode($link);
if(strpos($link, "?") > 0){
return $link;
} else {
return $link . "?{$param}";
}
},10000);
}
});
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment