WordPress.org

Ready to get started?Download WordPress

Forums

Adding Fields (12 posts)

  1. dlopeman
    Member
    Posted 4 years ago #

    I'm finding it rather difficult to add fields to functions.php for P2.

    Really, all I want to do is add a TITLE input... So users can put a title on their posting. I see that P2 figures out the TITLE for you.

    I also saw the other post where someone makes it the first line in your post. This isn't good enough for me. I don't want to have to "teach" my subscribers anything! It's also funny to me that the title function in P2 checks to see if your post is a IMAGE or VIDEO... when you don't have the capability to upload either!! (well, I do, now... but not in P2 Original)

    Once I can figure this out, I want to have other fields, too.

    Hmmmmmm - I just thought of something while typing this... I removed the TAGs fields... I would if I can figure it out by looking at that........

  2. dlopeman
    Member
    Posted 4 years ago #

    Hey - I did it!!! I now have a TITLE field.

    Wow - so what did I do... holy moly - let's see............

    I hope CutNPaste work good here!

    So first: /inc/p2.js

    function newPost(trigger) {
    var thisForm = $(trigger.target);
    var thisFormElements = $('#posttext, #tags, #my_title, :input',thisForm).not('input[type=hidden]');
    var submitProgress = thisForm.find('span.progress');
    var posttext = $.trim($('#posttext').val());

    if(jQuery('.no-posts')) jQuery('.no-posts').hide();

    if ("" == posttext) {
    $("label#posttext_error").text('All fields are required').show().focus();
    return false;
    }
    var my_title = $.trim($('#my_title').val());
    if ("" == my_title) {
    $("label#posttext_error").text('You need to add a TITLE').show().focus();
    return false;
    }
    toggleUpdates('unewposts');
    if (typeof ajaxCheckPosts != "undefined")
    ajaxCheckPosts.abort();
    $("label#posttext_error").hide();

    thisFormElements.attr('disabled', true);
    thisFormElements.addClass('disabled');

    submitProgress.show();
    var tags = $('#tags').val();
    if (tags == p2txt.tagit) tags = '';
    var args = {action: 'prologue_new_post', _ajax_post:nonce, posttext: posttext, my_title: my_title, tags: tags};
    var errorMessage = '';
    $.ajax({
    type: "POST",
    url: ajaxUrl,
    data: args,
    success: function(result) {
    if ("0" == result)
    errorMessage = p2txt.not_posted_error;

    $('#posttext').val('');
    $('#my_title').val('');
    $('#tags').val(p2txt.tagit);

  3. dlopeman
    Member
    Posted 4 years ago #

    Well - every where you see "my_title"

    I also did the functions.php and added stuff:

    function prologue_new_post() {
            if( 'POST' != $_SERVER['REQUEST_METHOD'] || empty( $_POST['action'] ) || $_POST['action'] != 'prologue_new_post' ) {
                die();
            }
            if ( !is_user_logged_in() ) {
                    die('<p>'.__('Error: not logged in.', 'p2').'</p>');
            }
            if( !current_user_can( 'publish_posts' ) ) {
                    die('<p>'.__('Error: not allowed to post.', 'p2').'</p>');
            }
    
            check_ajax_referer( 'ajaxnonce', '_ajax_post' );
    
            $user_id                = $current_user->user_id;
            $post_content   = $_POST['posttext'];
            $post_title     = trim( $_POST['my_title'] );
    
            //$tags                 = trim( $_POST['tags'] );
            //if ( $tags == __('Tag it', 'p2') || $tags == 'Tag it' ) $tags = '';
    
            //$post_title = prologue_title_from_content( $post_content );
    
            $post_id = wp_insert_post( array(
                    'post_author'   => $user_id,
                    'post_title'    => $post_title,
                    'post_content'  => $post_content,
                    'post_status'   => 'publish'
            ) );
    
            echo $post_id? $post_id : '0';
            exit;
    }

    There's only one line here. And Comment out the part where it's derived from the Content...

    OH, I disabled TAGs, BTW... so be sure you uncomment that above if you want it... I may have deleted some lines, too...

    Make a BACKUP!!

  4. dlopeman
    Member
    Posted 4 years ago #

    Don't you love when people solve their own crap!?!?! LOL

  5. dlopeman
    Member
    Posted 4 years ago #

    Now I need to figure out the tabindex order... and how the posttext field gets focus on refresh... cuz then the tabindex gets out of order!!

  6. dlopeman
    Member
    Posted 4 years ago #

    OH - and I almost forgot - you of course have to add the HTML part to the form:

    TITLE: <input id="my_title" type="text" autocomplete="off" value="" tabindex="1" size="30" name="my_title"/>
  7. cubecolour
    ɹoʇɐɹǝpoɯ
    Posted 4 years ago #

    Not sure installation is the best forum for this, but this is an interesting & useful tip. Ta for sharing.

  8. chucksanders
    Member
    Posted 4 years ago #

    thanks for the tip

  9. dlopeman
    Member
    Posted 4 years ago #

    functions.php - i posted some code above (without the code tics!)

    And sorry about the placement... I thought this was the area for ALL P2 related stuff...

    I'll see about looking where else to put this...

  10. dlopeman
    Member
    Posted 4 years ago #

    OH - I see what you mean by the wrong place to post this!!!

    I'm really sorry folks. I began this post in the P2 Theme area and I assumed (and you know what they say about those who assume) it would post to the same "current" location by default.

    Not very intuitive, IMHO...

    Is there a moderator who can move this to the right location?

  11. dlopeman
    Member
    Posted 4 years ago #

    ok - weird, still... I'm in this:
    http://wordpress.org/tags/p2

    and I see my post there... as a tag??...

    This whole concept of tags is strange to me, which is why I removed TAGs from my P2 themed site! HAHA

  12. dlopeman
    Member
    Posted 4 years ago #

    well - back to the topic - even if it IS in the wrong place (which probably because I actually ADDED tags...)

    Be sure to limit the number of characters. P2 already had for the other function, because it would strip 40 characters off the $content... Well - I'll figure out how to apply that to my mods.

    It's something I wanted to do to the content, too, anyway!!! I don't need long-winded descriptions of the women drinking beer pix!!!

    If you are curious, then join in the fun!
    http://www.womendrinkingbeer.com

    :)

Topic Closed

This topic has been closed to new replies.

About this Topic