Inpsyde\MultilingualPress\Asset\AssetManager::add_script_data PHP Method

add_script_data() public method

Adds the given data to the given script, and handles it in case the script has been enqueued already.
Since: 3.0.0
public add_script_data ( Inpsyde\MultilingualPress\Asset\Script | string $script, string $object_name, array $data ) : Inpsyde\MultilingualPress\Asset\Script | null
$script Inpsyde\MultilingualPress\Asset\Script | string Script object or handle.
$object_name string The name of the JavaScript variable holding the data.
$data array The data to be made available for the script.
return Inpsyde\MultilingualPress\Asset\Script | null Script object if it exists, null if not.
    public function add_script_data($script, $object_name, array $data)
    {
        if (!$script instanceof Script) {
            $script = $this->get_script((string) $script);
            if (!$script) {
                return null;
            }
        }
        $script->add_data($object_name, $data);
        if (wp_script_is($script->handle())) {
            $this->handle_script_data($script);
        }
        return $script;
    }

Usage Example

 /**
  * @param string $hook
  *
  * @return void
  */
 public function load_script($hook)
 {
     if ('nav-menus.php' !== $hook) {
         return;
     }
     $this->asset_manager->add_script_data('multilingualpress-admin', 'mlpNavMenusSettings', ['action' => $this->handle, 'metaBoxId' => $this->handle, 'nonce' => (string) $this->nonce, 'nonceName' => $this->nonce->action()]);
 }
All Usage Examples Of Inpsyde\MultilingualPress\Asset\AssetManager::add_script_data