最新文章
相关函数1、rest_api_init 钩子函数,注册接口的相关信息需要挂载到此钩子上。2、register_rest_route 接口路由函数代码:add_action( 'rest_api_init', 'first_route_hook' ); function first_route_hook() { register_rest_route( 'rangtuo/v1', 'test/(?P id [\d]+)', [ 'methods' = 'GET', 'callback' = 'first_action_callback' ] ); } funct
管理员 2023-10-28 WordPress 301
在互联网上 WooCommerce 是世界上最受欢迎的开源电子商务解决方案。WooCommerce 平台是免费的、灵活的平台,并借助全球社区发展壮大。 开源自由意味着您完全永久拥有商店的内容和数据。无论您是要开展业务、进行在线实体零售,还是为客户开发站点,都可以使用 WooCommerce 打造将内容与商务紧密结合的商店。使用适合您品牌和行业的主题创建漂亮、显眼的店面。与托管的电子商务解决方案不同,WooCommerce 可以自由导出所有内容,也可以将站点迁移到所选的任何平台。开发人员可以使用 WooCommerce 创建、定制和扩展商店,以符合客户端的确切规格,并通过扩展程序或自定义解决方案
管理员 2023-10-28 WordPress 186
简介WordPress v4.4以后,已经内置了WP REST API。接口文档:https://developer.wordpress.org/rest-api/The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects. It is the foundation of the WordPress Block
管理员 2023-10-28 WordPress 238
WordPress 自带的 RESTful API 内置的身份验证方法是 Cookie Authentication ,登录仪表板时,会生成cookie。为了防止CSRF,需要在请求的地址后面,加上一个 nonce 参数“_wpnonce”。CSRF请参考:https://javascript.net.cn/article?id=683nonce生成,参考:https://verytheme.com/archives/136如果想使用JWT(JSON Web Token),官方建议使用插件 https://wordpress.org/plugins/jwt-authentication-for
管理员 2023-10-28 WordPress 265
WordPress 可以自由组织代码结构,这篇文章介绍我项目中路由相关的代码结构。一,添加路由add_action( 'rest_api_init', function () { register_rest_route( 'rangtuo/v1', '/author/(?P id \d+)', array( 'methods' = 'GET', 'callback' = 'test_callback', )); }); function test_callback($request){ $request- get_url_param
管理员 2023-10-28 WordPress 312
在开发 WordPress RESTful API 时,用来返回结果集。可以修改 http 请求的状态码。$data = array( 'some', 'response', 'data' ); // Create the response object $response = new WP_REST_Response( $data ); // Add a custom status code $response- set_status( 201 ); // Add a custom header $response- header( 'Location', 'http://exampl
管理员 2023-10-28 WordPress 184
WordPress 5.6 以后内置了RESTful API,并且建议用户一定不要关闭,否则会影响WordPress后台的某些功能。调用某些接口的时候,会提示{ code: "rest_cannot_edit", message: "抱歉,您不能编辑此用户。", data: {status: 401} } Cookie Authentication 是 WordPress 内置的身份验证方法。登录仪表板时,会生成cookie。 但是,REST API包含一种称为nonce的技术来避免CSRF的问题。使用内置Javascript API的开发人员,WordPress 会自动处理 no
管理员 2023-10-28 WordPress 230
WordPress的插件目录在 wp-content/plugins/ 下,一个插件一个目录,安装插件时可以把解压的插件上传到这个目录下或者在wordpress后台安装插件。plugins_url()echo plugins_url(); //输出:https://rangtuo.com/wp-content/plugins echo plugins_url('',__FILE__); //输出:https://rangtuo.com/wp-content/plugins/myplugin echo plugins_url('js/myscript.js',__FILE__); //输出:ht
管理员 2023-10-28 WordPress 191
什么是 WordPress 插件 ?插件( Plugins )是如何与 WordPress 交互的WordPress 为插件提供了多种丰富的 APIs。每一种 API( 应用程序接口 )使插件和 WordPress 以不同的方式交互。下面是 WordPress 提供的主要 APIs 以及他们的功能列表:插件: 给插件提供一系列的钩子( hooks )来使用 WordPress 的相关部分。WordPress 包含两种不同类型的钩子: 动作( Actions )和过滤器( Filters )。动作让你可以在运行时的特定时刻触发自定义的插件代码。例如,可以在用户在 WordPress 中注册了一个
管理员 2023-10-28 WordPress 202
当需要访问一个路径调用相应的模板时,可以使用下面的方法:function rt_rewrite_rules( $wp_rewrite ) { $rt_rules = [ 'orders(.*)$' = 'index.php?rt_custom_page=orders', 'users/([^/]*)/collections/?' = 'index.php?rt_custom_page=collections', 'users/([^/]*)/?' = 'index.php?rt_custom_page=user-center&
管理员 2023-10-28 WordPress 214
WordPress 循环读取文章数据的方法一般使用 query_posts(),但是 query_posts() 这个函数有一些缺点,可能会干扰那些用到的Loop(循环)的插件。可能使一些 WordPress 条件标签失效。这时候最好的选择就是使用 WP_Query 类了。用法:$args = array('post_type'= 'post'); $the_query = new WP_Query( $args ); if ( $the_query- have_posts() ) { echo ' ul '; while ( $the_query- have_posts(
管理员 2023-10-28 WordPress 163
1, bloginfo(‘template_url’)输出:http://localhost/wordpress/wp-content/themes/mytheme2, bloginfo(‘template_directory’)输出:http://localhost/wordpress/wp-content/themes/mytheme3, get_template_directory_uri()输出:http://localhost/wordpress/wp-content/themes/mytheme4, get_stylesheet_directory_uri()输出:http://l
管理员 2023-10-28 WordPress 184
sanitize_user( $username, $strict ) 简介清理用户名,去掉所有不安全的字符。删除 HTML 标签,8进制,HTML实体,如果 $strict 参数设置为 true,将删除所有非 ASCII 字符,只保留数字,字母,_,空格,.,-,@。参数$username (string) (required) 要清理的用户名。Default: None$strict (boolean) (optional) 如果设置为 true,限制 $username 为数字,字母,_,空格,.,-,@。Default: false返回值(string)The sanitized us
管理员 2023-10-28 WordPress 241
wp_signon()函数用于授权给用户登陆wordpress并可记住该用户名称。该函数取代了wp_login。WordPress 2.5版本起启用。验证成功返回WP_User信息,验证失败则返回WP_Error的信息,该函数用于开发WordPress 登录功能。函数结构wp_signon($credentials, $secure_cookie) 参数说明:$credentials – (数组)(可选),提交的登录信息,如用户名、密码,默认值为空数组array()。$secure_cookie – (字符串或布尔型)(可选),是否使用安全Cookie,默认值为空。如果$credentials
管理员 2023-10-28 WordPress 190
WordPress 默认调用头像的函数是 get_avatar(),在开发中可以使用这个函数完成自定义头像。add_filter( 'get_avatar' , 'my_custom_avatar' , 1 , 5 ); function my_custom_avatar( $avatar, $id_or_email, $size, $default, $alt) { if ( ! empty( $id_or_email- user_id ) ) { $avatar = get_bloginfo('template_directory') . '/assets/imag
管理员 2023-10-28 WordPress 218
一,根据查询字符串排序WordPress默认排序是按照文章发布时间的,有时候我们需要按照其他方式来排序,或者提供其他方式排序的功能。如果只是基本的排序,比如按照修改时间,或者按照评论数之类的,不需要做任何改动,直接在url加上orderby参数就可以的。比如就是http://test.com/?orderby=comment_count //按评论数量排序http://test.com/?orderby=modified //按修改时间http://test.com/?orderby=rand //随机排序http://test.com/?orderby=ID //ID大小按照浏览量 http
管理员 2023-10-28 WordPress 234
WordPress文章编辑页,设置文章置顶,还需要修改文章调用函数。 ?php $sticky = get_option('sticky_posts'); rsort( $sticky ); // 文章数组逆向排序 $sticky = array_slice( $sticky, 0, 3); // 限制只有3个置顶文章 $args = array( "cat"= $product_id, "posts_per_page" = 8, 'post__in' = $sticky ); query_posts($args); while(have_posts()): the
管理员 2023-10-28 WordPress 199
参考主题WordPress自带主题, twentytwentyone,在文章模版下面,有个函数 : ?php comments_template(); ? 这个函数会引用主题下的 comments.php,在该文件的底部有个函数 comment_form 函数,就是用来生成表单的。//Declare Vars $comment_send = 'Send'; $comment_reply = 'Leave a Message'; $comment_reply_to = 'Reply'; $comment_author = 'Name'; $comment_email = 'E-Mail';
管理员 2023-10-28 WordPress 197
相关函数1、rest_api_init 钩子函数,注册接口的相关信息需要挂载到此钩子上。2、register_rest_route 接口路由函数代码:add_action( 'rest_api_init', 'first_route_hook' ); function first_route_hook() { register_rest_route( 'rangtuo/v1', 'test/(?P id [\d]+)', [ 'methods' = 'GET', 'callback' = 'first_action_callback' ] ); } funct
管理员 2023-10-28 WordPress 176
在页面中,常常需要对分类添加各种字段,使用下面方法,可以添加自定义字段。字段类型可以是text或者radio各种类型。 // 分类添加字段 function ems_add_category_field(){ echo ' div class="form-field" label for="cat-keywords" 关键词 /label input name="cat-keywords" id="cat-keywords" type="text" value="" size="40" p 输入关键词 /p /div '; } add_action('cate
管理员 2023-10-28 WordPress 182
随机推荐
如何使用命令修改 MySQL 数据库名称
MySQL 删除逗号分隔字段中的某一个值
JavaScript console 的用法
JavaScript Date 类型
WordPress 文章置顶循环
WordPress 上传附件
JavaScript 函数
WordPress 插件开发