![]() #9 /public_html/wp-content/themes/generatepress/single.php(29): generate_do_template_part() #8 /public_html/wp-content/themes/generatepress/inc/theme-functions.php(572): get_template_part() #7 /public_html/wp-includes/general-template.php(204): locate_template() #6 /public_html/wp-includes/template.php(716): load_template() #4 /public_html/wp-content/themes/generatepress/content-single.php(99): do_action() #3 /public_html/wp-includes/plugin.php(474): WP_Hook->do_action() #2 /public_html/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters() ![]() #1 /public_html/wp-includes/class-wp-hook.php(307): GeneratePress_Hook->execute_hook() #0 /public_html/wp-content/plugins/gp-premium/elements/class-hooks.php(215): eval() I don’t want to bother too much with this issue, maybe it would be good to wait for the imminent integration of WP Show Posts in GenerateBlocks PRO, anyway, for information purposes there goes a new bug that has appeared: PHP Fatal error: Uncaught Error: Call to undefined function wpsp_display() in /public_html/wp-content/plugins/gp-premium/elements/class-hooks.php(215) : eval()'d code:18 I know that soon WP Show Posts plugin will be integrated in GenerateBlocks PRO (I wait impatiently :P) but could the supposed problem with foreach be solved in the meantime? (I’m using PHP 8.1) PHP Warning: foreach() argument must be of type array|object, bool given in ****/public_html/wp-content/plugins/gp-premium/elements/class-hooks.php(215) : eval()'d code on line 7 Well, it works correctly, but in error_log I get this warning: $list = get_page_by_title( 'related', 'OBJECT', 'wp_show_posts' ) $tag_string = get_tag( get_query_var( 'tag' ) ) $tag_string = implode( ', ', $tags_list) Nothing more nothing less.Ĭoming back to indention, the only advantage of the shortened code, I must say that I happily accept the disadvantage of more whitespace in a code I want to read, if the code is expressive and not tuned for shortness.I am using the WP Show Posts plugin for related posts, I added it in a hook with this code: It does a) what it says and b) what it has to do. It is not only much more easy to understand, it is also more responsible with resources by not wasting time on a superfluous loop. ![]() When reading that code I know exactly what is happening. Looking at the long code, I read "if not empty then foreach". In this case, the developer already considered that there might not be any $definition (wouldn't $definitions make more sense?) set, but instead of handling that properly and skip further processing of that non existing value, a default value is passed to the foreach loop in order to trick the loop to do what the developer was too lazy to implement. Why should looping over an empty array be default behaviour? Every line of code costs time and if there is some code executed, there should be a reason for it. Looking at the short form, I read "if null then loop over empty array", which leaves me confused. What I like is that it avoids another indention which might be taken as an advantage over the "longer" code, but that's it. I don't see any advantages of the short form over the long code ( if (!empty.) other than that it is shorter, but I have learned not to over-optimize for the sake of readability.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |