How to include all files within a folder to functions.php?

You can include/require all *.php files recursively using following function. foreach(glob(get_template_directory() . “/*.php”) as $file){ require $file; } Alternatively You can use following function as-well. $Directory = new RecursiveDirectoryIterator(get_template_directory().’functions/’); $Iterator = new RecursiveIteratorIterator($Directory); $Regex = new RegexIterator($Iterator, ‘/^.+\.php$/i’, RecursiveRegexIterator::GET_MATCH); foreach($Regex as $yourfiles) { include $yourfiles->getPathname(); } P.S Got the solution From Here.

Check if term object is in array

WordPress has the wp_list_pluck function, which can be helpful here. We can make an array of just term IDs from the array of objects like: $term_ids = wp_list_pluck( $subcat_terms, ‘term_id’ ); Then we can check in_array: $this_id = 42; if( in_array( $this_id, $term_ids ) ){ // do something }

Use is_product_category() properly

is_product_category() is to be used on woocommerce category archive pages only so first make sure that you are on category archive. instead of category number use category slug name is_product_category(‘category-slug’) no need to run OR(||) condition just use is_product_category(‘category-slug1′,’category-slug2’) to get same output

Refactor create_function

There is an inbuilt function for returning null: __return_null. So you can replace create_function(‘$a’, ‘return null;’); with just ‘__return_null’ (note the quotes) as it seems $a is not used anyway. Or you can use an anonymous function as the argument directly: function($a) {return null;} (no quotes). Either way since the argument is expecting a function … Read more

page template for attachement page?

WordPress supports several types of attachment templates. The function get_attachment_template in wp-includes/theme.php provides this support; it is called in wp-includes/template-redirect.php. If your theme includes attachment.php all of your attachments will be rendered with that template. If your theme also includes image.php then all of your images will use that template as long as they have … Read more

Generating add_settings_section() calls dynamically

Try this instead: function settings_sections() { // array containing settings identifiers $array = ( ‘SOMETHING’, ‘SOMETHING2’, ‘SOMETHING3’, ‘SOMETHING4’ ); // loop through settings identifiers and generate settings sections foreach( $array as $v) { add_settings_section( $v . ‘_settings’, $v . ‘ Settings’, ‘generate’, $v . ‘_page’ ); } } echo outputs a string, you should just … Read more

Disable single post page

Although I’m also curious as to why you’d want to do this, and would probably suggest using a custom post type instead, this would probably work (actually works for any single post type except pages and attachments): add_action( ‘pre_get_posts’, ‘wpse44983_single_post_404’ ); function wpse44983_single_post_404( $query ) { if ( $query->is_main_query() && $query->is_single() ) { $query->is_404 = … Read more

How do I deactivate a plugin for some roles

This is actually a basic PHP problem: if (in_array(‘Participant’, ‘Subscriber’, $current_user->roles)) { That’s not how in_array works. in_array checks if the first bit is in the second bit. So is Participant inside $current_user->roles. What you’ve written however, checks if Participant is inside Subscriber, then passed an array as the 3rd argument, which is meant to … Read more