Bestway to write php functions

The use of function_exists is a very bad habit that should simply be avoided in favor of using actions and filters. If you want child themes to be able to override some functionality you need to be very specific about which one and how, and function_exists is usually not specific enough for that.

Retrieve array of attachment IDs attached to a given Post ID

found a solution: thought it might be worth sharing… //// We use $gallery_media as an array containing all attachment IDs that have been approved by the admin before $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘orderby’ => ‘post_date’, ‘order’ => ‘ASC’, ‘post_status’ =>’any’, ‘post_parent’ => $post->ID, // This queries a custom field I … Read more

How to Overwrite validate_plugin function

My solution: generate a backtrace in the function and bail early if called from validate_active_plugins(). function action_option_active_plugins( $value, $option ) { // Look at the call backtrace and bail early if called from validation function. $backtrace = debug_backtrace( 2 ); // Exclude [‘object’] and [‘args’] foreach( $backtrace as $frame ) { if( $frame[‘function’] === ‘validate_active_plugins’ … Read more

Manually return false for function_exists

Have your function return your HTML rather than echo it. Perform the logic in the function to see if the image/logo are present and only return the HTML if that’s the case, otherwise returning null/false. function my_header_function( $output = false ) { if ( /*image and logo have been uploaded */ ) { $output = … Read more