标签: wordpress-plugin

使用未清理的名称值按名称获取术语

我想要做的是以编程方式设置woocommerce产品类别.

我有什么是术语名称test & sample和帖子的ID 9,所以设置的产品类别我已经使用get_term_bywp_set_object_terms

$name  = 'test & sample';
$posid = 9;
//get the term based on name
$term = get_term_by('name', $name, 'product_cat');
//set woocommerce product category
wp_set_object_terms($posid, $term->term_id, 'product_cat');
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我的问题是未经过计算的价值$name.什么是迄今为止我所做的是取代&&哪些工作.

$name = str_replace('&', '&', 'test & sample');
$posid = 9;
//get the term based on name
$term = get_term_by('name', $name, 'product_cat');
//if term does exist,then use set object terms
if(false != $term){
  //set woocommerce product category …
Run Code Online (Sandbox Code Playgroud)

wordpress themes wordpress-plugin

5
推荐指数
1
解决办法
1060
查看次数

减少PHP插件恶意的可能性

我想知道你用什么步骤来保护下载的插件不被恶意?

例如,wordpress如何确保您下载的插件不会简单地执行 unlink('/')

我假设它部分取决于下载器安装插件以使用他或她自己的判断,但插件系统是否采取措施来最小化运行第三方插件的安全风险?

谢谢!马特穆勒

php security wordpress plugins wordpress-plugin

4
推荐指数
1
解决办法
181
查看次数

具有自定义功能的Wordpress自定义角色无法访问仪表板

我正在编写一个插件,它创建一个新的post_type和一个相应的角色,只能添加/编辑/等新的post_type.一切都按预期工作,但分配了我的自定义角色的用户无法查看仪表板.用户登录后,会立即收到以下错误:

"您没有足够的权限来访问此页面."

但是,登录成功,当用户浏览网站时,"编辑"链接会显示在自定义帖子上.该用户甚至可以编辑/通过工具栏添加新的自定义职位,但只要他/她点击"仪表盘"或其他任何环节没有直接联系到自定义post_type他们得到上面的错误消息.

我认为这意味着我的自定义功能正在运行......但太好了(因为太严格了).我还想允许基本的"订阅者"权限以及我为自定义post_type定义的功能.我已阅读并重新阅读能力与角色的抄本,看来,我应该能够做什么,我希望通过添加'read' => true到我的能力阵列,但它似乎并不奏效.这是我的代码:

add_action('init', 'setup_dictionary_post');

//Register custom post type 
function setup_dictionary_post() {

$capabilities = array(
    'publish_posts' => 'publish_dictionary_entry',
    'edit_posts' => 'edit_dictionary_entry',
    'edit_others_posts' => 'edit_others_dictionary_entry',
    'delete_posts' => 'delete_dictionary_entry',
    'delete_others_posts' => 'delete_others_dictionary_entry',
    'read_private_posts' => 'read_private_dictionary_entry',
    'edit_post' => 'edit_dictionary_entry',
    'delete_post' => 'delete_dictionary_entry',
    'read_post' => 'read_dictionary_entry'
);

$labels = array(
    'name' => 'Dictionary Entries',
      'singular_name' => 'Dictionary Entry',
      'menu_name' => 'Dictionary Entries',
      'add_new' => 'Add New',
      'add_new_item' => 'Add New Dictionary Entry',
      'edit' => 'Edit entry',
      'edit_item' => 'Edit …
Run Code Online (Sandbox Code Playgroud)

wordpress wordpress-plugin

4
推荐指数
1
解决办法
4319
查看次数

如何在WordPress中自动在页面中显示页面的特色图像?

我需要你的帮助以下内容.

我为我的页面设置的功能图像不会显示在页面本身中.是否有任何插件或我可以做的事情,以便让我为帖子和页面设置的特色图像显示在相应的条目中?

任何建议都非常感谢!

wordpress image wordpress-theming wordpress-plugin

4
推荐指数
1
解决办法
2万
查看次数

如何在WordPress插件中使用多媒体上传器?

我尝试在wordpress插件中添加多个上传选项,我在插件中重复了这段代码(两次),只更改了id名称.

                    <script language="JavaScript">
jQuery(document).ready(function($) {
    jQuery('#upload_image_button').click(function() {
        formfield = jQuery('#upload_image').attr('name');
        tb_show('', 'media-upload.php?type=image&TB_iframe=true');
        return false;
    });

    window.send_to_editor = function(html) {
        imgurl = jQuery('img', html).attr('src');
        jQuery('#upload_image').val(imgurl);
        tb_remove();
    };

});
                    </script>
<input id="upload_image" style=" margin-left:303px;" type="text" size="36" name="upload_image_template" value="<?php echo get_option('upload_image_template'); ?>" />
                        <input id="upload_image_button" type="button" value="Browse" />
Run Code Online (Sandbox Code Playgroud)

每当我尝试上传媒体帧的图像并且上传过程成功完成时.但Insert Into Post获取正确的URL但粘贴在不同的输入框中.例如:

1) [text box1] [browse Button]
2) [text box2] [browse button]
Run Code Online (Sandbox Code Playgroud)

当我使用文本框一上传图像时,[insert post]该图像路径显示在[text box 2] 我不确定问题是我的还是该脚本不支持多文件上传选项.

javascript php wordpress wordpress-plugin

4
推荐指数
1
解决办法
1万
查看次数

如何在插件中使用is_page()?

我希望我的插件只在某个页面中注册一个脚本.

例如,在我的插件文件中,我想写这样的东西:

if (is_page()) {
    $pageid_current = get_the_ID();
    $page_slug = get_post($pageid_current)->post_name;

    if ($page_slug == 'articles'){
        wp_register_script('myscript', '/someurl/main.js');
    }
}
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

is_page被错误地调用.在运行查询之前,条件查询标记不起作用.在此之前,他们总是返回虚假.有关更多信息,请参阅WordPress中的调试.(此消息是在3.1版中添加的.)

如何在插件内部在某个页面中注册脚本?

wordpress wordpress-plugin

4
推荐指数
1
解决办法
3841
查看次数

如何降低Amazon Cloudfront成本?

我有一个网站在过去几天流量爆炸.我正在使用带有W3 Total Cache插件的Wordpress和Amazon Cloudfront来提供网站上的图像和文件.

问题是Cloudfront的成本非常巨大,过去一周接近500美元.有没有办法降低成本?也许使用其他CDN服务?

我是CDN的新手,所以我可能没有很好地实现这一点.我创建了一个cloudfront发行版,并在W3 Total Cache Plugin上配置了它.但是,我没有使用S3而且不知道我应该或如何.说实话,我不太确定Cloudfront和S3之间的区别.

谁能在这里给我一些提示?

wordpress amazon-s3 wordpress-plugin amazon-web-services

4
推荐指数
2
解决办法
7877
查看次数

wordpress:使用polylang插件的媒体库问题

我正在开发一个使用Wordpress的网站,我正在使用Polylang插件为多种不同的语言制作内容.

我正在使用Polylang两种语言:荷兰语(主要)和英语(次要).当我用荷兰语页面上传图像时,一切都很好.但是当我创建英文页面并想要添加已经上传的图像时,图像库是空的.有人知道如何让他们出现在那里?

谢谢!

php wordpress wordpress-theming wordpress-plugin

4
推荐指数
1
解决办法
5117
查看次数

具有自定义分类的WP-API自定义帖子类型

我正在与https://github.com/WP-API/WP-API作斗争我正在尝试使用名为listing_categy的自定义分类法添加自定义帖子类型:查询此终结点:

http://example.com/subfolder/wp-json/taxonomies/listing_categy/terms

给我这个:

[
  {
    "ID": 9,
    "name": "buying",
    "slug": "buying-2",
    "description": "",
    "parent": null,
    "count": 1,
    "link": "http:\/\/example.com\/subfolder\/listing_categy\/buying-2\/",
    "meta": {
      "links": {
        "collection": "http:\/\/example.com\/subfolder\/wp-json\/taxonomies\/listing_categy\/terms",
        "self": "http:\/\/example.com\/subfolder\/wp-json\/taxonomies\/listing_categy\/terms\/7"
      }
    }
  },
  {
    "ID": 10,
    "name": "selling",
    "slug": "selling-2",
    "description": "",
    "parent": null,
    "count": 0,
    "link": "http:\/\/example.com\/subfolder\/listing_categy\/selling-2\/",
    "meta": {
      "links": {
        "collection": "http:\/\/example.com\/subfolder\/wp-json\/taxonomies\/listing_categy\/terms",
        "self": "http:\/\/example.com\/subfolder\/wp-json\/taxonomies\/listing_categy\/terms\/8"
      }
    }
  }
]
Run Code Online (Sandbox Code Playgroud)

处理发布的php文件是https://github.com/WP-API/WP-API/blob/master/lib/class-wp-json-posts.php:

  /**
   * Create a new post for any registered post type.
   *
   * @since 3.4.0
   * @internal 'data' …
Run Code Online (Sandbox Code Playgroud)

rest wordpress json wordpress-plugin

4
推荐指数
2
解决办法
6653
查看次数

Yoast SEO | 如何创建自定义变量

只是不知道是否有创建的方式自定义变量,这样我可以添加在页面的元标题创建我的自定义变量.

Yoast SEO有预定义变量的列表在这里.

如果我可以创建自己的变量,那将是很棒的.有没有办法得到这个?

提前致谢!

php wordpress wordpress-plugin

4
推荐指数
2
解决办法
3525
查看次数