Craft Video Dictionary https://www.craftvideodictionary.org
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.php 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /*
  3. * Remove COMMENTS in its entirety
  4. */
  5. // Removes COMMENTS from admin menu
  6. add_action( 'admin_menu', 'remove_admin_menus' );
  7. function remove_admin_menus() {
  8. remove_menu_page( 'edit-comments.php' );
  9. }
  10. // Removes COMMENTS from post and pages
  11. add_action('init', 'remove_comment_support', 100);
  12. function remove_comment_support() {
  13. remove_post_type_support( 'post', 'comments' );
  14. remove_post_type_support( 'page', 'comments' );
  15. }
  16. // Removes COMMENTS from admin bar
  17. add_action( 'wp_before_admin_bar_render', 'remove_comments_admin_bar' );
  18. function remove_comments_admin_bar() {
  19. global $wp_admin_bar;
  20. $wp_admin_bar->remove_menu('comments');
  21. }
  22. // Allow [shortcode] in templates
  23. add_action( 'acf/init', 'set_acf_settings' );
  24. function set_acf_settings() {
  25. acf_update_setting( 'enable_shortcode', true );
  26. }
  27. add_filter( 'acf/shortcode/allow_in_block_themes_outside_content', '__return_true' );
  28. // General Settings - Set Default Featured Image Placeholder if none exists
  29. if ( ! class_exists( 'DefaultThumbnailID' ) ) {
  30. class DefaultThumbnailID {
  31. private static $instance;
  32. public function __construct() {
  33. // Add the option field to the General page.
  34. add_action( 'admin_init', array( &$this, 'show_default_thumbnail_id_option' ) );
  35. // Check if the default featured image exists.
  36. add_filter( 'has_post_thumbnail', array( &$this, 'set_has_post_thumbnail_value' ) );
  37. // Display the default featured image.
  38. add_filter( 'post_thumbnail_html', array( &$this, 'set_default_post_thumbnail_image' ), 10, 4 );
  39. }
  40. public static function get_instance() {
  41. if ( is_null( self::$instance ) ) {
  42. self::$instance = new self();
  43. }
  44. return self::$instance;
  45. }
  46. public function show_default_thumbnail_id_option() {
  47. register_setting(
  48. 'general', // General page
  49. '_default_thumbnail_id' // Option name
  50. );
  51. add_settings_field(
  52. 'default_thumbnail_id', // ID
  53. __( 'Default thumbnail ID', 'text-domain' ), // Option title
  54. array( &$this, 'display_input_field' ), // Display callback
  55. 'general', // General page
  56. 'default' // General page section
  57. );
  58. }
  59. public function display_input_field() {
  60. $value = get_option( '_default_thumbnail_id' );
  61. $value = wp_attachment_is_image( $value ) ? $value : '';
  62. ?>
  63. <input id="default_thumbnail_id" value="<?php echo esc_attr( $value ); ?>" name="_default_thumbnail_id"/>
  64. <?php
  65. }
  66. function set_has_post_thumbnail_value( $has_image ) {
  67. $default_thumbnail_id = get_option( '_default_thumbnail_id' );
  68. if ( ! empty( $default_thumbnail_id ) ) {
  69. $has_image = true;
  70. }
  71. return $has_image;
  72. }
  73. function set_default_post_thumbnail_image( $image, $post_id, $post_thumbnail_id, $size ) {
  74. $default_thumbnail_id = get_option( '_default_thumbnail_id' );
  75. if ( empty( $image ) && ! empty( $default_thumbnail_id ) ) {
  76. $image = wp_get_attachment_image( $default_thumbnail_id, $size );
  77. }
  78. return $image;
  79. }
  80. }
  81. // Instantiate the class object.
  82. DefaultThumbnailID::get_instance();
  83. }
  84. ?>