Auto Populate Posts
-
Hello everyone, what follows in this thread is my Auto Populate Posts hack that I am giving to the WordPress community…
Thanks! ??
-
Hello everyone,
Here is what I call my “Auto Populate Posts” wordpress hack that allows you to click buttons on the Add New Post page of the WordPress Admin and have predetermined content auto fill into either the Title, Content, and/or Excerpt fields of a new post.
Please view the original support thread (www.ads-software.com/support/topic/308554) for my purpose of needing this functionality, which in short was to create templates for post fields if specific types of posts I regularly publish within WordPress without having to copy & paste from a text file.
This shall be considered version 1.0 of this Auto Populate Posts hack.
If anyone would like to cleanup or further develop this hack (especially into a plugin), and post the updates here, then that would be great!
I am not skilled in coding, so this is a rough and non-elegant implementation, however, the basic functionality works properly.
This Auto Populate Post hack was developed for WordPress version 2.8.4 on a LAMP (linux, apache, mysql, php) platform and also utilizes javascript.
This hack is not supported, is highly experimental, and all risk & liability lies solely with the individual users of this code.
————————–
Installation Instructions (4 Steps):
– Step #1: Copy the following piece of code and paste it into the /wp-admin/edit-form-advanced.php core WordPress file…paste it between the following two lines at line #596 as of WP 2.8.4…
<div id=”post-body-content”>
PASTE CODE HERE
<div id=”titlediv”><!-- Auto Populate Posts Hack 1.0 --> <?php $autopopulatepostsfile = get_template_directory()."/autopopulateposts.php"; if(!file_exists($autopopulatepostsfile)) { echo("<p style='font-weight:bold; color:#C00; margin-bottom:20px;'>The file named 'autopopulateposts.php' was not found in your currently active WP theme named '".get_current_theme()."'. Please uninstall this Auto Populate Posts hack or upload the 'autopopulateposts.php' file to this current theme's root directory at '".get_template_directory()."'.<br /><br /><span style='margin-left:20px; display:inline-block;'>- To uninstall this Auto Populate Posts hack, remove code between the <-- Auto Populate Posts Hack --> tags in core file '/wp-admin/edit-form-advanced.php' around line 596.</span><br /><br /><span style='margin-left:20px; display:inline-block;'>- For more info about this hack see: <a href='https://bit.ly/AutoPopulatePosts' target='_blank'>bit.ly/AutoPopulatePosts</a></span><br /><br /><span style='margin-left:20px; display:inline-block;'>- This hack is not supported by the author. Created for WordPress version 2.8.4. The source code may be freely distributed without restriction. :)</span></p>"); } else { include_once($autopopulatepostsfile); } ?> <!-- Auto Populate Posts Hack 1.0 -->
– Step #2: Open a new text file (in a program such as Notepad), paste the following code into it and save the file as “autopopulateposts.php”. Edit the table of predetermined Title, Content, & Excerpt data in this file as you require.
<!-- End Auto Populate Posts Hack 1.0 / bit.ly/AutoPopulatePosts / Created for WordPress version 2.8.4 / This hack is not supported by the author. / The source code may be freely distributed without restriction. :) --> <script type="text/javascript" type="text/javascript"> //<![CDATA[ if(document.createElement) (function(){ var radiostitle = function(e){ e = e || window.event; var t = e.target || e.srcElement, t2, c = 0; if (t.name == 'stitle'){ t2 = t.parentNode; while (t2.nextSibling){ t2 = t2.nextSibling; if (t2.firstChild && t2.firstChild.nodeValue) document.getElementById('title').value = t2.firstChild.nodeValue; } } }; if (document.addEventListener) document.addEventListener('click', radiostitle, false); else if (document.attachEvent) document.attachEvent('onclick', radiostitle); })(); //]]> </script> <script type="text/javascript" type="text/javascript"> //<![CDATA[ if(document.createElement) (function(){ var radioscontent = function(e){ e = e || window.event; var t = e.target || e.srcElement, t2, c = 0; if (t.name == 'scontent'){ t2 = t.parentNode; while (t2.nextSibling){ t2 = t2.nextSibling; if (t2.firstChild && t2.firstChild.nodeValue) document.getElementById('content').value = t2.firstChild.nodeValue; } } }; if (document.addEventListener) document.addEventListener('click', radioscontent, false); else if (document.attachEvent) document.attachEvent('onclick', radioscontent); })(); //]]> </script> <script type="text/javascript" type="text/javascript"> //<![CDATA[ if(document.createElement) (function(){ var radiosexcerpt = function(e){ e = e || window.event; var t = e.target || e.srcElement, t2, c = 0; if (t.name == 'sexcerpt'){ t2 = t.parentNode; while (t2.nextSibling){ t2 = t2.nextSibling; if (t2.firstChild && t2.firstChild.nodeValue) document.getElementById('excerpt').value = t2.firstChild.nodeValue; } } }; if (document.addEventListener) document.addEventListener('click', radiosexcerpt, false); else if (document.attachEvent) document.attachEvent('onclick', radiosexcerpt); })(); //]]> </script> <style type="text/css"> .app-autopopulateposts-items td { border:1px solid #464646; width:55px; max-width:105px; height:20px; max-height:35px; overflow:hidden; white-space:nowrap; padding-left:1px; padding-right:1px; } .app-autopopulateposts-items td:hover { width:100%px; max-width:100%; background-color:#FFC; } </style> <div style="width:99%; background-color:#464646; padding:2px 1px 2px 1px; font-weight:bold; color:#fff;"><div style="text-align:left; float:left; width:45%; padding-left:7px;">Auto Populate Posts...</div><div style="text-align:right; float:right; width:45%; padding-right:7px;"><a href="https://bit.ly/AutoPopulatePosts" target="_blank" style="color:#fff; font-style:normal; font-size:10px;">Info Link</a></div><div style="clear:both; line-height:0px; height:0px;"> </div></div> <div style="width:99%; max-height:170px; overflow:scroll; margin-bottom:20px; border:1px solid;"> <table style="width:50%; padding:5px;"> <tr> <td style="text-align:center; font-weight:bold; text-decoration:underline; font-size:14px;">Post Title</td> <td style="text-align:center; font-weight:bold; text-decoration:underline; font-size:14px;">Post Content</td> <td style="text-align:center; font-weight:bold; text-decoration:underline; font-size:14px;">Post Excerpt</td> </tr> <tr> <td style="vertical-align:top; padding:0px 5px 0px 5px;"> <table class="app-autopopulateposts-items"> <tr> <td><input name="stitle" type="radio"></td> <td>EDIT: Post Title #1:</td> <td>EDIT: This is title #1</td> </tr> <tr> <td><input name="stitle" type="radio"></td> <td>EDIT: Post Title #2:</td> <td>EDIT: This is title #2</td> </tr> <tr> <td><input name="stitle" type="radio"></td> <td>EDIT: Post Title #3:</td> <td>EDIT: This is title #3</td> </tr> <tr> <td><input name="stitle" type="radio"></td> <td>EDIT: Post Title #4:</td> <td>EDIT: This is title #4</td> </tr> <tr> <td><input name="stitle" type="radio"></td> <td>EDIT: Post Title #5:</td> <td>EDIT: This is title #5</td> </tr> </table> </td> <td style="vertical-align:top; padding:0px 5px 0px 5px;"> <table class="app-autopopulateposts-items"> <tr> <td><input name="scontent" type="radio"></td> <td>EDIT: Post Content #1:</td> <td>EDIT: This is content #1</td> </tr> <tr> <td><input name="scontent" type="radio"></td> <td>EDIT: Post Content #2:</td> <td>EDIT: This is content #2</td> </tr> <tr> <td><input name="scontent" type="radio"></td> <td>EDIT: Post Content #3:</td> <td>EDIT: This is content #3</td> </tr> <tr> <td><input name="scontent" type="radio"></td> <td>EDIT: Post Content #4:</td> <td>EDIT: This is content #4</td> </tr> <tr> <td><input name="scontent" type="radio"></td> <td>EDIT: Post Content #5:</td> <td>EDIT: This is content #5</td> </tr> </table> </td> <td style="vertical-align:top; padding:0px 5px 0px 5px;"> <table class="app-autopopulateposts-items"> <tr> <td><input name="sexcerpt" type="radio"></td> <td>EDIT: Post Excerpt #1:</td> <td>EDIT: This is excerpt #1</td> </tr> <tr> <td><input name="sexcerpt" type="radio"></td> <td>EDIT: Post Excerpt #2:</td> <td>EDIT: This is excerpt #2</td> </tr> <tr> <td><input name="sexcerpt" type="radio"></td> <td>EDIT: Post Excerpt #3:</td> <td>EDIT: This is excerpt #3</td> </tr> <tr> <td><input name="sexcerpt" type="radio"></td> <td>EDIT: Post Excerpt #4:</td> <td>EDIT: This is excerpt #4</td> </tr> <tr> <td><input name="sexcerpt" type="radio"></td> <td>EDIT: Post Title #5:</td> <td>EDIT: This is excerpt #5</td> </tr> </table> </td> </tr> </table> <div style="text-align:center; font-weight:bold; color:#C00; font-style:italic;">To edit your auto populate content, edit the autopopulateposts.php file.</div> </div> <!-- End Auto Populate Posts Hack 1.0 / bit.ly/AutoPopulatePosts / Created for WordPress version 2.8.4 / This hack is not supported by the author. / The source code may be freely distributed without restriction. :) -->
– Step #3: Upload this newly edited “autopopulateposts.php” file to the root of your WordPress theme located at /wp-content/themes/YOURTHEMEDIRECTORY.
– Step #4: Go to your WordPress Admin to the Add New Post form and a table of radio buttons should appear at the top of the left column of wide input fields (likely above your Title field). You should be able to click on the radio buttons in this table and have the Title, Content, & Excerpt fields auto fill with the predetermined content without having to type or paste it in.
————————–
Current Bugs:
– The form’s html table does not display nicely in Internet Explorer 8, however, it is still usable and the functionality works well. Firefox, Safari, & Chrome display properly.————————–
Future Plans:
– I plan to add functionality to auto populate the Categories field in the future when I have more time to figure the right code out for auto checking multiple checkboxes with the click of a button, likely using javascript.————————–
If you have received some benefit from this Auto Populate Posts hack, would like to make a suggestion, or can improve upon it, then I’d enjoy hearing from you in this thread.
Thank you! ??
Great hack and great concept!. What I’d like to know though is how can I “auto-populate” pages? I’m running a MU site and when the user signs up I’d like to have one page already populated with a form. All they’ll need to do is enter info in the fields.
Anyone have any thoughts…?
Thanks
Hi seolun4tic,
Thanks for the complements on my Auto Populate Posts hack!
If I’m understanding your need correctly, it is a bit different than mine…
Where mine is a form to optionally be used in real-time whenever adding a new post. Could be applied to the Add New Page form too.
However, it sounds like you want to have one standard page created only one time, upon each new user signup. If so, then this would first mean adding code to insert the standard page into the database behind the scenes whenever anyone signs up.
Then it also sounds like you want some type of form template that users can systematically fill out to edit that page after they signup. At this point, you could use my auto populate form method, but rather put it in the Edit Page form (I believe within wp-admin/edit-page-form.php) and insert a condition where this form template only shows itself when editing this one standard page you want to achieve it with.
If I got that right, I could see where that would be useful in a lot of scenarios. However, I don’t have the skill to implement this for you, but it shouldn’t be too hard for an experienced php/mysql developer.
If you create this in the future, feel free to post a link to it back here, as I would be interested.
Thanks!
Looks like this plugin might be of interest:
https://www.ads-software.com/extend/plugins/post-template/
- The topic ‘Auto Populate Posts’ is closed to new replies.