FilterHooks.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | namespace RT\ThePostGrid\Controllers\Hooks; |
| 4 | |
| 5 | use Cassandra\Varint; |
| 6 | use RT\ThePostGrid\Helpers\Fns; |
| 7 | |
| 8 | class FilterHooks { |
| 9 | |
| 10 | public static function init() { |
| 11 | add_filter( 'tpg_author_arg', [ __CLASS__, 'filter_author_args' ], 10 ); |
| 12 | add_filter( 'plugin_row_meta', [ __CLASS__, 'plugin_row_meta' ], 10, 2 ); |
| 13 | |
| 14 | $settings = get_option( 'rt_the_post_grid_settings' ); |
| 15 | if ( isset( $settings['show_acf_details'] ) && $settings['show_acf_details'] ) { |
| 16 | add_filter( 'the_content', [ __CLASS__, 'tpg_acf_content_filter' ] ); |
| 17 | } |
| 18 | add_filter( 'wp_head', [ __CLASS__, 'set_post_view_count' ], 9999 ); |
| 19 | add_filter( 'admin_body_class', [ __CLASS__, 'admin_body_class' ] ); |
| 20 | } |
| 21 | |
| 22 | |
| 23 | public static function admin_body_class($clsses){ |
| 24 | $settings = get_option('rt_the_post_grid_settings'); |
| 25 | |
| 26 | if( isset($settings['tpg_block_type']) && in_array($settings['tpg_block_type'], ['elementor', 'shortcode']) ) { |
| 27 | $clsses .= 'tpg-block-type-elementor-or-shortcode'; |
| 28 | } |
| 29 | |
| 30 | return $clsses; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | public static function set_post_view_count( $content ) { |
| 35 | if ( is_single() ) { |
| 36 | $pId = get_the_ID(); |
| 37 | Fns::update_post_views_count( $pId ); |
| 38 | } |
| 39 | |
| 40 | return $content; |
| 41 | } |
| 42 | |
| 43 | public static function filter_author_args( $args ) { |
| 44 | $defaults = [ 'role__in' => [ 'administrator', 'editor', 'author' ] ]; |
| 45 | |
| 46 | return wp_parse_args( $args, $defaults ); |
| 47 | } |
| 48 | |
| 49 | public static function plugin_row_meta( $links, $file ) { |
| 50 | if ( $file == RT_THE_POST_GRID_PLUGIN_ACTIVE_FILE_NAME ) { |
| 51 | $report_url = 'https://www.radiustheme.com/contact/'; |
| 52 | $row_meta['issues'] = sprintf( '%2$s <a target="_blank" href="%1$s">%3$s</a>', |
| 53 | esc_url( $report_url ), |
| 54 | esc_html__( 'Facing issue?', 'the-post-grid' ), |
| 55 | '<span style="color: red">' . esc_html__( 'Please open a support ticket.', 'the-post-grid' ) . '</span>' ); |
| 56 | |
| 57 | return array_merge( $links, $row_meta ); |
| 58 | } |
| 59 | |
| 60 | return (array) $links; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | public static function tpg_acf_content_filter( $content ) { |
| 65 | // Check if we're inside the main loop in a post or page. |
| 66 | if ( is_single() && in_the_loop() && is_main_query() && rtTPG()->hasPro() ) { |
| 67 | $settings = get_option( rtTPG()->options['settings'] ); |
| 68 | |
| 69 | $data = [ |
| 70 | 'show_acf' => isset( $settings['show_acf_details'] ) && $settings['show_acf_details'] ? 'show' : false, |
| 71 | 'cf_group' => isset( $settings['cf_group_details'] ) ? $settings['cf_group_details'] : [], |
| 72 | 'cf_hide_empty_value' => isset( $settings['cf_hide_empty_value_details'] ) ? $settings['cf_hide_empty_value_details'] : false, |
| 73 | 'cf_show_only_value' => isset( $settings['cf_show_only_value_details'] ) ? $settings['cf_show_only_value_details'] : false, |
| 74 | 'cf_hide_group_title' => isset( $settings['cf_hide_group_title_details'] ) ? $settings['cf_hide_group_title_details'] : false, |
| 75 | ]; |
| 76 | |
| 77 | return $content . Fns::tpg_get_acf_data_elementor( $data, null, false ); |
| 78 | } |
| 79 | |
| 80 | return $content; |
| 81 | } |
| 82 | |
| 83 | } |
| 84 |