Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help with action variables and catching a URL

  • I’m adding an action to a simple plugin, and BP seems not to be catching the URL (WP returns a 404). Here’s what I’m trying to do:

    User clicks on the link to perform the action. The anchor has the url:
    http://site.com/members/username/library/delete-map/57/2/value?_wpnonce=cc13d43458

    The link returns a 404 page, but I’m able to check that the component, action and variable look like this:

    Array
    (
        [component] => library
        [action] => delete-map
        [action_variables] => Array
            (
                [0] => 57
                [1] => 2
                [2] => value
            )
    
    )

    The function to catch the URL:

    function bp_library_pane_do_something() {
    
    	if ( bp_is_current_component( 'library' ) && bp_is_current_action( 'delete-map' ) ) {
    		//Code here. For testing, I've been using bp_core_redirect( bp_displayed_user_domain() );
    	}
    }
    add_action( 'bp_actions', 'bp_library_pane_do_something' );

    If I need to post any other pieces of code to explain, please let me know. Thanks in advance for your help.

    -David

Viewing 4 replies - 1 through 4 (of 4 total)

  • modemlooper
    Moderator

    @modemlooper

    try hooking to bp_init instead of bp_actions

    Thanks for the response. Hooking to bp_init doesn’t fix the behavior, though.

    -David

    I’ve altered this slightly to make it more like the BP-Skeleton-Component’s example (adding the screen name to the uri) and my action is still not catching the URI:

    My button’s link looks like:
    http://site.local/members/username/library/maps/delete-map/57/2/value?_wpnonce=12345678

    My action’s filter:
    if ( bp_is_current_component( 'library' ) && bp_is_current_action( 'maps' ) && bp_is_action_variable( 'delete-map', 0 ) )

    Part of the $bp global:

    Array
    (
        [component] => library
        [action] => maps
        [action_variables] => Array
            (
                [0] => delete-map
                [1] => 57
                [2] => 2
                [3] => value
            )
    
    )

    I’m no longer getting a 404. Now the URI lands on the “maps” screen, which is the default screen of the component, but keeps the long URI intact. I can verify that my component/action/variable filter works by adding the code to the screen:

    if ( bp_is_current_component( 'library' ) && bp_is_current_action( 'maps' ) && bp_is_action_variable( 'delete-map', 0 ) ) {
    		  	echo "The conditions are satisfied.";
    		  }

    I’m wondering if maybe I should just perform this action using AJAX. Any ideas? Thanks in advance for your help.

    -David

    I did solve this by moving the logic that enables the action into the screen function, instead of attaching a separate function to bp-actions.

    So the screen function first looks to see if that action is requested. If so, it does it, then redirects. Otherwise it isn’t enabled and the template kicks in.

    This is the approach taken in the BP-Skeleton-Component accept/reject terms example.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Help with action variables and catching a URL’ is closed to new replies.
Skip to toolbar