Forums

Posts 2 Posts
[resolved] Cannot access protected variables in filter passed arguments (4 posts)

  1. magadanski_uchen
    Member
    Posted 6 months ago #

    I needed to modify the arguments for the box rendering and tried doing so using the "p2p_connectable_args" filter, however the second argument passed (the instance of the P2P_Directed_Connection_Type object itself) has all of its variables set to protected (and it's ctype property also does), so this whole argument doesn't seem to do anything at all. The same issue would apply to the "p2p_connected_args" filter as well.

    I managed to modify the arguments by using some of the global variables in WordPress (global $post, and some of the existing arguments), however I believe this is an issue that need to be taken into consideration, as in other cases there might not be alternatives.

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Posted 6 months ago #

    The args are protected, but you can access them directly via a magic method:

    So, instead of $ctype->args['some_arg'] you can just do $ctype->some_arg.

  3. magadanski_uchen
    Member
    Posted 6 months ago #

    The thing is that the cytpe object is protected itself, so it cannot be accessed. So everything that's left to use is just the following properties: direction, cardinality and other_cardinality.
    Some get_ctype() method would really be a nice feature for the P2P_Directed_Connection_Type class for the next version. I guess that then there will no problems at all.

  4. scribu
    Member
    Posted 6 months ago #

    Like I said, you can access these properties through the magic method. It will cascade to the P2P_Connection_Type instance. Just try it.

    Also, there's already a method for getting the instance itself:

    $ctype->lose_direction()

Reply

You must log in to post.

About this Plugin

About this Topic