Call to undefined function is_home() or any conditional tags

It’s a timing issue. This tries to call is_home() before that function exists. $my_ver = check_home(); It works in the function called by add_action because then is_home() does exist because WP has fully loaded. If you load php files in your plugin, then you can call check_home anytime in those files. For example: define( ‘MY_PLUGIN_PATH’, … Read more

How best to handle database version dependence (from $wp_db_version)

I sorted this out. It looks like the core team rolls out new versions of the database with their beta program. So, it’s plenty easy to get advance warning. And, the database upgrades live in wp-admin/includes/upgrade.php. There’s a sequence of functions in there named things like upgrade_500, upgrade_560, upgrade_590. They’re named for the WordPress version … Read more

Undefined variable’s error when expected to have passed the content of variable [closed]

The problem is that the code ignores scope, a fundamental programming concept. This scope: function form_validation() { … $error_message=”Too short!”; … } and this scope: function save_to_db() { … … echo $error_message;… } Are not the same. It would be unreasonable and illogical to expect it to transfer over. When you assign $error_message a value … Read more

Hook after attachment added and cropped

There is to filters needed for optimizing all images, that will be uploaded: add_filter(‘wp_handle_upload’, ‘random_function’, 10, 2); add_filter(‘image_make_intermediate_size’, ‘rand_function2’, 10, 1); function random_function($array, $string) { // Some random action with main image return $array } function rand_function2($file) { // Some random action with cropped images return $file }