rid = $this->post_translation->get_element_trid( $post_id ); return $this->post_translation->get_element_translations( false, $trid, false ); } /** * @param int $post_id */ private function add_post_id_to_original_option( $post_id ) { $this->update_original_option( $post_id, array( $this, 'add_post_id' ) ); } /** * @param string $option * @param int $post_id */ private function add_post_id( $option, $post_id ) { $sticky_posts = $this->get_sticky_posts( $option ); if ( ! in_array( $post_id, $sticky_posts, true ) ) { $sticky_posts[] = $post_id; update_option( $option, $sticky_posts, true ); } } /** * @param int $post_id */ private function remove_post_id_from_original_option( $post_id ) { $this->update_original_option( $post_id, array( $this, 'remove_post_id' ) ); } /** * @param int $post_id * @param callable $callback */ private function update_original_option( $post_id, $callback ) { remove_filter( 'pre_option_sticky_posts', array( $this, 'pre_option_sticky_posts_filter' ) ); remove_filter( 'pre_update_option_sticky_posts', array( $this, 'pre_update_option_sticky_posts' ) ); call_user_func( $callback, 'sticky_posts', $post_id ); add_filter( 'pre_update_option_sticky_posts', array( $this, 'pre_update_option_sticky_posts' ), 10, 1 ); add_filter( 'pre_option_sticky_posts', array( $this, 'pre_option_sticky_posts_filter' ), 10, 0 ); } /** * @param string $option * @param int $post_id */ private function remove_post_id( $option, $post_id ) { $sticky_posts = $this->get_sticky_posts( $option ); if ( ( $key = array_search( $post_id, $sticky_posts ) ) !== false ) { unset( $sticky_posts[ $key ] ); update_option( $option, array_values( $sticky_posts ), true ); } } /** * @param string $lang * * @return array */ private function get_option_by_lang( $lang ) { $sticky_posts = $this->get_sticky_posts( 'sticky_posts_' . $lang ); return $sticky_posts; } /** * @param string $option Default is sticky_posts * @return array */ private function get_sticky_posts( $option = 'sticky_posts' ) { $sticky_posts = get_option( $option, array() ); return is_array( $sticky_posts ) ? $sticky_posts : []; } }