User roles and Javascript
- This topic has 9 replies, 2 voices, and was last updated 7 years, 7 months ago by Ray.
-
AuthorPosts
-
March 13, 2017 at 6:19 pm #6263Troy WelchParticipant
Hi, I’m experiencing an interesting problem. In addition to Cbox I’m also running the Advanced Access Manager (AAM) plugin.
Depending on the user role javascript runs or not. There are two cases at the moment. In both cases things work fine for Super Admins/admins, but for Editor/Author roles the following occurs:
- Home page: jquery.bxslider.min.js is not being properly executed although the script is being downloaded in the head of the document. In the div nest for admin users div.flexslider is followed by div.bx-wrapper then div.bx-viewport. Whereas, in the editors/authors div.flexslider is followed directly by div.slides. The resulting slide are rendered at 0 height without slide logic so basically do not appear on the page.
- A similar thing happens with the blogs list. Admin users have a normal display, editor/author are not able to see sites set to network only privacy level, but are able to see sites set to the more public two options.
I think both of these are related to some javascript not running for the editor/author level users. The behaviour is the same on chrome and firefox dev using test accounts at various permissions levels.
Do you guys have any thoughts on where I might starting digging on this?
Thanks,
Troy
March 13, 2017 at 6:52 pm #6265RayKeymasterHi Troy,
1. Does the slider work as expected if the AAM plugin is deactivated? All theme assets are enqueued using WP’s
wp_enqueue_script()
without any role restrictions. However, it looks like the slider JS only loads if the homepage is using the bundledtemplates/homepage-template.php
file as its page template:
https://github.com/cuny-academic-commons/cbox-theme/blob/3e426baa15a1fc07682da32bf5773bcafcacdd92/engine/config/infinity.ini#L147Is your homepage using a different custom page template?
To tell if you are using a different custom page template, check out this guide:
https://www.smashingmagazine.com/2015/06/wordpress-custom-page-templates/#1-assigning-custom-page-templates-from-the-wordpress-editor
2. What is the “blogs list”? Are you referring to the Sites Directory (example.com/sites/) or a widget with a list of Blogs?
March 14, 2017 at 2:04 pm #6279Troy WelchParticipantThanks Ray (apologies if this double-posts, I edited to remove some html code that got copied over and my edited version doesn’t seem to be showing.)
- The problem I have is that these issues are occurring on a live site (instructors and participants in a live program) and I risk confusing some people if I disable the plugin. I haven’t had a chance to back the live site up to a development server yet. Also, the slider renders fine for Super-admins. I have some test accounts still active and the slider does not work for a test instructor. If give that account super-admin on the network the slider works fine. So it does appear to be capability (by extension from the roles) related.My understanding of AAM is that upon activation it “zeros” capabilities. (as opposed to roles) So I had to add some of those back. My understanding (I use the word understand so that my understanding can be corrected if flawed) is that several elements of CBox/Buddypress run on custom post types. It is like that I need to “re-enable” read access to these for the users.
I have a custom post type of my own installed and operational, so it doesn’t seem that the standard capabilities are in effect for the CBox/Buddypress CPTs and may, in fact, not be accessible in the AAM plugin.
Although I hate to, I might have to dive into the database and have a look around. Although, I am going to first try the dev-mode setting to regenerate the css and js in case it is that simple.
- I am referring to the Site Directory and the more privacy options. If my understanding is correct here:
Allow search engines to index this site
Discourage search engines from indexing this site
Note: Neither of these options blocks access to your site — it is up to search engines to honor your request.
Visible only to registered users of this network
Visible only to registered users of this site
Visible only to administrators of this siteThe top two options open the site to the public internet, the bottom three don’t.
Further, the top 3 options should put the site in the Site Directory list, the bottom two shouldn’t.
The way it is currently working for us is that only top setting will put the site into the Site Directory list.
Super-admins see a full Directory regardless of Site Visibility setting.
I have the feeling that this is capabilities related as well and if I solve either issue that I’ll solve them both.
March 15, 2017 at 2:32 pm #6285RayKeymaster1. Sorry, I re-read your initial post and it looks like you say that the bxSlider JS is loaded, but the slide output is not.
On the “CBOX Theme Options” page, under “Homepage > Slider Setup”, what do you have the slider set up to use – “Show Site Features” or “Show Featured Post from a Category”?
If you are using “Show Site Features”, in this case, the slider uses the custom post type “features” and the capability type is inherited from posts:
https://github.com/cuny-academic-commons/cbox-theme/blob/3e426baa15a1fc07682da32bf5773bcafcacdd92/engine/includes/feature-slider/setup.php#L45It is quite possible that your AAM plugin could be restricting the slider posts due to this.
If you’re using the “Show Featured Post from a Category” option, then AAM could also be restricting posts made to the category you have chosen for the slider.
AAM has tons of configuration options for restricting post output:
https://aamplugin.com/help/how-to-manage-wordpress-post-and-category-accessHave you taken a look at their settings page to see if you have set it up properly?
2. Sounds more like a BuddyPress problem than with AAM.
BuddyPress only displays public sites in the Sites Directory for non-super admins:
https://buddypress.trac.wordpress.org/browser/tags/2.8.2/src/bp-blogs/classes/class-bp-blogs-blog.php?marks=188-189#L163I had to work around this for another site I work on to modify the
wb.public = 1
clause.March 15, 2017 at 3:34 pm #6286Troy WelchParticipantThanks for the follow-up Ray, I also changed my thinking on the relatedness of these two issues this morning. I started by running a diff on the source of the generated pages.
In the case of my first issue one of the things that jumped out of the code diff (but oddly not when I was looking at the rendered pages with my own eyes) was that the page footer for non-super-admin users is not full rendering. (On the home page only).
This includes some of the footer JS in particular:
<script type=”text/javascript”>
var cbox_slider;
jQuery(document).ready(function(){
cbox_slider = jQuery(‘.slides’).bxSlider({
adaptiveHeight: true,
autoHover: true,
mode: “fade”,
video: true,
useCSS: false,
controls: false,
pause: 10000,
speed: 600,
});cbox_slider.startAuto();
});
</script>The header script is being downloaded, as I mentioned before. My JS is on the weak side and I haven’t had a chance to review the header script in detail, but my working guess is that the absence of this footer script is not helping the cause any.
Of course, there’s also footer content missing so my working plan is to first try and get the footer rendering and see if that changes anything.
In terms of your feedback items:
We are using the Show Site Feature option. I’ll double check my settings, but all users should have read capabilities on all post types. We are using posts for only a couple of things, but I do also have an additional post type in there.
Issue 2, I’ll have a good look at the at the statement you highlighted and see if I can get my head around what might be happening.
Thanks again.
Oh, I’ll also mention that we are presenting our project at a couple of conferences in late spring/early summer. I’ll be giving the CBox team a huge shout-out for both the product and the exceptional support.
Cheers
March 15, 2017 at 4:27 pm #6287RayKeymaster1. Since you say your production site cannot be modified, I would try to reproduce your problem in a fresh, local environment.
Just use the CBOX Theme as your active theme with only the AAM plugin activated.
2. Here’s the code that I used to modify the Sites Directory query:
https://gist.github.com/r-a-y/2b0d574c46ce5b3ce83319d55be175beMake whatever modifications you need to make.
—-
Nice to hear that you will be presenting at a few conferences about your CBOX-powered site. Let us know how it goes!
March 15, 2017 at 4:54 pm #6288Troy WelchParticipantFirst problem; I’m current rooting around the footer template/part/widgets php file trying to find a spot where capabilities might be tapped (I should also see where that js snippet above comes from and if there is anything there hitting capabilities):
Everything seems to be hitting the page except the results of the three dynamic_sidebar calls. (left, middle, right) and the javascript I indicated above. All other divs, “powered by cbox” line and other javascript are hitting the page.
I do have a new local install of CBox & theme. I installed the AAM plugin, but was unable to install the premium extensions as we are only license for one url and it “phones home”. Much of the rest of the environment is also absent (additional plugs, child theme, templates, SSL, etc.) In any event there doesn’t seem to be a problem on the clean site. So somewhere between the two…
Second problem is waiting.
Thanks again for digging into this.
March 16, 2017 at 3:40 pm #6295Troy WelchParticipantUnderstanding deepens a little.
Okay, so still on the first problem, if I load a non-super-user page and enter the above javascript snippet, the slider springs to life and renders fine. (This could be expected I suppose)
So following on my very last reply in this thread, my new problem statement is:
What is prohibiting the addition of the javascript snippet and the results of the three dynamic_sidebar calls to the footer of the home page for non-super-admin users and why only on the homepage.
I see that this JS comes from the cbox_theme_flex_slider_script() function on the ‘close_body’ hook in the/feature-slider/setup.php file. Which is in turn required from:
/engine/includes/setup-cbox.php in turn from
/engine/includes/setup.php from
/engine/infinity.php from
functions.php
Perhaps I can trace those files back and see if they are being fully executed or if some non-super-admin thing is getting in their way.
I have other avenues to explore, I do have customizations to templates/homepage-template.php in my child theme but all those did was add an additional widget are beneath the slider. However, I may have introduced error. So I’ll check that.
The other lines of exploration, which are time-consuming rabbit holes, are to install debug bar or a remote debugger and see if I can spot the difference between super-admin and non-super-admin users on this issue.
I’d love any other suggestions.
t
March 21, 2017 at 3:13 pm #6298Troy WelchParticipantUpdate: I’ve broken out issue 2 into another thread. It was the initial issue from one of my users anyway.
Issue 1 has just been messing with my head and giggling loudly in the background.
By chance I happened to log in with a different test account and the display of the slider and footer works find. I’m not longer of the opinion that roles and capabilities have anything to do with the issue.
The issue being incomplete rendering of the footer including the javascript that loads the slider. I also did not hear that any of my users were experiencing this particular issue, I ran upon it while attempting to diagnose Issue 2 above. (now busted out into its own thread).
So, I’ve asked my users to all let me know (luckily only a couple of dozen of them at the moment) if any of them are experiencing rendering difficulties of the footer/slider on the home page. Unless I hear that any of them are, I’m going to think of the issue as closed and write it off to some anomaly with my testing account.
Cheers,
t
March 23, 2017 at 2:26 pm #6300RayKeymasterI would roll back your custom modifications to the
homepage-template.php
andfooter.php
templates and try to duplicate your problem.Then, reintroduce your mods one at a time to try and find what code could be causing the issue.
But, it sounds looks like your users are not experiencing the problem any more.
-
AuthorPosts
- You must be logged in to reply to this topic.