Smart Post Show

  1. Home
  2. Docs
  3. Smart Post Show
  4. Hooks: Actions and Filters

Hooks: Actions and Filters

A comprehensive guideline on how to use Smart Post Show filter hooks. We have added the following hooks for developers to extend functionalities. Simply add the following custom code to your current theme’s functions.php file. It’s recommended to keep the code in the functions.php file of your child theme. Because you might lose your customizations if the theme is updated. Keeping the modified codes in your parent theme’s child theme is therefore the best practice.

1) How to change the plugin name

2) How to grant plugin access to editors

3) How can the plugin be made visible to the authors

4) How to change the plugin’s default placeholder image

5) How to hide posts that don’t have the thumbnail

 

1) How to change the plugin name

If you want to change the Smart Post Show plugin name for any reason, you can easily do it with the following custom code. If you check the code, you will see there is a filter hook (sp_post_carousel_post_type_labels) available in the plugin by which you can make the modification.

add_filter( 'sp_post_carousel_post_type_labels', 'sp_show_change_menu_name' );
/**
 * Change plugin menu name.
 *
 * @param array $labels The labels.
 * @return string
 */
function sp_show_change_menu_name( $labels ) {
    unset( $labels['menu_name'] );
    $new_menu_name = array( 'menu_name' => __( 'My Plugin', 'smart-post-show' ) );
    return array_merge( $new_menu_name, $labels );
}

2) How to grant plugin access to editors

If you want to give the plugin access to the editors, you can do it easily with the help of the following custom code. If you check the code, you will see there is a filter hook (sp_pc_dashboard_capability) available in the plugin which allows you to modify the plugin’s functionality.

// Plugin visible to editor
add_filter( 'spf_chosen_ajax_capability', 'sp_pc_dashboard_capability_to_editor' );
add_filter( 'sp_pc_dashboard_capability', 'sp_pc_dashboard_capability_to_editor' );
function sp_pc_dashboard_capability_to_editor() {
    return 'edit_others_pages';
}

3) How can the plugin be made visible to the authors

If you want to make the plugin visible to the authors, you can do it easily with the help of the following custom code. If you check the code, you will see there is a filter hook (pcp_user_role_permission) available in the plugin which allows you to modify the plugin’s functionality.

// Plugin visible to author
add_filter( 'pcp_user_role_permission', 'sp_pc_dashboard_capability_to_author' );
function sp_pc_dashboard_capability_to_author() {
    return 'edit_posts';
}

4) How to change the plugin’s default placeholder image

If you want to change the default placeholder image of the plugin, you can do it easily with the help of the following custom code. If you check the code, you will see there is a filter hook (pcp_no_thumb_placeholder) available in the plugin which allows you to modify the plugin’s functionality.

// Placeholder image modified
add_filter( 'pcp_no_thumb_placeholder', 'pcp_no_thumb_placeholder_modified' );
function pcp_no_thumb_placeholder_modified( $placeholder_img ){
    // set your placeholder image url.
    $placeholder_img = 'http://smart-post-show-pro.local/wp-content/uploads/2021/11/25.jpg';
    return $placeholder_img;
}

5) How to hide posts that don’t have the thumbnail

If you want to hide posts that have no thumbnails, you can do it easily with the help of the following custom code. If you check the code, you will see there is a filter hook (sps_without_thumbnail_post_hide) available in the plugin which allows you to modify the plugin’s functionality.

// Hide posts without thumbnail
add_filter( 'sps_without_thumbnail_post_hide', '__return_false' );