Skip to:
Content
Pages
Categories
Search
Top
Bottom

help in writing a function? hooks? actions?


  • Masoud
    Participant

    @masoud1111

    hi.
    i want to know how can i write a function in bp-custom.php
    i know this :
    function thisandthat()
    {
    }
    add_action();
    or add_filter();
    but i dont know when should i use filter, and when or where should i use action.
    —-
    i dont want to edit core codes…
    i want to write a function to call bpnoaccess action from
    bp_core_no_access
    but i dont even know how should i write and use that action or filter for it so
    i can send my string to original function.
    please help. i dont know how should i do it.

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

  • shanebp
    Moderator

    @shanebp

    Please use the code button when sharing code.

    If the hook uses apply_filters, then use add_filter.

    function masoud_core_no_access( $r ){
    
       // $r is an array
       // make adjustments or other calls and then return it
    
       return $r; 
    }
    add_filter( 'bp_core_no_access', 'masoud_core_no_access' );

    Masoud
    Participant

    @masoud1111

    hi. tnx for your answer.
    tnx for mention the use of ‘code’. i will do it in future.
    in these past 2days i’m trying to do what you said in different ways. but i keep seeing error.
    so i come back here.
    sorry i dont know a lot about coding.. 🙁
    i’ve tried many codes. some of these codes:

    first:

    function masoud_core_no_access( $r ){
    $mode=1;
    $r=$mode;
       return $r; 
    }
    add_filter( 'bp_core_no_access', 'masoud_core_no_access' );

    second:

    function masoud_core_no_access( $r ){
    $mode=1;
    $r=$mode;
    $r = apply_filters( 'bp_core_no_access', $r );
       return $r; 
    }
    add_filter( 'bp_core_no_access', 'masoud_core_no_access' );

    third:

    function masoud_core_no_access( $r ){
    $mode=1;
    $r=$mode;
    $redirect=get_home_url ( int $blog_id = null, string $path = '/login', string|null $scheme = null );
    apply_filters( 'bp_no_access_mode', $mode, $root, $redirect, $message );
       return $r; 
    }
    add_filter( 'bp_core_no_access', 'masoud_core_no_access' );

    fourth:

    function masoud_core_no_access( $mode ){
    $mode=1;
    apply_filters( 'bp_no_access_mode', int $1, $root . '/login', $redirect, $message );
       return $mode; 
    }
    add_filter( 'bp_core_no_access', 'masoud_core_no_access' );

    fifth:

    function masoud_core_no_access( $mode , $redirect ){
    $mode=1;
    $redirect=get_home_url ( int $blog_id = null, string $path = '/login', string|null $scheme = null );
    apply_filters( 'bp_no_access_mode', $mode, $root, $redirect, $message );
    }
    add_filter( 'bp_core_no_access', 'masoud_core_no_access' );

    i dont know what to do else!
    i’ve tried whatever i knew about coding and all seemed to be wrong…

    i want to call mode 1. so it points to root.
    and set redirect_url to a page like “login” so ==>> ‘site.com/login’

    i tried to do it with
    $redirect=get_home_url ( int $blog_id = null, string $path = '/login', string|null $scheme = null );
    but it didnt work.

    how should i suppose to do it? to make it right?

    tnx for your notice and help.


    Masoud
    Participant

    @masoud1111

    @shanebp
    oops!
    i have to use “root”
    instead of “redirect” 😐
    because root points for not-logged-in-users.
    and redirect points for successfully-logged in users!
    sorry for that mistake.
    now i’ve set
    root = $redirect=get_home_url ( int $blog_id = null, string $path = '/login', string|null $scheme = null );
    but error again! 🙁

    correction:
    i want to call mode 1. so it points to root.
    and set root landing page for not logged in users to a page like “login” so ==>> ‘site.com/login’


    shanebp
    Moderator

    @shanebp

    $r is an array

    Try

    function masoud_core_no_access( $r ){
    
       $r['mode'] = 1;
    
       $r['root'] = site_url( '/login/' );
    
       return $r; 
    }
    add_filter( 'bp_core_no_access', 'masoud_core_no_access' );

    Masoud
    Participant

    @masoud1111

    @shanebp
    many thanks to you for your help.
    but unfortunately this code you said, does not work.
    and still redirected to wp-login.php
    i put the code in bp-custom.php

    what other codes do you suggest please?
    thanks for your notice.


    shanebp
    Moderator

    @shanebp

    Try using some other page:

    $r['root'] = site_url( '/put-slug-here/' );

    If that works, it should give you a clue.
    If not, I don’t have any more suggestions.


    Masoud
    Participant

    @masoud1111

    @shanebp
    no still not working. but thank you for your help and notice.


    Masoud
    Participant

    @masoud1111

    @shanebp
    thank you very much.
    the code above run with no eror.
    —–
    UPDATE:
    i put it in my theme functions.php. and it works.
    by mistake i was thinking that i have to put it in bp-custom.php to make it work.
    but it has to be in FUNCTIONS.PHP of your THEME.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar