name, array( 'Twitter', 'Facebook', 'LinkedIn' ) ) ? 'Social' : $category[0]->name; $args['link'] = NULL; $args['heading'] = 'h1'; } elseif ( $post_type == 'quote' ) { $args['title'] = 'Libro de citas'; $args['link'] = NULL; $args['heading'] = 'h1'; } } return $args; } /* * Tag page with excerpt and featured image. * See http://www.kriesi.at/support/topic/archive-page-with-excerpt-and-featured-image/ */ add_filter( 'avf_blog_style', 'avia_change_tag_page_layout', 10, 2 ); function avia_change_tag_page_layout( $layout, $context ) { if ( is_tag() ) { $layout = 'single-small'; } return $layout; } /* * Register new icons as a theme icons fot GitHub and GitLab. * See https://kriesi.at/documentation/enfold/custom-social-icons/ */ add_filter( 'avf_default_icons', 'avia_add_custom_icon', 10, 1 ); function avia_add_custom_icon( $icons ) { $icons['github'] = array( 'font' =>'fontello', 'icon' => 'uf09b' ); $icons['gitlab'] = array( 'font' =>'fontello', 'icon' => 'uf296' ); return $icons; } add_filter( 'avf_social_icons_options', 'avia_add_custom_social_icon', 10, 1 ); function avia_add_custom_social_icon( $icons ) { $icons['GitHub'] = 'github'; $icons['GitLab'] = 'gitlab'; return $icons; } /* * Add new class in Links and Social, Twitter, Facebook & LinkedIn posts. * See https://tommcfarlin.com/add-class-to-single-post/ */ add_filter( 'post_class', 'add_simple_class' ); function add_simple_class( $classes ) { $category = get_the_category(); if ( !empty( $category ) && in_array( $category[0]->term_id, array( 1569, 1561, 1562, 1563, 1564 ) ) ) { $classes[] = 'post-entry-simple'; } return $classes; } /* * Breadcrumb formatting for social and categories content. * See http://www.kriesi.at/support/topic/how-to-modify-in-child_theme-the-function-avia_breadcrumbs-finished-with-s */ add_filter( 'avia_breadcrumbs_trail', 'avia_change_breadcrumb', 50, 2 ); function avia_change_breadcrumb( $trail, $args ) { if ( is_single() ) { $category = get_the_category(); if ( !empty( $category ) ) { // Correct breadcrumb for Blog, Bloc de notas & Fotoblog single posts: if ( in_array( $category[0]->term_id, array( 982, 978, 976 ) ) && strpos( $trail[1], 'social' ) ) { switch ( $category[0]->term_id ) { case 982: // Blog array_splice( $trail, 1, 2, array( 'Blog' ) ); break; case 978: // Bloc de notas array_splice( $trail, 1, 2, array( 'Bloc de notas' ) ); break; case 976: // Fotoblog array_splice( $trail, 1, 2, array( 'Álbum de fotos' ) ); } } // Social breadcrumb for Twitter, Facebook & LinkedIn content: elseif ( in_array( $category[0]->term_id, array( 1562, 1563, 1564 ) ) ) { unset ( $trail[2] ); } } } elseif ( is_tag() || is_category( array( 982, 978, 976 ) ) ) { // Posts breadcrumb for Blog, Bloc de notas & Fotoblog categories: array_splice( $trail, 1, 0, array( 'Entradas' ) ); } return $trail; } /* * Auto generate the post title if it's empty and post has content. And share * content in social networks if required. */ add_filter( 'wp_insert_post_data', 'before_save_post', 1, 2 ); function before_save_post( $data, $postarr ) { // Title for Instagram captures: if ( $data['post_title'] == 'INSTAGRAM' ) { $dotpos = strpos( $data['post_content'], '. ' ); $title_instagram = $dotpos > 0 ? substr( $data['post_content'], 0, $dotpos ) : $data['post_content']; $title_instagram = trim( strip_tags( preg_replace( '!\s+!', ' ', str_replace( ' ', ' ', $title_instagram ) ) ) ); $title_words = explode( ' ', $title_instagram ); if ( count( $title_words ) > 12 ) { $title_instagram = implode( ' ', array_slice( $title_words, 0, 12 ) ) . ' …'; } else { $data['post_content'] = substr( $data['post_content'], $dotpos + 2 ); } $data['post_title'] = $title_instagram; } $title = preg_replace( '!\s+!', ' ', str_replace( ' ', ' ', $data['post_title'] ) ); $text_title = trim( strip_tags( $title ) ); $content = preg_replace( '!\s+!', ' ', str_replace( ' ', ' ', $data['post_content'] ) ); $text_content = trim( strip_tags( $content ) ); if ( empty( $text_title ) ) { if ( ! empty( $text_content ) ) { $content_words = explode( ' ', $text_content ); $text_title = implode( ' ', array_slice( $content_words, 0, 4 ) ); $data['post_title'] = count( $content_words ) > 4 ? "$text_title …" : $text_title; } } // Retrieve the list of categories for the post: $categories = $postarr['post_category']; if ( is_array( $categories ) ) { if ( $categories[0] == 0 ) { array_shift( $categories ); } } else { // For posts sent from the WordPress App: $categories = $postarr['tax_input']['category']; if ( ! is_array( $categories ) ) { $categories = array(); } } // Count post categories: $num_categories = count( $categories ); // Review post only for Álbum de fotos, Social, Twitter, Facebook & LinkedIn categories: $num_social_categories = count( array_intersect( array( 976, 1561, 1562, 1563, 1564 ), $categories ) ); // Adapting content for pure social posts: # if ( $num_categories == $num_social_categories ) { # $post_content = trim( strip_tags( $content, '
' ) );
/*
Remove html attributes except for anchor tag:
/ Start Pattern
< Match '<' at beginning of tags
( Start Capture Group $1 - Tag Name
[a-z] Match 'a' through 'z'
[a-z0-9]+ Match 'a' through 'z' or '0' through '9' one or more times
) End Capture Group
[^>]*? Match anything other than '>', Zero or More times, not-greedy (wont eat the /)
(\/?) Capture Group $2 - '/' if it is there
> Match '>'
/i End Pattern - Case Insensitive
*/
# $post_content = preg_replace( "/<([a-z][a-z0-9]+)[^>]*?(\/?)>/i", '<$1$2>', $post_content );
# $data['post_content'] = str_replace( array( '', '', '', '' ), array( '', '', '', '' ), $post_content );
# }
// Nothing to do if there aren't social categories:
if ( $num_social_categories > 0 ) {
// Preparing post excerpt for Twitter:
$text_excerpt = $text_content;
if ( ! empty( $text_title ) && mb_strpos( $text_content, $text_title ) !== 0 ) {
$text_excerpt = empty( $text_content ) ? $text_title : "$text_title. $text_content";
}
$text_excerpt = html_entity_decode( $text_excerpt );
// Límite máximo.
// Debería ser de 280 caracteres menos los enlaces al blog y a la imagen
// destacada; pero como el plugin SNAP sigue acortando a 140 se opta por
// no restar nada ya que hay margen suficiente hasta los 280:
$limit = 140;
/* // Se le resta el enlace al blog:
$limit -= 25;
// Se le resta el enlace a la imagen destacada (si la tiene):
if (has_post_thumbnail()) {
$limit -= 25;
}
*/
// Se prepara el texto que se puede mostrar:
if ( strlen( $text_excerpt ) > $limit ) {
preg_match_all( '#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $text_excerpt, $matches );
for ( $i = 0; $i < count( $matches[0] ); $i++ ) {
$text_excerpt = str_replace( $matches[0][$i], shorten_url( $matches[0][$i] ), $text_excerpt );
}
if ( strlen( $text_excerpt ) > $limit ) {
$text_excerpt = mb_substr( $text_excerpt, 0, $limit - 1 );
$text_excerpt = mb_substr( $text_excerpt, 0, mb_strrpos( $text_excerpt, ' ' ) ) . '…';
}
}
$data['post_excerpt'] = $text_excerpt;
}
return $data;
}
function shorten_url( $long_url ) {
$bitly_login = 'o_7sko9rcpp7';
$bitly_apikey = 'R_f414bf78d22443c6a6bad3c58921fd96';
$bitly_shorten = "http://api.bit.ly/v3/shorten?login=" . $bitly_login . "&apiKey=" . $bitly_apikey . "&longUrl=" . $long_url . "&format=json";
return json_decode( file_get_contents( $bitly_shorten ) )->data->url;
}
/*
* Default image fallback.
* See https://www.artifaktdigital.com/use-yoast-seo-ogimage-as-a-fallback-featured-image-a-tutorial/
*
# add_filter( 'post_thumbnail_html', 'social_post_defautl_thumbnail', 20, 5 );
function social_post_defautl_thumbnail( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
global $wpdb;
if ( empty( $html ) ) {
// Return you Yoast SEO default image if the post thumbnail html is empty:
$opt = get_option( 'wpseo_social' );
$url = $opt['og_default_image'];
if ( $id !== '' ) {
// Retrieves the attachment ID from the file URL:
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid = '%s';", $url ) );
$id = $attachment[0];
return wp_get_attachment_image( $id, $size );
}
}
return $html;
} */
/*
* Add a button to display the number of characters in Title and Content editor;
* and also add a character counter to the Excerpt box (with no limit).
* See https://premium.wpmudev.org/blog/character-counter-excerpt-box
*/
add_action( 'admin_head-post.php', 'char_counter_js' );
add_action( 'admin_head-post-new.php', 'char_counter_js' );
function char_counter_js() {
if ( get_post_type() == 'post' ) { echo '
';
}
}
/*
* Ensure that AccessPress Social Auto Post works in all cases.
*
add_action( 'publish_post', 'publish_social_post', 10, 2 );
function publish_social_post( $ID, $post ) {
$auto_post = $_POST['asap_auto_post'];
if ( $auto_post == 'yes' || $auto_post == '' ) {
$plugin_asap_dir = ABSPATH . 'wp-content/plugins/accesspress-social-auto-post/';
// Only Facebook and LinkedIn:
include_once( $plugin_asap_dir . 'api/facebook/facebook.php' );
# include_once( $plugin_asap_dir . 'api/twitter/codebird.php' );
# include_once( $plugin_asap_dir . 'api/tumblr/TumblrAPIClient.php' );
include_once( $plugin_asap_dir . 'api/linkedin/liOAuth.php' );
include( $plugin_asap_dir . 'inc/cores/auto-post.php' );
$check = update_post_meta( $post->ID, 'asap_auto_post', 'no' );
$_POST['asap_auto_post'] = 'no';
}
} */
/*
* New widget for Enfold theme. Display the single post header with the slider,
* title and meta info.
*/
add_action( 'widgets_init', function() {
register_widget( 'enfold_post_header_widget' );
});
class enfold_post_header_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID:
'enfold_post_header_widget',
// Widget name will appear in UI:
__( 'Enfold Cille Post Header', 'avia_framework' ),
// Widget description:
array( 'description' => __( 'Display the single post header with the slider, title and meta info', 'avia_framework' ) )
);
}
public function widget( $args, $instance ) {
global $avia_config;
echo $args['before_widget'];
$blog_style = avia_get_option( 'single_post_style', 'single-big' );
$blog_global_style = avia_get_option( 'blog_global_style', '' );
$the_id = get_the_ID();
// Get the current post id, the current post class and current post format:
$url = '';
$current_post = array();
$current_post['the_id'] = $the_id;
$current_post['post_type'] = get_post_type( $current_post['the_id'] );
$current_post['post_class'] = 'post-entry-' . $current_post['the_id'] . ' ' . $blog_style;
$current_post['post_class'] .= $current_post['post_type'] == 'post' ? '' : ' post';
$current_post['post_format'] = get_post_format() ? get_post_format() : 'standard';
$current_post['post_layout'] = avia_layout_class( 'main', false );
// Retrieve slider and title for this post...
$size = strpos( $blog_style, 'big' ) ? strpos( $current_post['post_layout'], 'sidebar' ) !== false ? 'entry_with_sidebar' : 'entry_without_sidebar' : 'square';
if ( ! empty( $avia_config['preview_mode'] ) && ! empty( $avia_config['image_size'] ) && $avia_config['preview_mode'] == 'custom' ) {
$size = $avia_config['image_size'];
}
$current_post['slider'] = get_the_post_thumbnail( $current_post['the_id'], $size );
if ( get_post_meta( $current_post['the_id'], '_avia_hide_featured_image', true ) ) {
$current_post['slider'] = '';
}
$current_post['title'] = get_the_title();
// Now apply a filter, based on the post type... (filter function is located in includes/helper-post-format.php):
$current_post = apply_filters( 'post-format-' . $current_post['post_format'], $current_post );
// Extract the variables so that $current_post['slider'] becomes $slider, $current_post['title'] becomes $title, etc...
extract( $current_post );
// Default link and preview image description:
$link = avia_image_by_id( get_post_thumbnail_id(), 'large', 'url' );
$desc = get_post( get_post_thumbnail_id() );
if ( is_object( $desc ) ) {
$desc = $desc->post_excerpt;
}
$featured_img_desc = $desc != '' ? $desc : the_title_attribute( 'echo=0' );
// Echo preview image:
if ( strpos( $blog_global_style, 'elegant-blog' ) === false ) {
if ( strpos( $blog_style, 'big' ) !== false ) {
if ( $slider ) $slider = "$slider";
if ( $slider ) echo "',
'after_title' => '
',
) );
add_action( 'loop_end', 'wp_content_after_loop' );
function wp_content_after_loop( $query ) {
if ( $query->is_main_query() && is_active_sidebar( 'after-loop' ) ) {
dynamic_sidebar( 'after-loop' );
}
}
/*
* Restore the font size in the tag cloud widget using a copy of the entire Avia
* stylesheet "enfold/css/avia-snippet-widget.css" from Enfold 4.5, and removing
* the font size line in the tag cloud styles.
* See https://kriesi.at/support/topic/tag-cloud-widget-display/#post-684196
*/
add_action( 'wp_enqueue_scripts', 'wp_change_layoutcss', 20 );
function wp_change_layoutcss() {
wp_dequeue_style( 'avia-widget-css' );
wp_enqueue_style( 'avia-widget-css-child', get_stylesheet_directory_uri() . '/avia-snippet-widget.css' );
}
/*
* Remove Avia Framework debug information in child theme.
* See http://www.kriesi.at/support/topic/removal-of-theme-debug-info/#post-386207
*/
add_action( 'init', 'avia_remove_debug' );
function avia_remove_debug() {
remove_action( 'wp_head', 'avia_debugging_info', 1000 );
}
/*
* Disable the W3 Total Cache Footer Comment.
* See https://www.dylanbarlett.com/2014/01/disabling-w3-total-cache-footer-comment/
*/
add_filter( 'w3tc_can_print_comment', '__return_false', 10, 1 );
/*
* Adding legal information in socket using a shortcode.
* See http://www.kriesi.at/support/topic/how-do-i-add-a-dynamic-current-year-to-socket
*/
add_shortcode( 'infolegal', 'infolegal_func' );
function infolegal_func( $atts ) {
$legal = '