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
admin 2023-10-28 WordPress 234
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
admin 2023-10-28 WordPress 197
什么是 WordPress 插件 ?插件( Plugins )是如何与 WordPress 交互的WordPress 为插件提供了多种丰富的 APIs。每一种 API( 应用程序接口 )使插件和 WordPress 以不同的方式交互。下面是 WordPress 提供的主要 APIs 以及他们的功能列表:插件: 给插件提供一系列的钩子( hooks )来使用 WordPress 的相关部分。WordPress 包含两种不同类型的钩子: 动作( Actions )和过滤器( Filters )。动作让你可以在运行时的特定时刻触发自定义的插件代码。例如,可以在用户在 WordPress 中注册了一个
admin 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&
admin 2023-10-28 WordPress 207
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(
admin 2023-10-28 WordPress 162
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
admin 2023-10-28 WordPress 197
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
admin 2023-10-28 WordPress 253
wp_signon()函数用于授权给用户登陆wordpress并可记住该用户名称。该函数取代了wp_login。WordPress 2.5版本起启用。验证成功返回WP_User信息,验证失败则返回WP_Error的信息,该函数用于开发WordPress 登录功能。函数结构wp_signon($credentials, $secure_cookie) 参数说明:$credentials – (数组)(可选),提交的登录信息,如用户名、密码,默认值为空数组array()。$secure_cookie – (字符串或布尔型)(可选),是否使用安全Cookie,默认值为空。如果$credentials
admin 2023-10-28 WordPress 197
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
admin 2023-10-28 WordPress 233
一,根据查询字符串排序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
admin 2023-10-28 WordPress 248
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
admin 2023-10-28 WordPress 211
参考主题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';
admin 2023-10-28 WordPress 308
相关函数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
admin 2023-10-28 WordPress 164
在页面中,常常需要对分类添加各种字段,使用下面方法,可以添加自定义字段。字段类型可以是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
admin 2023-10-28 WordPress 182
为什么要使用favicon图标打开网页时,浏览器中标签中会显示favicon图标收藏网站时,收藏夹会显示favicon图标创建快捷方式时,favicon会作为网站快捷方式的桌面图标WordPress添加favicon图标方法图片制作好了以后,就可以上传到网站作为浏览器图标了,这里我们为大家准备了4种方法,你可以任意挑选一个自己喜欢的使用方法一:使用WordPress自带的自定义模块打开WordPress的主题自定义模块,仪表盘 – 外观 – 自定义选择 站点身份 – 站点图标,上传自己刚刚制作的favicon图标方法二,制作favicon.ico图标使用ico转换工具把设计好的图片直接转换成
admin 2023-10-28 WordPress 196
WordPress 默认情况下,生成多个文章id,导致不连续,且数据库冗余。会造成连续的两篇文章,ID数值可能会相差很多wp-congfig.php添加define( 'AUTOSAVE_INTERVAL', false ); //禁用历史修订版本 define('WP_POST_REVISIONS', false ); //自动保存时间设置超过一天
admin 2023-10-28 WordPress 202
使用 tag__in 可以调用有特定标签的文章。//获取一个标签的文章 根据标签别名获取有这个标签的文章: $query = new WP_Query( 'tag=cooking' ); //根据标签 ID 获取有这个标签的文章: $query = new WP_Query( 'tag_id=13' ); //获取多个标签的文章 根据标签的别名获取带有这几个标签其中一个的文章: $query = new WP_Query( 'tag=bread,baking' ); //根据标签别名获取同时拥有几个标签的文章: $query = new WP_Query( 'tag=bread+baking+
admin 2023-10-28 WordPress 188
主样式表(style.css)style.css是每个WordPress主题所需的样式表(CSS)文件。 它控制网页的演示(视觉设计和布局)。位置为了使WordPress将主题模板文件的集合识别为有效的主题,style.css文件需要位于主题的根目录中,而不是子目录。有关如何将style.css文件包含在主题中的更详细说明,请参阅“启动脚本和样式”的“样式表”部分。基本结构WordPress使用style.css的标题注释部分在“外观(主题)”仪表板面板中显示有关主题的信息。示例这是style.css的头部分的一个例子。/* Theme Name: Twenty Seventeen Theme
admin 2023-10-28 WordPress 222
WordPress 一共有以下12个表,默认表前缀是 “wp_”wp_commentmeta 存储评论的元数据meta_id:自增唯一ID comment_id:对应评论ID meta_key:键名 meta_value:键值 wp_comments 存储评论comment_ID:自增唯一ID comment_post_ID:对应文章ID comment_author:评论者 comment_author_email:评论者邮箱 comment_author_url:评论者网址 comment_author_IP:评论者IP comment_date:评论时间 comment_date_gmt
admin 2023-10-28 WordPress 164
消毒是清理或过滤您的输入数据的过程。 无论数据来自用户还是API或Web服务,当您不知道期望或不想严格的数据验证时,您都可以使用清除信息。消除数据的最简单方法是使用内置的WordPress功能。消毒系统的帮助函数提供了一种有效的方式来确保您最终获得安全的数据,并且您需要尽可能少的努力:sanitize_email() sanitize_file_name() sanitize_html_class() sanitize_key() sanitize_meta() sanitize_mime_type() sanitize_option() sanitize_sql_orderby() sani
admin 2023-10-28 WordPress 189
随机推荐
WP_Query 函数
WordPress RESTful API 的授权方式
WordPress 添加 Favicon 图标的方法
Nginx 使用 Njs 授权访问文件
WordPress 常用函数 / sanitize_user
Flame 插件
二分查找法
WordPress 添加自定义接口