class-activation.php
3 years ago
class-admin-interface.php
3 years ago
class-common-methods.php
3 years ago
class-content-management.php
3 years ago
class-deactivation.php
3 years ago
class-disable-components.php
3 years ago
class-security.php
3 years ago
class-settings-fields-render.php
3 years ago
class-settings-sanitization.php
3 years ago
class-settings-sections-fields.php
3 years ago
class-utilities.php
3 years ago
class-disable-components.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\CLasses; |
| 4 | |
| 5 | /** |
| 6 | * Class related to the Disable Components feature |
| 7 | * |
| 8 | * @since 2.2.0 |
| 9 | */ |
| 10 | class Disable_Components { |
| 11 | |
| 12 | /** |
| 13 | * Disable comments for post types |
| 14 | * |
| 15 | * @since 2.7.0 |
| 16 | */ |
| 17 | public function disable_comments_for_post_types_edit() { |
| 18 | |
| 19 | $options = get_option( ASENHA_SLUG_U ); |
| 20 | $disable_comments_for = $options['disable_comments_for']; |
| 21 | |
| 22 | foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) { |
| 23 | if ( $is_commenting_disabled ) { |
| 24 | remove_post_type_support( $post_type_slug, 'comments' ); |
| 25 | remove_post_type_support( $post_type_slug, 'trackbacks' ); |
| 26 | remove_meta_box( 'commentstatusdiv', $post_type_slug, 'normal' ); |
| 27 | remove_meta_box( 'commentstatusdiv', $post_type_slug, 'side' ); |
| 28 | remove_meta_box( 'commentsdiv', $post_type_slug, 'normal' ); |
| 29 | remove_meta_box( 'commentsdiv', $post_type_slug, 'side' ); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Hide existing comments from the frontend post |
| 37 | * |
| 38 | * @since 2.7.0 |
| 39 | */ |
| 40 | public function hide_existing_comments_on_frontend( $comments, $post_id ) { |
| 41 | $options = get_option( ASENHA_SLUG_U ); |
| 42 | $disable_comments_for = $options['disable_comments_for']; |
| 43 | $current_post_type = get_post_type(); |
| 44 | |
| 45 | foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) { |
| 46 | if ( ( $current_post_type === $post_type_slug ) && $is_commenting_disabled ) { |
| 47 | return array(); // return an empty array instead of the existing comments array |
| 48 | } else { |
| 49 | return $comments; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Close commenting on the frontend |
| 56 | * |
| 57 | * @since 2.7.0 |
| 58 | */ |
| 59 | public function close_commenting_on_frontend() { |
| 60 | $options = get_option( ASENHA_SLUG_U ); |
| 61 | $disable_comments_for = $options['disable_comments_for']; |
| 62 | $current_post_type = get_post_type(); |
| 63 | |
| 64 | foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) { |
| 65 | if ( ( $current_post_type === $post_type_slug ) && $is_commenting_disabled ) { |
| 66 | return false; // close commenting |
| 67 | } else { |
| 68 | return true; // keep commenting open |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | } |