1

Mostra link de edição apenas após X período de tempo no WordPress + JetEngine


/*
Shortcode que verifica se o post foi postado a certo tempo, caso positivo mostra opção de editar.

[check_time_to_edit time="3600" link="/account/pagina"]  

link = caminho da pagina onde tem o formulário [sem barra no final]

time = 60 (em segundos) ==> 1 minuto
time = 3600 (em segundos) ==> 1 hora
time = 43200 (em segundos) ==> 12 horas
*/

function function_edit_after_time($atts) {

    $a = shortcode_atts( array(
        'link' => '',
		'time' => '',
    ), $atts );
	
	$time = $a['time'];
	$link = $a['link'];

    $post_id = get_the_ID();
    $post_modified = get_post_modified_time( 'U', false, $post_id );
    $current_time = current_time( 'U' );
    $difference = $current_time - $post_modified;
    if ( $difference >= $time ) {
        return '<a href="'.$link.'/?_post_id='.$post_id.'" class="btn-editpost"><i class="fa fa-edit"></i> Editar</a>';
    } 
}
add_shortcode( 'check_time_to_edit', 'function_edit_after_time' );




Criado por: Dante Testa

Carregando publicação patrocinada...