Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Matthew Rowland

    (@conundrum89)

    Yes, you can simply

    add_filter( 'gtf_get_mark_topic_read_link', 'my_mark_topic_read_link' );

    and

    add_filter( 'gtf_get_mark_forum_read_link', 'my_mark_forum_read_link' );

    The first argument to both your custom functions will be $content, the default content of the links. From there, you can use str_replace() to replace the parts of the link you don’t want with an empty string, thereby removing them. Then return the results of that, and it’ll be displayed in place of the default links.

    Plugin Author Matthew Rowland

    (@conundrum89)

    As to changing what is returned after clicking on the link, unfortunately there’s no easy way to do that. The safest way would be to do:

    remove_action( 'wp_ajax_mark_topic_read', 'gtf_mark_topic_read' );
    add_action( 'wp_ajax_mark_topic_read', 'my_mark_topic_read' );

    and then recreate the contents of gtf_mark_topic_read in your own functions.php file. That way, if I ever update the plugin, your changes won’t be overriden.

    You’d have to do the same thing for wp_ajax_mark_forum_read, of course.

    Thread Starter Robkk

    (@robkk)

    matthew im glad that you have an answer to this :D, but i have no idea how to create the function haha

    Plugin Author Matthew Rowland

    (@conundrum89)

    Which one?

    For the first ones, you’ll simply want to define:

    function my_mark_topic_read_link( $content ) {
       $content = str_replace(...);
    
       return $content;
    }

    Use the str_replace() docs to figure out what you want to use as each argument: https://au1.php.net/manual/en/function.str-replace.php

    For the second ones, after removing my action and adding your own, you can just define the function like so:

    function my_mark_topic_read() {
       // content here
    }

    And in the middle, put the entire contents of the gtf_mark_topic_read() function. Then you can edit it however you like.

    Thread Starter Robkk

    (@robkk)

    str_replace() is just blowing my mind , i read alot from the link you gave me and it made it kind of worse ??

    2nd function should be this??

    function my_mark_topic_read() {
    	$topic_id = intval($_POST['topic_id']);
    	$user_id = get_current_user_id();
    
    	$result = gtf_update_topic_last_read_meta( $user_id, $topic_id );
    
    	if ($result === true)
    		die("Marked as Read");
    	else if ($result === false)
    		die("Failed to Update");
    	else
    		die($result);
    }
    Plugin Author Matthew Rowland

    (@conundrum89)

    I don’t have the code in front of me right now, but that looks right. Now you can change what’s in the die("Marked as Read") and die("Failed to Update") lines to change what gets output to the screen when the user clicks the button.

    The first one is when the operation is successful, and the second one is when it fails for some reason.

    Thread Starter Robkk

    (@robkk)

    hey Matthew can you post the full code to the solution whenever your close to the code to your plugin ??

    creating functions confuses the eff out of me :(.

    i seriously dont know how to use string replace to edit this

    function gtf_get_mark_topic_read_link( $topic_id = 0 ) {
    if ( !bbp_is_single_topic() ) {
    return;
    }

    $topic_id = bbp_get_topic_id( $topic_id );

    $url = admin_url(‘admin-ajax.php’);

    $content = “
    <span id=’gtf-mark-topic-read’>
    <span id=’gtf-mark-topic-read-{$topic_id}’>
    <a href='#' rel='nofollow'>Mark Topic Read</a> <—change to Mark Read
    </span>
    ?|? <—delete this
    </span>
    <script type=’text/javascript’>
    jQuery(‘#gtf-mark-topic-read-link’).click( function(e) {
    e.preventDefault();
    var data = {
    action: ‘mark_topic_read’,
    topic_id: jQuery(this).data(‘topic’)
    };
    jQuery.post(‘{$url}’, data, function(response) {
    jQuery(‘#gtf-mark-topic-read-{$topic_id}’).html(response);
    });
    });
    </script>
    “;

    return apply_filters( ‘gtf_get_mark_topic_read_link’, $content, $topic_id );
    }

    function gtf_update_topic_last_read_meta( $user_id, $topic_id ) {
    $last_reply_id = bbp_get_topic_last_reply_id( $topic_id );
    $last_read_id = get_user_meta( $user_id, ‘gtf-last-read-‘ . $topic_id, true );
    if ( empty( $last_read_id ) ) {
    return add_user_meta( $user_id, ‘gtf-last-read-‘ . $topic_id, $last_reply_id, true );
    } else if ( $last_read_id < $last_reply_id ) {
    return update_user_meta( $user_id, ‘gtf-last-read-‘ . $topic_id, $last_reply_id );
    } else {
    return “Already Read”; <— change to Marked Read
    }
    }

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘function for custom mark as read text , and remove |’ is closed to new replies.