Compatibility issue between php code and Headway Theme

This is a bit of a crazy situation. A couple of weeks ago, i was trying to edit one page in the visual editor of Headway Theme 3. I can use the Grid mode but the Design mode does not load. I tried in Chrome and in Firefox, and nothing works to load that page. Other pages are loading fine. Looking further, there is one code that i am using for the page to display or redirect the user based on s2M conditional. The code is this:

<?php if (current_user_can('access_s2member_ccap_element') OR current_user_can('access_s2member_ccap_diamond')){ ?>
<script type="text/javascript">
window.location = 'http://scrapbookcampus.com/element-creation-index/';
</script>
<?php } else {?><?php } ?>

The code itself works fine and has worked fine for months (and it still works). Initially, that code was in a custom code block. I tried changing it to a content block. No go. If i remove that code completely, the page will load fine in the editor. I contacted Headway and they can’t explain why this is happening. I only noticed that a couple of weeks ago, when i needed to tweak that one particular page. It was loading fine before. I tried desabling all the plugins and if s2M is disabled, of course that loads fine (with odd code showing) but as soon as s2M is reactivated, it won’t load.

That has not been any update to the Headway theme in months so that didn’t change. I know the last update to s2M was in February. I cannot remember when was the last time i had to tweak that page in the Design mode so i have no clue if it is from the last s2M update or not.

Can anyone help me out?

The page in question is this one: http://scrapbookcampus.com/creative-scrap/memberships

I’ll start by saying that the way a redirect should normally be done in WP is in a plugin or the active theme’s functions.php file.

What I’d suggest is that you try replacing this:

 ?>
<script type="text/javascript">
window.location = 'http://scrapbookcampus.com/element-creation-index/';
</script>
<?php

with this:

wp_redirect( "http://scrapbookcampus.com/element-creation-index/" );
exit;

But, since you’re using Headway, I have no idea where you should place the whole code.

How would that code redirect based on ccaps? I need visitors who have a particular ccap to be redirected (instead of seeing the sale page) while other visitors should not be redirected and still see the sale page. This code is something i got from s2M, years ago and it always worked.

Your code performs the redirect using javascript. Mine performs it using PHP which, frankly, is what you should be using for this type of redirect.

Just replace the bit I said to replace, and leave the bit with the ccaps in place.

Oh i see. I misread, thinking that i was to replace the whole code. Ok i’ll try that and update you.

No luck. It still does not let the page load in the editor.

In that case, my guess is that the code runs too late in the Headway code block (or whatever you call it) for PHP to work, and that’s why you were given a javascript solution before. So I offer two alternatives, which are both intended just to replace this line from your original code:

window.location = 'http://scrapbookcampus.com/element-creation-index/';

You can try instead either this:

window.location.href = 'http://scrapbookcampus.com/element-creation-index/';

or this:

window.location.replace('http://scrapbookcampus.com/element-creation-index/');

If this is the entire problem (you cannot edit code in the WordPress backend), edit the code offline and update via FTP. I turn off the code editor in WordPress in every site I manage, even my own. It takes 30 seconds (max) to download a file and then upload it again after editing. Keeping the code editor active is a security loophole and, in the case of client sites, just asking for trouble. Editing live code is always a bad idea, in any case. (Yeah, I do it too…)

The very reason i chose Headway as a theme is to not have to code (or minimally). I have NO CLUE how i would edit the format and such offline. The Design mode of the editor is not in the WP backend so to speak , and it is for the formating (colors, padding, font size, etc.) which i really don’t do in WP itself. I can load the grid mode (where i can add blocks and block content) but not the Design mode.

In that case, my guess is that the code runs too late in the Headway code block (or whatever you call it) for PHP to work, and that’s why you were given a javascript solution before. So I offer two alternatives, which are both intended just to replace this line from your original code:

window.location = ‘http://scrapbookcampus.com/element-creation-index/’;
You can try instead either this:

window.location.href = ‘http://scrapbookcampus.com/element-creation-index/’;
or this:

window.location.replace(‘http://scrapbookcampus.com/element-creation-index/’);

I’ll give this a try later, tonight.

@Cassel, you try to edit the page as Admin, which is usual way to edit a page. But Admin have all possible rights! And the code caches YOU and try to redirect you in Design mode, because then the page loads like in user’s browser. So you should deactivate the code before to run Design more and reactivate it after you finish editing. Note that the code will be inactive for your visitors too…

I know i CAN do that. I also know that while i work with the code deactivated, members who should be redirected won’t be (which is quite annoying). The problem is that this code WAS NOT affecting the Design mode of the visual editor before, but it does NOW, so there is something that changed. Since HT has not had any update in many months, it can’t be a change in HT, so since it is ONLY affected when s2M is active, i suspect that it has something to do with s2M, and i am hoping that the s2M developers might have a chance to have a look at it. If it affects me, it might affect others.
Maybe i am not posting at the right place and the developers are not following here?

I think it is much more likely that something has changed on your host, perhaps by their adding a cross-scripting filter which blocks your javascript.

Perhaps, but I doubt it’s a widespread issue. First, you are using Headway, which is a law unto itself. And second, you are, as a result, using a javascript redirect when it would normally make more sense to use a PHP redirect in the active theme’s functions.php file. A PHP redirect won’t get stopped by a cross-scripting filter.

1 Like

Not to put a damper on anyone’s enthusiasm for s2Member, WebSharks does not provide any support for compatibility problems with themes other than the default WordPress theme. We are not WebSharks, but neither are we able to know what kind of compatibility issues exist between s2Member and every theme anyone could possibly choose to use.

I agree with Tim that is likely to be a problem with your hosting and not with s2Member.

You may lock the page for others temporary, like to make it draft or private.

Sure, this don’t answers your questions, but gives you a workaround. Changes can be in other plugins too, or in the browser…