themehybrid / hybrid-core

Official repository for the Hybrid Core WordPress development framework.
GNU General Public License v2.0
689 stars 144 forks source link

hybrid_get_post_layout should catch the default post_id #153

Closed sharmashivanand closed 6 years ago

sharmashivanand commented 6 years ago

Currently the function is declared as hybrid_get_post_layout( $post_id ). This does not catch the post_id by default.

Can we define it like:

hybrid_get_post_layout( $post_id = '' ) {
    if ( ! $post_id )
        $post_id = get_the_ID();
        …
        …
        …
}

Eg: the function hybrid_has_post_layout( $layout, $post_id = '' ) is already following the same norm.

Use case:

https://core.trac.wordpress.org/ticket/21256#comment:28

define( '1c', '720' );
define( '2c-l', '560' );

add_action( 'template_redirect', 'lander_content_width' );

function lander_content_width() {
    if(hybrid_has_post_layout()){
        hybrid_set_content_width( constant(hybrid_get_post_layout()) );
    }
    else{
        hybrid_set_content_width( constant(hybrid_get_default_layout()) );
    }
}
justintadlock commented 6 years ago

The reason for the difference between the two is that hybrid_has_post_layout() is a template tag and hybrid_get_post_layout() is a function wrapper for get_post_meta().

Honestly, the functions should probably be in separate functions-layouts.php and template-layouts.php files to separate these things but I've kept them together just to cut back on extra files.

If I made this change, it'd make sense to make the same change with user and term layout getter functions. It'd also make sense to make this change elsewhere in the framework where it follows the same pattern.

It's something that I'd need to mull over. For my own sanity and keeping things consistent, I'd want to look at how I do this across the board (in themes and plugins).


As far as your custom function is concerned, I wouldn't use hybrid_has_post_layout() in template_redirect without explicitly passing in get_queried_object_id() anyway.

justintadlock commented 6 years ago

Closing this one simply because layouts have been removed in 5.0.