| Server IP : 146.59.209.152 / Your IP : 216.73.216.46 Web Server : Apache System : Linux webm005.cluster131.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 User : infrafs ( 43850) PHP Version : 8.2.29 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/infrafs/INFRABIKEDE/wp-content/plugins/weglot/src/actions/ |
Upload File : |
<?php
namespace WeglotWP\Actions;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use WeglotWP\Models\Hooks_Interface_Weglot;
use WeglotWP\Services\Button_Service_Weglot;
/**
* Registe widget weglot
*
* @since 2.0
*/
class Register_Widget_Weglot implements Hooks_Interface_Weglot {
/**
* @return void
* @see HooksInterface
*/
public function hooks() {
add_action( 'widgets_init', array( $this, 'register_a_widget_weglot' ) ); // @phpstan-ignore-line
add_action( 'init', array( $this, 'weglot_widget_block' ) );
add_action( 'init', array( $this, 'weglot_menu_block' ) );
// Hook the enqueue functions into the editor.
add_action( 'enqueue_block_editor_assets', array( $this, 'my_block_plugin_editor_scripts' ) );
}
/**
* @return string
* @since 2.0
*/
public function register_a_widget_weglot() {
register_widget( 'WeglotWP\Widgets\Widget_Selector_Weglot' ); // @phpstan-ignore-line
}
/**
* Enqueue block JavaScript and CSS for the editor
*/
public function my_block_plugin_editor_scripts() {
// Enqueue block editor styles.
wp_enqueue_style( 'weglot-editor-css', WEGLOT_URL_DIST . '/css/front-css.css', array( 'wp-edit-blocks' ), WEGLOT_VERSION );
}
/**
* @return string
* @since 2.0
*/
public function weglot_widget_block_render_callback( $block_attributes, $content ) {
$type_block = $block_attributes['type'];
/** @var $button_service Button_Service_Weglot */
$button_service = weglot_get_service( 'Button_Service_Weglot' );
$button = $button_service->get_html( 'weglot-widget weglot-widget-block' );
if ( 'widget' === $type_block ) {
$button = $button_service->get_html( 'weglot-widget weglot-widget-block' );
$button = str_replace( 'name="menu" ', 'name="menu" value=""', $button );
$button = str_replace( 'data-wg-notranslate=""', '', $button );
} elseif ( 'menu' === $type_block ) {
$button = $button_service->get_html( 'weglot-menu weglot-menu-block' );
$button = str_replace( 'name="menu" ', 'name="menu" value=""', $button );
$button = str_replace( 'data-wg-notranslate=""', '', $button );
}
return $button;
}
/**
* @return void
* @since 2.0
*/
public function weglot_widget_block() {
register_block_type(
WEGLOT_DIR . '/blocks/weglot-widget/build',
array(
'api_version' => 2,
'attributes' => array(
'type' => array(
'default' => 'widget',
'type' => 'string',
),
),
'render_callback' => array( $this, 'weglot_widget_block_render_callback' ),
)
);
}
/**
* @return void
* @since 2.0
*/
public function weglot_menu_block() {
register_block_type(
WEGLOT_DIR . '/blocks/weglot-menu/build',
array(
'api_version' => 2,
'attributes' => array(
'type' => array(
'default' => 'menu',
'type' => 'string',
),
),
'render_callback' => array( $this, 'weglot_widget_block_render_callback' ),
)
);
}
}