Need Help With PHP to Customize Password-Protected Post Notification
-
Note: To get a feel for what I’m talking about here check, out the way my index works (not how most of the post titles are actually off-site links). And then look at what happens when a post title links to a password-protected archive page instead.
I’m designing a theme for freelance writers to show off their work to potential clients.
Of course, when you sell an article, you no longer hold the copyright so posting the full text or a scan on the Web is a no-no. This is often not a problem because many publications offer their content online as well, so it’s just as easy to link out to their sites. I’ve designed my theme to be used with the a custom field called “livelink,” so when you browse through the posts, the headline (post title) links off to an outside Web site if the livelink field is filled in, if not the link defaults to the permalink.
But not every publication has a Web site yet (believe it or not) and sometimes publications don’t put every scrap of content online, either. For this reason writers want to hold an archive version of each article inside a password-protected post — either a scanned image or the raw text of the article — for the just-in-case.
That way, the permalink to head to a password-protected page so we don’t violate any copyrights. I can just send a a potential client the password if I want him or her to be able to see the clip on my siteFor example, an article I wrote for Rolling Stone was not posted on the Web. I have a scanned version inside the post page, but I want to display a small alert for anyone browsing my site explaining the copyright situation, which also directs them to the off-site article (if available) and prompts them for the password. Here’s what I want my alert to look like.
I generated that screenshot by running some code in The Loop. This is similar to the PHP calls I make when displaying the post titles. It renders clean and simple:
<div class="alert2"><a href="https://cspencerbeggs.com/clips/rollingstone/" class="bluelink" title="Browse more articles published by Rolling Stone">Rolling Stone</a> published and holds the copyright on this article, which can be <a href="https://cspencerbeggs.com/clips/topics/humor/hotblasphemy/" class="bluelink" title="Hot Blashphemy">viewed live on their site</a>. A password-protected copy is retained on this site.<br /> <label><b>Password:</b></label> <input name="post_password" type="password" size="20" /> <input type="submit" name="Submit" value="Submit" /></div><br />
On the backend (again, this is if it were The Loop), the code is a mess of PHP used to call the various variables needed to display all the link info:
<div class="alert2"><a href="<?php bloginfo('url'); ?>/clips/<?php topcat_the_main_category_slug() ?>/" class="bluelink" title="Browse more articles published by <?php topcat_the_main_category() ?>"><?php topcat_the_main_category() ?></a> published and holds the copyright on this article, which can be <a href="<?php if (get_post_meta($post->ID,'livelink',true)) {echo get_post_meta($post->ID,'livelink',true);} else {the_permalink();}; ?>" class="bluelink<?php if (get_post_meta($post->ID,'livelink',true)) { ?> offsite<?php } ?>" <?php if (get_post_meta($post->ID,'livelink',true)) { ?>rel="external" title="Read this article on the <?php topcat_the_main_category() ?> Web site"<?php } else { ?>title="<?php the_title(); ?>"<?php } ?>>viewed live on their site</a>. A password-protected copy is retained on this site.<br /> <label><b>Password:</b></label> <input name="post_password" type="password" size="20" /> <input type="submit" name="Submit" value="Submit" /></div><br />
<b>NOTE:</b> I’m using the invaluable Top Cat plugin to generate the part of the category link for the publication.
Finally my question: The message for the password-protected post info is generated by the function get_the_password_form() post-template.php file in ~/wp-includes/post-template.php
I tried to hack it, but I just end up with PHP errors. I’m not sure how to escape “s and whatnot in PHP. Can anyone point me in the right direction to getting my alert to render on the password-protected pages?
- The topic ‘Need Help With PHP to Customize Password-Protected Post Notification’ is closed to new replies.