checked ) ) return $update_data; $wpcom_themes_to_check = array_filter( array_keys( $update_data->checked ), array( __CLASS__, 'is_wpcom_slug' ) ); if ( empty( $wpcom_themes_to_check ) ) return $update_data; $request_data = array(); foreach ( $wpcom_themes_to_check as $theme_to_check ) { $request_data[] = array( 'theme' => $theme_to_check, 'version' => $update_data->checked[ $theme_to_check ] ); } $user_agent = is_multisite() ? 'WordPress MS' : 'WordPress'; $user_agent .= '/' . $GLOBALS['wp_version'] . '; ' . home_url(); $options = array( 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ), 'body' => json_encode( $request_data ), 'user-agent' => $user_agent, 'headers' => array( 'Content-Type' => 'application/json' ) ); $raw_response = wp_remote_post( 'http://public-api.wordpress.com/rest/v1/themes/update-check', $options ); // something went wrong. leave it alone. if ( 200 !== wp_remote_retrieve_response_code( $raw_response ) ) return $update_data; $response_data = json_decode( wp_remote_retrieve_body( $raw_response ), true ); if ( ! $response_data || ! is_array( $response_data ) || ! isset( $response_data['updates'] ) ) return $update_data; $update_data->response = array_merge( $update_data->response, $response_data['updates'] ); return $update_data; } /** * Fire on admin_notices on a multisite network to try to get the updater plugin installed. * Will show admin notices and email the site admin. * Won't fire if this file is in a plugin directory. * @return void */ public function maybe_nag_for_plugin() { // Show to super admins, email site admin when a non-super-admin views an admin page. if ( is_super_admin() ) self::output_notice(); else self::maybe_email_site_admin(); } /** * Admin-ajax callback for hiding the admin nag shown to super admins * @return void */ public function hide_plugin_nag() { if ( isset( $_REQUEST['nonce'] ) && wp_verify_nonce( $_REQUEST['nonce'], 'wpcom-theme-updates-hide-nag' ) ) { self::set_option( 'hide_admin_nag', true ); } } /** * Emails the network site admin about installing the WP.com Theme Updater plugin. Will only email once. * @return void */ public function maybe_email_site_admin() { if ( self::get_option( 'sent_email_nag' ) ) return; $theme = wp_get_theme(); $message = "The theme \"$theme->Name\" has recently been installed and activated on your Network.\n"; $message .= 'To automatically receive updates for this WordPress.com theme, please install the WordPress.com Theme Updates plugin:' . "\n\n"; $message .= 'http://wordpress.org/plugins/' . self::PLUGIN_SLUG . "\n\n"; $message .= 'You will only receive this reminder once.'; $subject = sprintf( '[%s] Theme Updates', get_site_option( 'site_name' ) ); wp_mail( get_site_option( 'admin_email' ), $subject, $message ); self::set_option( 'sent_email_nag', true ); } /** * Prints the admin notice for installing the WP.com Theme Updater plugin. * @return void */ protected function output_notice() { if ( self::get_option( 'hide_admin_nag' ) ) return; $theme = wp_get_theme(); $install_url = wp_nonce_url( network_admin_url( 'update.php?action=install-plugin&plugin=' . self::PLUGIN_SLUG ), 'install-plugin_' . self::PLUGIN_SLUG ); $message = sprintf( __( 'Thanks for installing %1$s from WordPress.com!
To keep this theme up-to-date on your Multisite network, please install the WordPress.com Theme Updates plugin and Network Activate it.', 'wordpresscom-theme-updates' ), $theme->Name, esc_url( $install_url ) ); $hide = __( 'Don‘t show me this.', 'wordpresscom-theme-updates' ); $message .= " {$hide}"; ?>

false, 'sent_email_nag' => false ) ); if ( isset( $opt[ $key ] ) ) return $opt[ $key ]; return false; } /** * Set/update an option as a member of our single site option. * @param string $key The key to set on our site option * @param string $value The value to set in $key */ protected function set_option( $key, $value ) { $opt = get_site_option( self::PLUGIN_SLUG, array( 'hide_admin_nag' => false, 'sent_email_nag' => false ) ); $opt[ $key ] = $value; update_site_option( self::PLUGIN_SLUG, $opt ); } /** * Checks if a theme slug is a WordPress.com slug. Looks for `-wpcom` suffix. * @param string $slug WordPress theme id/slug * @return boolean True if it is a WordPress.com theme slug */ public static function is_wpcom_slug( $slug ) { return preg_match( '/-wpcom$/', $slug ); } } // Hook it up. add_action( 'after_setup_theme', array( 'WPCom_Theme_Updater', 'init' ) ); endif; // if class_exists()