| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /*
- * Remove COMMENTS in its entirety
- */
- // Removes COMMENTS from admin menu
- add_action( 'admin_menu', 'remove_admin_menus' );
- function remove_admin_menus() {
- remove_menu_page( 'edit-comments.php' );
- }
- // Removes COMMENTS from post and pages
- add_action('init', 'remove_comment_support', 100);
- function remove_comment_support() {
- remove_post_type_support( 'post', 'comments' );
- remove_post_type_support( 'page', 'comments' );
- }
- // Removes COMMENTS from admin bar
- add_action( 'wp_before_admin_bar_render', 'remove_comments_admin_bar' );
- function remove_comments_admin_bar() {
- global $wp_admin_bar;
- $wp_admin_bar->remove_menu('comments');
- }
-
- // Allow [shortcode] in templates
- add_action( 'acf/init', 'set_acf_settings' );
- function set_acf_settings() {
- acf_update_setting( 'enable_shortcode', true );
- }
-
- add_filter( 'acf/shortcode/allow_in_block_themes_outside_content', '__return_true' );
-
- // Order by custom field value by meta_key 'lastname'
- function my_pre_get_posts( $query ) {
- // do not modify queries in the admin
- if( is_admin() ) {
- return $query;
- }
- // only modify queries for 'event' post type
- if( isset($query->query_vars['post_type']) && $query->query_vars['post_type']) {
- $query->set('orderby', 'meta_value');
- $query->set('meta_key', 'lastname');
- $query->set('order', 'ASC');
- }
- // return
- return $query;
- }
-
- add_action('pre_get_posts', 'my_pre_get_posts');
-
-
- // General Settings - Set Default Featured Image Placeholder if none exists
- if ( ! class_exists( 'DefaultThumbnailID' ) ) {
- class DefaultThumbnailID {
- private static $instance;
- public function __construct() {
- // Add the option field to the General page.
- add_action( 'admin_init', array( &$this, 'show_default_thumbnail_id_option' ) );
- // Check if the default featured image exists.
- add_filter( 'has_post_thumbnail', array( &$this, 'set_has_post_thumbnail_value' ) );
- // Display the default featured image.
- add_filter( 'post_thumbnail_html', array( &$this, 'set_default_post_thumbnail_image' ), 10, 4 );
- }
- public static function get_instance() {
- if ( is_null( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
- public function show_default_thumbnail_id_option() {
- register_setting(
- 'general', // General page
- '_default_thumbnail_id' // Option name
- );
- add_settings_field(
- 'default_thumbnail_id', // ID
- __( 'Default thumbnail ID', 'text-domain' ), // Option title
- array( &$this, 'display_input_field' ), // Display callback
- 'general', // General page
- 'default' // General page section
- );
- }
- public function display_input_field() {
- $value = get_option( '_default_thumbnail_id' );
- $value = wp_attachment_is_image( $value ) ? $value : '';
- ?>
- <input id="default_thumbnail_id" value="<?php echo esc_attr( $value ); ?>" name="_default_thumbnail_id"/>
- <?php
- }
- function set_has_post_thumbnail_value( $has_image ) {
- $default_thumbnail_id = get_option( '_default_thumbnail_id' );
- if ( ! empty( $default_thumbnail_id ) ) {
- $has_image = true;
- }
- return $has_image;
- }
- function set_default_post_thumbnail_image( $image, $post_id, $post_thumbnail_id, $size ) {
- $default_thumbnail_id = get_option( '_default_thumbnail_id' );
- if ( empty( $image ) && ! empty( $default_thumbnail_id ) ) {
- $image = wp_get_attachment_image( $default_thumbnail_id, $size );
- }
- return $image;
- }
- }
- // Instantiate the class object.
- DefaultThumbnailID::get_instance();
- }
-
-
|