| 1 |
<?php |
| 2 |
/** |
| 3 |
* Multisite Language Switcher integration class file. |
| 4 |
* |
| 5 |
* @package Activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub\Integration; |
| 9 |
|
| 10 |
use Activitypub\Collection\Outbox; |
| 11 |
|
| 12 |
/** |
| 13 |
* Compatibility with the Multisite Language Switcher plugin. |
| 14 |
* |
| 15 |
* @see https://github.com/lloc/Multisite-Language-Switcher/ |
| 16 |
*/ |
| 17 |
class Multisite_Language_Switcher { |
| 18 |
/** |
| 19 |
* Initialize the class, registering WordPress hooks. |
| 20 |
*/ |
| 21 |
public static function init() { |
| 22 |
\add_action( 'save_post', array( self::class, 'ignore_outbox_post' ), 9, 2 ); |
| 23 |
\add_action( 'save_post', array( self::class, 'unignore_outbox_post' ), 11, 2 ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Short-circuit saving Multisite Language Switcher data for the Outbox post type. |
| 28 |
* |
| 29 |
* @param int $post_id The post id. |
| 30 |
* @param \WP_Post $post The post object. |
| 31 |
*/ |
| 32 |
public static function ignore_outbox_post( $post_id, $post ) { |
| 33 |
if ( Outbox::POST_TYPE === $post->post_type ) { |
| 34 |
\add_action( 'msls_main_save', '__return_null' ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Remove short-circuit for Multisite Language Switcher data. |
| 40 |
* |
| 41 |
* @param int $post_id The post id. |
| 42 |
* @param \WP_Post $post The post object. |
| 43 |
*/ |
| 44 |
public static function unignore_outbox_post( $post_id, $post ) { |
| 45 |
if ( Outbox::POST_TYPE === $post->post_type ) { |
| 46 |
\remove_action( 'msls_main_save', '__return_null' ); |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|