Articles of function exists

Redeclare theme's function in a plugin

I’m trying to figure out how to redeclare a theme’s function from within a plugin. The problem is that I’m getting a “Fatal error: Cannot redeclare” when trying to activate the plugin. But if I add the code to already activated plugin – everything is working as expected. Is there something obvious that I’m missing? […]

Clean way of using ob_start() and ob_end_clean() in wordpress

I want to pass some json data to JS from wordpress(PHP) and was thinking to use ob_start() and ob_end_clean() in wordpress but i am not sure weather any other plugins are using the same functions. I was thinking to manually add ob_start() at the beginning of the theme header and clear the document when necessary. […]

Check from functions.php if function exists in footer.php

I am trying to secure the copyrights links from footer.php file and I want to create a function in footer php which will have those links and then I want to check from functions.php if that function exists in the footer and in case it doesn’t I would like to show an exit(); function. I […]

check if a file in a plugin folder exists from a locale installation

I need to check if a file exist in my plugin dir: if (fileexists) { … } else { … } However, if in place of fileexists I use file_exists(WP_PLUGIN_DIR . “/myplugin/myfile.ext”) it returns always true, whereas if I use file_exists(plugins_url( “myfile.ext”, __FILE__ )) it returns always false, irrespective of the argument I use is […]

How to replace a function using a child theme?

I have the following function where I would like to replace the image nopic.jpg I have updated by deleting some redundant options. if ( ! function_exists( ‘TaskerDev_get_first_post_image_fnc’ ) ) : function TaskerDev_get_first_post_image_fnc($pid, $w = 100, $h = 100) { //——————— // build the exclude list $exclude = array(); $args = array( ‘order’ => ‘ASC’, ‘post_type’ […]

Override a theme function in a child theme?

Most if not all of the answers to this question are pretty old, or are for edge cases. I have a child theme for a commercial theme (“Total”). The parent theme’s functions.php loads functions from several php files in its “framework” folder. The function I am targeting is in fonts.php, called wpex_standard_fonts: if ( ! […]

override pluggable.php functions

I just not only want to override a pluggable function (wp_new_user_notification) but I want to make sure that if any other plugin is overriding the same function, so my function , override that too or I want my overridden function to work instead of other plugin that is overriding the same function (wp_new_user_notification). May be […]

Twenty Eleven Child theme error when attempting to use a rewritten function

I attempted to make a minor change to a function in the Twenty Eleven theme (wordpress 3.4.2) I get this error message: Fatal error: Cannot redeclare twentyeleven_widgets_init() (previously declared in /home/labfocus/public_html/wp-content/themes/twentyeleven-child/functions.php:10) in /home/labfocus/public_html/wp-content/themes/twentyeleven/functions.php on line 438 Here is the function that I am attempting to add in place of the original <?php if ( !function_exists(‘twentyeleven_widgets_init’)) […]

Where does function_exists() look to decide whether a function exists?

The documentation says: Checks the list of defined functions, both built-in (internal) and user-defined, for function_name. ( SOURCE: http://php.net/manual/en/function.function-exists.php) Does the function merely scan the single php document using function_exists, looking for any functions that match? For example if I have if ( function_exists( ‘get_custom_header’ ) in header.php, will the function look for get_custom_header in […]

if custom post type exist

I want to test if custom post type mobile exist. I used if custom post type exist in the loop, but it doesn’t work. Any suggestion why my code is not working <?php /* The loop */ ?> <?php if ( have_posts() ) : ?>… <?php while ( have_posts() ) : the_post(); ?> <? if( […]