Ich entwickle ein Plugin und benutze normale Hooks und Filter. Ich versuche jetzt jedoch, meine Funktion an die Antworten der Admin-Ajax-Aufrufe von WP zu binden.
Zum Beispiel im Bildschirm Plugins Add New Ich möchte meine Funktion ausführen, nachdem die Ajax-Installation eines Plugins erfolgreich abgeschlossen wurde und die Schaltfläche "Activate" (Aktivieren) angezeigt wird. Wie kann ich dort meine Funktion bei erfolgreicher Ajax-Antwort auslösen?
Mit " plugin_install_action_links " kann ich die Aktionslinks über PHP steuern, aber was ist die Ajax-Entsprechung (wenn es eine gibt)?
WordPress Core ist etwas, bei dem Sie keine eigenen Hooks erstellen können. Mit diesen werden Hooks in WordPress erstellt
apply_filters
apply_filters_ref_array
apply_filters_deprecated
do_action
do_action_ref_array
do_action_deprecated
Das Einzige, was Sie tun können, ist, Ihre Funktion bei einem bestimmten WordPress-Core-Hook zu registrieren. Aber wo sind diese Haken?
Sie können diese Hooks in einer Funktion mit dem Namen activate_plugin
erwarten.
File: wp-admin/includes/plugin.php
512: /**
513: * Attempts activation of plugin in a "sandbox" and redirects on success.
514: *
515: * A plugin that is already activated will not attempt to be activated again.
516: *
517: * The way it works is by setting the redirection to the error before trying to
518: * include the plugin file. If the plugin fails, then the redirection will not
519: * be overwritten with the success message. Also, the options will not be
520: * updated and the activation hook will not be called on plugin error.
521: *
522: * It should be noted that in no way the below code will actually prevent errors
523: * within the file. The code should not be used elsewhere to replicate the
524: * "sandbox", which uses redirection to work.
525: * {@source 13 1}
526: *
527: * If any errors are found or text is outputted, then it will be captured to
528: * ensure that the success redirection will update the error redirection.
529: *
530: * @since 2.5.0
531: *
532: * @param string $plugin Plugin path to main plugin file with plugin data.
533: * @param string $redirect Optional. URL to redirect to.
534: * @param bool $network_wide Optional. Whether to enable the plugin for all sites in the network
535: * or just the current site. Multisite only. Default false.
536: * @param bool $silent Optional. Whether to prevent calling activation hooks. Default false.
537: * @return WP_Error|null WP_Error on invalid file or null on success.
538: */
539: function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
Beachten Sie, dass es einen optionalen Parameter
@param bool $silent
gibt, der verhindert Aktivierungs-Hooks aufruft. Standardmäßig istfalse
eingestellt.
In dieser Funktion finden Sie derzeit folgende Hooks:
File: wp-admin/includes/plugin.php
563: if ( ! $silent ) {
564: /**
565: * Fires before a plugin is activated.
566: *
567: * If a plugin is silently activated (such as during an update),
568: * this hook does not fire.
569: *
570: * @since 2.9.0
571: *
572: * @param string $plugin Plugin path to main plugin file with plugin data.
573: * @param bool $network_wide Whether to enable the plugin for all sites in the network
574: * or just the current site. Multisite only. Default is false.
575: */
576: do_action( 'activate_plugin', $plugin, $network_wide );
Einer noch...
File: wp-admin/includes/plugin.php
563: if ( ! $silent ) {
...
578: /**
579: * Fires as a specific plugin is being activated.
580: *
581: * This hook is the "activation" hook used internally by register_activation_hook().
582: * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename.
583: *
584: * If a plugin is silently activated (such as during an update), this hook does not fire.
585: *
586: * @since 2.0.0
587: *
588: * @param bool $network_wide Whether to enable the plugin for all sites in the network
589: * or just the current site. Multisite only. Default is false.
590: */
591: do_action( "activate_{$plugin}", $network_wide );
Und eine, die Sie tatsächlich brauchen ...
File: wp-admin/includes/plugin.php
605: if ( ! $silent ) {
606: /**
607: * Fires after a plugin has been activated.
608: *
609: * If a plugin is silently activated (such as during an update),
610: * this hook does not fire.
611: *
612: * @since 2.9.0
613: *
614: * @param string $plugin Plugin path to main plugin file with plugin data.
615: * @param bool $network_wide Whether to enable the plugin for all sites in the network
616: * or just the current site. Multisite only. Default is false.
617: */
618: do_action( 'activated_plugin', $plugin, $network_wide );
Ich habe gerade nach den Hook-Generator-Funktionen wie do_action
gesucht.
Was Sie tun plugin_install_action_links
ist ein filer Hook-Typ. Filter sind in der Regel dazu da, replace
bestimmte Dinge.
File: wp-admin/includes/class-wp-plugin-install-list-table.php
519: /**
520: * Filters the install action links for a plugin.
521: *
522: * @since 2.7.0
523: *
524: * @param array $action_links An array of plugin action hyperlinks. Defaults are links to Details and Install Now.
525: * @param array $plugin The plugin currently being listed.
526: */
527: $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
Mit "plugin_install_action_links" kann ich die Aktionslinks über PHP steuern, aber was ist die Ajax-Entsprechung (wenn es eine gibt)?
Es gibt eine Datei namens admin-ajax.php
. Sie können diese Datei untersuchen und Hooks verwenden, um Ihre spezifischen Aufgaben zu erledigen. Derzeit sind in admin-ajax.php
jedoch keine Filter definiert.