Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't see list of themes in backend now that I used a code snippet #251

Closed
ajtruckle opened this issue Apr 25, 2020 · 17 comments
Closed

Can't see list of themes in backend now that I used a code snippet #251

ajtruckle opened this issue Apr 25, 2020 · 17 comments

Comments

@ajtruckle
Copy link

Recently I added this code snippet:

// add a custom filter to modify the theme list
add_filter('enlighter_themes', function ($themes){
    // DEBUG: just display the dataset - uncomment the following line to debug issues
    // echo '<pre>', print_r($themes, true), '</pre>';

    // just show the default theme 
    return array(
     );
});

That was based on our discussion here. The problem I have now discovered is in my backend:

Theme

I thought it would atleast show "Atomic" but it shows none.

The theme customizer still lists all of them.

Ideally the front-end will be stripped so the user can only use the chosen theme. But i thought the backend would show all of them incase I want to change my mind as to what the default theme is.

@AndiDittrich
Copy link
Member

if you want to use Enlighter outside of bbPress you have to set at least one theme.

the empty array setting works for the TinyMCE plugin alone but not in conjunction with the Enlighter plugin (sorry for this - i'm testing the plugins standalone most of the time).

@ajtruckle
Copy link
Author

if you want to use Enlighter outside of bbPress you have to set at least one theme.

That is why I was surprised that in the backend I could not choose a theme anymore. Maybe something else going on?

@ajtruckle
Copy link
Author

I had to disable the code snippet so I could select the theme customizer.

Maybe:

Snippet

I should set the option to only run it in the front end or something? Or is there a bug? But by deactivating the above code I was able to select a theme in the backend. Activating the code I could no longer select a theme.

@AndiDittrich
Copy link
Member

the issue is that the "customizer" theme is also an item within the array

    // list of build-in themes
    const THEMES = array(
        'enlighter' => 'Enlighter',
        'godzilla' => 'Godzilla',
        'beyond' => 'Beyond',
        'classic' => 'Classic',
        'mowtoo' => 'MooTwo',
        'eclipse' => 'Eclipse',
        'droide' => 'Droide',
        'minimal' => 'Minimal',
        'atomic' => 'Atomic',
        'rowhammer' => 'Rowhammer',
        'bootstrap4' => 'Bootstrap4',
        'dracula'=> 'Dracula',
        'monokai' => 'Monokai',
        'wpcustom' => 'Theme Customizer'
    );

@ajtruckle
Copy link
Author

Ok, So what is the plan?

  1. We want to suppress the list of themes the user can select in the front end when creating a code block via bbPress.
  2. We do not want to suppress the list of themes in the backend, since only I have access to it.

@AndiDittrich
Copy link
Member

give me a few minutes....

but generally: without additional KSES filters it is not possible to suppress this (users can still edit the raw content)

AndiDittrich added a commit that referenced this issue Apr 25, 2020
@AndiDittrich
Copy link
Member

see: https://github.com/EnlighterJS/documentation/blob/master/wordpress/FilterHooks.md#filterenlighter_editor_themes

added in v4.2.0

@AndiDittrich
Copy link
Member

for your use case: you have to add some ACL related code to determine if the current user is admin/manager and if the request is related to the frontend/backend

@AndiDittrich
Copy link
Member

ACL related stuff is projected for the pro/enterprise editions only - sorry... (it requires a full rework of the TinyMCE plugin...)

you can easily do it on your own by building a custom version of the TinyMCE plugin and hook into the enlighter_resource filter

@ajtruckle
Copy link
Author

So I need to use this:

// add a custom filter to modify the theme list
add_filter('enlighter_editor_themes', function($themes){
    // DEBUG: just display the dataset - uncomment the following line to debug issues
    // echo '<pre>', print_r($themes, true), '</pre>';

    // unset the theme
    unset($themes['godzilla']);

    return $themes;
});

And add some wrapper logic to see if :

  • admin and backend - Do nothing and it will show all themes.
  • front end - return the empty array and it will only show the default theme.

Right?

@AndiDittrich
Copy link
Member

theoretically...^^

snippets

// frontend or dashboard area ?
if (is_admin()){}

// check frontend user privileges
$canEdit = is_user_logged_in() && (current_user_can('edit_posts') || current_user_can('edit_pages'));

@ajtruckle
Copy link
Author

I will look into it. Got work tonight so it will be tomorrow on my staging site.

The only other alternative was setting my snippet to only run in the front-end. If you look at the screen grab it has an option to run the snippet in backend or frontend or both. It is currently set to both.

@ajtruckle
Copy link
Author

I don't think I am understanding this quite right:

// add a custom filter to modify the theme list
add_filter('enlighter_editor_themes', function($themes){
    // DEBUG: just display the dataset - uncomment the following line to debug issues
    // echo '<pre>', print_r($themes, true), '</pre>';
  
  if (!is_admin()) // Front end
  {
	// check frontend user privileges
	if ( is_user_logged_in() && (current_user_can('edit_topics') || current_user_can('edit_replies') ) )
	  $canEdit = true ;
	
	if(!$canEdit) $themes = array();
  }

    // unset the theme
    unset($themes['godzilla']);

    return $themes;
});

Doh! I not downloaded your latest version.

@ajtruckle
Copy link
Author

Looks like I am doing something wrong. It doesn't seem to work. But this seems complicated to me.

  1. When we are in the backend and I go to the EnlighterJS settings page it should list all the themes.
    At the moment it does show them all. So that is good.

  2. When we are in the front edit and creating a bbPress forum post/reply we do not want to list all of the themes in the tiny MCE editor.

I had disabled the first snippet (add_filter('enlighter_themes', function ($themes)) as that was originally preventing the themes to show.

So I am getting confused. Now I have the themes show everywhere.

Note that in bbPress the actions are edit_topics and edit_replies.

@AndiDittrich
Copy link
Member

your snippet above should work with the latest snapshot. you should not use the enlighter_theme filter anymore for your use-case.

maybe your acl check is not correct. just try a simple clause with is_admin only

@AndiDittrich
Copy link
Member

@ajtruckle
Copy link
Author

That works great - thanks. :)

Noticed a typo in the comment wthin instead of within.

jdelasoie pushed a commit to epfl-si/wp-plugin-enlighter that referenced this issue May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants