Suspend
2 years ago
ActionScheduler.php
2 years ago
AdminPages.php
8 months ago
AdminUrl.php
8 months ago
DB.php
4 years ago
Post.php
5 years ago
Resources.php
5 years ago
SyncHash.php
8 months ago
WCTaxonomies.php
1 year ago
WcAdminPages.php
8 months ago
WpAdminPages.php
1 year ago
Post.php
40 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Utilities; |
| 4 | |
| 5 | use WPML\FP\Fns; |
| 6 | |
| 7 | class Post { |
| 8 | |
| 9 | /** |
| 10 | * This allows to create new posts immediately in the |
| 11 | * correct language and the correct translation group (if any). |
| 12 | * |
| 13 | * @param array $args |
| 14 | * @param string|null $lang |
| 15 | * @param int|null $trid |
| 16 | * |
| 17 | * @return int|\WP_Error |
| 18 | */ |
| 19 | public static function insert( array $args, $lang = null, $trid = null ) { |
| 20 | $saveInLang = $saveWithTrid = null; |
| 21 | |
| 22 | if ( $lang ) { |
| 23 | $saveInLang = Fns::always( $lang ); |
| 24 | add_filter( 'wpml_save_post_lang', $saveInLang ); |
| 25 | } |
| 26 | |
| 27 | if ( $trid ) { |
| 28 | $saveWithTrid = Fns::always( $trid ); |
| 29 | add_filter( 'wpml_save_post_trid_value', $saveWithTrid ); |
| 30 | } |
| 31 | |
| 32 | $newPostId = wp_insert_post( $args ); |
| 33 | |
| 34 | remove_filter( 'wpml_save_post_lang', $saveInLang ); |
| 35 | remove_filter( 'wpml_save_post_trid_value', $saveWithTrid ); |
| 36 | |
| 37 | return $newPostId; |
| 38 | } |
| 39 | } |
| 40 |