Blog

Code Snippet: Oxygen Editor Hint

Version: 1.2.0 (May 22, 2024)

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

This JSON download can be imported directly into the plugins Code Snippets or Advanced Scripts. Don't forget to activate the snippet after import.
If you are using a different snippet plugin, you can copy the source code instead and create a new snippet yourself.

ma-oxygen-editor-hint.code-snippets.json
Version 1.2.0, 2024-05-22

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.

Disclaimer

I have tested the code snippet to the best of my knowledge and belief. (See the section "TESTED WITH" in the source code)
I provide the code snippet for free use.
I cannot give a guarantee for the functionality in all conceivable WordPress environments.
Download and use of this code snippet is at your own risk and responsibility.

Change Log

See "Version History" in Source Code

Source Code

<?php
/*
Plugin Name:	MA 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.2.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-2024, Matthias Altmann

TESTED WITH:
Product		Versions
--------------------------------------------------------------------------------------------------------------
PHP 		7.4, ..., 8.1
WordPress	5.7, ..., 6.5.3
Oxygen		3.7, ..., 4.8.3
--------------------------------------------------------------------------------------------------------------


VERSION HISTORY
Date		Version		Description
--------------------------------------------------------------------------------------------------------------
2024-05-22	1.2.0		Changes:
						- Compatibility to Oxygen 4.8.3 with changed post meta keys
2024-01-24	1.1.1		Fixes: PHP 8 compatibility
2023-04-17	1.1.0		Moved call to init after the class definition for compatibility with WPCodeBox 2
						Tested with PHP 8.1, WordPress 6.2, Oxygen 4.5, Code Snippets 3.3.0, WPCodeBox 2.0.0b3.0
2022-02-11				Tested with PHP 8.0, WordPress 5.9, Oxygen 4.0 beta 1
2021-05-16	1.0.0		Initial release as Code Snippet
						Tested with PHP 7.4, WordPress 5.7.2, Oxygen 3.7.1
--------------------------------------------------------------------------------------------------------------
*/

if (!class_exists('MA_OxygenEditorHint')) :
class MA_OxygenEditorHint {
	const TITLE							= 'MA Oxygen Editor Hint';
	const SLUG							= 'ma-oxygen-editor-hint';
	const SHRT 							= 'maoeh';
	const VERSION						= '1.2.0';
	
	// ===== CONFIGURATION =====
	private $post_types 		= ['post','page']; 	// post types to show new column "Editor" in posts list

	//-------------------------------------------------------------------------------------------------------------------
	function __construct() {
		foreach ($this->post_types as $post_type) {
			add_filter( 'display_post_states', [$this, 'add_editor_hint'], 1000, 2 );
		}
	}
	//-------------------------------------------------------------------------------------------------------------------
	public function add_editor_hint($post_states, $post) {
		// Fix PHP 7+ warnings if another plugin returns unexpected type.
		$post_states = (array) $post_states;

		// Oxygen pre or post 4.8.3?
		$meta_function_name = function_exists('oxy_get_post_meta') ? 'oxy_get_post_meta' : 'get_post_meta';

		$oxy_shortcodes = call_user_func($meta_function_name, $post->ID, 'ct_builder_shortcodes', true) ?? '';
		if (trim($oxy_shortcodes) != '')  {
			// remove mis-leading editor hints from plugin "Classic Editor"
			unset($post_states['classic-editor-plugin']);
			// add "Oxygen" as editor hint
			$post_states[self::SHRT] = 'Oxygen';
		}
		return $post_states;
	}
}
if (is_admin() && !wp_doing_ajax() && !wp_doing_cron() ) {
	new MA_OxygenEditorHint();
}
endif;
First published: May 16, 2021 on Code Snippet: Oxygen Editor Hint
magnifier