Modifica y simplifica funciones personalizadas

Se elimina la función ssl_srcset() porque ya no aplica. Se añade la
función exclude_taxonomy_terms() para ocultar términos de taxonomía para
ayudar en la publicación de contenidos. También se simplifica la función
avia_change_breadcrumb(), y, sobre todo, la función before_save_post()
para la publicación de contenidos en redes sociales. Sólo se requiere
que el título sea obligatorio.

Y se extienden y corrigen estilos para la visualización de contenidos.
This commit is contained in:
Manuel Cillero 2020-04-19 09:34:42 +02:00
parent 31c05ebcdd
commit 5348d987b6
4 changed files with 213 additions and 199 deletions

View file

@ -21,15 +21,16 @@ if ( !function_exists( 'write_log' ) ) {
}
/*
* Force URLs in srcset attributes into HTTPS scheme.
* See http://wptavern.com/how-to-fix-images-not-loading-in-wordpress-4-4-while-using-ssl
* Add a post's category name to body class.
* See https://bavotasan.com/2011/add-a-posts-category-name-to-body-class-in-wordpress/
*/
add_filter( 'wp_calculate_image_srcset', 'ssl_srcset' );
function ssl_srcset( $sources ) {
foreach ( $sources as &$source ) {
$source['url'] = set_url_scheme( $source['url'], 'https' );
add_filter( 'body_class', 'add_category_name' );
function add_category_name( $classes = '' ) {
if ( is_single() ) {
$category = get_the_category();
$classes[] = 'category-' . $category[0]->slug;
}
return $sources;
return $classes;
}
/*
@ -51,15 +52,11 @@ function add_exif_data( $content ) {
add_filter( 'widget_tag_cloud_args', 'custom_tag_cloud_widget' );
function custom_tag_cloud_widget( $args ) {
$args['number'] = 0; // Adding a 0 will display all tags.
$args['largest'] = 26; // Largest tag.
$args['smallest'] = 11; // Smallest tag.
$args['largest'] = 38; // Largest tag.
$args['smallest'] = 12; // Smallest tag.
$args['unit'] = 'px'; // Tag font unit.
return $args;
}
add_filter( 'wp_generate_tag_cloud', 'xf_tag_cloud', 10, 3 );
function xf_tag_cloud( $tag_string ) {
return preg_replace( "/style='font-size:.+px/", "$0 !important", $tag_string );
}
/*
* Remove Pingbacks from Recent Comments Widget.
@ -72,36 +69,33 @@ function remove_pingbacks_recent_comments( $array ) {
}
/*
* Force avia_post_nav() to cycling categories.
* See http://www.kriesi.at/support/topic/avia_post_nav-function-not-cycling-categories-even-when-set-to-true
*/
add_filter( 'avia_post_nav_settings', 'avia_same_category_filter', 10, 1 );
function avia_same_category_filter( $settings ) {
$settings['same_category'] = true;
return $settings;
}
/*
* By default the post single page title will be “Blog Latest News”. This
* function alter this title to reflect the post category instead.
* This function alter default title.
* See http://www.kriesi.at/documentation/enfold/replace-the-default-blog-latest-news-title
*/
add_filter( 'avf_title_args', 'fix_single_post_title', 10, 2 );
function fix_single_post_title( $args, $id ) {
if (is_single()) {
$post_type = get_post_type();
$category = get_the_category();
if ( ! empty( $category ) && $post_type == 'post' ) {
// Social title for Twitter, Facebook & LinkedIn categories:
$args['title'] = in_array( $category[0]->name, array( 'Twitter', 'Facebook', 'LinkedIn' ) ) ? 'Social' : $category[0]->name;
$args['link'] = NULL;
$args['heading'] = 'h1';
}
elseif ( $post_type == 'quote' ) {
$title = $args['title'];
if ( is_single() ) {
if ( get_post_type() == 'quote' ) {
$args['title'] = 'Libro de citas';
$args['link'] = NULL;
$args['heading'] = 'h1';
}
}
else {
// Post categories by name:
$categories = array_values( array_column( get_the_category(), 'name' ) );
if ( in_array( $categories[0], array( 'Blog', 'Archivo de notas', 'Apuntes', 'Álbum de fotos' ) ) ) {
$args['title'] = $categories[0];
}
}
}
elseif ( is_category() || is_tag() ) {
$args['title'] = 'Publicado en: ' . mb_substr( $args['title'], mb_strpos( $args['title'], ': ' ) + 2 );
}
elseif ( is_tax( 'quote_author_tag' ) ) {
$args['title'] = 'Citas de ' . mb_substr( $args['title'], mb_strpos( $args['title'], ': ' ) + 2 );
}
if ( $args['title'] != $title ) {
$args['link'] = NULL;
$args['heading'] = 'h1';
}
return $args;
}
@ -136,49 +130,46 @@ function avia_add_custom_social_icon( $icons ) {
}
/*
* Add new class in Links and Social, Twitter, Facebook & LinkedIn posts.
* See https://tommcfarlin.com/add-class-to-single-post/
* Force avia_post_nav() to cycling categories.
* See http://www.kriesi.at/support/topic/avia_post_nav-function-not-cycling-categories-even-when-set-to-true
*/
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;
add_filter( 'avf_post_nav_settings', 'avia_same_category_filter', 10, 1 );
function avia_same_category_filter( $settings ) {
$settings['same_category'] = true;
return $settings;
}
/*
* Breadcrumb formatting for social and categories content.
* Hide some terms in taxonomy list under post in wordpress.
* See https://stackoverflow.com/questions/11245378/how-to-hide-some-categories-in-category-list-under-post-in-wordpress
*/
add_filter( 'get_the_terms', 'exclude_taxonomy_terms', 10, 3 );
function exclude_taxonomy_terms( $terms, $post, $taxonomy ) {
// List of taxonomy terms (slugs) to exclude:
$exclude_slugs = array( 'portada', 'pelis-y-series', 'lecturas', 'twitter', 'linkedin', 'facebook' );
if ( !is_admin() ) {
foreach( $terms as $key => $term ) {
if ( $term->taxonomy == "post_tag" && in_array( $term->slug, $exclude_slugs ) ) {
unset( $terms[$key] );
}
}
}
return $terms;
}
/*
* Breadcrumb formatting for 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( '<a href="/blog/category/blog">Blog</a>' ) );
break;
case 978: // Bloc de notas
array_splice( $trail, 1, 2, array( '<a href="/blog/category/notebook">Bloc de notas</a>' ) );
break;
case 976: // Fotoblog
array_splice( $trail, 1, 2, array( '<a href="/blog/category/photoblog">Álbum de fotos</a>' ) );
}
}
// Social breadcrumb for Twitter, Facebook & LinkedIn content:
elseif ( in_array( $category[0]->term_id, array( 1562, 1563, 1564 ) ) ) {
unset ( $trail[2] );
}
}
if ( is_tag() ) {
array_splice( $trail, 1, 0, array( '<a href="/tags">Etiquetas</a>' ) );
}
elseif ( is_tag() || is_category( array( 982, 978, 976 ) ) ) {
// Posts breadcrumb for Blog, Bloc de notas & Fotoblog categories:
array_splice( $trail, 1, 0, array( '<a href="/posts" title="Todas las entradas">Entradas</a>' ) );
elseif ( is_category() ) {
$trail = array();
}
return $trail;
}
@ -189,126 +180,91 @@ function avia_change_breadcrumb( $trail, $args ) {
*/
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( '&nbsp;', ' ', $title_instagram ) ) ) );
$title_words = explode( ' ', $title_instagram );
if ( count( $title_words ) > 12 ) {
$title_instagram = implode( ' ', array_slice( $title_words, 0, 12 ) ) . ' …';
$text_title = clean_content( $data['post_title'] );
$text_content = clean_content( $data['post_content'] );
$text_excerpt = clean_content( $data['post_excerpt'] );
if ( $text_title == 'INSTAGRAM' ) {
// Instagram captures:
if ( empty( $text_content ) ) {
$text_title = "He publicado en Instagram";
$text_excerpt = $text_title;
}
else {
$data['post_content'] = substr( $data['post_content'], $dotpos + 2 );
}
$data['post_title'] = $title_instagram;
}
$text_excerpt = text_with_limit( $text_content );
$title = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $data['post_title'] ) );
$text_title = trim( strip_tags( $title ) );
$content = preg_replace( '!\s+!', ' ', str_replace( '&nbsp;', ' ', $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 );
$dotpos = strpos( $data['post_content'], '. ' );
$text_title = $dotpos > 0 ? substr( $data['post_content'], 0, $dotpos ) : $data['post_content'];
$text_title = clean_content( $text_title );
$title_words = words_from_text( $text_title );
if ( count( $title_words ) > 10 ) {
$text_title = text_with_words( $title_words, 8 );
}
else {
$data['post_content'] = substr( $data['post_content'], $dotpos + 2 );
}
}
}
else {
// For posts sent from the WordPress App:
$categories = $postarr['tax_input']['category'];
if ( ! is_array( $categories ) ) {
$categories = array();
if ( empty( $text_title ) && ! empty( $text_content ) ) {
$text_title = text_with_words( words_from_text( $text_content ), 4 );
}
$text_excerpt = text_with_limit( $text_content, 140 - strlen( $text_title ) - 2 );
}
// 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, '<p><a><strong><b><em><i><br />' ) );
/*
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( '<b>', '</b>', '<i>', '</i>' ), array( '<strong>', '</strong>', '<em>', '</em>' ), $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;
}
$data['post_title'] = $text_title;
$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;
function clean_content( $content ) {
// Remove [av_...] Avia layout shortcodes to get only text:
$content = preg_replace( '/\[\/?av_one[^\]]*\]/', '', $content );
$content = preg_replace( '/\[\/?av_two[^\]]*\]/', '', $content );
$content = preg_replace( '/\[\/?av_three[^\]]*\]/', '', $content );
$content = preg_replace( '/\[\/?av_four[^\]]*\]/', '', $content );
$content = preg_replace( '/\[\/?av_section[^\]]*\]/', '', $content );
$content = preg_replace( '/\[\/?av_layout[^\]]*\]/', '', $content );
$content = preg_replace( '/\[\/?av_cell[^\]]*\]/', '', $content );
$content = preg_replace( '/\[\/?av_tab[^\]]*\]/', '', $content );
$content = preg_replace( '/\[\/?av_textblock[^\]]*\]/', '', $content );
// And then remove all shortcodes:
$content = strip_shortcodes( $content );
// Replace '&nbsp;' with space character:
$content = str_replace( '&nbsp;', ' ', $content );
// Convert more than one space in one:
$content = preg_replace( '!\s+!', ' ', $content );
// Return clean content:
return trim( strip_tags( $content ) );
}
function words_from_text( $text ) {
return explode( ' ', $text );
}
function text_with_words( $words, $number_of_words = 0 ) {
if ( $number_of_words > 0 && count( $words ) > $number_of_words ) {
return implode( ' ', array_slice( $words, 0, $number_of_words ) ) . ' …';
}
return implode( ' ', $words );
}
function text_with_limit( $text, $limit = 140 ) {
$text = mb_substr( $text, 0, $limit );
if ( mb_strlen( $text ) == $limit ) {
$text = mb_substr( $text, 0, mb_strrpos( $text, ' ' ) );
if ( mb_substr( $text, -1, 1 ) != '.' ) {
$text .= ' …';
}
}
return $text;
}
/*
* 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 );
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;
@ -337,6 +293,7 @@ function char_counter_js() {
if ( get_post_type() == 'post' ) { echo '
<script>
jQuery(document).ready(function(){
var total_length = 140;
var urls_regexp = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi);
function htmlDecode(input){
@ -373,7 +330,7 @@ jQuery(document).ready(function(){
var tuit_length = excerpt_length;
var urls = jQuery("#excerpt").val().match(urls_regexp);
if (urls) for (i = 0; i < urls.length; i++) tuit_length = tuit_length - urls[i].length + 23;
tuit_length = 140 - tuit_length;
tuit_length = total_length - tuit_length;
return excerpt_length.toString() + " / " + tuit_length.toString() + " (Twitter)";
}
jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:12px;right:34px;color:#666;\"><span id=\"excerpt_counter\"></span></div>");
@ -384,25 +341,6 @@ jQuery(document).ready(function(){
}
}
/*
* 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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

View file

@ -45,11 +45,20 @@ strong {
color: inherit !important;
}
div.container_wrap_first {
background: #ebeae9 url(images/bg-page.png) repeat-x 0 bottom;
background: #e1e1e1 url(images/bg-page.png) repeat-x center bottom -1px;
}
div.container_wrap_first > div.container:first-child {
background-color: #fff;
}
body.category-archivo div.container_wrap_first > div.container:first-child {
background: #fff url(images/notebook.jpg) repeat-y left top;
padding-left: 68px;
}
body.archive.tag div.container_wrap_first > div.container:first-child,
body.page-id-121962 div.container_wrap_first > div.container:first-child {
background: #fff url(images/dividers.jpg) repeat-y left top;
padding-left: 76px;
}
.main_color .av-inner-masonry-content {
opacity: .82;
filter: alpha(opacity=82); /* For IE8 and earlier */
@ -192,8 +201,9 @@ a.avia-cookie-consent-button:hover {
background-color: #e9146c;
height: 4px;
}
#menu-item-5544 {
#menu-item-5777 {
border-top: 1px solid #556372;
border-bottom: 1px solid #556372;
}
/*
@ -239,6 +249,7 @@ a.avia-cookie-consent-button:hover {
}
.entry-content-wrapper h3 {
font-size: 22px;
color: #c73e77;
}
.entry-content-wrapper h4 {
font-size: 20px;
@ -337,12 +348,16 @@ span[data-avia-tooltip] {
.post-entry .big-preview img {
margin: auto;
}
/* Links and Social posts */
article.post-entry-simple .entry-content-wrapper div.entry-content {
.post-entry.format-image .big-preview img {
max-height: 900px;
width: auto;
}
/* Apuntes posts */
article.category-apuntes .entry-content-wrapper div.entry-content {
border-left: 7px solid #3c8dbc;
padding-left: 20px;
}
article.post-entry-simple .entry-content-wrapper p {
article.category-apuntes .entry-content-wrapper p {
font-size: 1.235em;
line-height: 1.5em;
text-align: left;
@ -437,6 +452,10 @@ footer.entry-footer {
margin-bottom: 30px;
}
/* Comments */
li.comment {
margin: 0;
padding: 0;
}
.comment_content,
#top .commentlist .children ul {
padding-right: 18px !important;
@ -492,6 +511,15 @@ footer.entry-footer {
font-size: 15px;
}
/*
* Timelines.
*/
.multi-big .post_author_timeline,
.single-small .post_author_timeline,
.avia-icon-list .iconlist-timeline {
border-right-width: 3px;
}
/*
* EnlighterJS PLUGIN.
*/
@ -520,11 +548,21 @@ span.EnlighterJS {
/*
* PAGES STYLES.
*/
#tag_cloud-5 a {
#tag_cloud-5 a,
#tag_cloud-6 a {
display: inline;
float: none;
border: 0;
padding: 2px 3px;
white-space: nowrap;
}
/* Archive */
.page-id-5502 .avia-content-slider.avia-builder-el-2 .fake-thumbnail .slide-image {
display: none;
}
.page-id-5502 .avia-content-slider.avia-builder-el-2 .slide-meta,
.page-id-5502 .avia-content-slider.avia-builder-el-2 .slide-entry-excerpt {
font-size: 75%;
}
/*
@ -835,6 +873,20 @@ body.tax-quote_author_tag .quote-author a:hover {
background-color: #000;
}
#top .pagination {
padding: 10px 0;
}
#top .pagination .current,
#top .pagination a,
#top .fullsize .template-blog .pagination a {
box-shadow: 0px 0px 5px 0px #777777;
margin-left: 3px;
}
#top .pagination .current {
background-color: #777777;
color: #ffffff;
}
.av-image-caption-overlay-center p {
text-align: center !important;
}
@ -910,6 +962,15 @@ body.tax-quote_author_tag .quote-author a:hover {
}
}
@media (min-width: 768px) and (max-width: 929px) {
/* Title widgets */
.widget_nav_menu .nested_nav > li > a:before,
h3.widgettitle:before {
display: none;
}
.widget_nav_menu .nested_nav > li > a,
h3.widgettitle {
padding-left: 8px !important;
}
/* List items widgets */
ul.dpe-flexible-posts li img {
display: none;
@ -939,6 +1000,12 @@ body.tax-quote_author_tag .quote-author a:hover {
div.container_wrap_first {
background: #fff;
}
body.category-archivo div.container_wrap_first > div.container:first-child,
body.archive.tag div.container_wrap_first > div.container:first-child,
body.page-id-121962 div.container_wrap_first > div.container:first-child {
background: #fff;
padding-left: 30px;
}
#avia2-menu {
display: none;
}
@ -961,6 +1028,15 @@ body.tax-quote_author_tag .quote-author a:hover {
width: 31.3%;
margin: 0 1%;
}
/* Archive */
.page-id-5502 .avia-content-slider.avia-builder-el-1 .slide-meta,
.page-id-5502 .avia-content-slider.avia-builder-el-1 .slide-entry-excerpt {
font-size: 75%;
}
.page-id-5502 .avia-content-slider.avia-builder-el-2 .slide-meta,
.page-id-5502 .avia-content-slider.avia-builder-el-2 .slide-entry-excerpt {
font-size: 100%;
}
}
@media (max-width: 567px) {
/* LAYOUT */