Forum Replies Created

Viewing 15 replies - 31 through 45 (of 374 total)
  • Thread Starter ejm

    (@llizard)

    Thank you, bcworkz! I have been away from the computer pretty much all day and have just seen your reply. It is a lot to digest…. Here’s hoping I can apply what you have kindly set out. I’ll report back in the next couple of days. Many thanks again for your patience and care!

    Thread Starter ejm

    (@llizard)

    Thank you!

    Post the code over at pastebin.com. If you sign up there (for free, but not required), you’d be able to go back and edit your code later on in case you want to show me an updated version.

    I have done as you suggested. I suspect that there may be duplicate pieces of code….

    Here is what I have in my child functions file: pastebin[dot]com/FJtVCvt2

    No matter what I do, I cannot seem to get the field to be editable and if the field is left empty, it simply does not appear at all.

    I tried it in a test WP as well, with the same results….

    Thread Starter ejm

    (@llizard)

    I fear that I may have to start all over. No matter what changes I make, everything appears to be working exactly as before: the field remains filled in if it is filled in at the outset and cannot be removed or changed; the field remains empty if it is not filled in at the outset and cannot be filled in from the admin area….

    I just noticed you have $author .= " ($webname)";. That is where the parentheses are coming from. You’re using if ( $webname ) to conditionally check for an assigned value, which is good, but now that we’re storing empty strings at times, it’s going to add ” ()” for empty strings (or a trimmed space).

    This is what I thought was going to happen if I asked it to store an empty string. But, judging from the fact that an empty field does not appear as ” ()” beside the author, I guess I have not succeeded in storing the empty string.

    I’ll keep chipping away over the next few days. Maybe, by a miracle, it will suddenly work. I’ll report back.

    Many thanks for your help. I now have a vague inkling about which functions do what.

    Thread Starter ejm

    (@llizard)

    Than you again, for your response.

    re:

    I’m following your explanation except for how the parentheses appear when the field is not filled in.

    At this point, the parentheses do not appear if the field is not filled in. But if I put in an instruction to save an empty string if the value is ”, then wouldn’t it appear in the comment meta box as ()?

    function attach_websitename_to_author( $author ) {
        $webname = get_comment_meta( get_comment_ID(), 'webname', true );
        if ( $webname )
            $author .= " ($webname)";
       return $author;
     }
    

    Not knowing how to do it (and having tried a number of incorrect bits of code) I’m guessing that I have to say something like

    if ($_POST['webname'] = '')
       echo ' ';

    This didn’t throw any errors. But it also doesn’t seem to do anything….

    re:

    [Y]ou don’t need conditional logic on output, only upon form submit. For output, just echo out whatever is in comment meta, whether it be the saved value or an empty string.

    Once again, I understand the logic here, but am not certain of which code sections are used for the form submit. Is it this part??

    function add_comment_meta_values($comment_id) {
       if ( ( isset( $_POST['webname'] ) ) && ( $_POST['webname'] != '') ) {
            $webname = wp_filter_nohtml_kses($_POST['webname']);
            add_comment_meta($comment_id, 'webname', $webname);
        } 
    }
    add_action ('comment_post', 'add_comment_meta_values', 1);
    Thread Starter ejm

    (@llizard)

    Thank you for your reply and your patience with a rank beginner.

    re:

    I don’t fully understand what you’re trying to accomplish.

    I have added an optional field “website name” to my comments form. If it is filled in, I would like it to appear in the comments area on my WP as “commenter’s name (commenter’s website name)” AND in the editing area for the comments. If it is NOT filled in, I do not want empty parentheses to appear in the comments area on my WP.

    At this point, if the field is filled in, it appears on my WP as expected, as well as appearing in the editing area for the comments in WP-admin. However, if I try to edit the empty field in WP-admin, it remains empty. If I remove an entered value on the new optional field, it stays empty and cannot be filled in again. (I hope this is making sense.)

    I will work on implementing the following so that there is an empty string.

    function() {
      if $_POST value is set,
        then save the value
      else
        save an empty string
    }

    I’m guessing I’ll also somehow have to add an elseif to the following that if the string is empty, the parentheses should NOT appear.

    function webname_comment_meta_box( $comment ) {
        $webname = get_comment_meta( $comment->comment_ID, 'webname', true );
        wp_nonce_field( 'webname_comment_fields_update', 'webname_comment_fields_update', false );
        ?>
        <p>
            <label for="webname"><?php _e( 'Website Name', 'text-domain' ); ?></label>
            <input type="text" name="webname" value="<?php echo esc_attr( $webname ); ?>" class="widefat" />
        </p><?php
    }

    Something like if $webname == '' {echo ''} ???

    Thread Starter ejm

    (@llizard)

    Thank you for your reply, bcworkz.

    That makes sense that if the field is empty, no data is sent. And intellectually, I understand what you mean by “Change the logic to always save something as long as the comment is created, regardless of the field’s isset() result. You use isset() to decide if you save an empty string or the passed value, not to decide if anything should be saved at all.

    Alas, I do not know how to implement this.

    I thought it might be with the function update_option() but as usual, the codex is written for people who probably already know the answer to the question.

    Not to mention that apparently, update_option() “has been deprecated […] in favor of update() method instead” (https://developer.www.ads-software.com/reference/classes/wp_customize_setting/_update_option/).

    Is https://developer.www.ads-software.com/reference/classes/wpdb/update/ the page that might contain the information I need?

    Because I couldn’t wrap my head around the wp developer update page I took a shot and tried removing the “if isset” with the following:

    function update_comment_meta_values($comment_id) {
    if ( $_POST['webname'] != '') {
            $webname = wp_filter_nohtml_kses($_POST['webname']);
            add_comment_meta($comment_id, 'webname', $webname);
        } 
    }
    add_action ('comment_post', 'update_comment_meta_values', 1);

    It will probably come as no surprise to you that this did not work.

    Staring more at the coding at the bottom of the page on wpdb::update, I’m guessing that this contains clues to what I am trying to achieve. Is there another place I can refer to (something a little more along the lines of “wp for dummies”) to glean the answer?

    
    public function update( $table, $data, $where, $format = null, $where_format = null ) {
        if ( ! is_array( $data ) || ! is_array( $where ) ) {
            return false;
        }
     
        $data = $this->process_fields( $table, $data, $format );
        if ( false === $data ) {
            return false;
        }
        $where = $this->process_fields( $table, $where, $where_format );
        if ( false === $where ) {
            return false;
        }
     
        $fields = $conditions = $values = [... etc. etc. ...]
    Thread Starter ejm

    (@llizard)

    followup question on this posed in Developing with WordPress forum: https://www.ads-software.com/support/topic/adding-and-editing-non-required-field-in-comments/

    Thread Starter ejm

    (@llizard)

    This is great. Thank you for dealing with this so quickly!

    Thread Starter ejm

    (@llizard)

    Thank you!

    Thread Starter ejm

    (@llizard)

    Thank you!

    I have one more question: with the toggle method, is there a way to have the captcha disappear once the message has successfully been sent? Or is that something I have to do on my end with the contact form itself?

    Thread Starter ejm

    (@llizard)

    …forgot to note that this topic is now essentially “resolved”

    Thread Starter ejm

    (@llizard)

    I did not see that opt-out option on the plugin activation before. So, just now, I went to look again.

    Please note that the place to opt-out is not at all obvious. The opt-out does not appear in the activation area (I installed the plugin from my WP plugin dashboard). Additionally, when deactivating the plugin, the message that comes up saying that everything to do with the plugin has been erased gives the user a false sense of security.

    Please add a message about where to opt in or out of email on your set-up instructions.

    Thank you.

    Thread Starter ejm

    (@llizard)

    Thank you, John. I guessed that it may have been something you didn’t know about and am glad to learn that you have now added an “opt-out” option when the plugin is deactivated.

    It might also be a good idea to add a the “opt-out” option when activating the plugin. Alternatively, it could go in the settings area.

    Thread Starter ejm

    (@llizard)

    Rats. It must be another plugin that is in conflict then. Because it was working correctly for some time.

    Because I have only one plugin to do with searching (I think), I thought perhaps it was something to do with Relevanssi.

    Thank you for your reply. I will stare some more at the search results template.

    Thread Starter ejm

    (@llizard)

    Because they are not a security risk, that indicates to me that this would not be considered to be a “major issue”. I will refrain from creating a ticket.

    I just hope that if the WP developers do decide to stop maintenance on twenty twelve, there will be plenty of warning.

Viewing 15 replies - 31 through 45 (of 374 total)