Giter Club home page Giter Club logo

Comments (4)

markjaquith avatar markjaquith commented on August 20, 2024 1

Hey y'all. I have an issues/gutenberg branch that I'm using to track Gutenberg stuff. Thanks for the notice head start, @dhuyck!

Right now, both the meta box, and the new Gutenberg powered UI are active.

The toggle for the Gutenberg UI is currently broken, so this is very much a work-in-progress.

from page-links-to.

dhuyck avatar dhuyck commented on August 20, 2024

As a quick patch, I added these three lines to my downloaded version of the plugin in the is_supported_post_type() method (added as lines 380-382):

	if ( is_object( $type ) ) {
		$type = $type->id;
	}

This will show the metabox properly, but there would be additional work to make the ajax/React code update the notices properly in Gutenberg.

from page-links-to.

dhuyck avatar dhuyck commented on August 20, 2024

I did a little further work to make admin notices work in WP5+. It's a little raw and optimized to our installation (where we can assume browser up-to-date-ness), but it's working. I have updated the notify_of_external_link() function like so:

	/**
	 * Outputs a notice that the current post item is pointed to a custom URL.
	 *
	 * @return void
	 */
	public static function notify_of_external_link() {
		?>
		<div class="notice updated" id="page-links-to-notice"><p><?php _e( '<strong>Note</strong>: This content is pointing to a custom URL. Use the &#8220;Page Links To&#8221; box to change this behavior.', 'page-links-to' ); ?></p></div>
		<?php

		// verify we are using WP5+ and the block editor before generating our own block editor (Gutenberg) admin notices
		global $current_screen;
		if ( ! isset( $current_screen ) ) {
			$current_screen = get_current_screen();
		}
		$is_admin_user = ( current_user_can( 'administrator' ) ) ? 'true' : 'false';
		if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
			?>
			<script>
				document.addEventListener('DOMContentLoaded', function (event) {
					const isAdminUser = <?php echo $is_admin_user; ?>;
					if (isAdminUser) console.log('page-links-to: DOM loaded');
					if (wp.data !== undefined) {
						const pltNoticesHandle = 'page-links-to-notice';
						const pltNotices = document.querySelector('#' + pltNoticesHandle);

						const cleanupNoticeContent = function (contentObj) {
							const dismissButton = document.querySelector('#' + pltNoticesHandle + ' button.notice-dismiss');
							if (dismissButton) {
								contentObj.removeChild(dismissButton);
							}
							return contentObj.innerText; // only allows plaintext at this time
						};

						const pltNoticeContent = cleanupNoticeContent(pltNotices);

						if (pltNotices.classList.contains('notice-error')) {
							if (isAdminUser) console.log('page-links-to: error notice added');
							wp.data.dispatch('core/notices').createErrorNotice(pltNoticeContent, {isDismissible: true, id: pltNoticesHandle});
						} else if (pltNotices.classList.contains('notice-warning')) {
							if (isAdminUser) console.log('page-links-to: warning notice added');
							wp.data.dispatch('core/notices').createWarningNotice(pltNoticeContent, {isDismissible: true, id: pltNoticesHandle});
						} else if (pltNotices.classList.contains('notice')) {
							if (isAdminUser) console.log('page-links-to: info notice added');
							wp.data.dispatch('core/notices').createInfoNotice(pltNoticeContent, {isDismissible: true, id: pltNoticesHandle});
						}
					}
				});
			</script>
			<?php
		}
	}

from page-links-to.

dhuyck avatar dhuyck commented on August 20, 2024

Glad I could contribute! We love the single-purpose-ness of the plugin, and it gracefully solves a need we have in our multisite deployment. We have distributed admin users across our college campus, and a simple, intuitive UI like this one means fewer training hours for our departmental admins and other frequent editors. I look forward to upgrading to a fully-gutenbergged version instead of my hacked and patched version!

from page-links-to.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.