[1]

halow
Guest
May 20th, 2008 at 1:26 am

Hi, first of all, I’d like to say great work on this plugin.

I am just wondering how I would make it so that the Username of whoever submits the form is the Post Title?

I am comfortable changing the code also if that’s what I’ll need to do. Just need you to point me in the right direction.

Thanks

Permalink | Quote

[2]

admin
Guest
May 20th, 2008 at 9:04 am

I’d say the easiest way to do it is to create a form widget that you add as the last element of your form. For a simple example, look at widgets/tdomf-getcat-widget.php. Just make your own version of this file and put it in the widgets folder where it’ll get picked up by TDOMF.

If you do get it working, I’d be more than happy to add the widget to the release! :)

Permalink | Quote

[3]

halow
Guest
May 21st, 2008 at 5:21 am

Alright, haven’t had any luck with it yet.

What file specifies that the default Post Title is set to the current date?

Could I just simply replace that with something like which I think woud include the submitters name?

I am not too familiar with Wordpress Codex, so am I even heading in the right direction?

Permalink | Quote

[4]

halow
Guest
May 21st, 2008 at 5:23 am

Oops, that line above should say…

“Could I just simply replace that with something like <?php tdomf_the_submitter(); ?> which I think would include the submitters name?”

Permalink | Quote

[5]

admin
Guest
May 21st, 2008 at 4:37 pm

I guess so. You could look into the contexts of tdomf_the_submitter to see how its done.

Permalink | Quote

[6]

halow
Guest
May 21st, 2008 at 8:40 pm

Can you point me to the file and line of where the default post title is set to the date?

Permalink | Quote

[7]

admin
Guest
June 16th, 2008 at 9:10 pm

With v0.12, there is a new, possible nicer way to do this without so much hacking. Add an “Append to Post Content” widget to the bottom of your form and then add this piece of code:


<?php $title = false;
      if(is_user_logged_in()) {
         $title = "%%USERNAME%%";
      } else {
         $title = get_post_meta($post_id, TDOMF_KEY_NAME, true);
      } 

      if($title != false) {
         $postdata = array(
            "ID" => $post_id,
            "post_title" => $title );
         sanitize_post($postdata,"db");
         wp_update_post($postdata);
      } ?>

This should modify the post title to be either the username or the submitted name of the submitter. as long as it happens after all the other widgets, this will be the title of your post! :)

Permalink | Quote

[8]

Josh Kaufman
Guest
June 18th, 2008 at 4:11 pm

I’m having trouble with this code… I’m trying to set the form to always / automatically use the submitter’s name as the post title. (I’m not using registrations or comments on my site.) The 0.12 “Append to Post Widget” code doesn’t appear to be doing anything for me – the post title is blank.

Any help you can provide would be greatly appreciated! :-)

Permalink | Quote

[9]

admin
Guest
June 18th, 2008 at 7:41 pm

What is the order of widgets on your form, from top down on the Form Widgets page?

Permalink | Quote

[10]

Josh Kaufman
Guest
June 19th, 2008 at 11:47 pm

1. Who Am I
2. Content
3. Notify Me
4. I Agree
5. Append to Post Content 1 – includes custom code above

Thanks for your help!

Permalink | Quote

[11]

admin
Guest
June 20th, 2008 at 8:07 am

The code worked for me on my test site no problem. If you don’t allow registered users, you could probably shorten the code to something like:

<?php $postdata = array(
         "ID" => $post_id,
         "post_title" => get_post_meta($post_id, TDOMF_KEY_NAME, true) );
      sanitize_post($postdata,"db");
      wp_update_post($postdata); ?>

I assume you've made "Name" on the Who Am I widget required? I'll double check that the code is okay.

Permalink | Quote

[12]

admin
Guest
June 20th, 2008 at 8:23 am

Bugger. I discovered a bug that would break this widget if you’re not logged in. Which is why the code is not working. I’ve fixed it, and you can grab the updated version from SVN here (before I make an official release).

BTW You can use this simpiler code too:

<?php $postdata = array(
         "ID" => $post_id,
         "post_title" => "%%USERNAME%%" );
      sanitize_post($postdata,"db");
      wp_update_post($postdata); ?>

Permalink | Quote

[13]

Josh Kaufman
Guest
June 20th, 2008 at 5:41 pm

Still no dice… after updating the plugin and code, I still get “20-06-08(16:39:29)” for the post title instead of the username. I’m not showing the “Post Title” in the Content Widget options – does that make a difference?

Permalink | Quote

[14]

admin
Guest
June 21st, 2008 at 12:29 pm

Shouldn’t. Try this code:

Submitted by <?php echo '%%USERNAME%%''; ?>

This should add the line to the end of your post saying “Submitted by USERNAME”. If this works, then there is something wrong with updating the title of the post.

Permalink | Quote

[15]

Josh Kaufman
Guest
June 22nd, 2008 at 2:59 pm

Tried your code, and the “Submitted by USERNAME” didn’t show up in the submitted post, so it looks like there’s an issue with the “Append to Post Content” widget.

“%%WIDGET:append-1%%” is being called in the Form Hacker, so not sure where the issue is.

Thanks again for your help on this – you’ve been fantastically responsive! :-)

Permalink | Quote

[16]

admin
Guest
June 23rd, 2008 at 8:11 am

Could you open your copy of include/tdomf-msgs.php and see what is at line 57. You should see seomthing like this:

$message = preg_replace('/'.TDOMF_MACRO_USERNAME.'/',tdomf_protect_input(get_post_meta($post_id,TDOMF_KEY_NAME,true)),$message);

Note the position of the ( ) brackets. Is this what you see?

Josh Kaufman said:
Thanks again for your help on this – you’ve been fantastically responsive! :-)

Thanks. :) Though this week the demand for help has been much higher than previous weeks!

Permalink | Quote

[17]

Adam
Guest
July 8th, 2008 at 10:53 pm

This isn’t working for me either. I’m trying everything you suggested to get the username to be the title but nothing seems to work. Do you have any other advice?

Also, as a less important sidenote, is there anyway for people who don’t want to deal with html tags to make clickable links in the form? Perhaps the addition of a button or something like how it is above this very form I’m typing in?

Permalink | Quote

[18]

admin
Guest
July 9th, 2008 at 7:56 am

Adam said:
This isn’t working for me either. I’m trying everything you suggested to get the username to be the title but nothing seems to work. Do you have any other advice?

What version of the plugin are you using?

Also, as a less important sidenote, is there anyway for people who don’t want to deal with html tags to make clickable links in the form? Perhaps the addition of a button or something like how it is above this very form I’m typing in?

What do you mean “clickable links”? Could you be more specific because I’m not sure what you’re asking. If your talking abou the buttons above the comment form, yes you can have them in TDOMF too. There is an option in the Content widget called “Quicktags”. Enabling this will enable the button toolbar.

Permalink | Quote

[19]

Adam
Guest
July 9th, 2008 at 1:46 pm

I’m using version 0.12.3 (build 40) of the plugin. I’ve tried appending all the bits of code you suggested but none seem to have any effect. Could there be some setting I don’t have enabled?

Quicktags. Right. Exactly what I was looking for – thank you so much.

Thank you so much for your quick response. This seems like something that should be doable but I can’t figure it out. There doesn’t seem to be anywhere in the code available in the form hacker that assigns the date/time as the default title.

Permalink | Quote

[20]

Adam
Guest
July 9th, 2008 at 1:48 pm

I should add that the “this post was submitted by…” works great so that’s not the issue.

Permalink | Quote

[21]

admin
Guest
July 9th, 2008 at 1:50 pm

Adam said:
I’m using version 0.12.3 (build 40) of the plugin. I’ve tried appending all the bits of code you suggested but none seem to have any effect. Could there be some setting I don’t have enabled?

How are you appending the bits of code? I assume your using the Append to Content widget and not the form hacker?

Thank you so much for your quick response.

No probs. I’m going on holidays next week so if I can’t fix it this week, it isn’t going to be fixed till August! :|

This seems like something that should be doable but I can’t figure it out. There doesn’t seem to be anywhere in the code available in the form hacker that assigns the date/time as the default title.

The Form Hacker can’t be used to assign the date/time for the title. The Form Hacker is used to modify the appearance of the Form only. As in, it only gets excuted when the Form is initially displayed. To add some code for after the post is submitted you have to use the “Append to Content” widget.

Permalink | Quote

[22]

admin
Guest
July 9th, 2008 at 1:56 pm

Adam said:
I should add that the “this post was submitted by…” works great so that’s not the issue.

Oh, I didn’t see that. I have it working on my test blog using this code in an Append to Content widget:

<p>Submitted by <?php echo %%USERNAME%% ?></p>

<?php $postdata = array(
         "ID" => $post_id,
         "post_title" => %%USERNAME%% );
      sanitize_post($postdata,"db");
      wp_update_post($postdata); ?>

Permalink | Quote

[23]

Adam
Guest
July 9th, 2008 at 2:17 pm

I’m doing exactly that. I have the following widgets:

1. Who Am I (but I don’t have it showing anything since I want people to have to log in)
2. Content (I don’t have Title showing)
3. Upload Files
4. Append to Post Content 1 (with that code you suggested)

Nothing’s happening and when I go back to look at the appended code, it’s become:

$post_id,
\”post_title\” => %%USERNAME%% );
sanitize_post($postdata,\”db\”);
wp_update_post($postdata); ?>

Those slashes are going in. That can’t be good, right? Any other suggestions or reasons why this could not be working?

Permalink | Quote

[24]

Adam
Guest
July 9th, 2008 at 2:18 pm

Also, that “this post was submitted by” thing just shows up, I don’t have it appended or anything.

Permalink | Quote

[25]

admin
Guest
July 9th, 2008 at 2:21 pm

Adam said:
Those slashes are going in. That can’t be good, right? Any other suggestions or reasons why this could not be working?

Ack! Sounds like we have a magic quotes problem. Go into you’re phpinfo (from the main TDOMF page) and see for the “magic_quotes_gpc” variable. What is this set to?

It’s set to On in my configuration and I don’t get the slashes.

Adam said:
Also, that “this post was submitted by” thing just shows up, I don’t have it appended or anything.

There is an option that you can enable to do that automatically. You must have it enabled.

Permalink | Quote

[26]

Adam
Guest
July 9th, 2008 at 2:23 pm

Ah! Mine is off! How do I turn it on?

Permalink | Quote

[27]

admin
Guest
July 9th, 2008 at 2:26 pm

It’s off? But then why are slashes getting added?

Permalink | Quote

[28]

Adam
Guest
July 9th, 2008 at 2:27 pm

I thought you said yours is on and you don’t get slashes and mine is off and I am getting slashes. So I just need to turn it on so I can be like you. Right?

Permalink | Quote

[29]

admin
Guest
July 9th, 2008 at 2:28 pm

Okay, quick fix, open widgets/tdomf-append-widget.php and at line 71, change:

$newoptions['message'] = $_POST["append-message-$number"];

to

$newoptions['message'] = stripslashes($_POST["append-message-$number"]);

Then go to the Append to Content Widget, enter the code without the extra slashes and save it. Hopefully the slashes won’t appear again.

Permalink | Quote

[30]

admin
Guest
July 9th, 2008 at 2:32 pm

BTW What is your magic_quotes_sybase set to? If this is On, it might be setting the slashes when saving it to the database?

Permalink | Quote

[31]

admin
Guest
July 9th, 2008 at 2:36 pm

Adam said:
I thought you said yours is on and you don’t get slashes and mine is off and I am getting slashes. So I just need to turn it on so I can be like you. Right?

Eh, I guess. I’m not 100% it will work. You have magic quotes turned off yet you’re getting slashes. I don’t know why you would be getting slashes if magic quotes is turned off. You might end up with double slashes and turning on magic quotes won’t help.

You can turn on magic quotes a few ways. The method I use is to edit .htaccess file and add:

php_value magic_quotes_gpc 1

Permalink | Quote

[32]

Adam
Guest
July 9th, 2008 at 2:45 pm

It totally worked!!! I put the stripslash command into the widget. Thank you so much! As long as I have you, can you tell me how I would change the appended code in case I want the title to say “posted by %%USERNAME%%.” I’m sure it’s simple, I just don’t want to muck about in there now that it actually works.

Permalink | Quote

[33]

admin
Guest
July 9th, 2008 at 2:49 pm

Adam said:
It totally worked!!! I put the stripslash command into the widget.

It’s only a quick fix. I’m not sure it’ll work it’s way into the main code base so be careful upgrading.

Thank you so much! As long as I have you, can you tell me how I would change the appended code in case I want the title to say “posted by %%USERNAME%%.” I’m sure it’s simple, I just don’t want to muck about in there now that it actually works.

I’m guessing it should be something like:

<?php $postdata = array(
         "ID" => $post_id,
         "post_title" => "Posted by %%USERNAME%%" );
      sanitize_post($postdata,"db");
      wp_update_post($postdata); ?>

Permalink | Quote

[34]

Adam
Guest
July 9th, 2008 at 5:50 pm

Hmm…that doesn’t seem to work. I’ve tried a couple other options and they all end up defaulting back to the date as the title. If you’re not out the door yet, I’d love some help, but if you’re busy packing, don’t worry about it.

Enjoy your holiday and thank you so much for all your help.

Permalink | Quote

[35]

admin
Guest
July 10th, 2008 at 9:03 am

Maybe then something like this?

<?php $postdata = array(
         "ID" => $post_id,
         "post_title" => "Posted by".%%USERNAME%% );
      sanitize_post($postdata,"db");
      wp_update_post($postdata); ?>

Permalink | Quote

Advertisments

Join the Discussion