Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2017-10-17 14:47:11

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

WordPress editor always forced to text view

This is strange. When I'm using the WordPress theme created by my Backlight configuration, the page/post editor view is always forced to text.

I can change the theme to the builtin Twenty SixteenVersion and this doesn't happen.

Normally, if you are editing a page and switch to visual it stays visual. Even when you leave that edit, and then open a new page to edit. It will open in visual mode. So by default WordPress will keep your last setting.

But with the Backlight theme I'm finding it's always being forced to text view. I can change it to visual, and then after updating the page it's switches back to text again.


--Jim

Offline

#2 2017-10-17 16:39:10

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: WordPress editor always forced to text view

Yes, it's in the theme. An opinionated move on my part, as the WP visual editor is pretty crap. You're the only person thus far that's raised it as an issue.

My intention was to have the Text editor as default. I didn't realize it would null your preference, though. This is the snippet I'm using:
http://wp-snippets.com/set-default-editor/

I'll have a look at whether I can figure out how to keep the intent, while honoring the user preference. Open to ideas if you solve it before I do.


Matt

The Turning Gate, http://theturninggate.net

Offline

#3 2017-10-17 16:46:23

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: WordPress editor always forced to text view

I maybe have something. Maybe. Can you test this?

Edit /inc/theme_admin.php

Change:

add_filter("wp_default_editor", create_function("", "return 'html';"));

Replace with:

	function set_default_editor() {
		$r = 'html';
		if ( wp_get_current_user() ) { // look for cookie
			$r = get_user_setting('editor', 'html');
		}
		return $r;
	}
	add_filter( 'wp_default_editor', 'set_default_editor' );

And what I'm hoping this will accomplish is:

1. Uses 'Text/HTML' editor by default.
2. When a new user is created, the 'Text/HTML' editor is default.
3. When the user changes to the 'Visual' editor as preference, this setting will be preferred.


Matt

The Turning Gate, http://theturninggate.net

Offline

#4 2017-10-17 17:41:34

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: WordPress editor always forced to text view

Matthew wrote:

My intention was to have the Text editor as default.

I'll add your change and see how it works, then let you know.

I understand your intent of always using the text editor. I think people using WordPress are used to how it normally behaves. A change in the behavior just shows up as "broken."

If you didn't alter the behavior, it works for you since WP will "remember" your preference.

I use both the visual and the text editor. It also works for me since I'm always jumping back and forth, and I'm expecting it to be how it was last time. I even go the extra mile and customize the WP admin css so my visual editor looks close to the actual page.


--Jim

Offline

#5 2017-10-17 23:52:03

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: WordPress editor always forced to text view

Like I said, it's an opinionated move on my part. That WP does not remember your personal preference, though, is entirely an unintentional and undesirable side-effect. I only want to softly encourage people to use the text editor. The visual editor, I find, often does stupid things, like leaving being empty <p></p> tags in the markup when a paragraph is removed.


Matt

The Turning Gate, http://theturninggate.net

Offline

#6 2017-10-18 05:51:51

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: WordPress editor always forced to text view

Nope, that change still has the editor being forced to html/text.

I just deleted the wp_default_editor filter. At least for now it behaves as I'm used to. I know it will get wiped out with the next update.

This would be a good custom option for the theme. So far I see only "google analytics, as set in Backlight" is the only setting. Adding a few more there like the editor preference would be nice.


--Jim

Offline

#7 2017-10-18 11:24:14

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: WordPress editor always forced to text view

Odd. The function above seems to be working for me. After selecting the Visual editor and either updating my post, or creating a new one, I then get the visual editor by default.

Did you re-export the theme to Wordpress after making the change?


Matt

The Turning Gate, http://theturninggate.net

Offline

#8 2017-10-18 12:23:11

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: WordPress editor always forced to text view

Matthew wrote:

Did you re-export the theme to Wordpress after making the change?

D'oh!

Looking at the /inc/theme_admin.php just now I see it had been reset back to the original "opinionated" filter LOL

What I just confirmed is changing a template in Backlight is over-writing the theme_admin.php as well. So changing that file isn't going to work.

That brings up another more general point I was going to ask about.

Is it possible to create a child theme, so Backlight doesn't over-write things like the above?

This also becomes an issue when updating Backlight. Usually I have a child theme and will be safe to change functions.php or other files within the theme.


--Jim

Offline

#9 2017-10-18 12:28:20

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: WordPress editor always forced to text view

Have you tried creating a child theme per the WordPress codex?


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#10 2017-10-18 12:33:29

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: WordPress editor always forced to text view

rod barbee wrote:

Have you tried creating a child theme per the WordPress codex?

I've created them in the past but haven't tried it for Backlight. I wasn't sure it would work.

The Backlight doc page for this MIA.

http://backlight.theturninggate.net/doc … ild_themes

Has anyone done this?


--Jim

Offline

#11 2017-10-18 12:58:13

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: WordPress editor always forced to text view

Child themes work with Backlight. Did it for my site.


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#12 2017-10-18 14:02:38

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: WordPress editor always forced to text view

Not only do they work, but I have endeavored to make Backlight's themes child-theme-friendly. For example, most functions do a "function_exists" check, allowing child themes to overwrite them. Though not the one we're discussing. I'll maybe have to add these in an update.

The Turning Gate is running on a child-theme, in fact, as I've written some custom taxonomy stuff for our shop pages.


Matt

The Turning Gate, http://theturninggate.net

Offline

#13 2017-10-18 21:51:12

Tiggrrr42
Member
From: Gateshead, UK
Registered: 2017-10-10
Posts: 15
Website

Re: WordPress editor always forced to text view

There's another approach you can use for functions you want to be always available regardless of theme changes.

You can put the functions into a simple plugin - the source I borrowed the idea from called this a "functionality plugin" (I can't recall where I got the idea, as it was a few years ago).

Create a suitably named folder in the WordPress plugins folder, and add your new PHP file in there. It should looks something like this:

<?php
/*
Plugin Name: My Site Functionality Plugin
Description: Repalces functions.php in child theme
Version: 1.0
License: GPL
Author: Your name
Author URI: http://yoursite.com
*/

// Note about the following function

// Your functions here

?>

Once it's saved, it will appear in your plugins list where it can be activated as normal.

I find this handy for various little WordPress tweaks.

Offline

#14 2017-10-18 23:02:35

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: WordPress editor always forced to text view

I can confirm that Backlight is child theme friendly, I am a wordpress idiot and even I could easily implement a child theme on my site. ;-)

Offline

#15 2017-10-19 05:02:52

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: WordPress editor always forced to text view

Matthew wrote:

Not only do they work, but I have endeavored to make Backlight's themes child-theme-friendly. For example, most functions do a "function_exists" check, allowing child themes to overwrite them. Though not the one we're discussing.

Got the child theme setup. Added the set_default_editor to functions.php, but that's not working.

Seems the default is still set to 'html' by the parent theme. I didn't see a way to remove that filter, or how to override it.


--Jim

Offline

#16 2017-10-19 05:36:17

Tiggrrr42
Member
From: Gateshead, UK
Registered: 2017-10-10
Posts: 15
Website

Re: WordPress editor always forced to text view

You could try adding a priority to your filter - a higher number would make it run later, and so more likely to "win".

WordPress add_filter documentation

Offline

#17 2017-10-19 07:04:00

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: WordPress editor always forced to text view

Tiggrrr42 wrote:

You could try adding a priority to your filter - a higher number would make it run later, and so more likely to "win".

Even brute force doesn't seem to do the trick. I added this to my child theme's functions.php

add_filter( 'wp_default_editor', create_function('', 'return "tinymce";'), 1 );

I was thinking I could remove the builtin filter, but Backlight adds the filter without using a function name so I can't remove it. I can alter the original code in the parent theme, and that works until I update a template. Since I'm in the middle of creating the theme it's getting instantly overwritten.


--Jim

Offline

#18 2017-10-19 07:41:03

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: WordPress editor always forced to text view

where is the code in the parent theme? the inc/ folder? I ask because if you just put a function in the child theme it might not work unless it's in the same folder as in the parent theme.
For example, if the file with the function is in the "template-parts" folder of the parent, you need to create a folder in the child theme named "template-parts" and place file with the function in that folder.

Found that out after banging my head on the desk for an hour or two while trying to add author information to posts.....


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#19 2017-10-19 10:15:33

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: WordPress editor always forced to text view

As I said, Jim, that particular function is not able to be overwritten by a child theme in the current version. I will change this in the next update. For now, you'll just need to hack the module with your change.

Child themes can override any function existing within a "function_exists" check in the parent.


Matt

The Turning Gate, http://theturninggate.net

Offline

Board footer

Powered by FluxBB