首页 \ 问答 \ 如何更改wordpress颜色选择按钮文本?(how to change the wordpress color picker button text?)

如何更改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
更新时间:2021-10-04 13:10

最满意答案

我不确定你在这里尝试了什么,但这里是我的“可能最接近的代码投影到可编译的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 ,已知holderTypeHolder[Foo]类型,因此我们知道holder.ElementType = Foo

2.它不适用于T <: TypeHolder[_] T#ElementType ,因为正如签名中的存在性所说, T可以是TypeHolder forSome unspecified ElementType

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 }}]

那么TTypeHolder之间的每个连接都会丢失,并且它会失败的原因与上面的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 whole TypeHolder[T] construction doesn't seem to contain any information beyond T itself, so why not use T 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 instantiate Client, the holder is known to be of type TypeHolder[Foo], therefore we know holder.ElementType = Foo.

2. It does not work with T#ElementType for T <: TypeHolder[_], because, as the existential in the signature says, T can be a TypeHolder forSome unspecified ElementType:

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 existential

class Client[T, H <: TypeHolder { type ElementType = X forSome { type X }}]

then again every connection between T and TypeHolder would be lost, and it would fail for very much the same reason as T#ElementType above: you just can't replace the element type by some unknown existential and then hope to be able to pass Foo 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.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)