*/ private $plugin_notices = []; /** * The memoization cache for existing plugins. * * @var ?Collection */ private $plugins; /** * Displays messages on the plugins page in the dashboard. * * @since 1.0.0 * * @param string $page * * @return void */ public function display_plugin_messages( string $page ): void { if ( 'plugins.php' !== $page ) { return; } $messages = []; $plugins = $this->get_plugins(); $plugin_updates = get_plugin_updates(); foreach ( $plugins as $plugin ) { $plugin_file = $plugin->get_path(); $resource = $plugin_updates[ $plugin_file ] ?? null; if ( empty( $resource ) ) { continue; } if ( ! empty( $resource->update->license_error ) ) { $messages[] = $resource->update->license_error; } if ( empty( $messages ) ) { continue; } $message_row_html = ''; foreach ( $messages as $message ) { $message_row_html .= sprintf( '
%s
', $message ); } $message_row_html = sprintf( '%s', $message_row_html ); $this->plugin_notices[ $plugin->get_slug() ] = [ 'slug' => $plugin->get_slug(), 'message_row_html' => $message_row_html, ]; } } /** * Get plugin notices. * * @since 1.0.0 * * @return array */ public function get_plugin_notices(): array { return apply_filters( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/plugin_notices', $this->plugin_notices ); } /** * Add notices as JS variable * * @param string $page * * @return void */ public function store_admin_notices( string $page ): void { if ( 'plugins.php' !== $page ) { return; } add_action( 'admin_footer', [ $this, 'output_notices_script' ] ); } /** * Output the plugin-specific notices script. * * @since 1.0.0 * * @return void */ public function output_notices_script(): void { $notices = $this->get_plugin_notices(); if ( empty( $notices ) ) { return; } foreach ( $this->get_plugins() as $resource ) : $notice = $notices[ $resource->get_slug() ] ?? null; if ( ! $notice ) { continue; } ?> get_plugins() as $resource ) { $transient = $resource->check_for_updates( $transient ); } } catch ( Throwable $exception ) { return $transient; } return $transient; } /** * Get the collection of Plugins/Services. * * @return Collection */ protected function get_plugins(): Collection { if ( isset( $this->plugins ) ) { return $this->plugins; } return $this->plugins = Config::get_container()->get( Collection::class )->get_plugins(); } /** * Intercept plugins_api() calls that request information about our plugin and * use the configured API endpoint to satisfy them. * * @see plugins_api() * * @param mixed $result * @param string|null $action * @param array|object|null $args * * @return mixed */ public function inject_info( $result, ?string $action = null, $args = null ) { $relevant = ( 'plugin_information' === $action ) && is_object( $args ) && ! empty( $args->slug ); if ( ! $relevant ) { return $result; } if ( apply_filters( 'stellarwp/uplink/' . $args->slug . '/prevent_update_check', false ) ) { return $result; } $plugin = $this->get_plugins()->offsetGet( $args->slug ); if ( ! $plugin ) { return $result; } return $plugin->validate_license()->to_wp_format(); } }