Advertisement
Guest User

Untitled

a guest
May 4th, 2023
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: MB Blocks Wpml
  4.  * Description: WPML Translations support for mb blo .
  5.  * Version:     0.0.1
  6.  * Text Domain: mb-blocks
  7.  * Domain Path: /languages/
  8.  *
  9.  * @package    Meta Box
  10.  * @subpackage MB Blocks Wpml
  11.  */
  12.  
  13. // Prevent loading this file directly.
  14. defined("ABSPATH") || die();
  15.  
  16. function mb_block_get_wpml_cfg($nodes) {
  17.   $result = [];
  18.   foreach ($nodes as $node) {
  19.     if ($node["translate"]) {
  20.       $result[] = [
  21.         "value" => "",
  22.         "attr" => [
  23.           "name" => $node["id"],
  24.         ],
  25.       ];
  26.     } else {
  27.       if ($node["fields"]) {
  28.         $sub = mb_block_get_wpml_cfg($node["fields"]);
  29.         if (count($sub)) {
  30.           $result[] = [
  31.             "value" => "",
  32.             "attr" => [
  33.               "name" => $node["id"],
  34.             ],
  35.             "key" => [
  36.               "value" => "",
  37.               "attr" => [
  38.                 "name" => "*",
  39.               ],
  40.               "key" => $sub,
  41.             ],
  42.           ];
  43.         }
  44.       }
  45.     }
  46.   }
  47.   return $result;
  48. }
  49.  
  50. add_filter("wpml_config_array", function ($config) {
  51.   $rwmb_registry = rwmb_get_registry("meta_box");
  52.   $blocks = $rwmb_registry->get_by(["type" => "block"]);
  53.  
  54.   foreach ($blocks as $mb_id => $block) {
  55.     $cfg = mb_block_get_wpml_cfg($block->meta_box["fields"]);
  56.     if (count($cfg)) {
  57.       $config["wpml-config"]["gutenberg-blocks"]["gutenberg-block"][] = [
  58.         "value" => "",
  59.         "attr" => [
  60.           "type" => "meta-box/$mb_id",
  61.           "translate" => "1",
  62.         ],
  63.         "key" => [
  64.           "value" => "",
  65.           "attr" => [
  66.             "name" => "data",
  67.           ],
  68.           "key" => $cfg,
  69.         ],
  70.       ];
  71.     }
  72.   }
  73.  
  74.   return $config;
  75. });
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement