Error: Call to undefined function get_meta() in functions.php - php

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.

Related

Use of undefined constant ABSPATH

I am using WP for the first time. I'm just trying to create a very basic script to echo the user's id and am having all sorts of issues.
The code is this and is currently located in wp-content/plugins (i'm not really sure where these things should be):
<?php
require_once ABSPATH . '/wp-includes/pluggable.php';
$user = wp_get_current_user();
echo $user->get_site_id();
I'd had it without the require initially but I was getting a function not defined error for wp_get_current_user. Now I'm getting Warning: Use of undefined constant ABSPATH - assumed 'ABSPATH'...
Is there some sort of predefined set of files that I need to include or some specific directory I need to be putting my scripts so that these variables and functions are in scope? My understanding was that these things are supposed to be global.
Did you try code like that:
add_action('init', 'some_function_name');
function some_function_name() {
$user = wp_get_current_user();
echo $user->get_site_id();
}
The WordPress comes with hooks (actions and filters) to let other developers modify either core parts of the WordPress or code from other plugins / themes.
The code I describe in my answer, it is running your code when the whole WordPress , all the Plugins and the theme are loaded, thus you should have by default the wp_get_current_user() function and you should not need to include manually the pluggable.php.
This seems like is going to solve your problem.
Read more on hooks here: https://developer.wordpress.org/plugins/hooks/.
Side note. Keep in mind that in order to run your custom code you should register a proper WordPress plugin and activate it. If you have made a php file in the plugins folder, and you loaded using PHP functions like require/include the plugin probably will not operate as you expect although the source code it could be perfect. To get more details on how to write your own plugin, you could read here: https://developer.wordpress.org/plugins/

How can i call a plugin shortcode from within a function with theme functions.php file?

I use a plugin (Popup Builder) on my WordPress site. Whenever I create a new popup with the plugin, it creates a shortcode for that popup. I want to call on that shortcode from within the theme functions.php file. But I can't seem to get it to work properly.
The shortcode runs only if conditions are met. And in this example it's when a visitor access the site for the first time. I then check for a certain cookie and if that cookie does not exist, the popup will fire up and force the visitor to choose one option from a list of options, and then the cookie will be set with the correct value, once they do.
However I cant seem to find a solution that fires the popup at all. An I also get this notice: Notice: do_shortcode_tag was called incorrectly. Attempting to parse a shortcode without a valid callback:
function check_for_cookies() {
// Check if cookie is already set
if(isset($_COOKIE['tln_valgt_fylke'])) {
// Do this if cookie is set
$string .= 'Hi, and welcome back!' ;
return $string;
} else {
// Do this if the cookie doesn't exist
$shortcode = do_shortcode("[sg_popup id=163]");
return $shortcode;
}
}
add_action('init', 'check_for_cookies');
What am I doing wrong, and what if this is not a good way of accomplishing what I want, then what is?
This is just a guess
But, I think its a timing issue. You are using the init action to hook into another plugins shortcodes. It's possible that plugin has not yet registered it's shortcode via add_shortcode or if it has registered it, it may not have "included" the file that defines the callback for it (for whatever reason).
In fact it seems likely because:
do_shortcode_tag was called incorrectly. Attempting to parse a shortcode without a valid callback
This indicates the shortcode was called and no callback existed for it. This is not a problem with your code per say. But it says that the plugin has not yet loaded the file that contains the callback.
You could test this by hooking into an action that happens later in the execution chain, after you know all plugins have been loaded and initialized. Like even wp_head
Perhaps you could even get away with changing the priority of the hook:
add_action('init', 'check_for_cookies', 20); //default is 10
This way it's triggered at the end of init, but even then it may be too soon. The only real way to know is to look at the code for the plugin and find out when it's registering it's "stuff". An easy way to do that is add this code to the plugins shortcode callback:
try{
throw new \Exception();
}catch(\Exception $e){
die("<pre>{$e->getTraceAsString()}</pre>");
}
This will throw and then catch an exception, and then output the stacktrace. Which may show you exactly where the shortcode is being setup. You'll have to trigger the callback (obviously) for it to work. You can also use print_r(debug_backtrace()) but it's much harder to read IMO.
PS I been doing a lot of WP work lately and I just had an issue with action timing ... lol. That was why I thought of it, I spent the last 2 days refactoring code. In my case I an replacing the add/edit/profile parts of the user system on both the front and back end. It's a sort of subuser plugin. And there is a lot of competing actions related to that if you know what I mean...

Gravityforms not found message - WP Plugin hook

I'm trying to hook onto the WP Gravityforms plugin's not found message.
I've found a hook(gform_form_not_found_message) for this but it doesn't seem to be firing. What am I doing wrong here?
My code:
function notfoundmessage($message, $id){
$message = 'test';
return $message;
}
add_filter( 'gform_form_not_found_message', 'notfoundmessage', 10, 2);
I tried several thing like writing the function inline, including it from the main plugin file, including it in an oop way but none of them seem to work. I was thinking that maybe I need to require a gravityforms Class but I can't find anything about that in the documentation.
Link to the hook in the documentation
It turned out the filter isn't applied yet in the version I'm using. For other people having this issue, make sure you are using the latest version of Gravityforms.

Exclude a function in PHP (Wordpress)

I recently purchased a Wordpress theme and having some problems with importing a feature from another theme (from the same author).
The author of the themes helped me a lot with importing some stuff to the new theme. While both themes share many similarities, there's still some tweaking that needs to be done.
One of the issues I'm currently facing is with a PHP file I imported from the original theme to the new one. Both Wordpress themes work with minisites, but the author coded them differently for each Wordpress.
When I copy/paste boxes.php from the old theme to the new theme, I get this error message:
Fatal error: Call to undefined function it_get_minisite() in /home/vincevc73/domains/quirk.be/public_html/wp-content/themes/explicit/inc/boxes.php on line 13
The author told me I had to exclude this, but I have no idea how to do this. I read I had to put /*-*/ around the functions to exclude it, but I'm not sure where to put these marks exactly
The it_get_minisite function appears three times in the file
$minisite = it_get_minisite($post->ID);
if($minisite)
{
#override general theme options with minisite-specific options
$boxes_layout = $minisite->boxes_layout;
}
#get the current minisite $minisite = it_get_minisite($post->ID);
if($minisite)
{
#add post type to query args
if(it_targeted('boxes', $minisite))
$boxesargs['post_type'] = $minisite->id;
}
$minisite = it_get_minisite(get_the_ID(), true);
I think he meant that you should remove all the code which requires this function. But then you will also have to remove the code which requires "$minisite" too. But that's only a guess based on the information you posted.

Wordpress loop inside of function = fatal error

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

Categories