devgeniem/dustpress-comments
Composer 安装命令:
composer require devgeniem/dustpress-comments
包简介
A WordPress plugin that enables commenting for DustPress based themes.
README 文档
README
Comments Helper
DustPress helpers are a handy tool for creating templates with a bit more logic. Comments Helper is a DustPress plugin for enabling commenting in DustPress based themes.
Use Comments Helper with your desired parameters and DustPress will provide an AJAX powered commenting for your posts and pages. This plugin provides base templates for a quick start. Just install and enable the plugin. You can override the templates with your own templates by adding them with the corresponding names in /partials directory inside your theme, for example starting with the container in: wp-content/themes/best-theme-ever/partials/commentscontainer.dust.
To enable full page caching on pages using DustPress Comments the helper parameters must be passed via filter or model functions. You have to provide two functions: one for fetching the comments parameters and another for comment form parameters. The filter slug or the model name will be written into the comments section dataset and into a hidden input field in the comment form. Each AJAX request will include the slug or the model name for the DustPress Comments to be able to retrieve the correct helper parameters. There are examples of both cases at the end of this document.
Functionalities
- threaded comment loading (threaded commenting is enabled via the WordPress discussion settings)
- comment list rendering
- form rendering
- ajaxified pagination (pagination is enabled via the WordPress discussion settings and uses the DustPress Pagination helper)
- ajaxified comment submission
- ajaxified and JS powered replying
- status message displaying and hiding with JS and CSS
- external JS invocation
- support for multiple commenting sections on one page!
- support for full page caching!
Included base templates
- comments-container.dust (the comments section)
- comments.dust (comment list, pagination, form)
- comment.dust (single comment)
Accepted parameters
We will document a full list of parameters in the near future! If you have questions of the helper usage, please contact us at info@geniem.com or create a new issue.
Example usage
We provide two options for using the helper and passing parameters for its use.
Model functions for helper parameters
Both functions will get the current post id as a parameter.
class CommentsModel extends \DustPress\Model {
public function get_comments_args( $post_id ) {
// This disables replying to comments.
$args['reply'] = false;
return $args;
}
public function get_form_args( $post_id ) {
$args['title_reply'] = __('Comment', 'POF');
$args['label_submit'] = __('Submit', 'POF');
$args['class_submit'] = 'button radius';
$args['remove_input'] = array( 'url' );
$args['input_class'] = 'radius';
return $args;
}
}
Then in your dust partial pass this model for your helper as a string.
{@comments model="CommentsModel" /}
Filter functions for helper parameters
The other way to pass parameters for the helper is to create two filter functions. The filter slug to be passed for the helper is the third part of the filter string devided with /. Each function must extend the passed $args array and then return it.
add_filter( 'dustpress/comments/my_comments/get_comments_args', 'my_comments_get_comments_args', 1, 2 );
function my_comments_get_comments_args( $args, $post_id ) {
$args['reply'] = false;
return $args;
}
add_filter( 'dustpress/comments/my_comments/get_form_args', 'my_comments_get_form_args', 1, 2 );
function my_comments_get_form_args( $args, $post_id ) {
$args['remove_input'] = array( 'url' );
return $args;
}
Then in your dust partial pass the filter slug for your helper as a string.
{@comments filter_slug="my_comments" /}
Extended functionality
DustPress Comments extends WordPress comment form functionalities with some additional features. Use the following associative keys in your comment form params with the corresponding value types:
- replace_input: array( '{field_name}' => {some_html} )_
- replace a comment form input field by assigning an array key to match the name field of the input
- remove_input: array( '{field_name}' )_
- remove comment form input by assigning array key to match the input name field
External JavaScript function invocation
If you need to hook your own scripts into DustPress Comments, we provide a handy way of adding external listeners for JavaScript actions. This is done via accessing the global Comments object under the window object which holds our global DustPress object.
var myFunction = function(state, container) {
if ('success' === state) {
alert('Your comment was posted!');
}
};
window.DustPress.Comments.addListener(myFunction);
Each time DustPress Comments is performing an action it will fire your listener function with two parameters. state refers to the state commenting is in and container is the current commenting section as a jQuery object. The section also works a wrapper object for you to fetch all the data that is linked into the commenting at the current state.
Go and build a loader or some other neat functionality!
States
- submit
- reply
- cancelReply
- paginate
- success
- error
devgeniem/dustpress-comments 适用场景与选型建议
devgeniem/dustpress-comments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.53k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 06 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「javascript」 「plugin」 「theme」 「wordpress」 「ajax」 「comments」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 devgeniem/dustpress-comments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 devgeniem/dustpress-comments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 devgeniem/dustpress-comments 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
PHP client for the Google Closure Compiler API in one file.
A Bootstrap 4.x base theme for SilverStripe
统计信息
- 总下载量: 4.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2016-06-08
