Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Last active February 21, 2024 21:34
Show Gist options
  • Save igorbenic/56f84e0101d28ab0278f654d1e253ca7 to your computer and use it in GitHub Desktop.
Save igorbenic/56f84e0101d28ab0278f654d1e253ca7 to your computer and use it in GitHub Desktop.
Simple Feature Requests & GeneratePress snippets
<?php
add_action( 'jck_sfr_after_single_loop', 'jck_disable_theme_comments');
/**
* Disable the default theme comments form by disabling comments after the plugin comments form is rendered.
*/
function jck_disable_theme_comments() {
add_filter( 'comments_open', function( $open, $post_id ) {
if ( 'cpt_feature_requests' === get_post_type( $post_id ) ) {
return false;
}
return $open;
}, 20, 2 );
}
<?php
/**
* This will use the Archive Page GeneratePress sidebar settings.
*/
add_filter( 'generate_sidebar_layout', function( $layout ) {
// If on a page or the singular cpt_feature_requests.
if ( is_page() || is_singular('cpt_feature_requests')) {
$post = get_post();
$parent = JCK_SFR_Post_Types::get_archive_page_id();
if ( $parent ) {
if ( $parent === $post->post_parent
|| is_singular('cpt_feature_requests')
|| 'cpt_feature_requests' === $post->post_type ) {
$layout_meta = get_post_meta( $parent, '_generate-sidebar-layout-meta', true );
if ( $layout_meta ) {
return $layout_meta;
}
}
}
}
// Or else, set the regular layout
return $layout;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment