Blog

Code Snippet: Oxygen Editor Hint

(2021)

Contents

Introduction

Oxygen is a powerful plugin for WordPress that deactivates the WordPress theme, supports the creation of own templates with a visual builder and thus enables a fully individual design for your website.

Also page and posts can be designed with Oxygen Builder instead of Gutenberg editor.

Unfortunately, in the administration overview of pages and posts it is not immediately recognizable whether a page or post was created with Gutenberg or with Oxygen.

Solution

I developed a code snippet that shows a hint in the administration lists for pages and posts if Oxygen was used for design.

Download

The code snippet is available for download here:

oxygen-editor-hint.code-snippets.json
Version 1.0.0, 2021-05-16

For installation and use of the downloaded JSON file you will need the plugin Code Snippets or Advanced Scripts.
You can install the JSON file using the "Import" function of the plugin. 
Don't forget to activate the snippet after import.

Alternative: At the end of this page you can view and copy the complete source code of the snippet.

New functionalities and bug fixes are documented in the change log.

Disclaimer

I have developed and tested the code snippet to the best of my knowledge under WordPress 5.7.2 and Oxygen 3.7.1 .
I provide the code snippet for free use.
I cannot give any guarantee for the functionality because of the countless possible variations in WordPress environments.
Download and use of this code snippet is at your own risk and responsibility.

Donation

I enjoy developing code snippets and solving requirements with them. I provide the snippets free of charge.

If you like, you can honor my many hours of work with a small coffee donation via PayPal.

  When clicking the button, a connection to PayPal is established.

Your donation will of course be taxed properly by me.

Change Log

See "Version History" in Source Code

Source Code

<?php
/*
Plugin Name:	MA Page/Post Oxygen Editor Hint
Description:	Show hint "Oxygen" as editor in posts/pages list
Author:			<a href="https://www.altmann.de/">Matthias Altmann</a>
Project:		Code Snippet: Oxygen Editor Hint
Version:		1.0.0
Plugin URI:		https://www.altmann.de/en/blog-en/
Description:	en: https://www.altmann.de/en/blog-en/code-snippet-oxygen-editor-hint/
				de: https://www.altmann.de/blog/code-snippet-oxygen-editor-hinweis/
Copyright:		© 2021, Matthias Altmann
*/

if (is_admin() && !wp_doing_ajax() && !wp_doing_cron() ) {
	MA_OxygenPostState::init();
}
class MA_OxygenPostState {
	// ===== CONFIGURATION =====
	private static $post_types 		= ['post','page']; 	// post types to show new column "Editor" in posts list


	//-------------------------------------------------------------------------------------------------------------------
	public static function init() {
		foreach (self::$post_types as $post_type) {
			add_filter( 'display_post_states', array( __CLASS__, 'ma_editorcolumn_add_post_state' ), 1000, 2 );
		}
	}
	//-------------------------------------------------------------------------------------------------------------------
	public static function ma_editorcolumn_add_post_state($post_states, $post) {
		// Fix PHP 7+ warnings if another plugin returns unexpected type.
		$post_states = (array) $post_states;
		$post_meta = get_post_meta($post->ID,'',true);
		if (isset($post_meta['ct_builder_shortcodes']) && (trim(@$post_meta['ct_builder_shortcodes'][0]) != ''))  {
			// remove mis-leading editor hints from plugin "Classic Editor"
			unset($post_states['classic-editor-plugin']);
			// add "Oxygen" as editor hint
			$post_states['ma_editorcolumn'] = 'Oxygen';
		}
		return $post_states;
	}
}
magnifier