bulk_actions_factory = $bulk_actions_factory; $this->feedback_list_view_factory = $feedback_list_view_factory; $this->backend_styles = $backend_styles; $this->backend_scripts = $backend_scripts; $this->wpdb = $wpdb; } /** * method add_hooks */ public function add_hooks() { add_action( 'admin_menu', array( $this, 'add_translation_feedback_list_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts_action' ) ); add_action( 'current_screen', array( $this, 'bulk_actions_callback' ) ); add_filter( 'posts_where', array( $this, 'maybe_exclude_rating_only_status' ), 10, 2 ); } /** * Define translation feedback list menu and callback */ public function add_translation_feedback_list_menu() { if ( current_user_can( 'manage_options' ) ) { add_submenu_page( apply_filters( 'icl_menu_main_page', WPML_PLUGIN_FOLDER . '/menu/languages.php' ), __( 'Translation Feedback', 'sitepress' ), __( 'Translation Feedback', 'sitepress' ), 'manage_options', self::PAGE_HOOK, array( $this, 'translation_feedback_list_display' ) ); } else { add_menu_page( __( 'Translation Feedback', 'sitepress' ), __( 'Translation Feedback', 'sitepress' ), 'read', self::PAGE_HOOK, array( $this, 'translation_feedback_list_display' ) ); } } /** * Callback to display the feedback list page */ public function translation_feedback_list_display() { $view = $this->feedback_list_view_factory->create(); echo $view->render_page(); } /** * @param string $hook */ public function admin_enqueue_scripts_action( $hook ) { if ( $this->is_page_hook( $hook ) ) { $this->backend_styles->enqueue(); $this->backend_scripts->enqueue(); } } public function bulk_actions_callback( $current_screen ) { $hook = isset( $current_screen->id ) ? $current_screen->id : null; if ( $this->is_page_hook( $hook ) ) { $bulk_actions = $this->bulk_actions_factory->create(); $bulk_actions->process(); } } /** * @param string $hook * * @return bool */ private function is_page_hook( $hook ) { return strpos( $hook, self::PAGE_HOOK ) !== false; } /** * @param string $where * @param WP_Query $query * * @return string */ public function maybe_exclude_rating_only_status( $where, $query ) { if ( isset( $query->query_vars['exclude_tf_rating_only'] ) && $query->query_vars['exclude_tf_rating_only'] ) { $where .= " AND {$this->wpdb->posts}.post_status <> 'rating_only'"; } return $where; } }