v1.4.2
This commit is contained in:
parent
6a8de6e2e2
commit
a80a4aa4f9
8168 changed files with 3186001 additions and 9155 deletions
148
includes/class-manager-dependency.php
Normal file
148
includes/class-manager-dependency.php
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
/**
|
||||
* ROBOTSTXT Manager dependency notice for iDrivee2 Media Upload.
|
||||
*
|
||||
* @package iDrivee2Media
|
||||
* @since 1.4.2
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace iDrivee2Media;
|
||||
|
||||
/**
|
||||
* Prevent direct access to this file.
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the ROBOTSTXT Manager plugin and warns when it is missing.
|
||||
*
|
||||
* Plugin updates are served through ROBOTSTXT Manager (Manager by ROBOTSTXT).
|
||||
* When it is not installed and active, a dismissible notice is shown on the
|
||||
* plugins list page and a persistent notice is shown on the plugin settings
|
||||
* page, so administrators know updates will not be delivered.
|
||||
*
|
||||
* @since 1.4.2
|
||||
*/
|
||||
class Manager_Dependency {
|
||||
|
||||
/**
|
||||
* ROBOTSTXT Manager plugin page URL.
|
||||
*
|
||||
* @since 1.4.2
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private const MANAGER_PLUGIN_URL = 'https://www.robotstxt.software/plugins/robotstxt-manager/';
|
||||
|
||||
/**
|
||||
* Register hooks for the admin notices.
|
||||
*
|
||||
* @since 1.4.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register(): void {
|
||||
add_action( 'admin_notices', array( $this, 'render_plugins_page_notice' ) );
|
||||
add_action( 'network_admin_notices', array( $this, 'render_plugins_page_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the ROBOTSTXT Manager plugin is installed and active.
|
||||
*
|
||||
* Matches any active plugin whose directory slug is "robotstxt-manager",
|
||||
* so the main file name does not matter. On Multisite, network-activated
|
||||
* plugins are matched as well.
|
||||
*
|
||||
* @since 1.4.2
|
||||
*
|
||||
* @return bool True when ROBOTSTXT Manager is active.
|
||||
*/
|
||||
public static function is_manager_active(): bool {
|
||||
$active = get_option( 'active_plugins', array() );
|
||||
if ( is_array( $active ) ) {
|
||||
foreach ( $active as $basename ) {
|
||||
if ( is_string( $basename ) && str_starts_with( $basename, 'robotstxt-manager/' ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$network_active = get_site_option( 'active_sitewide_plugins', array() );
|
||||
if ( is_array( $network_active ) ) {
|
||||
foreach ( array_keys( $network_active ) as $basename ) {
|
||||
if ( is_string( $basename ) && str_starts_with( $basename, 'robotstxt-manager/' ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the dismissible notice on the plugins list page.
|
||||
*
|
||||
* @since 1.4.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_plugins_page_notice(): void {
|
||||
global $pagenow;
|
||||
|
||||
$current_page = isset( $pagenow ) && is_string( $pagenow ) ? $pagenow : '';
|
||||
if ( 'plugins.php' !== $current_page ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( self::is_manager_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf(
|
||||
'<div class="notice notice-warning is-dismissible"><p>%s</p></div>',
|
||||
wp_kses_post( self::message_html() )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the persistent notice for the plugin settings page.
|
||||
*
|
||||
* @since 1.4.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function render_settings_notice(): void {
|
||||
if ( self::is_manager_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf(
|
||||
'<div class="notice notice-warning"><p>%s</p></div>',
|
||||
wp_kses_post( self::message_html() )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the shared warning message HTML.
|
||||
*
|
||||
* @since 1.4.2
|
||||
*
|
||||
* @return string Message HTML with an escaped link.
|
||||
*/
|
||||
private static function message_html(): string {
|
||||
return sprintf(
|
||||
/* translators: %s: link to the ROBOTSTXT Manager plugin page. */
|
||||
esc_html__( 'To receive plugin updates, the ROBOTSTXT Manager plugin must be installed and active. Download it from %s.', 'idrivee2-media-upload' ),
|
||||
'<a href="' . esc_url( self::MANAGER_PLUGIN_URL ) . '">ROBOTSTXT Manager</a>'
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue