“Post-From-Site: Add a new post directly from your website – no need to go to the admin side.”
Version 1.9.0
Released 9.22.09
Download!
This new wordpress plugin allows you to post straight from your front-end (i.e. website) – perfect for a quick update! Also useful if you have multiple users and don’t need them to see the admin side of things (this is the reason the plugin was initially developed).
Just put the function in your template file wherever you want to quickpost link to show up, and there it will be! Once clicked on, a box will pop up and you can type your post there. You need to give it a title and content (or else it won’t post), you can also choose to add it to categories, or (if allowed in the settings) attach an image. After hitting post you may need to refresh to see the new post, but your post will be there.
The code snippet you need is (this is also written on the settings page):
<?php if (function_exists('post_from_site')) {post_from_site();} ?>
On the settings page, you can customize the link text, background color, title/text color, and even add your own CSS to tailor pfs to your site.
In v1.6.20+, you can also generate custom links for posting to a specific category. These can be generated at the bottom of the settings page.
As for permissions, you can limit the categories pfs can post t0 and allow/disallow uploading of images. If you’d rather have pfs’s posts approved before they are visible, you can set the post status to ‘pending’ or ‘draft’. Same with the comment status, it can default to ‘open’ (allowing comments) or ‘closed’ (not allowing comments).
Adding images – custom placement
1.9.0 introduced a new tag, [!--image--], which you can type into your post content to control the placement of your image. Just add
[!--image--]
wherever you want the image to appear. You can even use the tag multiple times, if you want the image to show up in multiple places.
History/Notes/Changelog:
6.03.09: First version released!
6.22.09: 1.6.20 released – added/improved image support, added auto-detection of plugin file to avoid the error reported on v1.6.3, added category-specific links, cleaned up the code.
9.22.09: 1.9.0 released – continued improving image support, added ability to tag posts, create new categories and tags.
If you have any comments or questions, or requested features, let me know!
Current proposed features are (stared * features should be avalible in the next release):
- AJAX form submission *
- Multiple image support *
- Integration with the WP gallery
- A login box, so you truly never have to see the wordpress admin pages
- Make a widget for even simpler integration.
If you’re commenting for help with an error, I can’t help unless you give me either a detailed description or a link to the not-working site. I do want to help, but I can’t if I don’t know what went wrong!
Kelly, thanks for your answer. I’ve deleted the outcommented lines and it’s working well ! In my case of use, an alert for successful post is important because the post takes the pending status. So, the poster can’t know if his post has been well posted… An eventual refresh of the page will not tell him this info.
For my ideal, the answer of good posting should be written in the window of “Post from site” and then the poster should click on a button to close the window.
Have a good prog ;o))
If you want, I can give you the french translation I’ve done of your script…
If quick post is called from a … / category / xx page, then xx will not be displayed in the category dropdown list. This seems to be because that category is selected, changing the ‘<option …’ statement so the regex fails for that category.
The fix is to force the selection of non-existent category 0: post_from_site.php line 49 should be changed to
$categories = wp_dropdown_categories(
“exclude=$excats&echo=0&hide_empty=0&selected=0″);
that is, add ‘&selected=0′.
Kelly, I’ve downloaded the 1.9.0 update and am still getting double, triple and more posts. It manifests if a user uses the post-from-site dialog and immediately refreshes the page after posting. I suspect you need to add a check in your pfs_submit function to insure the dialog box was previously displayed as pfs_submit is being recalled on screen refreshes.
One way to avoid the multiple-posting which occurs due to refreshes after a post is to use a session variable, as follows:
1. Add somewhere near the top of post_from_site.php the following:
if (!session_id())
session_start();
2. Add to the form (say, just above <input type="submit" …) a new hidden input:
<input type="hidden" name="pfs_form_key" value="<?php echo rand(1,10000); ?>" />
3. Replace the code following the form (the "<?php if (isset($_POST['submit']))…") with
<?php
if (isset($_POST[&apo;submit&apo;])){
$is_new_post = true;
if (isset($_SESSION["pfs_form_key"]) && isset($_POST["pfs_form_key"])) {
if($_POST["pfs_form_key"] == $_SESSION["pfs_form_key"] ){
$is_new_post = false;
}
}
if($is_new_post){
$_SESSION["pfs_form_key"] = $_POST["pfs_form_key"];
pfs_submit($_POST);
}
}
This seems to work quite well — though I’ve only tested it for a few hours, so there may be some surprises. (I do have two plugins in my system which also start sessions; so far, this doesn’t seem to be problematic.) Any comments from session experts?
This could also have been done with cookies rather than sessions.
Thanks Kim, I had researched and came to a similar solution but had not yet implemented it, I just wanted Kelly to know there was still a problem lurking! -Glenn
We will be using the plugin for people to post requests to our site. I love the fact that they don’t have to go to the admin pages to do so and glad I found your plugin. I have several questions or requests for enhancements:
1. Can you make a link to the post popup from within a post or page?
2. Can you access the quicktags like those from within the wordpress post window?
3. Is there a way for the post author’s name to show, maybe even their gravatar? Can posters possibly be added as users after making a post? (There would have to be a place for them to add their email address then.)
1. Not currently, but I can definitely add that to the list.
2. Yep. The textbox in the popup is effectively the same as the one in the admin section.
3. Part 1 of your question is probably best handled in the post template file, see here for editing templates, you’ll probably want something like the_author() and get_avatar(). The second part of your question is outside the scope of this plugin in its current form, though it probably wouldn’t be too difficult if you wanted to try doing it yourself. A quick look at the codex shows a wp_insert_user() function, whether that’s a good approach or not I can’t say. Obviously, this is somewhat advanced, and I don’t know your experience level. Though let me know if you do decide to write it yourself, and I’ll be happy to answer any other questions you have.
I’m working on a web site with easy-to-read information about the Swedish political system and its parties. I’m using Post From Site for the parties’ individual blogs.
Suddenly I have a problem with posting to a category.
I generate the links in the bottom of the settings page as described, but the posts end up in the WordPress “default post category” as set in wordpress/settings/writing anyway.
Everything worked until I changed the “default post category” from Uncategorised (or whatever the default is called) to Weekly news.
Now every post made by Post From Page ends up in Weekly news, or some other category that I select in wordpress/settings/writing…
Any suggestions?
Sorry, I forgot to say that I am otherwise very happy with the plugin.
More info:
Post From Site version: 1.9
In PFS settings “What categories can’t quickpost users post to” I have excluded the Weekly news. I also tried removing that exclusion.
WP version: 1.8.4 and 1.8.5
(I’m also using “Login with Ajax” plugin)
Everything seems to work within PFS. If I echo $categories[0]
from
$postarr['post_category'] = $categories; (in the PFS php file)
it outputs ’8′ which is the right cat. I’m logged in as ’8′ (social democrats). It also coincides with the category link that I generated on PFS settings page:
post_from_site(8,’Write a post in the S category’);
It seems wordpress just overrides whatever category PFS is trying to post in!
Best regards /Andreas
What other plugins do you have installed?
Is there anything unique to your install, like default things renamed or changes to the file structure?
Can you post to the other categories through the admin page?
OK after som more hair-tearing I realize that it’s some kind of clash with the Role Scoper plugin.
Role Scoper enables a multi user blog wher each user can only post to his own category (among many other things). From the back end that is.
Actually I was surprised that Role Scoper and PFS played along so nicely from start. Then something broke it, I have no idea what.
So I deactivated Role Scoper, and now the bloggers can only post from the front end.
From that perspective, it’s very nice that a user can be subscriber and still post via PFS. Unfortunately they cannot edit their posts afterwards…
regards / Andreas
Thanks for a very practical and useful plugin. Do you think of adding some kind of a WYSIWYG kind of editor in the next release? If not, I think of modifying this plugin for such a feature enhancement for my site, do you suggest anything?
Thanks
I don’t plan on adding that at this time. If you want to try it yourself, you could look at TinyMCE, which I believe is what the admin editor uses.
(Please forgive this duplication. I posted this comment over at redradar.net/2009/10/housekeeping/#comments, but it seems this is the place other folks visit and comment.) I am using pfs 1.9.0, WP 2.8.5.
I’ve done fresh installs to both a WAMP and a Linux server, and find the following:
1. The path to the script and style files is incorrect in WAMP, missing /’s around “plugins”, so it looks like this:
…/wp-contentpluginspost-from-site/pfs_display.js
So in WAMP I have to fix these paths, while in Linux it works either way. (I think this is simply a problem with Windows backslashes getting lost in the RE, where they are special.) I suggest this fix:
//Set plugin dirname
define(‘POSTFROMSITE_PLUGIN_DIR’, dirname(plugin_basename(__FILE__)));
add_action(‘init’,'pfs_includes’);
function pfs_includes(){
wp_enqueue_script( ‘pfs_display’, WP_PLUGIN_URL.’/’.POSTFROMSITE_PLUGIN_DIR.’/pfs_display.js’);
wp_enqueue_style( ‘pfs_style’, WP_PLUGIN_URL.’/’.POSTFROMSITE_PLUGIN_DIR.’/pfs_style.php’);
}
2. The “You must be logged in…” message fails in IE8 (it displays raw html). This is due to improper quoting of $page in post_from_site.php line 147 — this is what you provide:
echo "<div id=\"alert\">You need to be logged in to post.
<a href=".get_bloginfo(‘url’)."/wp-login.php?redirect_to=$page’>
Log in</a></div><br />";
There is no quote before $page, and a single quote after, which does not match the double-quote at the end. Fix the quotes and it works in IE8.
[Amazing! For once IE8 makes sense -- this shouldn't work in any browser, but it does work in all others!]
3. With your code, I can’t get a popup window. I’ve fixed this with a change in the javascript, but I don’t know javascript well enough to know why this works for me, or why it works for you without the change. Here’s the change:
In pfs_display.js, line 17, you have
postboxes[i].style.display = ‘none’;
Firebug complains that postboxes[i].style is not defined. (And it doesn’t work for me in any browser, not just cautious Firefox.)
But if I remove “style.” from this line, making it
postboxes[i].display = ‘none’;
everything works! I get a popup, and can post. But I don’t see why the “style.” isn’t appropriate — it’s what I would have written.
(Also, everything works with i in place of postboxes[i]:
i.display = ‘none’;
which makes more sense to me, given the “for (i in …)” statement.)
So the upshot is: these problems are fixed in both Windows and Linux, and in IE8, if the path computation is done properly, if the quotes are fixed in that “must be logged in” message, and if “style.” is removed in that one place in the javascript.
But this all must work for you in its original form, so I wonder why that “style.” works for you and not for me. Any ideas?
1. As I said, this will be fixed in 2.0, using plugins_url().
2. You’re right, this is a typo. That line should be:
echo "<div id=\"alert\">You need to be logged in to post. <a href='".get_bloginfo('url')."/wp-login.php'>Log in</a></div><br /><script type='text/javascript'>alert('you must be logged in');</script>";[$page doesn't actually do anything and can be removed.]
3. I can’t duplicate the error you’re getting. Can you try printing i and postboxes[i] & showing me the results?
Regarding the error I’ve had with the javascript — evidently it’s an interaction with some plugin I’ve added: Your code works (as I would expect) on a fresh WP install, unmodified except for placing your code in a template file. And it fails to work in my setup even using a stock default theme, so it’s not a template problem.
The error firebug reports is that postboxes[i].style is not defined. This error prevents the next line from executing, so #pfs_postbox+id doesn’t get made visible.
I would continue with a search for the conflict, but I just noticed: the javascript in question — the “postboxes” stuff — doesn’t do anything, as far as I can see. (The only element with class=”pfs_postbox” is already given style=”display:none”, and I think nothing ever changes that.) If I remove it, that is, remove
everything works just fine (and so function getElementsByClassName is not needed, either), and my conflict error goes away.
If I find the conflict I’ll let you know (it may be a problem in other contexts). Of course, if you are close to your new Ajaxed release, all this javascript is probably very different (perhaps you will use jquery or …), and this may be obsolete.
Removing that would become a problem if you have more than one form on a page, as it ensures that the form associated with the link you’ve clicked on is the only one displaying.
If you’ve clicked to display postbox_2 and then clicked again to display postbox_1, postbox_2 would still be visible, and assuming 2 was further down the html than 1, it would be covering postbox_1. This is why I ‘clear the field’ by setting everything to display:none.
But if it works fine without that code for you, go ahead and remove it.
In post_from_site.php, if I place anything except a newline (even a space) in areas escaped from php at the top level (ie, not inside a function body), for example ?> <?php, I get the errors I mentioned before:
Firebug says, when bringing up pfs:
and, as you would expect, pfs is missing a lot of style.
And on the admin page, I get
This is entirely repeatable on two servers (XAMPP, Linux server), on a fresh unmodified install of WordPress 2.8.5 as well as my own site.
Furthermore, from a brief test it seems to occur even if the offending non-php characters are in another plugin’s php file.
Is this a known restriction? If it is, then I think all the top-level escapes from php should be removed, for editing safety.
If I’m interpreting your problem correctly, this is a known PHP ‘issue’ to do with how it interprets whitespace outside of php tags. It’s fairly well known and easily google-able, so I probably won’t change my code. I’m not even sure why you’d need to put anything outside the php tags anyway.
Yes, you are correct, it’s well-known. But the problem has nothing to do with “interpreting whitespace”, but is just the usual output-before-headers conflict.
The problem arose for me when, trying to understand your code, I reformatted for readability. I just put in a bit of white space between the first two functions; that prettifying led to
wp_enqueue_style( 'pfs_style', get_bloginfo('url'). ...
<?php } ?>
<?php
/* * *
Looks perfectly fine, doesn’t it? But of course, it’s not, immediately putting out a newline. However, I didn’t get the usual headers warning on this page (that showed up on the admin page, and I didn’t recoginze the connection there — DUH), but just a strange load failure of a file due to the wrong MIME type. Not obvious.
So that’s why we should avoid those silly leave-and-come-right-back escapes — they fail if we don’t come right back! And they add nothing to code clarity.
Thanks for your wake-me-up response, as foolish as it makes me feel. Oh well, it happens.
Looking forward to your release of the new version. As I said before, this is a very important plugin.
This plugin is EXACTLY what I am looking for and I am so excited about it, however, I get the error that is mentioned in your FAQs with a “quick post” link that doesn’t do anything. In your FAQs you say to double check that the CSS file is in the right folder, but when I downloaded the plugin, there isn’t a .css folder. Am I missing a file when I try to download it from WordPress? Please help!
The CSS file is ‘pfs_style.php’. If you’re downloading it from wordpress, all the files should be there & in the proper places. The problem you could be having is either something is interfering with the javascript, or the popup does work, but the positioning is wrong and it’s off the page. If you are familiar with CSS, you can edit the css in the ‘pfs_style.php’ file (just don’t rename it). If you aren’t, or this doesn’t help, give me a link to your site and I can try to figure out your problem.
Using a local WAMP stack, I cant get this to work, with any permutation. Basically, the link to the popup shows, but it’s not a link I can click. ALL the files are present in the plugin directory and I havse the latest versions of WP and PFS. Can you help?!
Ok, I resolved this by installing test site online, the post box now appears. It seems that there are problems using pfs on a local server for some reason. Still looking for a way to embed post box in the main page …
Is it possible to embed the Pfs form into a page and not use a link to open a popup? I want to use it like the twitter site, where it’s immeadiately available to registered members. Please post code if you can…
Thanks
Hi richard did you find out how to do this im after the same thing
Hello,
I know this seems to be an ongoing thing with this plugin, but I ran into some problems with this plugin not working properly. I tried to fix it myself, but after several hours just resigned myself to the fact that I am not a PHP programmer. Any help would be greatly appreciated, and I am hoping that perhaps we can help each other make this great plugin even better. Here’s the deal:
I installed and activated the plugin, and put the code on the page. The link shows up, but doesn’t do anything. I confirmed all of the files were in their proper places, but began to realize that even though the files were where they were suppose to be, it wasn’t linking to the CSS and JAVA properly. With the plugin installed as-is here’s what the link it turns out looks like:
note that there is no ‘/’ between ‘wp-content’, ‘plugins’ & ‘post-from-site’. From my tinkering around in the code I decided it probably had something to do with this:
require_once(dirname(__FILE__).’/../../../wp-admin/includes/admin.php’);
add_action(‘init’,'pfs_includes’);
function pfs_includes(){
$path = split(‘wp-content’,__FILE__,2);
wp_enqueue_script( ‘pfs_display’, get_bloginfo(‘url’).’/wp-content’.dirname($path[1]).’/pfs_display.js’);
wp_enqueue_style( ‘pfs_style’, get_bloginfo(‘url’).’/wp-content’.dirname($path[1]).’/pfs_style.php’);
putting a ‘/’ after ‘/wp-content’ takes care of one of the missing ‘/’, but the ‘dirname($path[1])’ seems to generate the erronous ‘pluginspost-from-site’ part of the URL, and I don’t know how to fix that.
Anyway, that’s what I got. I really hope you can help, and that this post helps. I’m keeping the plugin active so you can troubleshoot the live plugin if you like. The URL is http://briancoale/blog/
Thanks!
-Brian
Hey I noticed it omitted the dynamic link I poosted after “the link it turns out looks like:”
I’ll try and post it again (without brackets):
link rel=’stylesheet’ id=’pfs_style-css’ href=’http://briancoale.com/blog/wp-contentpluginspost-from-site/pfs_style.php?ver=2.8.6′ type=’text/css’ media=”
script type=’text/javascript’ src=’http://briancoale.com/blog/wp-contentpluginspost-from-site/pfs_display.js?ver=2.8.6′
Where
wp-contentpluginspost-from-site/
should be
wp-content/plugins/post-from-site/
And the Google Chrome Developer tools tell me there’s a “uncaught reference error: pfsopen is not defined”
Thanks again!
UPDATE:
I think I got it to work by Frankensteining some of the older code in with the newer code. I know this is dirty and nasty, but at least for now it works. When the new version comes out, or if you have a better resolution I’ll definitely install it or change the code to whatever is better.
RUNDOWN:
I changed this:
function pfs_includes(){
$path = split(‘wp-content’,__FILE__,2);
wp_enqueue_script( ‘pfs_display’, get_bloginfo(‘url’).’/wp-content’.dirname($path[1]).’/pfs_display.js’);
wp_enqueue_style( ‘pfs_style’, get_bloginfo(‘url’).’/wp-content’.dirname($path[1]).’/pfs_style.php’);
?>
to this:
function pfs_includes(){
$path = split(‘wp-content’,__FILE__,2); ?>
<script language='javascript' src='/pfs_display.js’>
<link rel="stylesheet" type="text/css" media="screen" href='/pfs_style.php’ />
Very strange that dirname is doing that. If it’s still not working for you, you can change pfs_includes to:
This should work – it’ll fix all the linking issues, which is why chrome is telling you pfsopen is not defined.
Definitely let me know if it’s still not working, and let me know your WP version and server OS (unix vs windows, I don’t need anything more detailed). Hope this helps.
That’s weird, I tried that code and it didn’t seem to work out. Like I said, I really don’t know enough about php… But the other code:
function pfs_includes(){
$path = split(‘wp-content’,__FILE__,2); ?>
<script language='javascript' src='/pfs_display.js’>
<link rel="stylesheet" type="text/css" media="screen" href='/pfs_style.php’ />
seems to work.. This is from an older version of the plugin and, for whatever reason, that old code seems to work. You can stop by the site and verify that it’s working. The post from site link will be directly underneath the last post displayed on the first page of the blog. It’s kind of small, so might have to look for it.
Thanks!
Ok I don’t know if your getting my replies or not, I’ve replied twice now and it doesn’t show on the page, and if I try to reply again it says I’ve already posted that. So I hope you’re getting these…
For whatever reason your reply got sent to my spam filter, but I let it through. Anyway, I’m glad it’s working now, though I think you’re back to using a hack-y way of including things (it’s not a problem presuming nothing changes, but if something does, it will most likely break).
By any chance are you hosted on a windows server?
Actually yes I am, probably shot myself in the foot for that one didn’t I?
I’m using WordPress v 2.9 and post-from-site v 1.9.0. The plugin installs and I do get the link text in the desired location, where I added the code. However, it doesn’t seem to be including the js or css files. I get js error that the open function is missing. When I click on the link text nothing happens.
Thanks!
Kim,
Thanks for the plugin. I really wanted to have something where our website users can just use the website as the front-end and never see the admin panel, so I was so happy to get your plugin working on my site. I got all the bugs worked out in my blog and only then realized that this still isn’t quite possible because a user still has to go to the admin panel to log in. I see you have this listed as a future enhancement. I’d just like to cast my vote to get that up a running as soon as possible… otherwise the main benefit (for me) really isn’t there at all! In the meantime, if you have any suggestions on things I could do to modify something on my site to do this myself, I’d be interested. I’m not all that experienced with this stuff, learning as I go, but I can probably figure it out with a little direction.
Im using wordpress-mu and i get an error when i try to activate this plugin. Has anyone ever managed to make it work on wpmu?
I have download the plugin, evry file is complete but it shows the link and doesnt pop up the post textbox
Thanks for the plugin – it’s great. One thing I would like to do is have the user redirected back to the pfs page after the user is told to log in.
I don’t know php in any depth. Can someone let me know if it’s possible and if so, how to go about doing it? Thanks,
Brett