Hello,

I am trying to add a few custom modifications to a classifieds theme for Wordpress. It uses custom fields to get all the information in a post. Phone number, location, price, etc. It was designed to send an email to the user, the user clicks a confirmation link which has a password which is already generated. Basically I would like to change the script around a bit so that a logged in user would not have to go through all the email confirmation process.

I got it to not send the email ... and I got stuck.

Code which adds the post but sends email(if more of the code is needed please let me know):

if (!$error){
  
// post information
                $data = array
                (
                    'ID' => cG("post"),
                    'post_status' => "publish"
                );
                // update post
                wp_update_post($data);
 

                // post information
                $data = array
                (
                    'post_title' => cP("title"),
                    'post_content' => cPR("description"),
                    'post_status' => "draft",
                    'post_category'    => array(cP("category")),
                    'tags_input'    => cP("tags")
                );

                // insert post
                $published_id = wp_insert_post($data);
                $post_password = generatePassword();


                // add custom fields        
                if (cP(contact_name)!="") add_post_meta($published_id, 'contact_name', cP("contact_name"), true);

Now this is what actually gets the post from draft to published:

<?php if (cG("pwd") && is_numeric(cG("post"))) : ?>

    <?php if (cG("pwd")==get_post_meta(cG("post"), "password", true) && cG("action")=="confirm") :
                // post information
                $data = array
                (
                    'ID' => cG("post"),
                    'post_status' => "publish"
                );
                // update post
                wp_update_post($data);
    ?>                            
    <div class="intro">
      <p><?php _e('Your ad has been confirmed, thank you', "wpct"); ?></p>

I was thinking of using the below code to directly publish the post if the user is logged in and if not, the regular email confirmation.

<?php
if ( is_user_logged_in() ) {

global $current_user;
      get_currentuserinfo();

    echo 'Welcome, registered user!';
echo 'User ID: ' . $current_user->ID . "\n";
} else {
    echo 'Welcome, visitor!';
};
?>

Any help will be appreciated.

Thank you!

Ok ... so I tried something out and it works. The only problem is that a previous post gets reposted ... hopefully this won't be such a big problem to fix.

This is what I did.

if (!$error){
  
// post information
                $data = array
                (
                    'ID' => cG("post"),
                    'post_status' => "publish"
                );
                // update post
                wp_update_post($data);
 

                // post information
                $data = array
                (
                    'post_title' => cP("title"),
                    'post_content' => cPR("description"),
                    'post_status' => "draft",
                    'post_category'    => array(cP("category")),
                    'tags_input'    => cP("tags")
                );

                // insert post
                $published_id = wp_insert_post($data);
                $post_password = generatePassword();


                // add custom fields        
                if (cP(contact_name)!="") add_post_meta($published_id, 'contact_name', cP("contact_name"), true);

(code#1) I used this code, changed the post_status to publish and

if ( is_user_logged_in() ) { (code#1)

and else code#2 is called which still has the post_status set to draft.

I still have a few things that I want to implement. First of all I would like the logged in users to be able to update the post.

If anybody can give me a few pointers I will give you my sister :)

You can choose any theme in wordpress from display setting in dashboard of wordpress. Look at this website bsapk.com a classified site you may like this theme too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.