I have installed a plugin wp-fb-autoconnect
I have activated it in the dasboard. Now I would to use a function from it.
In my theme folder, in one of my templates I want to add FB connect button
if( function_exists(‘jfb_output_facebook_btn’) )
{
jfb_output_facebook_btn();
jfb_output_facebook_init();
jfb_output_facebook_callback();
}
function_exists(‘jfb_output_facebook_btn’) returns false. The function is located in main.php in the plugin folder and i can see it. What's wrong? Please help.
UPDATE
The problem in general. A plugin has declared a function. I need to get access to that function from my theme folder.
‘jfb_output_facebook_btn’ uses formatted quotes. Did you copy/paste that snippet from a blog? Try:
if( function_exists('jfb_output_facebook_btn') )
{
jfb_output_facebook_btn();
jfb_output_facebook_init();
jfb_output_facebook_callback();
}
Be very careful of the kind of quotation marks you pass to PHP!
(BTW: Awesome user name. That game is brutal difficult.)
Related
i created an addon moodule in WHMCS and its working just fine!
now im trying to work and learn hooks
i have tried somethings for client side and it worked but i have problem in admin side
here is what i tried so far in hooks.php on my module directory:
add_hook('AdminAreaPage', 1, function($vars) {
$extraVariables = [];
if ($vars['filename'] == 'addonmodules') {
$extraVariables['newVariable1'] = $vars['admin_username'];
}
return $extraVariables;
});
but when i in list.php (a file in module directory) want to get the $extraVariables like below, its null !
<?php var_dump($extraVariables); ?>
what im doing wrong or whats im missing?
i simply just want to get data im creating in hook in my module files
does whmcs hook variables only works and have access in tpl files?
As seen in the documentation, the answer is, yes variables are only available inside the template(s)
Response
Accepts a return of key/value pairs to be made available to the template layer as additional template variables.
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/
Ok, bear with me as I spend most of my days writing C#, JavaScript, HTML, etc. and not PHP.
I am trying to create a WordPress plugin. I would like someone with edit rights to be able to place a token such as [[DONATIONFORM]] in the body of the page content. At runtime that token would be replaced with an actual form.
I have gotten as far as defining a plugin and having it show up in the list of plugins. I have created a function in one of the plugin files called GenerateDonationForm(). I just don't know how to have it run when someone puts in a token.
You need to use the shortcode api
From the docs:
As a quick start for those in a hurry, here's a minimal example of the PHP code required to create a shortcode:
function foobar_func( $atts ){
return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
Make sure that your function returns the output, as opposed to echoing it!
My site is http://www.empoweryourfamily.org/wordpress/
I was working on a plugin and wrote the following code in functions.php
add_action( 'wp_enqueue_scripts', 'table' );
function table() {
wp_register_script('table1', plugins_url() . '/Webinar_Reg/table.js', false, null, true);
if(is_admin()){
wp_enqueue_script('table1');
}
}
But, the moment I clicked on update everything went blank and now neither the frontend nor the backend is opening.
You most likely have a syntax error in functions.php or the function table() is already defined.
Try rolling back the changes you just applied.
Otherwise try looking in the server log for a specific error.
Using table as a function name is bad practice. You should name a function in such a way that it will be completely unique. Use something like mypluginname_table or mytheme_table where mypluginname is the name of your plugin and mytheme the name of your theme. And remember, function names needs to be unique, no two functions can have the same name, except if one is wrapped in a if(!function_exists()) {} conditional statement
I just replaced the modified functions.php file with the old(backup file) file and it is opening properly now. Thanks for your answers.
I am creating new shortcodes for Wordpress on my local version of a Wordpress website.
In functions.php, I am adding for example:
function shortTest() {
return 'Test for shortcodes ';
}
add_shortcode('shortTestHTML', 'shortTest');
Adding the function only is OK, but when I add the add_shortcode() portion, I get a major issue.
It breaks something somehow and I get 500 errors, meaning I can't even load my website locally anymore.
Any thoughts???
Thanks so much!
EDIT:
From PHP Error Log:
[21-Jun-2011 19:02:37] PHP Fatal error: Call to undefined function add_shortcode() in /Users/jonas/Sites/jll/wp-includes/functions.php on line 4505
1) Make sure that you have included shortcodes.php file somewhere (for example, in wp-load.php or whatever other more appropriate place may be).
require_once( ABSPATH . '/wp-includes/shortcodes.php' );
2) Make sure that this file does exist on your installation (which I think you have otherwise we would see a different error).
3) Where do you call this function from (I see it is called from functions.php, but which place)? Possible problem here -- functions.php is loaded prior to shortcodes.php, and if you do use that add_shortcode function before shortcodes.php is loaded you most likely will see this error. Double check your code in that place -- maybe move the call to add_shortcode to another place.
mentioned functions.php is not in wp-include/ directory.
it is in: wp-content/themes/<your-theme-name>/functions.php
adding this in functions.php you say? Well I don't know about that, the way I did it was create a folder inside the wp-content/plugins folder, e.g. shortcodetest.
Inside this folder create a shortcodetest.php file.
in that file you basically write your code:
<?php
/*
Plugin Name: ShortCodeTest
Plugin URI: http://www.example.net
Description: Print a test message
Version: 0.1
Author: anonymous
Author URI: http://www.example.net
*/
add_shortcode('shortcodetest', 'shortcodetest_function');
function shortcodetest_function() {
return "test of shortcode";
}
?>
Then you login as admin, you will see a plugin ShortCodeTest, activate it. Then you can use the shortcode in your posts.
Note that the comments are important... they show up in the plugin description.
I got a way to execute them but it's a little triky :)
You need to change a little bit your template by putting your shortcode (for example: [inline ....]) between <shortcode></shortcode> then
Here is the function to place at the end of your function.php.
function parse_execute_and_echo_shortcode($_path) {
$str = file_get_contents($_path);
while (strrpos($str, "<shortcode>")) {
$beginShortcode = strrpos($str, "<shortcode>");
$endShortcode = strrpos($str, "</shortcode>");
$shortcode = substr($str, $beginShortcode + 11, $endShortcode - ($beginShortcode+11));
$shortcode = do_shortcode($shortcode);
$str = substr_replace($str, $shortcode, $beginShortcode, $endShortcode + 12);
}
echo $str;
}
Then you can call function parse_execute_and_echo_shortcode and giving it the path to your file containing the shortcodes.
Hope that can help someone
Check your error.log file (it should be in your apache log folder).
It probably has to do with add_shortcode not existing as a function.
Put your shortcode in the file /wp-includes/shortcodes.php this way you make sure it will be loaded when all the blows and whistles are up and running.