Archived topic
Media Library crashed: funtions.php in child theme
14 replies · Started by Dominik on April 17, 2016
Dear Tom,
sorry for bothering you again, but my heart is bleeding after all day fight against this problem.
In details: My media library doesn't work in grid mode (list shows itself nicely) and adds files with lots of troubles. Tried disabling plugins - still same problem, tried changing my child theme into GP parent theme - media library works like brand-new feature.
I know that the problem is caused by my functions.php file in the child theme. Removing it obviously crashes the theme, but media library works then fine. After my research I sadly admit I have no HTML comments in my functions.php file. What's wrong with it then?
Please, help me find a reason. My whole day is wasted. Shame.
<?php
function theme_enqueue_styles() {
$parent_style = 'generatepress';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style )
);
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
if ( ! function_exists( 'generate_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function generate_posted_on() {
if ( 'post' !== get_post_type() )
return;
$categories = get_the_category();
if ( (! empty( $categories )) AND ($categories[0]->name == 'Krótkie pytania')) {
$date = apply_filters( 'generate_post_date', true );
$author = apply_filters( 'generate_post_author', true );
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Odpowiedź z %2$s, %5$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() ),
esc_attr( get_the_time() )
);
// If our date is enabled, show it
if ( $date ) :
printf( '<span class="posted-on">%1$s</span>',
$time_string
);
endif;
$zadajacy = get_post_meta( get_the_ID(), 'zadajacy', true );
echo '. Pytanie nadesłał(a) <span class="zadajacy">' . $zadajacy . '</span>.';
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
comments_popup_link( __( 'Leave a comment', 'generatepress-child' ), __( '1 Comment', 'generatepress-child' ), __( '% Comments', 'generatepress-child' ) );
echo '</span>';
}
}
else { //jeśli nie krótkie pytanie, to co?
$date = apply_filters( 'generate_post_date', true );
$author = apply_filters( 'generate_post_author', true );
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Opublikowano %2$s, %5$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() ),
esc_attr( get_the_time() )
);
// If our date is enabled, show it
if ( $date ) :
printf( '<span class="posted-on">%1$s</span>',
$time_string
);
endif;
/* // If our author is enabled, show it
if ( $author ) :
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>',
__( 'by','generate'),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'generate' ), get_the_author() ) ),
esc_html( get_the_author() )
)
);
endif; */
$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generate' ) );
if ( $categories_list ) {
printf( ' w kategorii <span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>.',
_x( 'Categories', 'Used before category names.', 'generate' ),
$categories_list
);
}
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
comments_popup_link( __( 'Leave a comment', 'generatepress-child' ), __( '1 Comment', 'generatepress-child' ), __( '% Comments', 'generatepress-child' ) );
echo '</span>';
}
}
}
endif;
if ( ! function_exists( 'generate_entry_meta' ) ) :
/**
* Prints HTML with meta information for the categories, tags.
*
* @since 1.2.5
*/
function generate_entry_meta()
{
$categories = apply_filters( 'generate_show_categories', true );
$tags = apply_filters( 'generate_show_tags', true );
$comments = apply_filters( 'generate_show_comments', true );
if ( 'post' == get_post_type() ) {
$tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
if ( $tags_list && $tags ) {
printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
_x( 'Tags', 'Used before tag names.', 'generatepress' ),
$tags_list
);
}
}
}
endif;
if ( ! function_exists( 'generate_content_more' ) ) :
/**
* Prints the read more HTML to post content using the more tag
*/
add_filter( 'the_content_more_link', 'generate_content_more' );
function generate_content_more( $more ) {
$more_jump = apply_filters( 'generate_more_jump','#more-' . get_the_ID() );
$kateg1 = get_the_category();
$kateg = $kateg1[0]->name;
if ($kateg == 'Krótkie pytania') {
return '<p class="read-more-container"><a class="read-more content-read-more" href="'. get_permalink( get_the_ID() ) . $more_jump . '">' . 'Zobacz odpowiedź >>' . '</a></p>';
} else {
return '<p class="read-more-container"><a class="read-more content-read-more" href="'. get_permalink( get_the_ID() ) . $more_jump . '">' . 'Czytaj dalej >>' . '</a></p>';
}
}
endif;
function show_question_difficulty() {
$kateg1 = get_the_category();
$kateg = $kateg1[0]->name;
if ($kateg == 'Krótkie pytania') {
print '<div class="trudnosc" title="Poziom trudności">';
$trudnosc = get_post_meta( get_the_ID(), 'trudnosc', true );
$gwiazd = 0;
for (; $gwiazd < floor($trudnosc / 2); $gwiazd++) {
echo '<i class="fa fa-star" aria-hidden="true"></i>';
}
if (($trudnosc % 2) == 1) {
echo '<i class="fa fa-star-half-o" aria-hidden="true"></i>';
$gwiazd++;
}
for (; ($gwiazd < 5); $gwiazd++) {
echo '<i class="fa fa-star-o" aria-hidden="true"></i>';
}
print '</div>';
}
}
Hi there,
You can remove this block:
function theme_enqueue_styles() {
$parent_style = 'generatepress';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style )
);
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
It's not necessary.
I'm not seeing anything that would break your Media Library though.
Try removing one function at a time until it's fixed - that will narrow it down.
Let me know :)
Believe me or not. Removing one function at a time didn't solve my problem. But deleting all of them or deleting an entire file - problem was fixed. It drives me crazy. :(
Moreover, my child theme is coded within 4 dofferent files: style.css, functions.php, content.php and content-single.php. Removing each of them - exept functions.php - leaves the problem unsolved. I feel like my life is a mess right now... :)
Try adding this line into your functions.php file:
define( 'GP_IMAGE_RESIZER', true );
The resizer has been causing some issues in the Media Library lately, so it might be that.
I have a replacement for the current resizer ready :)
Unfortunately - still nothing. Well, I think I should leave it now and try sth tomorrow.
Weird, next thing to try is #1 on this page: https://generatepress.com/knowledgebase/debugging/
Nothing help. Disaster. Did everything twice, just to make sure no mistake was made.
Now what? Just praying, huh? :)
Increase your PHP memory limit?: https://generatepress.com/knowledgebase/increasing-memory-limit/
I'm a chemist and we sometimes say, that chemistry doesn't do all teh job. Sometimes alchemy is necessary. :) Experiments may be carried out properly, but sometimes the touch of magic (or just simple luck) is needed for our reaction to be successful.
I've tried simple trick - copied the functions.php file from the parent theme into my child theme and quickly switched the content. Result? All my functions just work, as well as my media library.
Simple answer: coding. For some reason (maybe you can explain me why?) functions.php has to be coded in ANSI, I believe it was in UTF-8 before. And that's it.
Gosh, what a day, almost midnight in here.
That is very strange, I've never heard of/experienced anything like it.
Glad you found the cause though and that it's working now :)
But that's true, it has to be a reason. Everything works beautiful, switching ANSI to UTF-8 brings the problem back. Why the hell media library is so sensitive for the character encoding, and the rest of the CMS is not? Wordpress bug or my ignorance?
That's weird indeed, but I hope someone who'd fight against similar issue, would also find our conversation helpful. If you must change the character encoding from UTF-8 to ANSI, you may cause some more problems - special characters (from Polish language) were no longer supported in the code. But the solution was easier than you might expect - special characters should be replaced with HTML character entities. For example, instead of "ź" you should use this entity: &#378;.
Never thought that character encoding could have taken all my day. Give it back! ; (
Seems a lot of people have experienced similar issues if you Google "WordPress functions.php UTF-8".
Yep I see it now. But how to find the reason of your issue in character enchoding? :D Most people who use Wordpress even don't know what UTF-8 is. To be honest, neither do I. :)
But as you said, I'm glad it can be tagged as a 'resolved' one. ;)
I don't think it's an issue with the child theme - it's been downloaded thousands of times.
It probably changed encoding when you uploaded it somehow - first I've heard of it.
Either way, good to know that it can even happen, should help me help someone if it happens again :)
