Call to undefined function, get_settings wordpress - wordpress

I have a Wordpress plugin with index.php that contains this line of code:
$plugindir = get_settings('home').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
When I echo that code I get this output:
my.site.nl/wp-content/plugins/Tutorials
On the index page I also have a button that redirects to uploader.php,
inside uploader.php I have this code:
$plugindir = get_settings('home').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
When I run the program I get an error that says:
Call to undefined function get_settings()
This error only applies on uploader.php, index.php works fine!
So it seems that I have to somehow let the uploader.php know that get_settings is a Wordpress function and it should recognize it, but I don't know how and I also don't know why the index page runs fine with the same code without including anything. I hope someone can help me out here.

index.php brings in all the WordPress functions as it loads. If you're loading another PHP file directly, you'll need to load in the WordPress functions by calling wp-load.php. See this answer (and the comments - you don't need to load all the files the answer mentions).

Try to use get_option('home') in place of get_settings('home') it may work.

Related

Wordpress shortcode does not work

I'm trying to create a simple shortcode function that would work in a link like this:
href="http://www.website.com">[short_code]
Please note, I had to remove the a tag because it wouldn't show. I want to be able to change the anchor text of a link with a single edit across multiple pages/posts.
to accomplish this, this is what I've done:
I've added include 'myshortcodes.php'; to functions.php file and created a file called myshortcodes.php
within that file I have the following code:
<?php
add_shortcode('hw', 'hello');
function hello() {
return 'Click Here For More Info';
}
Now when I put [hw] in href="http://www.website.com">[hw] it does work on my local wp install, however, when I do the same on my live server, it doesn't work, no matter what I do. It returns [hw] instead of 'Click Here For More Info'. Any ideas why? Thanks!
Maybe problems with php interpreter on server side.
Check if your server side doing include right.
Below and above your shortcode function place echo with something, and if it will echoes on your site, then we need to dig deeper.
And if it will not echoes, than the problem is in include function.

Integrating a Wordpress query into a PHPBB theme template

UPDATE: Managed to solve this by accident, answer is below.
I'm working on a site which requires several of the 'promoted' posts from the Wordpress blog to be displayed at the top of the forum.
(This is literally the only interaction between WP and PHPBB, there's no single sign-on or anything.)
I'm following the instructions listed here:
http://codex.wordpress.org/Integrating_Wordpress_with_Your_Website
and here:
https://wiki.phpbb.com/Tutorial.Template_syntax
As such, I've edited my theme's overall_header.html file to include this at the top:
<!-- PHP -->
define('WP_USE_THEMES', false);
<!-- ENDPHP -->
<!-- INCLUDEPHP ../wp-blog-header.php -->
Later, at the correct place in overall_header.html, I need to call the actual php file which contains the query, which I do so like so:
<!-- INCLUDEPHP ../wp-content/themes/mytheme/heroarea-secondary.php -->
But when I load the forum, I get a fatal error which causes the page to stop loading, with the following error message:
Fatal error: Call to a member function main() on a non-object in C:\Apache24\htdocs\test\wp-includes\functions.php on line 808
Now I know there's not actually anything wrong with functions.php so I assume the issue is in my configuration, but I have no idea why it doesn't work.
If I create a seperate, standalone PHP file which just has this:
<?php
define('WP_USE_THEMES', false);
require('C:/Apache24/htdocs/test/wp-blog-header.php');
include('C:/Apache24/htdocs/test/wp-content/themes/mytheme/heroarea-secondary.php');
?>
Then that works perfectly without any troubles and pulls the correct three posts from the 'promoted' category as desired. But as soon as I try and replicate it in PHPBB, I get the fatal error listed above.
Can anyone point me in the right direction?
I've tried including wp-load.php and wp-config.php but neither make a difference.
I actually just now managed to solve the issue.
The solution is to add
define('WP_USE_THEMES', false);
require('path/to/wp-blog-header.php');
To the bottom of common.php in the phpBB root directory.
Hope this helps anybody else in the future!

Warning: Cannot modify header information when using require or require_once

I'm WordPress newbie.
I'm creating a plugin that redirect to custom login page each unregistered user access a website, let say the custom login page : custom_login.php.
I am able to create a code to redirect it but it seems no wordpress functions work in custom_login.php. So, I think I have to load something through the file. I guess wp-load.php.
Then I add some codes below at the top of the page :
<?php
require( 'd:\xampp\htdocs\wordpress\wp-load.php' );
?>
But then I got this error :
Warning: Cannot modify header information.....
I changed to require_once but still get similar error.
Some solutions of this forum threads advice to delete any whitespace. Frankly, I don't know what does it mean but I tried to delete all whitespace anyway so that the code become :
<?php require('d:\xampp\htdocs\wordpress\wp-load.php');?>
But it does not solve anything. The error is still exist.
Please help me, the expert ones.
Thanks in advance
Try inserting a system path relative to localhost, like this:
require( '/wp-load.php' ); // or just
require( 'wp-load.php' ); //
All depends on the location you are trying to include wp-load.php from.
On the other hand, you don't have to include wp-load.php if you place the file custom_login.php. in the stylesheet directory as a template or as a custom page. The way to do it is:
.1 Rename the file to page-custom-login.php
.2 Move the file to the stylesheet directory (The theme directory)
.3 Go to admin and create a new page with the title "custom login"
That's all. Now WP will treat that file as a single custom page.
They are correct - you have a space before the opening php tag in one of your files. It can be a bit tricky to find, but look hard.
If you can't find it, try looking for ob_clean() php function to help.

Theming Webform in Drupal

I'm trying to theme my webform but I can't seem to get the new webform_form_#.tpl.php to load properly. When I go to the node page I get a blank page on firefox with an empty body.
So in Template.php i've added the following line (my webform is on node 4)
function phptemplate_webform_form_4 ($form) {
return _phptemplate_callback('webform_form_4', array('form' => $form));
}
I have a webform_form_4.tpl.php in my sites/all/theme/forest_floor/ directory which is a copy paste from the modules/webform/templates/webform-form.tpl.php
I've tried following the guide here, but I still get nothing when I visit the node page. Yes i've cleared the cache.
I've also tried removed everything in the webform_form_4.tpl.php and just added the
echo form_render($form); like between <?php ?> and I still get nothing.
Any suggestions?
A blank screen aka WSOD is properly due to a fatal PHP parse error. Try checking your apache error log.
The link you are following on drupal node/79086 is for the older v4 of drupal Maybe this can help you http://drupal.org/node/335020
Weird it won't let me login to reply (for some reason) it doesn't think i'm the one who wrote the question.
Checked the apache logs
PHP Fatal error: Call to undefined function _phptemplate_callback() in template.php
Am I calling an old function?

how to activate wordpress plugins internally?

I am creating a small utility which will help to rebuild install.php of WordPress.
What I want to achieve is, when user will install WordPress with this customized install.php, he'll get some plugins already activated.
I tried to put these lines at the end of install.php file
require_once('path...\wordpress\wp-includes\plugin.php');
activate_plugin('hello.php');
that activates Hello Dolly plugin but shows error 'invalid datatype for second argument on line 310' for plugin.php
Also, if I try plugins which are inside a folder, for example
require_once('path...\wordpress\wp-includes\plugin.php');
activate_plugin('plugin-folder\file.php');
its not getting activated.
[i've tried different combinations for sending arguments, echoing arguments in plugin.php etc. but activate_plugin() does receive correct argument. ]
Consider that plugins are already copied in wp-content/plugins directory.
Whats wrong? Is there any different way to achieve this?
Thanks
Instead of including plugin.php file, include the wp-load.php file
require_once('path...\wordpress\wpload.php');
wpload.php will automatically include all the file in the correct order, which should solve your issue.
Atlast I came up with a new activate_plugin function that I added to that file. Problem in old function is the check for active plugins. At first since there is no active plugin, it was returning null value, showing the error. I removed that for my use.
why we dont see errors when using from wordpress dashboard ? wordpress hides them.
Thanks anyway..

Resources