response ) || ! is_array( $data->response ) || empty( $data->response[ $base ] ) ) { return null; } $item = (object) $data->response[ $base ]; $version = isset( $item->new_version ) ? (string) $item->new_version : ''; if ( ! self::valid_version( $version ) || ! version_compare( $version, AGEVOW_VERSION, '>' ) ) { return null; } return array( 'version' => $version, 'package' => ! empty( $item->package ), 'php_ok' => empty( $item->requires_php ) || is_php_version_compatible( (string) $item->requires_php ), 'wp_ok' => empty( $item->requires ) || is_wp_version_compatible( (string) $item->requires ), ); } /** * Whether the current person should see the card for this version. * * @param string $version The available version. * @return bool */ public static function visible_for( $version ) { if ( ! current_user_can( 'update_plugins' ) ) { return false; } if ( is_multisite() && ! is_main_site() ) { return false; } return (string) get_user_meta( get_current_user_id(), self::DISMISS_META, true ) !== $version; } /** * Core's own "update this plugin" link, with core's own nonce. On a network * the update runs from the network admin, as WordPress's own link does. * * @return string */ public static function update_url() { $base = self::basename(); $path = 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $base ); return wp_nonce_url( is_multisite() ? network_admin_url( $path ) : self_admin_url( $path ), 'upgrade-plugin_' . $base ); } /** * The "Not now" link for one version: the Gate screen's own address with a nonce. * It carries no version: its nonce names the version the card showed, so the * handler reads nothing from the request but that nonce, and a link from an older * card is refused. * * @param string $version The version to hide. * @return string */ public static function dismiss_url( $version ) { return wp_nonce_url( self::back_url(), self::ACTION . ':' . $version, self::FIELD ); } /** * The Gate screen, where "Not now" lands. * * @return string */ public static function back_url() { return add_query_arg( array( 'page' => Admin::PAGE ), admin_url( 'admin.php' ) ); } /** * Print the card, or nothing. * * @return void */ public static function render() { $update = self::available(); if ( ! $update || ! self::visible_for( $update['version'] ) ) { return; } $ready = $update['php_ok'] && $update['wp_ok'] && $update['package']; if ( ! $update['php_ok'] ) { $why = __( 'It needs a newer version of PHP than this site runs. Ask your host to update PHP, then update the plugin.', 'agevow-age-verification-age-gate' ); } elseif ( ! $update['wp_ok'] ) { $why = __( 'It needs a newer version of WordPress. Update WordPress first, then the plugin.', 'agevow-age-verification-age-gate' ); } elseif ( ! $update['package'] ) { $why = __( 'WordPress cannot download it automatically on this site. Update it from the Plugins screen.', 'agevow-age-verification-age-gate' ); } else { $why = ''; } /* translators: %s: the new version number, like 1.2.0. */ $news = sprintf( __( 'Version %s of Agevow is available.', 'agevow-age-verification-age-gate' ), $update['version'] ); /* translators: %s: the version number this site runs now. */ $runs = sprintf( __( 'This site runs %s.', 'agevow-age-verification-age-gate' ), AGEVOW_VERSION ); ?>