Plugin deinstallieren, aktivieren, deaktivieren: typische Funktionen und Anleitungen
-
-
Ich habe so viel Zeit damit verschwendet,es zum Laufen zubringen.Das Problemist,dass der Init-Hookinnerhalb der Registrierung von Hooksnichtfunktioniert.Ichnehme an,dass keineinziger Haken (Aktion oder Filter)nicht sofrühfunktioniert.Lesen Sie die Notizenper Link unten. http://codex.wordpress.org/Function_Reference/register_activation_hook Es heißt: "Das Registrieren des Hooksin Ihrem Plugins_loaded-Hookist zu spät und wirdnicht ausgeführt! (Auch wennesfür register_deactivation_hookbis zum wp_loaded-Hook zufunktionieren scheint.)"I wasted so much time trying to get it working. The problem is that init hook not working inside of registering hooks. I suppose that not one hook (action or filter) will not work so early. Read the notes by link below. http://codex.wordpress.org/Function_Reference/register_activation_hook It says: "Registering the hook inside your plugins_loaded hook is too late and it won't run! (Even when it seems to work for register_deactivation_hook until the wp_loaded hook.)"
- 0
- 2011-11-09
- Anton
-
Ichbin derjenige,der den Kodex auf das aktualisiert hat,was Sieerwähnt haben,daher wird diesin der obigen ↑ Antwortberücksichtigt.:) :)I'm the one who updated the codex to what you mentioned, so this is considered in the above ↑ answer. :)
- 0
- 2012-02-28
- kaiser
-
1 Antworten
- Stimmen
-
- 2013-04-09
Um das aktuelle System auferforderliche Funktionen wie PHP-Version oderinstallierte Erweiterungen zutesten,können Sie Folgendes verwenden:
<?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: http://toscho.de * Licence: MIT * License URI: http://opensource.org/licenses/MIT */ /* * Don't start on every page, the plugin page is enough. */ if ( ! empty ( $GLOBALS['pagenow'] ) && 'plugins.php' === $GLOBALS['pagenow'] ) add_action( 'admin_notices', 't5_check_admin_notices', 0 ); /** * Test current system for the features the plugin needs. * * @return array Errors or empty array */ function t5_check_plugin_requirements() { $php_min_version = '5.4'; // see http://www.php.net/manual/en/extensions.alphabetical.php $extensions = array ( 'iconv', 'mbstring', 'id3' ); $errors = array (); $php_current_version = phpversion(); if ( version_compare( $php_min_version, $php_current_version, '>' ) ) $errors[] = "Your server is running PHP version $php_current_version but this plugin requires at least PHP $php_min_version. Please run an upgrade."; foreach ( $extensions as $extension ) if ( ! extension_loaded( $extension ) ) $errors[] = "Please install the extension $extension to run this plugin."; return $errors; } /** * Call t5_check_plugin_requirements() and deactivate this plugin if there are error. * * @wp-hook admin_notices * @return void */ function t5_check_admin_notices() { $errors = t5_check_plugin_requirements(); if ( empty ( $errors ) ) return; // Suppress "Plugin activated" notice. unset( $_GET['activate'] ); // this plugin's name $name = get_file_data( __FILE__, array ( 'Plugin Name' ), 'plugin' ); printf( '<div class="error"><p>%1$s</p> <p><i>%2$s</i> has been deactivated.</p></div>', join( '</p><p>', $errors ), $name[0] ); deactivate_plugins( plugin_basename( __FILE__ ) ); }
Testen Siemit einem Checkfür PHP 5.5:
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: http://toscho.de * Licence: MIT * License URI: http://opensource.org/licenses/MIT */ /* * Don't start on every page, the plugin page is enough. */ if ( ! empty ( $GLOBALS['pagenow'] ) && 'plugins.php' === $GLOBALS['pagenow'] ) add_action( 'admin_notices', 't5_check_admin_notices', 0 ); /** * Test current system for the features the plugin needs. * * @return array Errors or empty array */ function t5_check_plugin_requirements() { $php_min_version = '5.4'; // see http://www.php.net/manual/en/extensions.alphabetical.php $extensions = array ( 'iconv', 'mbstring', 'id3' ); $errors = array (); $php_current_version = phpversion(); if ( version_compare( $php_min_version, $php_current_version, '>' ) ) $errors[] = "Your server is running PHP version $php_current_version but this plugin requires at least PHP $php_min_version. Please run an upgrade."; foreach ( $extensions as $extension ) if ( ! extension_loaded( $extension ) ) $errors[] = "Please install the extension $extension to run this plugin."; return $errors; } /** * Call t5_check_plugin_requirements() and deactivate this plugin if there are error. * * @wp-hook admin_notices * @return void */ function t5_check_admin_notices() { $errors = t5_check_plugin_requirements(); if ( empty ( $errors ) ) return; // Suppress "Plugin activated" notice. unset( $_GET['activate'] ); // this plugin's name $name = get_file_data( __FILE__, array ( 'Plugin Name' ), 'plugin' ); printf( '<div class="error"><p>%1$s</p> <p><i>%2$s</i> has been deactivated.</p></div>', join( '</p><p>', $errors ), $name[0] ); deactivate_plugins( plugin_basename( __FILE__ ) ); }
Test with a check for PHP 5.5:
-
Berühren Sie verwirrt,so dass hierim Grunde kein Aufruf von "register_activation_hook"erfolgt - warumnicht?Wird dies auch vor odernach "register_activation_hook" ausgelöst und wird "register_activation_hook" ausgelöst,selbst wenn das obengenanntenichterfolgreichist?Touch confused, so basically there isn't a call to `register_activation_hook` here -- why not use it? Also will this fire before or after `register_activation_hook` and will `register_activation_hook` fire even if the above doesn't pass?
- 0
- 2013-07-31
- orionrush
-
Es wirdnurnach dem Aktivierungs-Hook auf der Plugin-Seite ausgeführt.It runs after the activation hook on the plugin page only.
- 0
- 2013-07-31
- fuxia
-
Ich verstehe - aber wenn das Plugin außerhalb der Plugin-Seite aktiviertist (z. B. als Teileiner Themenabhängigkeit),werden Ihre Überprüfungen übersprungen,nein?Also habeich versucht,"add_action" ("admin_notices","t5_check_admin_notices",0); "ineinen Aktivierungs-Hook zu verschieben,und das Plugin wird aktiviert,ohne die Überprüfungen durchzuführen...I see - but if the plugin is activated outside the plugin page (say as part of a theme dependency) then your checks will get skipped no? So I tried moving `add_action( 'admin_notices', 't5_check_admin_notices', 0 );` into an activation hook and the plugin activates without performing the checks . . .
- 0
- 2013-07-31
- orionrush
-
@kaiser haterklärt,wie der Aktivierungs-Hookfunktioniert,ich wollteeine Alternative zeigen.Wenn das Pluginnichtpro Plugin-Seite aktiviertist,kannein schwerwiegender Fehler auftreten,ja.Dieser Ansatz kannnicht ohneernsthaften Umschreiben aneinem Aktivierungs-Hookfunktionieren,da dieser Hooknach "admin_notices" ausgelöst wird.@kaiser has explained how the activation hook works, I wanted to show an alternative. If the plugin is not activated per plugin page a fatal error might happen, yes. This approach cannot work on an activation hook without serious rewrite, because that hook fires after `admin_notices`.
- 0
- 2013-07-31
- fuxia
-
Eigentlichnur über deneinfachen Weggestolpert: http://stackoverflow.com/a/13927297/362445Actually just stumbled on the easy way: http://stackoverflow.com/a/13927297/362445
- 0
- 2013-07-31
- orionrush
-
Denke,das sollteestun: `register_activation_hook (__FILE__,function () { add_option ('Activated_Plugin','Plugin-Slug'); }); add_action ('admin_init','load_plugin'); Funktion load_plugin () { if (! current_user_can ('enabled_plugins')) return; if (is_admin () &&get_option ('Activated_Plugin')=='Plugin-Slug') { delete_option ('Activated_Plugin'); add_action ('admin_notices','t5_check_admin_notices',0); }} } `Think this should do it: `register_activation_hook( __FILE__, function() { add_option('Activated_Plugin','Plugin-Slug'); }); add_action('admin_init', 'load_plugin'); function load_plugin() { if ( ! current_user_can( 'activate_plugins' ) ) return; if(is_admin()&&get_option('Activated_Plugin')=='Plugin-Slug') { delete_option('Activated_Plugin'); add_action( 'admin_notices', 't5_check_admin_notices', 0 ); } }`
- 0
- 2013-07-31
- orionrush
Ichmacheein WordPress-Plugin.Was sindtypische Dinge,dieichin die Deinstallationsfunktion aufnehmen sollte?
Sollichbeispielsweise Tabellen löschen,dieichin der Installationsfunktionerstellt habe?
Bereinigeichmeine Optionseinträge?
Sonstnochetwas?