I'm trying to get my theme ready for publication on WordPress.org
I got this feedback:
function_exist() it is not preferable 3.0 design
Now I wonder what I'm doing wrong.
In the current structure I have:
functions.php
:
/* Load JBST functions on 'after_setup_theme'. */
add_action( 'after_setup_theme', 'jbst_theme_setup' );
if ( ! function_exists( 'jbst_theme_setup' ) ):
function jbst_theme_setup() {
/* Load custom Skematik header functions. */
require( get_template_directory() . '/functions/skematik-header-functions.php' );
//more code
}
/functions/skematik-header-functions.php
defines the function like:
add_action( 'skematik_header', 'skematik_doc_type', 9 );
function skematik_doc_type() {
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width" />
<?php
}
In this case skematik_doc_type
can be removed with remove_action
but can't be overwritten, because it is not wrapped in a function_exists()
. Will this be the problem?
Do I have to wrap all functions in a function_exists()
and add them with add_action
? What are the rules for using function_exists()
or not?
function_exists
if the function is meant to be replaceable. That decision has to be made by the developer on a case by case basis. Voted to close as "primarily opinion based". There is no general answer to this question.