Created
August 9, 2022 13:48
-
-
Save angelcosta/7ab18f48b0d3441a822758bfbc6e7e41 to your computer and use it in GitHub Desktop.
some wp things
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
<?php | |
// Comentários | |
add_action('comment_post', 'doceblog_envia_notificacao', 10, 2); | |
function doceblog_envia_notificacao($comment_id, $approved) { | |
if ($approved) { | |
$filho = get_comment($comment_id); | |
if ($filho->comment_parent) { | |
$pai = get_comment($filho->comment_parent); | |
$pai_autor = $pai->comment_author; | |
$pai_email = $pai->comment_author_email; | |
$pai_comentario = $pai->comment_content; | |
$filho_autor = $filho->comment_author; | |
$site = get_bloginfo('name'); | |
$titulo = get_the_title($pai->comment_post_ID); | |
$link = get_comment_link($filho->comment_ID); | |
$email_autor = get_the_author_meta('user_email', $pai->comment_post_ID); | |
$cabecalho = sprintf('From: '. $site .' <%s>', get_option('admin_email')); | |
$assunto = "$filho_autor respondeu ao seu comentário no $site"; | |
$mensagem = "Olá, $pai_autor,\n\n"; | |
$mensagem .= "O seu comentário no post '$titulo' no $site recebeu uma resposta de $filho_autor.\n\n"; | |
$mensagem .= "Seu comentário original:\n"; | |
$mensagem .= "<em>$pai_comentario</em>\n\n"; | |
$mensagem .= "Para ler a resposta a este comentário, vá até $link\n\n"; | |
$mensagem .= "Obrigada por comentar no $site"; | |
if ($pai->comment_author_email != get_bloginfo('admin_email')) | |
wp_mail($pai->comment_author_email, $assunto, $mensagem, $cabecalho); | |
} | |
} | |
} | |
add_action( 'pre_ping', 'doceblog_no_ping' ); | |
function doceblog_no_ping( &$links ) { | |
foreach ( $links as $l => $link ) | |
if ( 0 === strpos( $link, get_option( 'home' ) ) ) { | |
unset($links[$l]); | |
} | |
} | |
add_filter( 'comment_form_default_fields', 'doceblog_remove_url', 20 ); | |
function doceblog_remove_url($fields) { | |
if(isset($fields['url'])) { | |
unset($fields['url']); | |
} | |
return $fields; | |
} | |
add_filter( 'get_comment_author_link', 'doceblog_remove_link' ); | |
function doceblog_remove_link( $author_link ){ | |
return strip_tags( $author_link ); | |
} | |
// Editor | |
add_filter('gutenberg_use_widgets_block_editor', '__return_false'); | |
add_filter('use_block_editor_for_post','__return_false'); | |
add_filter('use_widgets_block_editor', '__return_false'); | |
add_action('phpmailer_init', 'doceblog_mailgun'); | |
function doceblog_mailgun( $phpmailer ) { | |
$phpmailer->isSMTP(); | |
$phpmailer->Host = "smtp.mailgun.org"; | |
$phpmailer->SMTPAuth = true; | |
$phpmailer->Port = 587; | |
$phpmailer->Username = "@mg.doce.blog.br"; | |
$phpmailer->Password = "--a9d1cddc"; | |
$phpmailer->SMTPSecure = "tls"; | |
$phpmailer->From = get_bloginfo('admin_email'); | |
$phpmailer->FromName = get_bloginfo('name'); | |
} | |
// Estilos & Scripts | |
add_action( 'wp_enqueue_scripts', 'doceblog_scripts'); | |
function doceblog_scripts() { | |
wp_dequeue_style( 'wp-block-library' ); | |
wp_deregister_style( 'wp-block-library' ); | |
} | |
add_action('wp_head', 'doceblog_font_awesome'); | |
function doceblog_font_awesome () { | |
$fontawesome = '<script src="https://kit.js" crossorigin="anonymous"></script>'; | |
echo $fontawesome; | |
} | |
add_action( 'wp_print_styles', 'doceblog_remove_inline'); | |
function doceblog_remove_inline(){ | |
wp_styles()->add_data( 'wp-polls', 'after', '' ); | |
} | |
remove_action('wp_head', 'print_emoji_detection_script', 7); | |
remove_action('wp_print_styles', 'print_emoji_styles'); | |
//Links | |
add_filter('pre_option_link_manager_enabled', '__return_true' ); | |
function doceblog_links($id){ | |
$cursos = get_bookmarks( array( 'category' => $att['cat']) ); | |
return $cursos; | |
} | |
// Posts | |
add_action( 'init','doceblog_post_surpresa' ); | |
function doceblog_post_surpresa() { | |
global $wp; | |
$wp->add_query_var( 'surpresa' ); | |
add_rewrite_rule( 'surpresa/?$', 'index.php?surpresa=1', 'top' ); | |
} | |
add_action( 'template_redirect','doceblog_post_surpresa_template' ); | |
function doceblog_post_surpresa_template() { | |
if ( 1 == get_query_var( 'surpresa' ) ) { | |
$posts = get_posts( 'post_type=post&orderby=rand&numberposts=1' ); | |
foreach( $posts as $post ) { | |
$link = get_permalink( $post ); | |
} | |
wp_redirect( $link,307 ); | |
exit; | |
} | |
} | |
// Social | |
add_shortcode( 'dbsocial', 'doceblog_social' ); | |
function doceblog_social( $atts ) { | |
$rede = $atts['rede']; | |
$trans = get_transient( 'dbsocial_'.$rede ); | |
if( ! empty( $trans ) ) { | |
$dbsocial[$rede] = $trans; | |
} | |
else { | |
if ($rede == "email"){ | |
$sendy = "https://netmundo.com.br/sendy"; | |
$apikey = ""; | |
$listid = ""; | |
$postdata = http_build_query( | |
array( | |
'api_key' => $apikey, | |
'list_id' => $listid | |
) | |
); | |
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata)); | |
$context = stream_context_create($opts); | |
$result = file_get_contents($sendy.'/api/subscribers/active-subscriber-count.php', false, $context); | |
if($result) { | |
$dbsocial[$rede] = $result; | |
} | |
} | |
elseif ($rede == "pinterest"){ | |
$metas = get_meta_tags('http://pinterest.com/doceblogbr/'); | |
$dbsocial[$rede] = $metas['pinterestapp:followers']; | |
} | |
elseif ($rede == "visitas"){ | |
$response = wp_remote_retrieve_body (wp_remote_get( "https://api.clicky.com/api/stats/4?site_id=&sitekey=&type=visitors&date=last-month&output=json" )); | |
$json = json_decode( $response, true ); | |
$dbsocial[$rede] = $json[0][dates][0][items][0][value]; | |
} | |
elseif ($rede == "visitas-origem"){ | |
$response = wp_remote_retrieve_body (wp_remote_get( "https://api.clicky.com/api/stats/4?site_id=&sitekey=&type=links-domains&date=last-month&output=json" )); | |
$json = json_decode( $response, true ); | |
$dbsocial[$rede] = $json[0][dates][0][items][0][title]." (".$json[0][dates][0][items][0][value_percent]."%)"; | |
} | |
elseif ($rede == "visitas-dispositivos"){ | |
$response = wp_remote_retrieve_body (wp_remote_get( "https://api.clicky.com/api/stats/4?site_id=&sitekey=&type=operating-systems&date=last-month&output=json" )); | |
$json = json_decode( $response, true ); | |
$dbsocial[$rede] = $json[0][dates][0][items][0][title]." (".$json[0][dates][0][items][0][value_percent]."%), "; | |
$dbsocial[$rede] .= $json[0][dates][0][items][1][title]." (".$json[0][dates][0][items][1][value_percent]."%) e "; | |
$dbsocial[$rede] .= $json[0][dates][0][items][2][title]." (".$json[0][dates][0][items][2][value_percent]."%)"; | |
} | |
} | |
set_transient( 'dbsocial_'.$rede, $dbsocial[$rede], 60 ); | |
$resultado = $dbsocial[$rede]; | |
if (is_numeric($resultado)){ | |
$resultado = number_format($resultado, '0',',','.'); | |
} | |
return $resultado; | |
} | |
//Sorteios | |
add_shortcode('teste','doceblog_sorteio_ganhadores'); | |
function doceblog_sorteio_ganhadores($id){ | |
$ganhadores = get_post_meta($id, '_and_the_winner_is_confirmed'); | |
return $ganhadores; | |
} | |
add_filter('the_content','doceblog_sorteio_resultado'); | |
function doceblog_sorteio_resultado($content){ | |
global $post; | |
if (in_category('sorteios')){ | |
if ( get_post_meta($post->ID, '_and_the_winner_is_confirmed', TRUE)) { | |
$comentarios_ganhadores = doceblog_sorteio_ganhadores($post->ID); | |
foreach ($comentarios_ganhadores as $ganhador) { | |
$ganhadores[] = '<a href="'.get_comment_link($ganhador).'">'.get_comment_author($ganhador).'</a>'; | |
} | |
$ganhadores = implode(', ', $ganhadores); | |
$resultado = '<div class="alerta verde"><i class="fa fa-trophy"></i> Este sorteio já foi encerrado. Ganhador(es): '.$ganhadores. '</div>'; | |
} | |
} | |
if (!empty($resultado)) { return $resultado.$content; } | |
else {return $content;} | |
} | |
add_filter( "comment_class", "doceblog_sorteio_comentario",10,5); | |
function doceblog_sorteio_comentario( $classes, $class, $comment_comment_id, $comment, $post_id ) { | |
$ganhadores = doceblog_sorteio_ganhadores($comment->comment_post_ID); | |
if( in_array($comment->comment_ID, $ganhadores ) ) { | |
$classes[] = "ganhador"; | |
} | |
return $classes; | |
} | |
function doceblog_sorteio_ativo(){ | |
$args = array( | |
'meta_query' => array( | |
'relation' => 'AND', | |
array( | |
'key' => '_and_the_winner_is_contest', | |
'value' => '1', | |
), | |
array( | |
'key' => '_and_the_winner_is_confirmed', | |
'compare' => 'NOT EXISTS' | |
) | |
) | |
); | |
$sorteios = get_posts( $args ); | |
if ($sorteios && !is_single($sorteios[0]->ID)) { | |
echo '<div class="alerta verde sorteio"><i class="fa fa-gift"></i> Está havendo um sorteio no blog: <strong><a href="'. get_permalink( $sorteios[0]->ID ) .'">'.$sorteios[0]->post_title.'</a></strong> »</div>'; | |
} | |
} | |
// Widgets | |
add_filter('widget_text', 'do_shortcode' ); | |
remove_filter('comment_text', 'wptexturize'); | |
remove_filter('the_content', 'wptexturize'); | |
remove_filter('the_excerpt', 'wptexturize'); | |
remove_filter('the_title', 'wptexturize'); | |
// Categoria na Imagem | |
add_filter( 'post_thumbnail_html', 'doceblog_imagem_categoria'); | |
function doceblog_imagem_categoria ($output) { | |
$return = $output; | |
$cat = get_the_category ( get_the_ID() ); | |
$cat_id = $cat[0]->term_id; | |
$cat_data = get_option("taxonomy_$cat_id"); | |
$icone = '<i class="iconcat '.$cat_data['cat_icon'].'"></i> '; | |
if ( isset( $cat ) && ! is_singular() ) { | |
$return .= '<div class="featured-image-category-wrapper">'; | |
$return .= '<div class="featured-image-category">'.$icone .$cat[0]->name. '</div>'; | |
$return .= '</div>'; | |
} | |
return $return; | |
} | |
add_action( 'category_add_form_fields', 'doceblog_categoria_meta', 10, 2 ); | |
function doceblog_categoria_meta() { ?> | |
<div class="form-field"> | |
<label for="term_meta[cat_icon]"><?php _e( 'Font Awesome Icons', 'pt' ); ?></label> | |
<input type="text" name="term_meta[cat_icon]" id="term_meta[cat_icon]" value=""> | |
<p class="description"><?php printf(__( 'Choose your category icon from <a href="%s" target="_blank">Font Awesome Icons</a>. For example: <b>fa-wordpress</b>','pt' ), 'http://fontawesome.io/icons/'); ?></p> | |
</div> | |
<?php } | |
add_action( 'category_edit_form_fields', 'doceblog_categoria_meta_edit', 10, 2 ); | |
function doceblog_categoria_meta_edit($term) { | |
$t_id = $term->term_id; | |
$term_meta = get_option( "taxonomy_$t_id" ); ?> | |
<tr class="form-field"> | |
<th scope="row" valign="top"><label for="term_meta[cat_icon]"><?php _e( 'Font Awesome Icons', 'pt' ); ?></label></th> | |
<td> | |
<input type="text" name="term_meta[cat_icon]" id="term_meta[cat_icon]" value="<?php echo esc_attr( $term_meta['cat_icon'] ) ? esc_attr( $term_meta['cat_icon'] ) : ''; ?>"> | |
<p class="description"><?php printf(__( 'Choose your category icon from <a href="%s" target="_blank">Font Awesome Icons</a>. For example: <b>fa-wordpress</b>','pt' ), 'http://fontawesome.io/icons/'); ?></p> | |
</td> | |
</tr> | |
<?php } | |
add_action( 'edited_category', 'doceblog_categoria_meta_save', 10, 2 ); | |
add_action( 'create_category', 'doceblog_categoria_meta_save', 10, 2 ); | |
function doceblog_categoria_meta_save( $term_id ) { | |
if ( isset( $_POST['term_meta'] ) ) { | |
$t_id = $term_id; | |
$term_meta = get_option( "taxonomy_$t_id" ); | |
$cat_keys = array_keys( $_POST['term_meta'] ); | |
foreach ( $cat_keys as $key ) { | |
if ( isset ( $_POST['term_meta'][$key] ) ) { | |
$term_meta[$key] = $_POST['term_meta'][$key]; | |
} | |
} | |
update_option( "taxonomy_$t_id", $term_meta ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment