0

Have a news site and until recently, there were two ways to get behind the paywall legitimately. First was with a user/pass that was checked against a remote database and returned an AUTH value of yes or no. This part still works. The other method was by designating a Post or Page with a custom field called Free Story. Free Story would have a value of 1 or zero. 1 was YES IM FREE. Zero was, NO go with the user/auth system.

The site is quite old. Session Auth was used for some reason I do not know. Setting a Free Story value of true or 1 or yes should allow it to be frrely visible. OTherwise, only the user/pass will work. The list of 'accordion' items under custom fields is illustrative of what I see as corruption in the database from some ancient plugin. Free Story may or may not show up for users to choose, but they can Always create it and set it to their pref value.

I have no idea of how to debug this. I've been set to this on the fly with barest knowledge and my goes is to not make it worse. $post-id is the int value or post number assigned to the post in WP when it is created. If you don't change the permalinks settings, the url will end with that value.

In the code posted below, only initial 10-25 lines seem to be related to the Free Story custom field. THe remainder refers to how to handle AUTH and unAUTH from the user/pass system.

This system has worked for YEARs. I inherited this code and Only had the AUTH side modified to speed login for users, and that has been working along with Free Story for 2 years.

My guess, as a newbie walking into this fire, is that somehow Free Story's value is not passing into the post meta and not being recognized as 1 when the code below looks for it.

Indeed, when a user goes to assign the Free Story field, a series of choices for some kind of "accordion" system shows up. Making a new Field of the correct value does not seem to work. New plugins for custom fields also do not work. See attachment:

What one sees if clicking on Custom Field dropdown list. These are NOT our custom fields

The page.php theme template contain the following code; here's the entire php file:

    <?php get_header(); ?>

    <div id="content" class="archive">
<!-- Newzware Protection Code -->   

    <?php 
        $key = 'Free Story';
        $themeta = get_post_meta($post_id, $key, TRUE);
        if($themeta != '') {
        $free_story = 1; 
        }
     ?>

    <?php if($_SESSION['auth'] == '1' OR $free_story == '1') { ?>   

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="post" id="post_<?php the_ID(); ?>">

    <span id="map"><a href="<?php echo get_option('home'); ?>/"><?php _e('Home','arthemia');?></a> &raquo; <?php the_title(); ?></span>

    <h2 class="title"><?php the_title(); ?></h2>

        <div class="entry" style="padding-top:15px;">
        <?php the_content(__('<p>Read the rest of this page &raquo;</p>','arthemia')); ?>

        <?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong>','arthemia'), 'after' => '</p>', 'next_or_number' => 'number')); ?>

        </div>

    </div>

    <?php endwhile; endif; ?>


    <?php } else { ?>
                        <div class="panel panel-default" style="margin-top:10px;"><div class="panel-heading" style="background:#0079BD;" "color:#fff;" "text-align:center;"> Subscribe To The Journal</div><div class="panel-body">  <p style="text-align:center">&nbsp;
      </p>
           <div > If you are already registered with The Journal/ UpstateToday.com, please <a href='https://seneca.newzware.com/ss70v2/seneca/common/template.jsp?nwmodule=registration&nwpage=registration&returnPage=https://upstatetoday.com/utloginnw/&rpage=https://upstatetoday.com/newzware_auth.php' class=class='SumaPostContent'><b class="text-danger"> click here </b></a> to log in and continue reading. If not, <a href='https://seneca.newzware.com/ss70v2/seneca/common/template.jsp?nwmodule=nonsubscribers&nwpage=nonsubstart'><b class="text-danger"> please click here for subscription options </b>. </a>.</p></div>
</div></div>

    <!--    <div class='panel panel-default' style='margin-top:10px;'> <div class='panel-heading' style='background:#0079BD; color:#fff; text-align:center;'>Subscribe To The Journal</div><div class='panel-body'>  <p style='text-align:center'>
        If you are already registered with The Journal/ UpstateToday.com, please <a href='https://seneca.newzware.com/ss70v2/seneca/common/template.jsp?nwmodule=registration&nwpage=registration&returnPage=https://upstatetoday.com/utloginnw/&rpage=https://upstatetoday.com/newzware_auth.php' class=class='SumaPostContent'><b class="text-danger"> click here </b></a> to log in and continue reading. If not, <a href='https://seneca.newzware.com/ss70v2/seneca/common/template.jsp?nwmodule=nonsubscribers&nwpage=nonsubstart'><b class="text-danger"> please click here for subscription options </b>. </a>.</p></div></div>
    -->
    <?php } ?>


    <!-- End Newzware Protection Code --> 


    </div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Free Story and its value as entered on some stories

9
  • I'm not sure what the problem is, you seem to have glossed over how it isn't working and gone straight to trying to explain the code. Is Free Story not appearing in that dropdown? I see the code uses PHP Session variables, I'd strongly recommend against them in favour of cookies, they don't work on most web hosts, and WP uses cookies internally, as do most sites. How are you debugging the value of the variable? Are you just plugging it into that UI then checking it the page loads? Or are you actually looking at the value of the variable? Where does $post_id come from?
    – Tom J Nowell
    Nov 12, 2019 at 15:36
  • Please edit your question to answer those questions, even if the answer is "I don't know" that's valuable information to know
    – Tom J Nowell
    Nov 12, 2019 at 15:40
  • I'll try my best, but most of the answer is I don't know. I apologize for being far out of my newbie depth and trying to grasp what has failed here. No, Free Story does not always appear in the drop-down, but it can always be added. That behavior seems to have started when the access issue started. No idea about the Session Variable v cookie. I see that as not related to the free story aspect. Debugging by whether it works or not. $post_id is the int value of the wordpress post. I think maybe the TRUE in that variable shoudl be FALSE bc the WP codex shows it as such. more--
    – JC Corbin
    Nov 12, 2019 at 16:50
  • The part that is confusing to me is the last 2 lines: '$key = 'Free Story'; $themeta = get_post_meta($post_id, $key, TRUE); if($themeta != '') { $free_story = 1; }' What is 'if($themeta != '') saying? That if $free_story is not equal to 1, then ... what? Does the $free_story variable come from the post meta table? I don't know how it got there.
    – JC Corbin
    Nov 12, 2019 at 16:51
  • @TomJNowell Maybe I was unclear earlier. If you go to the site upstatetoday.com and try to view a page such as FullView from the menu, you will run into a subscribe option. CLicking on any home page post will show you the post. The difference is that I changed '<?php if($_SESSION['auth'] == '1' OR $free_story == '1') { ?>' to <?php if($_SESSION['auth'] == '1' OR $free_story == '1' OR 'yes' OR 'Yes') { ?> ONLY one of the posts is supposed to be Free, though. This one: upstatetoday.com/2019/11/school-shooter-sentencing-starts-today
    – JC Corbin
    Nov 12, 2019 at 17:03

1 Answer 1

0

First @TomJNowell is 100 percent right. It was the PHP and my ignorance of it.

Putting in the following code from a year-old backup seems to have fixed the issue in question, if not the underlying improvements that need to be made:

<?php 
    $key = 'Free Story';
    $themeta = get_post_meta($post->ID, $key, TRUE);
    if($themeta != '') {
    $free_story = 1; 
    }
 ?>

<?php if($_SESSION['auth'] == '1' OR $free_story == '1' ) { ?>

NOTE that $post_id from earlier has been replaced with the proper code to call the ID of the current post/page: $post->ID Also note that the TRUE value after $key appears to ask the meta to go through until it finds the $key (Free Story) I want and then operate on that value. I still don't get what if(@themeta != '') {$free_story = 1;} is saying. Is it saying that IF themeta is Null or empty, set $free_story to = 1? Regardless, That's a learning mission for me. Thank You Tom for your patience!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.