WordPress Plugin und Theme Aktualisierung ausblenden



Benachrichtigungen über bestimmte Plugin oder Theme Aktualisierungen, die man nicht installieren möchte, lassen sich ausblenden. Und das nicht nur gänzlich, sondern auch festgelegte Versionen.

Die einfachste und schnellste Methode ist die Änderung der Versionsnummer in der Plugin-Haupt- bzw. Theme style.css-Datei. Davon ist aber abzuraten. Es ist nicht im Sinne des Entwicklers sein Quellcode zu manipulieren. Ausserdem kann eine spätere Verwirrung über die tatsächlich installierte Version entstehen. Eine Filterfunktion in einem eigenen Plugin zu schreiben ist die bessere Lösung. Das hier weiter unten als Beispiel vorgestellte PHP-Code kann als Ansatz für ein Plugin dienen.

Update ausblenden

Nach der Installation und Aktivierung eines Plugins oder Themes erscheint im Dashboard eine Benachrichtigung über die Aktualisierung auf die neuste Version, falls es eine gibt. WordPress durchsucht standardmäßig regelmäßig alle 12 Stunden die Repositories nach neueren Versionen. Findet er eine, wird diese als Benachrichtigung und Aufforderung zur Aktualisierung angezeigt.

akismet-update-notification-2
Benachrichtigung über eine Plugin Aktualisierung
twentyfifteen-update-notification-2
Benachrichtigung über eine Theme Aktualisierung

Möchte man aus irgendeinem Grund die Updates nicht installieren und darüber auch nicht mehr informiert werden, kann man die Nachricht dauerhaft rausfiltern und ausblenden. Man braucht dafür ein Plugin, das auf die Filter-Hooks site_transient_update_plugins und site_transient_update_themes zugreifft und die vorhandene Update-Informationen entfernt.


Anzeige

Update Filter Beispiel

Das hier aufgeführe Beispiel ist kein Plugin. Es demonstriert die Filterfunktionen für Plugin und Theme Updates und dient als Ansatz für das eigene Plugin.

Filterfunktionen

In dem Verzeichnis /wp-content/themes/{aktivierter-theme-name}/inc erstellt man zwei neue Dateien: disable-upgrades.php und disable-upgrades.json.

In der disable-upgrades.php wird folgendes eigetragen (die Pfade zum Theme anpassen!):

<?php
/** WordPress plugin and theme Upgrade Deactivation */

if ( ! function_exists( 'plugins_api' ) ) {
      require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
}

if ( ! function_exists( 'themes_api' ) ) {
      require_once( ABSPATH . 'wp-admin/includes/theme.php' );
}

/** Remove plugin update notifications */
function remove_plugin_update_notifications( $value ) {

	//var_dump($value); //show object structure
	
    if ( isset( $value ) && is_object( $value ) ) {
		// load disabled plugin upgrade versions from json file
		$string = file_get_contents( ABSPATH . 'wp-content/themes/seos-magazine-child/inc/disable-upgrades.json' );
		$obj_array = json_decode($string);
		if ( ! isset ( $obj_array->plugins )) {
			return $value;
		}
		$plugins = $obj_array->plugins;
		
		//disable plugin upgrade notifications
		foreach ( $plugins as $plugin ) {
			if ( isset( $value->response[ $plugin->file ] ) ) {
				
				/** Get last update version */
				$update_version = $value->response[$plugin->file]->new_version;

				/** Remove plugin update notification if listed */
				if ( in_array( "all", $plugin->disabled_versions ) || in_array( $update_version, $plugin->disabled_versions )) {
					unset( $value->response[ $plugin->file ] );
				}
			}
		}
    }

    return $value;
}
add_filter( 'site_transient_update_plugins', 'remove_plugin_update_notifications' );

/** Remove theme update notifications */
function remove_theme_update_notifications( $value ) {

	//var_dump($value); //show object structure
	
    if ( isset( $value ) && is_object( $value )) {
		// load disabled theme upgrade versions from json file
		$string = file_get_contents( ABSPATH . 'wp-content/themes/seos-magazine-child/inc/disable-upgrades.json' );
		$obj_array = json_decode($string);
		if ( !isset ( $obj_array->themes )) {
			return $value;
		}
		$themes = $obj_array->themes;
		
		//disable themes upgrade notifications
		foreach ( $themes as $theme ) {
			if ( isset( $value->response[ $theme->slug ] ) ) {

				/** Get last update version */
				$update_version = $value->response[$theme->slug]['new_version'];

				/** Remove theme update notification if listed */
				if ( in_array( "all", $theme->disabled_versions ) || in_array( $update_version, $theme->disabled_versions )) {
					unset( $value->response[ $theme->slug ] );
				}	
			}
		}
    }

    return $value;
}
add_filter( 'site_transient_update_themes', 'remove_theme_update_notifications' );
?>

Konfigurationsdatei

In der disable-upgrades.json-Datei werden die Plugin und Theme Versionen eingetragen, deren Aktualisierungsbenachrichigungen augeblendet werden sollen.

{
	"plugins": [
	
		{
			"slug":"loco-translate",
			"file":"loco-translate/loco.php",
			"disabled_versions":[ "all" ]
		},
		{
			"slug":"akismet",
			"file":"akismet/akismet.php",
			"disabled_versions":[ "4.1", "4.1.1" ]
		}
	],
	"themes": [
	
		{
			"slug":"twentyfifteen",
			"disabled_versions":[ "2.3" ]
		}
	]
}

Wird anstelle einer Versionsnummer der Wert all angegeben, werden alle zukunftigen Update-Benachrichtigungen ausgeblendet.

Das JSON-Hauptobjekt besteht aus zwei Objektarrays (plugins und themes). Die einzelnen Plugin- und Theme-Objekte enthalten ausser ihrer Hauptordnernamen (slug) und Dateipfad bei Plugins (file), einen disabled_versions-Array mit den unterdrückten Aktualisierungsbenachrichtigungen für die angegebenen Versionen. Nach der Ausführung werden sie nicht mehr angezeigt.

akismet-update-disabled-2
Keine Plugin-Aktualisierung auf bestimmte Version
twentyfifteen-update-disabled-2
Keine Theme-Aktualisierung auf bestimmte Version


Anzeige

admin.php ergänzen

Am Ende der Datei /wp-admin/includes/admin.php werden die Filterfunktionen eingebunden (Theme-Pfad anpassen!):

require_once(ABSPATH . 'wp-content/themes/seos-magazine-child/inc/disable-upgrades.php');

Diese Zeile wird nach einer WordPress-Aktualisierung überschrieben und entfernt. Aus diesem Grund ist es sinnvol ein eigenes Plugin zu erstellen, damit man sie nicht immer wieder neu eintragen muss.

$value-Hook-Objekt Struktur

Das von dem site_transient_update_plugins-Hook übergebene Objekt $value hat folgende Struktur:

object(stdClass)[5923]
  public 'last_checked' => int 1549198443
  public 'checked' => 
    array (size=6)
      'akismet/akismet.php' => string '4.1' (length=3)
      'hello.php' => string '1.7' (length=3)
      'loco-translate/loco.php' => string '2.2.0' (length=5)
      'theme-check/theme-check.php' => string '20160523.1' (length=10)
      'wordpress-importer/wordpress-importer.php' => string '0.6.4' (length=5)
      'wp-disable-update/wp-disable-update.php' => string '1.0.0' (length=5)
  public 'response' => 
    array (size=1)
      'akismet/akismet.php' => 
        object(stdClass)[5921]
          public 'id' => string 'w.org/plugins/akismet' (length=21)
          public 'slug' => string 'akismet' (length=7)
          public 'plugin' => string 'akismet/akismet.php' (length=19)
          public 'new_version' => string '4.1.1' (length=5)
          public 'url' => string 'https://wordpress.org/plugins/akismet/' (length=38)
          public 'package' => string 'https://downloads.wordpress.org/plugin/akismet.4.1.1.zip' (length=56)
          public 'icons' => 
            array (size=2)
			  '2x' => string 'https://ps.w.org/akismet/assets/icon-256x256.png?rev=969272' (length=59)
			  '1x' => string 'https://ps.w.org/akismet/assets/icon-128x128.png?rev=969272' (length=59)
          public 'banners' => 
            array (size=1)
              '1x' => string 'https://ps.w.org/akismet/assets/banner-772x250.jpg?rev=479904' (length=61)
          public 'banners_rtl' => 
            array (size=0)
              empty
          public 'tested' => string '5.0.3' (length=5)
          public 'requires_php' => boolean false
          public 'compatibility' => 
            object(stdClass)[5924]
              ...
  public 'translations' => 
    array (size=0)
      empty
  public 'no_update' => 
    array (size=4)
      'hello.php' => 
        object(stdClass)[5925]
          public 'id' => string 'w.org/plugins/hello-dolly' (length=25)
          public 'slug' => string 'hello-dolly' (length=11)
          public 'plugin' => string 'hello.php' (length=9)
          public 'new_version' => string '1.6' (length=3)
          public 'url' => string 'https://wordpress.org/plugins/hello-dolly/' (length=42)
          public 'package' => string 'https://downloads.wordpress.org/plugin/hello-dolly.1.6.zip' (length=58)
          public 'icons' => 
            array (size=2)
              '2x' => string 'https://ps.w.org/hello-dolly/assets/icon-256x256.jpg?rev=969907' (length=63)
              '1x' => string 'https://ps.w.org/hello-dolly/assets/icon-128x128.jpg?rev=969907' (length=63)
          public 'banners' => 
            array (size=1)
              '1x' => string 'https://ps.w.org/hello-dolly/assets/banner-772x250.png?rev=478342' (length=65)
          public 'banners_rtl' => 
            array (size=0)
              empty
      'loco-translate/loco.php' => 
        object(stdClass)[5926]
          public 'id' => string 'w.org/plugins/loco-translate' (length=28)
          public 'slug' => string 'loco-translate' (length=14)
          public 'plugin' => string 'loco-translate/loco.php' (length=23)
          public 'new_version' => string '2.2.0' (length=5)
          public 'url' => string 'https://wordpress.org/plugins/loco-translate/' (length=45)
          public 'package' => string 'https://downloads.wordpress.org/plugin/loco-translate.2.2.0.zip' (length=63)
          public 'icons' => 
            array (size=2)
              '2x' => string 'https://ps.w.org/loco-translate/assets/icon-256x256.png?rev=1000676' (length=67)
              '1x' => string 'https://ps.w.org/loco-translate/assets/icon-128x128.png?rev=1000676' (length=67)
          public 'banners' => 
            array (size=1)
              '1x' => string 'https://ps.w.org/loco-translate/assets/banner-772x250.jpg?rev=745046' (length=68)
          public 'banners_rtl' => 
            array (size=0)
              empty
      'theme-check/theme-check.php' => 
        object(stdClass)[5927]
          public 'id' => string 'w.org/plugins/theme-check' (length=25)
          public 'slug' => string 'theme-check' (length=11)
          public 'plugin' => string 'theme-check/theme-check.php' (length=27)
          public 'new_version' => string '20160523.1' (length=10)
          public 'url' => string 'https://wordpress.org/plugins/theme-check/' (length=42)
          public 'package' => string 'https://downloads.wordpress.org/plugin/theme-check.zip' (length=54)
          public 'icons' => 
            array (size=1)
              '1x' => string 'https://ps.w.org/theme-check/assets/icon-128x128.png?rev=972579' (length=63)
          public 'banners' => 
            array (size=2)
              '2x' => string 'https://ps.w.org/theme-check/assets/banner-1544x500.png?rev=904294' (length=66)
              '1x' => string 'https://ps.w.org/theme-check/assets/banner-772x250.png?rev=904294' (length=65)
          public 'banners_rtl' => 
            array (size=0)
              empty
      'wordpress-importer/wordpress-importer.php' => 
        object(stdClass)[5928]
          public 'id' => string 'w.org/plugins/wordpress-importer' (length=32)
          public 'slug' => string 'wordpress-importer' (length=18)
          public 'plugin' => string 'wordpress-importer/wordpress-importer.php' (length=41)
          public 'new_version' => string '0.6.4' (length=5)
          public 'url' => string 'https://wordpress.org/plugins/wordpress-importer/' (length=49)
          public 'package' => string 'https://downloads.wordpress.org/plugin/wordpress-importer.0.6.4.zip' (length=67)
          public 'icons' => 
            array (size=3)
              '2x' => string 'https://ps.w.org/wordpress-importer/assets/icon-256x256.png?rev=1908375' (length=71)
              '1x' => string 'https://ps.w.org/wordpress-importer/assets/icon.svg?rev=1908375' (length=63)
              'svg' => string 'https://ps.w.org/wordpress-importer/assets/icon.svg?rev=1908375' (length=63)
          public 'banners' => 
            array (size=1)
              '1x' => string 'https://ps.w.org/wordpress-importer/assets/banner-772x250.png?rev=547654' (length=72)
          public 'banners_rtl' => 
            array (size=0)
              empty
	  'wp-rollback/wp-rollback.php' => 
        object(stdClass)[6604]
          public 'id' => string 'w.org/plugins/wp-rollback' (length=25)
          public 'slug' => string 'wp-rollback' (length=11)
          public 'plugin' => string 'wp-rollback/wp-rollback.php' (length=27)
          public 'new_version' => string '1.6' (length=3)
          public 'url' => string 'https://wordpress.org/plugins/wp-rollback/' (length=42)
          public 'package' => string 'https://downloads.wordpress.org/plugin/wp-rollback.1.6.zip' (length=58)
          public 'icons' => 
            array (size=2)
              '2x' => string 'https://ps.w.org/wp-rollback/assets/icon-256x256.jpg?rev=1159170' (length=64)
              '1x' => string 'https://ps.w.org/wp-rollback/assets/icon-128x128.jpg?rev=1159170' (length=64)
          public 'banners' => 
            array (size=1)
              '1x' => string 'https://ps.w.org/wp-rollback/assets/banner-772x250.jpg?rev=1948781' (length=66)
          public 'banners_rtl' => 
            array (size=0)
              empty


Anzeige

Das site_transient_update_themes-Hook übergibt das $value-Objekt:

object(stdClass)[6636]
  public 'last_checked' => int 1549234654
  public 'checked' => 
    array (size=7)
      'bornholm' => string '1.1.2' (length=5)
      'seos-magazine-child' => string '1.0.0' (length=5)
      'seos-magazine' => string '1.2.2' (length=5)
      'ttut-society' => string '1.0.0' (length=5)
      'twentyfifteen' => string '2.2' (length=3)
      'twentyseventeen' => string '2.0' (length=3)
      'twentysixteen' => string '1.8' (length=3)
  public 'response' => 
    array (size=1)
      'twentyfifteen' => 
        array (size=4)
          'theme' => string 'twentyfifteen' (length=13)
          'new_version' => string '2.3' (length=3)
          'url' => string 'https://wordpress.org/themes/twentyfifteen/' (length=43)
          'package' => string 'https://downloads.wordpress.org/theme/twentyfifteen.2.3.zip' (length=59)
  public 'translations' => 
    array (size=0)
      empty

 


 

War diese Seite für dich informativ? Hat sie dir gefallen und geholfen?

Dann unterstütze die Weiterentwicklung mit einer kleinen Spende!

Die Spenden werden für die Lizenzen sowie neue Hard- und Software verwendet, die für weitere Projekte auf dieser Webseite eingesetzt werden. Die Werbung alleine deckt gerade mal die Server Kosten.

 



Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert