[wp-trac] [WordPress Trac] #62043: Allow plugins and themes perform extra checks upon install/upgrade via filter
WordPress Trac
noreply at wordpress.org
Thu Sep 12 08:04:50 UTC 2024
#62043: Allow plugins and themes perform extra checks upon install/upgrade via
filter
------------------------------+------------------------------
Reporter: LeonidasMilossis | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
------------------------------+------------------------------
Comment (by LeonidasMilossis):
With the above PR, the following filters are introduced:
* `plugin_upgrader_checked_package`
* `theme_upgrader_checked_package`
That way, a plugin can extend the checks performed by core upon plugin
install, by hooking into the new filter, in order to check the minimum
required version of the main plugin whenever an add-on is
installed/upgraded, like:
{{{#!php
<?php
add_filter( 'plugin_upgrader_checked_package', [ $this,
'check_requirement' ], 10, 2 );
public function check_requirement( $source, $info ) {
$requires_xyz = ! empty( $info['Requires XYZ'] ) ? $info['Requires
XYZ'] : false;
if ( $requires_xyz === false ) {
return $source;
}
if ( version_compare( XYZ_VERSION, $requires_xyz, '>=' ) ) {
return $source;
}
$error = sprintf(
__( 'The XYZ version on your site is %1$s, however the
uploaded plugin requires %2$s.', 'xyz-addon' ),
XYZ_VERSION,
esc_html( $requires_xyz )
);
return new WP_Error(
'incompatible_xyz_required_version',
__( 'The package could not be installed because it\'s not
supported by the currently installed XYZ version.', 'xyz-addon' ),
$error
);
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62043#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list