• Resolved steeleweed

    (@steeleweed)


    I have a page under development and being tested. WP, BuddyPress and all plugins current.

    Page uses exec-php plugin. Coded PHP to display/process a search form for author name. PHP dynamically builds string for the shortcode to invoke ‘latestbyauthor plugin’ to return last 10 posts by author xxx.

    Testing found the following:

    Test 1) I enter username1
    got his last 10 posts as expected.
    Test 2) I enter user-name-two
    got his last 10 posts as expected.
    Test 3) I enter firstname lastname
    got nothing- unexpected.
    Test 4) I enter “firstname lastname”
    got my own last 10 posts – very unexpected.
    Test 5) I enter John Q Public
    got 10 posts but not the most recent.

    Also noticed when I manually added user ‘First Last’ to another site, the resulting username is First-Last’. WP is inserting the hyphen. I know there’s been a lot of discussion on the forums about names with blanks, so it looks like someone just decided not to have such usernames. Some users who’ve been in my system a long time have usernames with an embedded blank.
    John Q Public may predate firstname lastame, for example. Maybe the difference depends on whether the user was manually added via WP Admin or came in via the BuddyPress Registration process.

    Any ideas?

    http://wordpress.org/plugins/latest-posts-by-author/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter steeleweed

    (@steeleweed)

    FYI:

    Removed the brackets { and } from the string to verify output without executing it as shortcode. Result as expected was:

    latestbyauthor author=John Smith show=10

    Shortcode of [latestbyauthor author=John Smith show=10] fails to display John Smith’s posts. If I searched “John Smith”, PHP passes a string with backslash inserted front & back – and I get my own posts.

    Anything between ‘author=’ and ‘show=’ should be considered username.

    Plugin Author Alex Mansfield

    (@alexmansfield)

    The Latest Post by Author plugin was designed to work with login usernames, not display names. Also, according to the WordPress shortcode documentation, if a shortcode value has a space in it, then quotation marks are required. If you wouldn’t mind posting the code you’re using, I can try to test it out for you.

    Thread Starter steeleweed

    (@steeleweed)

    Programming various machines and languages for 50 years.
    My first attempt at PHP.

    Code on the page is:

    <?php
    if (!isset($_POST[‘submit’]))
    {
    echo ‘<form action=”” method=”post”>’;
    echo ‘Author: <input type=”text” name=”who”>
    ‘;
    echo ‘Number:<input type=”text” name=”many” value=”10″>
    ‘;
    echo ‘<input type=”submit” name=”submit” value=”Search”>’;
    echo “</form>”;
    }
    else
    {
    $q = “]”;
    $x = “[latestbyauthor author=”;
    $w = $_POST[‘who’];
    $y = ” show=”.$_POST[‘many’];
    $z = “$x”.”$w”.”$y”.”$q”;
    echo “$z”;
    }
    ?>

    Works for users with no space/blank in name.

    Trying to debug the problem, I removed the [ ] from $q and $x so that $z was just a string instead of shortcode.

    Search for John Doe created string:
    latestbyauthor author=John Doe show=10

    Search for “John Doe” created string:
    latestbyauthor author=\”John Doe\” show=10

    Don’t know where the \s came from. My bad PHP?

    Thread Starter steeleweed

    (@steeleweed)

    The code posted above lacks some ending apostrophes and/or semi-colons which were in the code – sloppy copy/paste 🙁

    Thread Starter steeleweed

    (@steeleweed)

    Fixed the problem by tweaking my cod based on your comment that quotes are needed.

    Instead of framing the name with quotes when entering into the form, I inserted quotes before and after the name when constructing the string for the short code.

    Search for John Smith now yields shortcode:
    [latestbyauthor author=”John Smith” show=10]
    It works!

    Search for John yields shortcode:
    [latestbyauthor author=”John” show=10]
    Quotes not needed but cause no problem. 🙂

    Thread Starter steeleweed

    (@steeleweed)

    BTW: Thanks for the prompt response – and the plugin.

    Thread Starter steeleweed

    (@steeleweed)

    Working code in case someone else wants a Page:

    <?php
    /*
    Search for posts by author.
    Returns list of links to posts.
    Requires:
    exec_php plugin
    latestbyauthor plugin
    */
    if (!isset($_POST[‘submit’]))
    {
    echo ‘<form action=”” method=”post”>’;
    echo ‘Author: <input type=”text” name=”who”>
    ‘;
    echo ‘Number:<input type=”text” name=”many” value=”10″>
    ‘;
    echo ‘<input type=”submit” name=”submit” value=”Search”>’;
    echo “</form>”;
    }
    else
    {
    $v = ‘”‘;
    $q = “]”;
    $x = “[latestbyauthor author=”.”$v”;
    $w = $_POST[‘who’];
    $y = “$v”.” show=”.$_POST[‘many’];
    $z = “$x”.”$w”.”$y”.”$q”;

    echo “$z”;]
    }
    ?>

    Plugin Author Alex Mansfield

    (@alexmansfield)

    I’m glad to hear that solved the problem for you. Thanks for sharing your updated code!

    Thread Starter steeleweed

    (@steeleweed)

    Code work bur you disable Editors from editing Admin’s posts, which is a problem. Role Manager plugi N/A or not supported by current WP.
    Is there a way to only block Editors if the post has PHP? We don’t put PHP in posts (altho we could, so I understand your logic), but I would like to use it ina Page (which editors never touch).

    Plugin Author Alex Mansfield

    (@alexmansfield)

    I’m not really sure about the Role Manager plugin and how it handles PHP in posts and pages. Sorry about that.

    Thread Starter steeleweed

    (@steeleweed)

    My mistake – the problem with disabling Editors from editing Admin’s post was not your plugin but the Exec-PHP plugin which is needed to execute your shortcode via PHP within a page. Problem solved by promoting he two Editors involved.

    Plugin Author Alex Mansfield

    (@alexmansfield)

    Thanks for posting your findings!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Usernames with blanks etc’ is closed to new replies.