outdated ) { return $this->outdated; } $this->outdated = false; // A 4.x-era addon is loaded: its own constant is authoritative. if ( defined( 'APD_PRO_VERSION' ) ) { if ( version_compare( APD_PRO_VERSION, self::MIN_PRO_VERSION, '<' ) ) { $this->outdated = array( 'version' => (string) APD_PRO_VERSION ); } return $this->outdated; } // Older addons define no constant, so read the headers of the active plugins that // could be it. Only a handful of files match the slug filter, so this stays cheap. if ( ! function_exists( 'get_plugin_data' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } foreach ( $this->get_active_plugin_files() as $file ) { if ( APD_PLUGIN_BASENAME === $file || ! preg_match( '/partial-payment|deposit|mepp/i', $file ) ) { continue; } $path = WP_PLUGIN_DIR . '/' . $file; if ( ! is_readable( $path ) ) { continue; } $data = get_plugin_data( $path, false, false ); $vendor = $data['Author'] . ' ' . $data['AuthorURI'] . ' ' . $data['PluginURI']; $is_apd_pro = false !== stripos( $vendor, 'mage' ) && preg_match( '/partial payment|deposit/i', $data['Name'] ) && preg_match( '/\bpro\b/i', $data['Name'] ); if ( $is_apd_pro && '' !== $data['Version'] && version_compare( $data['Version'], self::MIN_PRO_VERSION, '<' ) ) { $this->outdated = array( 'version' => $data['Version'] ); break; } } return $this->outdated; } /** * Plugin basenames active on this site, including network-activated ones. * * @return string[] */ private function get_active_plugin_files() { $files = (array) get_option( 'active_plugins', array() ); if ( is_multisite() ) { $files = array_merge( $files, array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) ) ); } return array_unique( array_filter( $files, 'is_string' ) ); } /** * Remember a dismissal for the Pro version that is installed now. * * Stored per version, so the notice returns if a different outdated build is installed. */ public function maybe_dismiss() { if ( empty( $_GET[ self::DISMISS_ARG ] ) ) { return; } check_admin_referer( self::DISMISS_ARG ); $outdated = $this->get_outdated_pro(); if ( $outdated && current_user_can( 'activate_plugins' ) ) { update_user_meta( get_current_user_id(), self::DISMISS_META, $outdated['version'] ); } wp_safe_redirect( remove_query_arg( array( self::DISMISS_ARG, '_wpnonce' ) ) ); exit; } /** * Print the notice. */ public function render() { $outdated = $this->get_outdated_pro(); if ( ! $outdated ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; $on_settings = $screen && 'toplevel_page_apd-deposits' === $screen->id; // The Deposits screen is where Pro looks missing, so it always explains why. Elsewhere // only users who can update plugins see it, and they may dismiss it. if ( ! $on_settings ) { if ( ! current_user_can( 'activate_plugins' ) ) { return; } if ( get_user_meta( get_current_user_id(), self::DISMISS_META, true ) === $outdated['version'] ) { return; } } // apd-keep-admin-notice survives the Deposits screen's notice filter; `inline` stops // WordPress from moving the notice inside that screen's custom header. $classes = 'notice notice-warning apd-keep-admin-notice' . ( $on_settings ? ' inline' : '' ); ?>