how to activate wordpress plugins internally? - wordpress

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..

Related

Custom page template on Wordpress 6.0 not shown when i edit a page

i've created a php file in my theme folder named page-test.
When i try to bind this template to any page, i can't see it
Impossible to guess what is the problem. Someone could help me ?
Thx
Can you make sure your child theme is activated, i mean where you put your file, also can you change file name to page_test.php
Let me know if problem fixed.
Ok i got it.
It's not in "page attribute" anymore but in the "modele (in french)" part.

Fire an action right after Appearance > Theme Options has been saved

I just started working with Wordpress (v. 3.6.1).
I have OptionTree installed and as it seems it handles the Theme Options page. I want to run my function (in a plugin or wherever else) right after the user saves the changes of this page.
So far I found out that option-tree/includes/ot-settings-api.php generates the form and it sets the form action to options.php (which is a wordpress core file). I was thinking about change the action to my custom php file and handle the save procedure and finally runs my own function. But this solution looks pretty ugly.
I wonder if there's another way to get the job done.
Thanks.
Thanks to #Sheikh Heera link (tutsplus) I could find a solution.
I think this is some kind of hack and I still don't know if it is the best way. Anyway I did this:
Create a file your-theme-settings.php in your theme lib folder.
Let Wordpress knows about your file by adding this code in your theme functions.php:
include_once('lib/your-theme-settings.php');
Add this code to your-theme-settings.php:
function your_theme_register_settings() {
register_setting('option_tree', 'option_tree', 'your_theme_validate_options');
}
function your_theme_validate_options($input) {
// do whatever you have to do with $input.
}
add_action('admin_init', 'your_theme_register_settings');
In step 3, I put 'option_tree' as 1st and 2nd argument of register_settings function, because I noticed that the Option Group and Option Name of OptionTree plugin is option_tree.
I'm not sure if this is the best solution, so I would be glad if you shares your ideas.

Call to undefined function, get_settings 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.

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.

Wordpress goes blank after publishing new content?

So out of no where after clicking the publish button the page just goes blank...
The url at the top is:
http://www.brightboxstudios.com/sociabulls/wp-admin/post.php
What's good news is it still posts the content :)
Not great at coding so details rock :)
I was getting same error, when I update the site content and press update it goes to /wp-admin/post.php and this appears as blank page.
It is solved by:
I removed all the spaces at the end of functions.php file, I had included a widget and there were some spaces in between older content and new widget function, when I removed the spaces everything is working fine.
if that don't work then
- go into wp-config.php and find this "define('WP_DEBUG', false);"
change its value, if it is flase, make it true or if it is true change it to false.
And everything must work Good.
Thanks
A blank page usually means Apache failed. Check your error logs. You'll probably find a line that starts with:
PHP Fatal error:
You can also display your errors on the screen instead of looking at the log.
There will be many reasons for blank page, you have not mention version for wp, php etc.
To solve wordpress blank page issue follow the steps
disable all plugin and try (if there is an error in plugins then enable 1 by 1)
switch to default theme and try (if there is an error in theme)
rename .htaccess and param-link to default (page/post id)

Resources