Sunday, January 29, 2023
HomeWordPress Developmentcapabilities - How can I modify or filter this variable in an...

capabilities – How can I modify or filter this variable in an present class? (Mai Theme)


I am making an attempt to make the most of present post-grid capabilities to indicate attachment posts however $post_status is difficult coded to be both ‘publish’ or ‘non-public’ whereas attachments have a standing of inherit. I added ‘inherit’ to their supply code to substantiate it really works however I’m making an attempt to attain this with out modifying the supply.

There are a pair layers of strategies within the Class earlier than it renders so I am having hassle determining how I can filter $post_status to ‘inherit’.

That is what I am making an attempt to do:

This works once I use $args for something however attachments.

operate my_attachment_grid() {
    $args = [
        'post_type' => 'attachment',
        'post_status' => 'inherit',
    ];
    do_grid( 'submit', $args );
}

That is what I am working with:

Right here is the operate (outdoors of Class). If I var_dump($grid) earlier than $grid->render(), I can see all of the default $args however $query_args is empty. $post_status is just not listed right here.

operate do_grid( $sort, $args = [] ) {
    $args = array_merge( [ 'type' => $type ], $args );
    $grid = new Mai_Grid( $args );
    $grid->render();
}

The Class itself:

Discover get_post_query_args() declares $post_status as ‘publish’, assigns it to $query_args, then apply_filters(). However as talked about above, $query_args is protected and empty in a brand new Object.

I imagine I ought to have the option add_filter() however I am undecided if I am calling it appropriately or if it is even doable because it’s exhausting coded inside and never displaying inside the default args.

class Grid {
    // all protected 
    public operate __construct( $args ) {
        $args['context']  = 'block'; // Required for Mai_Entry.
        $this->sort       = isset( $args['type'] ) ? $args['type'] : 'submit';
        $this->defaults   = $this->get_defaults();
        $this->args       = $this->get_sanitized_args( $args );
        $this->query_args = [];
    }

    public operate render() {
        $this->question = $this->get_query();
        // ...
        do_entries_open( $this->args ); // Open.
        $this->do_grid_entries(); // Entries.
        do_entries_close( $this->args ); // Shut.
    }

    public operate get_query() { // modify if submit question or time period question
        $this->query_args = $this->get_post_query_args();
        return $question;
    }

    public operate get_post_query_args() {
        $post_status="publish";
        $query_args = [
            'post_status' => $post_status,
            //..
        ]
        // ...
        return apply_filters( 'post_grid_query_args', $query_args, $this->args );
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments