jetpack.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Jetpack Compatibility File
  4. * See: https://jetpack.me/
  5. *
  6. * @package Varia
  7. */
  8. /**
  9. * Jetpack setup function.
  10. *
  11. * See: https://jetpack.com/support/content-options/
  12. */
  13. function varia_jetpack_setup() {
  14. add_theme_support( 'jetpack-content-options',
  15. array(
  16. 'blog-display' => 'content', // the default setting of the theme: 'content', 'excerpt' or array( 'content', 'excerpt' ) for themes mixing both display.
  17. 'author-bio' => false, // display or not the author bio: true or false.
  18. 'author-bio-default' => false, // the default setting of the author bio, if it's being displayed or not: true or false (only required if false).
  19. 'post-details' => array(
  20. 'stylesheet' => 'varia-style', // name of the theme's stylesheet.
  21. 'date' => '.posted-on', // a CSS selector matching the elements that display the post date.
  22. 'categories' => '.cat-links', // a CSS selector matching the elements that display the post categories.
  23. 'tags' => '.tags-links', // a CSS selector matching the elements that display the post tags.
  24. 'author' => '.byline', // a CSS selector matching the elements that display the post author.
  25. 'comment' => '.comments-link', // a CSS selector matching the elements that display the comment link.
  26. ),
  27. 'featured-images' => array(
  28. 'archive' => true, // enable or not the featured image check for archive pages: true or false.
  29. 'archive-default' => true, // the default setting of the featured image on archive pages, if it's being displayed or not: true or false (only required if false).
  30. 'post' => true, // enable or not the featured image check for single posts: true or false.
  31. 'post-default' => false, // the default setting of the featured image on single posts, if it's being displayed or not: true or false (only required if false).
  32. 'page' => true, // enable or not the featured image check for single pages: true or false.
  33. 'page-default' => false, // the default setting of the featured image on single pages, if it's being displayed or not: true or false (only required if false).
  34. ),
  35. )
  36. );
  37. }
  38. add_action( 'after_setup_theme', 'varia_jetpack_setup' );
  39. /**
  40. * Custom function to check for a post thumbnail;
  41. * If Jetpack is not available, fall back to has_post_thumbnail()
  42. */
  43. function varia_has_post_thumbnail( $post = null ) {
  44. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  45. return jetpack_has_featured_image( $post );
  46. } else {
  47. return has_post_thumbnail( $post );
  48. }
  49. }
  50. /**
  51. * Display a Featured Image on archive pages if option is ticked.
  52. */
  53. function varia_jetpack_featured_image_archive_display() {
  54. if ( ! function_exists( 'jetpack_featured_images_remove_post_thumbnail' ) ) {
  55. return false;
  56. } else {
  57. $options = get_theme_support( 'jetpack-content-options' );
  58. $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;
  59. $settings = array(
  60. 'archive-default' => ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1,
  61. );
  62. $settings = array_merge( $settings, array(
  63. 'archive-option' => get_option( 'jetpack_content_featured_images_archive', $settings['archive-default'] ),
  64. ) );
  65. if ( $settings['archive-option'] ) {
  66. return true;
  67. } else {
  68. return false;
  69. }
  70. }
  71. }