post-tools.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Classes\Post; |
| 5 | |
| 6 | |
| 7 | class Post_Tools { |
| 8 | |
| 9 | /** |
| 10 | * @param $post_id |
| 11 | * |
| 12 | * @return \WP_Post |
| 13 | * @throws Not_Found_Post_Exception |
| 14 | */ |
| 15 | public static function get_post( $post_id ): \WP_Post { |
| 16 | $post_id = (int) $post_id; |
| 17 | |
| 18 | if ( ! $post_id ) { |
| 19 | throw new Not_Found_Post_Exception( 'Empty post_id' ); |
| 20 | } |
| 21 | |
| 22 | $post = \get_post( $post_id ); |
| 23 | |
| 24 | if ( is_null( $post ) ) { |
| 25 | throw new Not_Found_Post_Exception( 'Not found post row' ); |
| 26 | } |
| 27 | |
| 28 | return $post; |
| 29 | } |
| 30 | |
| 31 | public static function get_title( $post ): string { |
| 32 | $title = get_the_title( $post ); |
| 33 | |
| 34 | return empty( $title ) ? __( '(no title)', 'jet-form-builder' ) : $title; |
| 35 | } |
| 36 | |
| 37 | } |