如何更改wordpress颜色选择按钮文本?(how to change the wordpress color picker button text?)
这是我使用的代码:
function SDS_admin_init() { wp_register_script( 'SDS-color-picker', plugins_url('/js/SDS-color-picker.js', __FILE__), array( 'wp-color-picker' ), false, true); } add_action( 'admin_init', 'SDS_admin_init' ); function SDS_admin_enqueue_scripts() { // check if this your page here with the upload form! if(get_post_type() !== 'post') return; wp_enqueue_script( 'SDS-color-picker' ); wp_enqueue_style( 'wp-color-picker' ); } add_action( 'admin_enqueue_scripts', 'SDS_admin_enqueue_scripts' );
这是我的SDS-color-picker脚本:
jQuery(document).ready(function($) { var myOptions = { defaultColor: false, change: function(event, ui){}, clear: function() {}, hide: true, palettes: true }; $('.my-color-field').wpColorPicker(myOptions); }); //onready
'.my-color-field'输入字段位于我的插件的元数据框中。 我想知道如何更改颜色选择器按钮上的文本“选择颜色”...也许使用wp_localize_script函数将一些默认参数传递给颜色选择器脚本???
我真的需要帮助! 谢谢
this is the code I m using:
function SDS_admin_init() { wp_register_script( 'SDS-color-picker', plugins_url('/js/SDS-color-picker.js', __FILE__), array( 'wp-color-picker' ), false, true); } add_action( 'admin_init', 'SDS_admin_init' ); function SDS_admin_enqueue_scripts() { // check if this your page here with the upload form! if(get_post_type() !== 'post') return; wp_enqueue_script( 'SDS-color-picker' ); wp_enqueue_style( 'wp-color-picker' ); } add_action( 'admin_enqueue_scripts', 'SDS_admin_enqueue_scripts' );
This is my SDS-color-picker script:
jQuery(document).ready(function($) { var myOptions = { defaultColor: false, change: function(event, ui){}, clear: function() {}, hide: true, palettes: true }; $('.my-color-field').wpColorPicker(myOptions); }); //onready
The '.my-color-field' input field is in a metabox of my plugin. I want to know how can I change the text 'select color' on the button of the color picker...maybe with the wp_localize_script function to pass some default parameters to the color picker script ???
I realy need help on this one! thanks
原文:https://stackoverflow.com/questions/18967809
最满意答案
我不确定你在这里尝试了什么,但这里是我的“可能最接近的代码投影到可编译的Scala”的版本:
import scala.language.higherKinds object Application extends App { private val foo = new Foo private val holder = new FooTypeHolder private val client = new Client(holder) client.showElementType(foo) } class Foo trait TypeHolder[T] { type ElementType = T } class FooTypeHolder extends TypeHolder[Foo] class Client[T, H[X] <: TypeHolder[X]](val holder: H[T]) { def showElementType(t: T): Unit = { println("show element type " + t.toString) println(t.getClass) } }
但它可能是这样的:
import scala.language.higherKinds object Application extends App { private val foo = new Foo private val holder = new FooTypeHolder private val client = new Client[Foo, FooTypeHolder](holder) client.showElementType(foo) } class Foo trait TypeHolder { type ElementType } class FooTypeHolder extends TypeHolder { type ElementType = Foo } class Client[T, H <: TypeHolder { type ElementType = T }](val holder: H) { def showElementType(t: T): Unit = { println("show element type " + t.toString) println(t.getClass) } }
或者这个?:
import scala.language.higherKinds object Application extends App { private val foo = new Foo private val holder = new FooTypeHolder private val client = new Client(holder) client.showElementType(foo) } class Foo trait TypeHolder[T] { type ElementType = T } class FooTypeHolder extends TypeHolder[Foo] class Client[H <: TypeHolder[_]](val holder: H) { def showElementType(t: holder.ElementType): Unit = { println("show element type " + t.toString) println(t.getClass) } }
我从根本上不了解你的代码是什么:
TypeHolder[T]
应该做什么,究竟是什么? 整个TypeHolder[T]
构造似乎不包含T
本身以外的任何信息,为什么不直接使用T
,像这样?:object Application extends App { private val foo = new Foo private val client = new Client[Foo] client.showElementType(foo) } class Foo class Client[T] { def showElementType(t: T): Unit = { println("show element type " + t.toString) println(t.getClass) } }
一些一般提示:
- 避免一次提出多个问题
- 避免在同一帖子中询问有关您之前问题的答案之一的多个问题。
- 这可能需要一些繁重的编辑......
编辑
我会尝试以与您在帖子中添加的顺序相同的顺序回答所有其他问题:
1.它与
holder.ElementType
一起holder.ElementType
,因为当你实例化Client
,已知holder
是TypeHolder[Foo]
类型,因此我们知道holder.ElementType = Foo
。2.它不适用于
T <: TypeHolder[_]
T#ElementType
,因为正如签名中的存在性所说,T
可以是TypeHolder
forSome
unspecifiedElementType
:T <: TypeHolder[_$1] forSome { type _$1 } T#ElementType = (TypeHolder[_])#ElementType = (TypeHolder[_$1] forSome { type _$1 })#ElementType = _$1
因此
T#ElementType
被设置为一些奇怪的合成存在类型_$1
,你得到的错误信息看起来有点像这样:typeHolder.scala:6: error: type mismatch; found : Main.foo.type (with underlying type Foo) required: _$1 client.showElementType(foo) ^
因此,将其设置为存在类型是完全没用的,您将永远无法找到满足此奇怪类型约束的术语。 您甚至无法强制转换为此类型,因为此类型甚至没有可以在代码中的任何位置引用它的名称。
说实话:这看起来像完全垃圾。 这整个预测根本不应该编译,为什么世界上任何人都希望存在量化的类型从量词下逃脱? 这可能应该报告为编译器问题。
3.定义
class Client[T, H <: TypeHolder { type ElementType = T }]
之所以有效,是因为它也能保持
T
型显式。 如果你用存在主义取而代之的话class Client[T, H <: TypeHolder { type ElementType = X forSome { type X }}]
那么
T
和TypeHolder
之间的每个连接都会丢失,并且它会失败的原因与上面的T#ElementType
非常相同:你只是不能用一些未知的存在替换元素类型然后希望能够通过Foo
它。4.在“是否可以定义客户端只使用一个类型参数?” - 当然,为什么不?
import scala.language.higherKinds object Application extends App { private val foo = new Foo private val holder = new FooTypeHolder private val client = new Client(holder) client.showElementType(foo) } class Foo trait TypeHolder { type ElementType } class FooTypeHolder extends TypeHolder { type ElementType = Foo } class Client[H <: TypeHolder](val holder: H) { def showElementType(t: H#ElementType): Unit = { println("show element type " + t.toString) println(t.getClass) } }
只是不要向
TypeHolder
添加任何类型参数,因此您不必在以后通过存在来删除它们。I'm not sure what you tried here, but here is my version of "probably closest projection of the code into compilable Scala":
import scala.language.higherKinds object Application extends App { private val foo = new Foo private val holder = new FooTypeHolder private val client = new Client(holder) client.showElementType(foo) } class Foo trait TypeHolder[T] { type ElementType = T } class FooTypeHolder extends TypeHolder[Foo] class Client[T, H[X] <: TypeHolder[X]](val holder: H[T]) { def showElementType(t: T): Unit = { println("show element type " + t.toString) println(t.getClass) } }
but it might as well be this:
import scala.language.higherKinds object Application extends App { private val foo = new Foo private val holder = new FooTypeHolder private val client = new Client[Foo, FooTypeHolder](holder) client.showElementType(foo) } class Foo trait TypeHolder { type ElementType } class FooTypeHolder extends TypeHolder { type ElementType = Foo } class Client[T, H <: TypeHolder { type ElementType = T }](val holder: H) { def showElementType(t: T): Unit = { println("show element type " + t.toString) println(t.getClass) } }
or maybe this?:
import scala.language.higherKinds object Application extends App { private val foo = new Foo private val holder = new FooTypeHolder private val client = new Client(holder) client.showElementType(foo) } class Foo trait TypeHolder[T] { type ElementType = T } class FooTypeHolder extends TypeHolder[Foo] class Client[H <: TypeHolder[_]](val holder: H) { def showElementType(t: holder.ElementType): Unit = { println("show element type " + t.toString) println(t.getClass) } }
What I fundamentally don't understand about your code is: what is the
TypeHolder[T]
supposed to do, exactly? The wholeTypeHolder[T]
construction doesn't seem to contain any information beyondT
itself, so why not useT
directly, like this?:object Application extends App { private val foo = new Foo private val client = new Client[Foo] client.showElementType(foo) } class Foo class Client[T] { def showElementType(t: T): Unit = { println("show element type " + t.toString) println(t.getClass) } }
Some general hints:
- Avoid asking multiple questions at once
- Avoid asking multiple questions about one of the answers to you previous question in the same posting.
- This probably gonna require some heavy editing...
Edit
I'll just try to answer all additional questions in more or less the same order as you've added them to your posting:
1. It works with
holder.ElementType
, because when you instantiateClient
, theholder
is known to be of typeTypeHolder[Foo]
, therefore we knowholder.ElementType = Foo
.2. It does not work with
T#ElementType
forT <: TypeHolder[_]
, because, as the existential in the signature says,T
can be aTypeHolder
forSome
unspecifiedElementType
:T <: TypeHolder[_$1] forSome { type _$1 } T#ElementType = (TypeHolder[_])#ElementType = (TypeHolder[_$1] forSome { type _$1 })#ElementType = _$1
thus
T#ElementType
is set to some weird synthetic existential type_$1
, and you get the error message that looks somewhat like this:typeHolder.scala:6: error: type mismatch; found : Main.foo.type (with underlying type Foo) required: _$1 client.showElementType(foo) ^
So, setting it to an existential type is completely useless, you will never be able to find a term that satisfies this weird type constraint. You can't even cast into this type by force, because this type doesn't even have a name by which it can be referenced anywhere in code.
To be honest: this seems like complete garbage. This whole projection shouldn't compile at all, why in the world would anyone want an existentially quantified type to escape from under its quantifier? This probably should be reported as a compiler issue.
3. The definition
class Client[T, H <: TypeHolder { type ElementType = T }]
works because it also keeps the type
T
explicit. If you replaced it by an existentialclass Client[T, H <: TypeHolder { type ElementType = X forSome { type X }}]
then again every connection between
T
andTypeHolder
would be lost, and it would fail for very much the same reason asT#ElementType
above: you just can't replace the element type by some unknown existential and then hope to be able to passFoo
to it.4. On "is it possible to define client use only one type parameter?" -- of, course, why not?
import scala.language.higherKinds object Application extends App { private val foo = new Foo private val holder = new FooTypeHolder private val client = new Client(holder) client.showElementType(foo) } class Foo trait TypeHolder { type ElementType } class FooTypeHolder extends TypeHolder { type ElementType = Foo } class Client[H <: TypeHolder](val holder: H) { def showElementType(t: H#ElementType): Unit = { println("show element type " + t.toString) println(t.getClass) } }
Just don't add any type parameters to
TypeHolder
, so you don't have to erase them by existentials later.
相关问答
更多-
可能有一个更优雅的解决方案,但您可以通过将类型的限制移动到方法而不是类型声明来实现此目的: trait Foo { type Bar val lowerBound: Bar val upperBound: Bar def foo(bar: Bar)(implicit ev: Bar => Ordered[Bar]) = { bar >= lowerBound && bar <= upperBound } } 然后你的FooImpl就像你拥有它一样: class FooImpl ...
-
Scala:抽象类型与泛型(Scala: Abstract types vs generics)[2023-07-25]
你在这个问题上有一个很好的观点: Scala类型系统的目的 与Martin Odersky的对话,第三部分 Bill Venners和Frank Sommers(2009年5月18日) 更新(2009年10月):下面的内容实际上已被Bill Venners的这篇新文章所证明: Scala中的抽象类型成员与通用类型参数 (参见末尾的摘要) (这是第一次采访的相关摘录,2009年5月,重点是我的) 一般原则 总有两个抽象概念: 参数化和 抽象会员。 在Java中你也有两个,但这取决于你抽象的内容。 在Java中 ... -
describer.describe的参数类型实际上是describer.X而不是D#X 。 你必须要知道的另一件事是A =:= B也可以作为从A到B的转换,但(至少目前)不是相反的。 所以以下应该工作。 def print[T <: Thing] (describer: Describer, thing: T) (implicit ev: T =:= describer.X) = describer.describe(thing) The type of the parameter of ...
-
所以基本上你想要以下设计: 在编译时, HouseBase的具体类型是已知的。 在编译时, Animal的具体类型是未知的。 为Animal提供特定类型的HouseBase提供的运行时动物数据。 无法更改Animal实现,并且真的不想更改HouseBase实现。 理想的事情当然是在编译时提供具体类型的Animal 。 由于似乎有一些知识(你知道在编译时为动物变量创建哪个HouseBase ),你可以尝试使用shapeless 类型安全转换来获得具体Animal类型的Option 。 但如果不可能,你必须使用 ...
-
填写你的例子中的空白,我做了这个编译: trait Monad[C[_]] { def >>=[A, B](f: A => C[B]): C[B] def >>[B](a: C[B]): C[B] } trait Lifter[C[_]] { class D { def >>=[A, B](f: A => C[B])(implicit m: Monad[C]): C[B] = { m >>= f } def >>[B](a: C[B])(implicit m ...
-
trait CanAdd[T <: CanAdd[T]] { def add(a: T): T } class A(val value:Int) extends CanAdd[A] { def add(that:A) = new A(value+that.value) } class B(val value:Boolean) extends CanAdd[B] { def add(that:B) = new B(value ^ that.value) } class User[X <: ...
-
我不确定你在这里尝试了什么,但这里是我的“可能最接近的代码投影到可编译的Scala”的版本: import scala.language.higherKinds object Application extends App { private val foo = new Foo private val holder = new FooTypeHolder private val client = new Client(holder) client.showElementType(foo) } ...
-
获取抽象类型的名称(Get name of abstract type)[2023-07-19]
在您调用myClassOf[T] T仍然是抽象的,因此编译器无法ClassTag生成ClassTag 。 您可以通过延迟ClassTag[T]的生成来解决它,直到知道ClassTag[T]为止。 trait Trait { type T def myClassOf[A:ClassTag] = implicitly[ClassTag[A]].runtimeClass def getType(implicit tag: ClassTag[T]) = { myClassOf[T].getSim ... -
Implicits是编译时构造,所以原则上它们不能直接依赖用户输入(程序员可以通过例如模式匹配来连接它)。 考虑下面的代码。 它按预期编译和工作: trait H { type A } case object Ha extends H { override type A = Int } case object Hb extends H { override type A = Long } trait Adder[T] { def add(a: T, b: T): T } im ...
-
只需像往常一样在使用站点添加Show[Value]类型的隐式参数: class UsingShow1 { type Value def showValues(values: List[Value])(implicit showValue: Show[Value]): String = values.map(showValue.show).mkString } 但是,您的UsingShow2类的更直接的翻译将如下所示: class UsingShow1 { type Value im ...