Tag Info

Hot answers tagged

68

There are three different hooks. They trigger in the following cases: Uninstall Deactivation Activation How-to trigger functions safely during the scenarios The following shows the right ways to safely hook callback functions that get triggered during the mentioned actions. As you could use this code in a plugin that uses plain functions, a class or ...


12

Your question is a bit specific if you "only" want to automatically import some posts/pages. There are other ways to do this then using a XML export file. If you have text-only posts, then you should use LOAD DATA INFILE. At first you have to export your posts. global $wpdb, $wp_filesystem; $tables = array( 'posts' => array( 'posts', ...


10

This is how I did it in some web apps: function run_activate_plugin( $plugin ) { $current = get_option( 'active_plugins' ); $plugin = plugin_basename( trim( $plugin ) ); if ( !in_array( $plugin, $current ) ) { $current[] = $plugin; sort( $current ); do_action( 'activate_plugin', trim( $plugin ) ); update_option( ...


9

To test the current system for required featurs like PHP version or installed extensions you can use something like that: <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Check Plugin Requirements * Description: Test for PHP version and installed extensions * Plugin URI: * Version: 2013.03.31 * Author: Thomas Scholz * Author URI: ...


6

Plugin activation process is coded to work with WP admin interface. It performs some checks to prevent enabling plugins with errors (loading such on start might break WP). It is handled by activate_plugin() function (source) which is documented as unusable elsewhere. So if you want to activate plugin by code the goal itself is relatively easy - to change ...


6

Maybe using the wp_redirect() function in the activation hook. In the following example myplugin_settings is a placeholder. Normally this simply is the $hook_suffix you get back from $hook_suffix = add_menu_page( /* etc. */ ); and similar functions. register_activation_hook(__FILE__, 'myplugin_activation'); function myplugin_activation() {     // Don't ...


5

Here is the fixed version of your code. class vsetup { function __construct() { register_activation_hook(__FILE__,array($this,'activate')); add_action( 'init', array( $this, 'create_taxonomies' ) ); } function activate() { $this->create_taxonomies(); wp_insert_term('Action','genre'); ...


5

For testing purposes you can use the log system (php_error.log): error_log('Plugin activated', 0); // Check for DB table existance if(!$this->hasDBTable()){ error_log('Database not present', 0); if($this->createCELabelsDBTables()){ error_log('Database was created.', 0); } else { error_log('Error creating the CE Labels ...


4

if( $installed_ver != $simple_location_version ) { on first run, $installed_ver is an empty string and $simple_location_version is NULL, so this inequality test will fail and your SQL will never be executed. if you check for strict inequality, it will work: if( $installed_ver !== $simple_location_version ) {


4

This is a little late, but I had to figure out the other part of this question on my own and thought I would share. To create a default menu and place it into a theme location, you will need a pre-existing location in the theme, and you will need to ensure any pages you link in your menu are also created already. In your theme's function.php, register any ...


4

Plugins are stored in an array in the 'active_plugins' option. The array contains the file path to each plugin that is active. To activate a plugin you need to determine what it's path will be, then pass that path to activate_plugin($plugin_path). This is easier said than done though, and (at least in 2.9) the core code does not make it easy. Before ...


4

Wrap your function in if( ! function_exists( 'wp_authenticate' ) ) to get rid of the error and successfully activate your plugin: if( ! function_exists( 'wp_authenticate' ) ){ function wp_authenticate(){} } This is necessary because in the context of activating a plugin, the function does already exist, only after it is activated will your plugin load ...


4

Allow me to re-introduce 2 things here: (a) "I am not asking how to... I've got that part sorted..." »» I've learnt over time to be OK with the fact that the approach to issues/fixes doesn't necessarily require some 'visible association' with the issue at hand. (b) "...would I have to do to strip out the parts..." "...clients are tradesmen, so even ...


4

You should be able to do it like this: register_activation_hook(__FILE__, 'my_plugin_activate'); add_action('admin_init', 'my_plugin_redirect'); function my_plugin_activate() { add_option('my_plugin_do_activation_redirect', true); } // Solution 1 function my_plugin_redirect() { if (get_option('my_plugin_do_activation_redirect', false)) { ...


3

You can use wp_get_theme: <?php $theme = wp_get_theme(); // gets the current theme if ('twentytwelve' == $theme->name || 'twentytwelve' == $theme->parent_theme) { // if you're here twenty twelve is the active theme or is // the current theme's parent theme } Or, you can simply check if a function in twentytwelve exists -- which is likely ...


3

You are right, this is very hacky. What I ending up doing was creating two new page templates Register and Activate and creating two new WordPress pages using those templates and then using a filter in my functions.php file to modify the behaviour one wpmu_signup_user_notification. Users will register on this new Register page and they will be sent an ...


3

Per the WP Codex, you need to be sure you are passing the directory and file: <?php If (is_plugin_active('plugin-directory/plugin-file.php')) { //plugin is activated } ?>


3

Comments might have been closed once. If you change this option later globally it doesn’t affect existing posts when comments were turned off per post. To test if comments really work create a new post and enable the discussion meta box on that screen: If you can comment while all plugins are disabled and the theme is TwentyEleven (default) – then ...


3

Link category is a simple taxonomy just like categories , named: link_category so to add one you can use wp_insert_term() eg: wp_insert_term( 'My link category', // the term 'link_category', // the taxonomy array( 'description'=> 'this is a description.', 'slug' => 'my-link-category' ) ); and to make all this happen on plugin ...


2

Code like this can do the trick. function plugin_activation_check(){ if ( some_check_here() ) { // this is the fail case deactivate_plugins(basename(__FILE__)); // Deactivate ourself wp_die("Message to user."); } } register_activation_hook(__FILE__, 'plugin_activation_check');


2

You could check if the constant SITE_ID_CURRENT_SITE matches get_current_site()->id. The following does this for the activation. During runtime you have to check it again. register_activation_hook( __FILE__, 'force_main_site_installation' ); function force_main_site_installation() { if ( defined( 'SITE_ID_CURRENT_SITE' ) and ...


2

You can add those without a button: register_activation_hook( __FILE__, 'my_plugin_install_function'); function my_plugin_install_function() { //post status and options $post = array( 'comment_status' => 'closed', 'ping_status' => 'closed' , 'post_author' => 1, 'post_date' => date('Y-m-d ...


2

Plugins are activated in a sandbox and their output is captured to check for errors, and redirect if activation was successful. Adding something in an activation hook will cause it to run once in that "invisible" sandbox on activation, and that's it. When you add an action, you're only adding it for that request, if you want your menu item to be visible on ...


2

You can read more about the details of activation on this answer. Basically you need to hook a function to register_activation_hook() - assuming, that this is from within your main plugin folder and not a subfolder: register_activation_hook( __FILE__, 'on_activation' ); function wpse65190_on_activation() { // Add an admin notice: add_action( ...


2

Themes don't currently have activation/deactivation/installation/uninstallation hooks. Your best bet is to "fake" it somehow, perhaps with a function that only executes one time, based on a switch that gets toggled when the function executes. e.g.: <?php function wpse45817_theme_activation() { // globalize our switch global ...


2

I believe the issue is that your function that sets up the settings initially isn't getting run upon activation. Add a call to your mouldings_register_settings_initial() in the activation hook, like this: function mouldings_activate() { global $wpdb, $mouldings_options; mouldings_register_settings_initial(); if ($mouldings_options === false){ ...


2

The main problem here is: wp-activate.php includes your header.php but not the functions.php. You may get fatal errors if you use functions in you header which are defined in your functions.php. I use two new files in my themes: header-activate.php and footer-activate.php When wp-activate.php is called the constant WP_INSTALLING is set to TRUE (for no ...


2

You have two options either define you register methods as static and then you can avoid instantiating your classes or even calling the MyActivation function ex: File1.php: Class File1 { static function file1_register() { //register some short codes; } static function file1_unregister() { //unregister previous short codes; } ...


2

Plugins with Network: true in their header cannot be seen, activated or deactivated in sub sites. The reason is simple: You need super admin rights to do something with them, and their settings section (if there are any) are visible in wp-admin/network/ only. Even if you are the super admin and on a sub site you will not see those menus usually, because the ...


2

A plugin header Network: false will be ignored by WordPress … unfortunately. But the activation hook gets a parameter $network_wide, and we can use that to deactivate the plugin during activation: <?php /** * Plugin Name: Prevent Network Activation * Plugin URI: http://wordpress.stackexchange.com/questions/76145/prevent-network-activation-of-plugin * ...



Only top voted, non community-wiki answers of a minimum length are eligible