* * @copyright (c) 2018, Incsub (http://incsub.com) */ /** * Class WP_Smush_Gutenberg for Gutenberg integration. * * @since 2.8.1 */ class WP_Smush_Gutenberg { /** * Module slug. * * @since 2.8.1 * * @var string $module */ private $module = 'gutenberg'; /** * WP_Smush_Gutenberg constructor. * * @since 2.8.1 */ function __construct() { // Filters the setting variable to add Gutenberg setting title and description. add_filter( 'wp_smush_settings', array( $this, 'register_setting' ), 6 ); // Filters the setting variable to add Nextgen to the Integration tab. add_filter( 'wp_smush_integration_settings', array( $this, 'add_setting' ), 1 ); // Disable setting. add_filter( 'wp_smush_integration_status_' . $this->module, array( $this, 'setting_status' ), 10, 2 ); // Hook at the end of setting row to output an error div. add_action( 'smush_setting_column_right_inside', array( $this, 'integration_error' ) ); // Register gutenberg block assets. add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_gb' ) ); // Show submit button when Gutenberg is active. add_filter( 'wp_smush_integration_show_submit', array( $this, 'show_submit' ) ); } /** * Filters the setting variable to add Gutenberg setting title and description. * * @since 2.8.1 * * @param array $settings Settings array. * * @return mixed */ public function register_setting( $settings ) { $settings[ $this->module ] = array( 'label' => esc_html__( 'Show Smush stats in Gutenberg blocks', 'wp-smushit' ), 'short_label' => esc_html__( 'Gutenberg Support', 'wp-smushit' ), 'desc' => esc_html__( 'Add statistics and the manual smush button to Gutenberg blocks that display images.', 'wp-smushit' ), ); return $settings; } /** * Adds the setting to the intgration_group array in the WpSmushBulkUi class. * * @used-by wp_smush_integration_settings filter * * @param array $settings Settings array. * * @return array */ public function add_setting( $settings ) { $settings[] = $this->module; return $settings; } /** * Prints the message for Gutenberg setup. * * @since 2.8.1 * * @param string $setting_key Settings key. * * @return null */ public function integration_error( $setting_key ) { // Return if not Gutenberg integration. if ( $this->module !== $setting_key ) { return; } // If Gutenberg is active, do not continue. if ( $this->is_gutenberg_active() ) { return; } ?>