我想扩展 WordPress (Gutenberg) 默认块 段落,让编辑者无需编写代码即可添加工具提示。
目标:
在职的:
丢失的:
任何帮助都是极好的!
WordPress 插件
<?php
/*
Plugin Name: KF Custom
*/
add_action( 'enqueue_block_editor_assets', function () {
wp_enqueue_script(
'kf-custom-script',
plugins_url( 'kf-custom-script.js', __FILE__ ),
array('wp-blocks', 'wp-rich-text')
);
});
add_action( 'enqueue_block_assets', function () {
wp_enqueue_style( 'kf-custom-style', plugins_url( 'style.css', __FILE__ ) );
});Run Code Online (Sandbox Code Playgroud)
kf-自定义脚本.js
(function(wp){
console.log(wp);
// Create Popover
const { Popover } = wp.components; …Run Code Online (Sandbox Code Playgroud)我有一个包含大量链接的PHP String $菜单.我需要用基于链接的ID替换href.
我需要
这就是我所拥有的:
<a href="http://www.test.de/start/">Link</a>
<a href="http://www.test.de/contact/">Another Link</a>
<a href="http://www.test.de/contact/sub/">Sub Link</a>
Run Code Online (Sandbox Code Playgroud)
这就是我想要的:
<a href="#start">Link</a>
<a href="#contact">Another Link</a>
<a href="#contact-sub">Another Link</a>
Run Code Online (Sandbox Code Playgroud)
我用preg_replace试了一下
$search = array(
"/http:\/\/www.test.de/",
"/".preg_quote('/">', '/')."/"
);
$replacement = array('#','">');
$menu = preg_replace($search,$replacement,$menu);
Run Code Online (Sandbox Code Playgroud)
我的解决方案看起来有点"脏,并没有取代中间的斜线.任何想法"真正的"模式来完成这个?