Tag Info

Hot answers tagged

74

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


13

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


12

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. THIS CODE DOESN'T WORK, READ BELOW register_activation_hook(__FILE__, 'cyb_activation'); function ...


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

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

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

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


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


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


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

We are using this wordpress plug in - New User Approve Provides functionality to approve/deny new user registrations.


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

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

To answer the The plugin generated 149 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin. Every echo statement will bring this up. Normally it's just the count of characters you echo-ed. Here is a link to my ...


2

The best hook I can find is wpmu_new_blog (line 1086, wp-includes/ms-functions.php, wpmu_create_blog()) - it passes 6 arguments like so; do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta ); $meta is an array of initial site options, not to be confused with the options generated by populate_options(). Programatically creating ...


2

Use some kind of a Controller and combine the calls to both classes in one callback for each action. The controller should be responsible for the real assignation of business logic to an event (action), not some code outside of your classes. The basic point is: Your plugin controller should not alter data, only Models should do that. The following example ...


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

if( 'twentytwelve' == get_option( 'template' ) ) { // do something }


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

Don't forget to change return to false in your af_wpmu_signup_user_notification. Otherwise two mails will be sent to user. One with the old link and one with the new one.


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



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