Adam Harley (Kawauso) (@kawauso)

Forum Replies Created

Viewing 25 replies - 101 through 125 (of 285 total)
  • @kawauso

    Member

    A normal sticky is at the top, but only for the forum it’s in.

    @kawauso

    Member

    Whoops, I need to use more test data next time.

    Change:

    foreach ($current_tags as $tag_key => $tag ) {
    if( in_array( $tag->name, $allowed_tags ) )
    unset( $allowed_tags[ $tag_key ] );
    }

    to

    $allowed_tags = array_flip( $allowed_tags ); // CHANGE PLACES!
    foreach( $current_tags as $tag ) {
    if( isset( $allowed_tags[ $tag->name ] ) )
    unset( $allowed_tags[ $tag->name ] );
    }
    $allowed_tags = array_flip( $allowed_tags ); // CHANGE PLACES!

    The closing ?> isn’t really important if there’s no non-PHP data after it

    @kawauso

    Member

    There are actually two links when you make a topic a sticky. You need to use the “to front” link for it to be stickied on the frontpage.

    In reply to: target=blank in Topic

    @kawauso

    Member

    It’s target="_blank", make sure you have the underscore. Otherwise, got an example? Are you using __ck__’s plugin to add _blank?

    @kawauso

    Member
    <?php
    /*
    Plugin Name: Restrict Topic Tags
    Description: Restricts tags to a pre-defined list.
    Author: Kawauso
    Version: 0.1
    */

    $allowed_tags = array(
    'test',
    'test2',
    );

    function restrict_topic_tags_form( $args = null )
    {
    $defaults = array( 'topic' => 0, 'submit' => __('Add ยป'), 'list_id' => 'tags-list' );
    $args = wp_parse_args( $args, $defaults );
    extract( $args, EXTR_SKIP );

    if ( !$topic = get_topic( get_topic_id( $topic ) ) ) {
    return false;
    }

    if ( !bb_current_user_can( 'edit_tag_by_on', bb_get_current_user_info( 'id' ), $topic->topic_id ) ) {
    return false;
    }

    global $page, $allowed_tags;

    $current_tags = bb_get_topic_tags( $topic->topic_id );
    foreach ($current_tags as $tag_key => $tag ) {
    if( in_array( $tag->name, $allowed_tags ) )
    unset( $allowed_tags[ $tag_key ] );
    }

    if( is_array( $allowed_tags ) && !empty( $allowed_tags ) ) { ?>
    <form id="tag-form" method="post" action="<?php bb_uri('tag-add.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN); ?>" class="add:<?php echo esc_attr( $list_id ); ?>:">
    <p>
    <select name="tag" id="tag">
    <option value=""><?php _e("Select a tag")?></option>
    <?php foreach( $allowed_tags as $tag ) { ?>
    <option value="<?php echo $tag?>"><?php echo $tag?></option>
    <?php } ?>
    </select>
    <input type="hidden" name="id" value="<?php echo $topic->topic_id; ?>" />
    <input type="hidden" name="page" value="<?php echo $page; ?>" />
    <?php bb_nonce_field( 'add-tag_' . $topic->topic_id ); ?>
    <input type="submit" name="submit" id="tagformsub" value="<?php echo esc_attr( $submit ); ?>" />
    </p>
    </form>
    <?php
    } // End if

    } // End function

    function restrict_topic_tags( $tag ) {

    global $allowed_tags;

    // if( !in_array( $tag, $allowed_tags ) )
    // return array();

    return array($tag);
    }

    add_filter( 'bb_add_topic_tags', 'restrict_topic_tags' );

    Then in your theme’s topic-tags.php, change <?php tag_form(); ?> to:

    <?php
    if( function_exists( 'restrict_topic_tags_form' ) )
    restrict_topic_tags_form();
    else
    tag_form();
    ?>

    In reply to: Admin Link in Sidebar

    @kawauso

    Member

    There are template function lists if you Google around, but I don’t know if any are up-to-date for 1.0.2

    I think bb_admin_link() and get_bb_admin_link() would do what you’re trying to do.

    @kawauso

    Member

    People were asking for something similar to this before:

    https://bbpress.org/forums/topic/combined-register-post

    Best of luck to you if you manage to get something like that working, I found it a royal pain to bypass the various checks that non-fully registered users can’t pass.

    @kawauso

    Member

    Yep, you have to sanitize yourself, the database objects presume anything they’re passed has been already

    @kawauso

    Member

    Ah I’d be lazier than that and just put a / in front of images, so it looks for it relative to the base directory

    @kawauso

    Member

    Add to your theme’s stylesheet:

    .search { display: none; }

    @kawauso

    Member

    Thanks for some great code Sam :)

    @kawauso

    Member

    $limit was passed something which wasn’t numeric because… I guess that’s what do_action() does when it doesn’t have any arguments? Doing a var_dump(), it appears to be an empty string, so I guess it just passed the default value of the argument variable.

    I found it because I noticed the SQL query wasn’t valid when it was run in phpMyAdmin and then noticed that there wasn’t anything after LIMIT.

    I don’t know if there’s any performance gain, but it’s how bbPress code is written iirc and in the case of calling the user table, it’s essential when you’re working with a WP/bbP integration (as the table prefix is different).

    So mostly it allows for the table names to be entirely variable, which is probably better practice in case a plugin changes them.

    @kawauso

    Member

    When I tried this (not using a manual call), it seemed that $limit was being passed something, but it wasn’t numeric. So I added in before the global line:

    if (!is_numeric($limit))

    $limit = 5;

    I also changed $query_recent_replies to:

    $query_recent_replies = "SELECT * FROM $bbdb->topics JOIN $bbdb->posts ON $bbdb->topics.topic_id = $bbdb->posts.topic_id $where ORDER BY post_time DESC LIMIT $limit";

    and first echo inside the foreach to:

    echo "n<li>". bb_get_profile_link( array( 'id' => $recent_reply->poster_id, 'text' => get_user_display_name( $recent_reply->poster_id ) ) ) . ' on <a href="' . get_topic_link($recent_reply->topic_id);

    but that’s more just my idea of cleaner code :)

    @kawauso

    Member

    <?php bb_profile_link( array( 'id' => get_post_author_id(), 'text' => get_post_author() ) ); ?>

    @bbback: you can avoid echoing get_ functions by dropping the get_, there’s always an echo alias function

    @kirpi.it: my bad, I left it using an echo function rather than returning the output

    In reply to: bbPress Codex – lolz

    @kawauso

    Member

    Any chance bbPress will get a codex proper then?

    @kawauso

    Member

    In your theme’s topic.php, change bb_topic_admin(); to bb_topic_admin( array( 'before' => '', 'after' => '' ) ); or to use <li> instead, put bb_topic_admin( array( 'before' => '<li>', 'after' => '</li>' ) ); and put <ul> and </ul> around the <?php tags

    In reply to: how to get gravatar?

    @kawauso

    Member

    Your Gravatar seems to display fine on the 2nd link for me

    @kawauso

    Member

    @kawauso

    Member

    Is the site database-based or just HTML?

    @kawauso

    Member

    $wpdb and $bbdb have nice sanitizing functions and caching of results if I remember correctly

    https://codex.wordpress.org/Function_Reference/wpdb_Class

    They can also be used to retrieve table names for the respective package

    @kawauso

    Member

    You shouldn’t need the separate <a> tag, that function should be returning a complete <a> tag with the text passed to it (or using the ID number if one is given)

    @kawauso

    Member

    bb_get_profile_link(post_author()) would probably work

    @kawauso

    Member

    It’s generated by the template logged-in.php, which in Kakumei looks like:

    <p class="login">
    <?php printf(__('Welcome, %1$s'), bb_get_profile_link(bb_get_current_user_info( 'name' )));?>
    <?php bb_admin_link( 'before= | ' );?>
    | <?php bb_logout_link(); ?>
    </p>

    So you’d want bb_get_profile_link(bb_get_current_user_info( 'name' ))

    @kawauso

    Member

    Aren’t PHP errors hidden by default?

    @kawauso

    Member

    Did you edit your active template or the copy in bb-templates? Only thing I can think of..

Viewing 25 replies - 101 through 125 (of 285 total)