Closed ajtruckle closed 4 years ago
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).
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?
I had to disable the code snippet so I could select the theme customizer.
Maybe:
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.
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'
);
Ok, So what is the plan?
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)
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
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
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 :
Right?
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'));
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.
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.
Looks like I am doing something wrong. It doesn't seem to work. But this seems complicated to me.
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.
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
.
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
That works great - thanks. :)
Noticed a typo in the comment wthin
instead of within
.
Recently I added this code snippet:
That was based on our discussion here. The problem I have now discovered is in my backend:
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.