commit 6860ca467b701572f0e7ac4821756243e914c5eb
Author: Boone B Gorges <boonebgorges@gmail.com>
Date:   Mon Nov 11 22:42:00 2019 +0000

    Some work toward forcing alt tags.
    
    See #8900.

diff --git a/wp-content/mu-plugins/cac-functions.php b/wp-content/mu-plugins/cac-functions.php
index 14fceb539f..954d66f17b 100644
--- a/wp-content/mu-plugins/cac-functions.php
+++ b/wp-content/mu-plugins/cac-functions.php
@@ -1686,6 +1686,34 @@ function cac_tooltip( $text ) {
 	);
 }
 
+/**
+ * Enqueues the 'force alt tags' script.
+ */
+add_action(
+	'admin_enqueue_scripts',
+	function( $hook_suffix ) {
+		$load = [
+			'post.php',
+			'post-new.php',
+		];
+
+		if ( ! in_array( $hook_suffix, $load, true ) ) {
+			return;
+		}
+
+		wp_enqueue_script(
+			'cac-force-alt-tags',
+			home_url( 'wp-content/mu-plugins/js/cac-force-alt-tags.js' ),
+			[ 'jquery' ]
+		);
+
+		wp_enqueue_style(
+			'cac-force-alt-tags',
+			home_url( 'wp-content/mu-plugins/css/cac-force-alt-tags.css' )
+		);
+	}
+);
+
 /**
  * "Selector" scripts.
  */
diff --git a/wp-content/mu-plugins/css/cac-force-alt-tags.css b/wp-content/mu-plugins/css/cac-force-alt-tags.css
new file mode 100644
index 0000000000..034ebf0015
--- /dev/null
+++ b/wp-content/mu-plugins/css/cac-force-alt-tags.css
@@ -0,0 +1,9 @@
+.alt-tag-warning {
+	color: #f00;
+	height: 100%;
+	margin-top: 10px; /* To match .media-toolbar-primary .media-button */
+}
+
+.media-sidebar .attachment-details .setting.has-error input {
+	border-color: #f00;
+}
diff --git a/wp-content/mu-plugins/js/cac-force-alt-tags.js b/wp-content/mu-plugins/js/cac-force-alt-tags.js
new file mode 100644
index 0000000000..dd3895e750
--- /dev/null
+++ b/wp-content/mu-plugins/js/cac-force-alt-tags.js
@@ -0,0 +1,122 @@
+(function($){
+	$(document).ready(function(){
+		var selection,
+		  $altInput,
+		  $mediaInsert,
+		  $toolbarEl;
+
+		var removeWarning = function() {
+			$toolbarEl.find('.alt-tag-warning').remove();
+		}
+
+		var disableSubmit = function() {
+			$mediaInsert.attr('disabled', 'disabled');
+		}
+
+		var enableSubmit = function() {
+			$mediaInsert.removeAttr('disabled');
+		}
+
+		var bindSelectionEvents = function() {
+			selection = wp.media.frame.state().get('selection');
+
+			$toolbarEl = wp.media.frame.toolbar.view.$el;
+
+			$mediaInsert = $toolbarEl.find('button.media-button-insert');
+
+			selection.on( 'selection:single selection:multiple', function() {
+				// This element is not available until 'selection'.
+				$('label[data-setting="alt"] input').on('keyup', checkForAltText);
+
+				checkForAltText();
+			});
+
+			var uploaderView = wp.media.frame.views.get('.media-frame-uploader')[0]
+			uploaderView.on('ready', function() {
+				uploaderView.uploader.success = function( attData ) {
+					console.log(1);
+					visibleSidebarCallback();
+					wp.media.frame.views.get('.media-frame-content')[0].sidebar.$el.addClass( 'visible' );
+				}
+			})
+		}
+
+		var checkForAltText = function() {
+			var hasAltText = true;
+			var imageIsSelected = false;
+
+			selection.each(function(item){
+				if ( ! hasAltText ) {
+					return;
+				}
+
+				if ( 'image' !== item.attributes.type ) {
+					return;
+				} else {
+					imageIsSelected = true;
+				}
+
+				if ( ! item.attributes.hasOwnProperty( 'alt' ) ) {
+					hasAltText = false;
+					return;
+				}
+
+				var $altInput = $('label[data-setting="alt"] input');
+
+				hasAltText = $altInput.length > 0 && 0 !== $altInput.val().length;
+			});
+
+			// Existing warning should be removed in all cases.
+			removeWarning();
+
+			// Nothing more to do.
+			if ( ! imageIsSelected ) {
+				return;
+			}
+
+			if ( hasAltText ) {
+				enableSubmit();
+
+			} else {
+				var warning = '<div id="alt-tag-warning" class="alt-tag-warning">You must supply alt text before inserting this image.</div>';
+
+				$toolbarEl.find('.media-frame-toolbar .media-toolbar-primary').append(warning);
+				var sidebar = wp.media.frame.views.get('.media-frame-content')[0].sidebar;
+				sidebar.$el.find('label.setting[data-setting="alt"]').addClass('has-error');
+
+				disableSubmit();
+			}
+		}
+
+		// Bind our events to successful uploads.
+		$(document).ready(function(){
+			if ( typeof wp.Uploader === 'function' ) {
+				$.extend( wp.Uploader.prototype, {
+					success: function( attachment ) {
+						// Selection events must be rebound after redraw.
+						bindSelectionEvents();
+
+						checkForAltText();
+					}
+				} );
+			}
+		});
+
+		// Bind to the 'selection' events.
+		wp.media.view.Modal.prototype.on( 'ready', function() {
+
+
+		// cannot make this work - have to hide the message when switching to Upload Files tab
+			var router = wp.media.frame.views.get('.media-frame-router')[0];
+
+			console.log(router.views.view);
+			router.on('ready',function(){
+				console.log('no no no');
+			});
+			router.on('browse',function(){
+				console.log('amybe');
+			});
+			wp.media.view.Modal.prototype.on( 'open', bindSelectionEvents );
+		});
+	});
+}(jQuery));
