I've been using the WordPress Customize.php functionality to allows users to customize my theme via the admin Customizer. It's been working fine offline in WAMP, but when I uploaded the theme to the testing server I received this message:
Fatal error: Can't use function return value in write context in [my url]/functions.php on line 181
The line it links to is a reference to get_theme_mod(), and in particular:
$page_data = get_page(get_theme_mod('page'));
Do I have to register the 'theme mods' in functions or something?
Right, I've found my issue - and another one has arose that I'm looking into...
For those that read this after searching the web having suffered the same problem, the reason I was receiving this error was because above this I was testing the get_theme_mod with an empty() function. Which, does not work as get_theme_mod is not a variable.
if(!empty(get_theme_mod('page'))){
$page_data = get_page(get_theme_mod('page'));
}
Related
I'm not a coder, just trying to update my wordpress site! I've bought a theme on Envato called "Birddi". When I try to upload my theme, I got this message :
Fatal error: Can't use function return value in write context in
/websites/ik/ikateyou.com/wordpress/wp-content/themes/birddi/inc/template.functions.php
on line 1748
This crashed my whole site and I couldn't get back into the admin area until I deleted the theme file. (My site is all messed up with a generic theme now so just ignore it)
Is there any way to fix this? I think this is the line...
$video_thumb = !empty(get_the_post_thumbnail_url($zkbirdi_meta_options['zkbirdi_format_video_local']['id'])) ? get_the_post_thumbnail_url($zkbirdi_meta_options['zkbirdi_format_video_local']['id'],'full') : get_the_post_thumbnail_url(get_the_ID(),'full');
Thankyou so much in advance!!
why don't you contact the theme developer
Try replacing that line with:
$video_thumb = get_the_post_thumbnail_url($zkbirdi_meta_options['zkbirdi_format_video_local']['id']);
$video_thumb = !empty( $video_thumb ) get_the_post_thumbnail_url($zkbirdi_meta_options['zkbirdi_format_video_local']['id'],'full') : get_the_post_thumbnail_url(get_the_ID(),'full');
In earlier versions of PHP empty() should be applied to variables not values. Alternatively, you may upgrade your version of PHP but that may cause even more problems. Incidentally, I think your version of PHP may be very old - 5.4 or older.
I have inherited a custom wordpress theme and am doing a few changes to it (all cosmetics of changing city names, etc) , but at the bottom of a post I get the error : "Fatal error: Call to undefined function get_meta()"
In my functions.php I have this:
function bardetails(){
$web = get_meta('web');
$email = get_meta('email');
//...
}
I have a Java background but am new to php and wordpress. I dont see anywhere else this function is called, but must be tied to a post.
Have looked and can find a lot of problems about "get_post_meta()" and "meta()" but nothing about this. It also seems to be working on the other site the theme is on. I used FTP to pull over everything and all the other parts of the site seem to work fine. Looked at the database for something that could help with no luck, and also have tried to find if this is some kind of library, as the intention of the function is clear and thats to grab the website/email of the post.
So is this just a straight custom function? And if so were should it be defined in a php/wordpress setup?
It was due to a plugin that was not installed. "More Fields" By Henrik Melin, Kal Ström is a seemingly defunct plugin that was needed that allows you to use "get_meta()". For now, I just copied over the plugin but seems like I need to find an alternative going forward.
I am getting this Warning and my Header and Footer on my Website are not showing them right.
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'remove_admin_bar_style_frontend' not found or invalid function name in /home/toolsebo/www/yr-1007/wp-includes/plugin.php on line 496
I tried to find the remove_admin_bar_style_frontend in my functions.php to remove it but i cant.
Please help me to get this fixed i really don't know how to go ahead.
wp-includes/plugin.php is a core file, it wouldn't be in there, that's just what's generating the error.
Look in your wp-content/themes/your_theme_name/ folder for a functions.php or similar file. The function will be in there.
This means you are calling the function "remove_admin_bar_style_frontend" but that function was not in your plugin or theme. Search for that initiating code block and comment it.Try to search add_action('....
I've been having this issue for a while but keep just working around it an thought I'd finally get it solved.
I'm trying to include files into my main plugin document (the one that has the plugin title and version in it) like this:
define('SBT_PLUGIN_URL', plugin_dir_url(__FILE__));
include(SBT_PLUGIN_URL . 'competition_table.php');
inside the competition_table.php is an add_shortcode(); function that needs to run, in order for the shortcode to be registered with wordpress:
function add_table() {
//Run code here
}
add_shortcode('competition_table', 'add_table');
When I run the code on the site the link resolves properly, including the correct file, however I get this Fatal Error:
Call to undefined function add_shortcode()
However if I add exactly the same code that is in the competition_table.php into my main plugin document then the code runs perfectly.
So basically, my question is, why is Wordpress not recognizing it's own function and how can I include the file to make the code run properly?
Thanks in advance
You have to develop with WP_DEBUG enabled. It dumps an error: wrapper is disabled in the server configuration. That lead me to this: "Trust me, you do not want to include from URLs.".
Then I realized you're defining that constant with plugin_dir_url(), when what you need is a path. The following magic constant does the job:
include_once __DIR__ . '/competition_table.php';
Thanks to the feedback from #b__ I have managed to solve this issue.
For some reason, Magic Constants don't always work with wordpress, however, you can use it's equivalent to get the same effect:
include_once dirname(__FILE__) . '/competition_table.php';
When including files for use in a wordpress plugin you should always include via a PATH, not by a URL.
I have my Wordpress blog on blog.mysite.com, and a totally different site (built in my framework) at www.mysite.com.
I know if the blog and another site are on the same server, and have correct permissions, I can use the following to "syndicate" my blogs to the non-blog site with:
define('WP_USE_THEMES', false);
require('/var/www/vhosts/mysite/subdomains/blog/httpdocs/wp-config.php');
query_posts('showposts=5');
...and then run a loop on the page.
The problem is that since my non-blog site is a framework, everything except for my front controller lives in a function - and this is creating the following error for me:
Fatal error: Call to undefined method
stdClass::set_prefix()
(btw, I'm fairly certain the fact that this code is called within a function that is causing the error...when I put the code on the front controller (not in function), the error disappears)
I would REALLY like to have recent blog listings on my non-blog site to spruce it up. Any ideas on how to do this?
Well I guess you forgot to write
global $wpdb
inside the function