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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. // Order by custom field value by meta_key 'lastname'
  29. function my_pre_get_posts( $query ) {
  30. // do not modify queries in the admin
  31. if( is_admin() ) {
  32. return $query;
  33. }
  34. // only modify queries for 'event' post type
  35. if( isset($query->query_vars['post_type']) && $query->query_vars['post_type']) {
  36. $query->set('orderby', 'meta_value');
  37. $query->set('meta_key', 'lastname');
  38. $query->set('order', 'ASC');
  39. }
  40. // return
  41. return $query;
  42. }
  43. add_action('pre_get_posts', 'my_pre_get_posts');
  44. // General Settings - Set Default Featured Image Placeholder if none exists
  45. if ( ! class_exists( 'DefaultThumbnailID' ) ) {
  46. class DefaultThumbnailID {
  47. private static $instance;
  48. public function __construct() {
  49. // Add the option field to the General page.
  50. add_action( 'admin_init', array( &$this, 'show_default_thumbnail_id_option' ) );
  51. // Check if the default featured image exists.
  52. add_filter( 'has_post_thumbnail', array( &$this, 'set_has_post_thumbnail_value' ) );
  53. // Display the default featured image.
  54. add_filter( 'post_thumbnail_html', array( &$this, 'set_default_post_thumbnail_image' ), 10, 4 );
  55. }
  56. public static function get_instance() {
  57. if ( is_null( self::$instance ) ) {
  58. self::$instance = new self();
  59. }
  60. return self::$instance;
  61. }
  62. public function show_default_thumbnail_id_option() {
  63. register_setting(
  64. 'general', // General page
  65. '_default_thumbnail_id' // Option name
  66. );
  67. add_settings_field(
  68. 'default_thumbnail_id', // ID
  69. __( 'Default thumbnail ID', 'text-domain' ), // Option title
  70. array( &$this, 'display_input_field' ), // Display callback
  71. 'general', // General page
  72. 'default' // General page section
  73. );
  74. }
  75. public function display_input_field() {
  76. $value = get_option( '_default_thumbnail_id' );
  77. $value = wp_attachment_is_image( $value ) ? $value : '';
  78. ?>
  79. <input id="default_thumbnail_id" value="<?php echo esc_attr( $value ); ?>" name="_default_thumbnail_id"/>
  80. <?php
  81. }
  82. function set_has_post_thumbnail_value( $has_image ) {
  83. $default_thumbnail_id = get_option( '_default_thumbnail_id' );
  84. if ( ! empty( $default_thumbnail_id ) ) {
  85. $has_image = true;
  86. }
  87. return $has_image;
  88. }
  89. function set_default_post_thumbnail_image( $image, $post_id, $post_thumbnail_id, $size ) {
  90. $default_thumbnail_id = get_option( '_default_thumbnail_id' );
  91. if ( empty( $image ) && ! empty( $default_thumbnail_id ) ) {
  92. $image = wp_get_attachment_image( $default_thumbnail_id, $size );
  93. }
  94. return $image;
  95. }
  96. }
  97. // Instantiate the class object.
  98. DefaultThumbnailID::get_instance();
  99. }