我想限制贡献者和作者用户只能查看和管理自己帖子的评论。
我尝试过以下过滤器但没有成功。
//Manage Your Own Comments Only
function myplugin_comments_thisuseronly( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit-comments.php' ) !== false ) {
if ( !current_user_can( 'edit_others_posts' ) ) {
global $current_user;global $wpdb;
$usersposts = $wpdb->get_results( $wpdb->prepare("SELECT ID FROM wp_posts WHERE post_author = %s", $current_user->id) );
$wp_query->set('comment_post_ID', array($usersposts));
}
}
}
Run Code Online (Sandbox Code Playgroud)
add_filter('parse_query', 'myplugin_comments_thisuseronly');
我也尝试过
$wp_query->set('comment_post_ID__in', array($usersposts));
Run Code Online (Sandbox Code Playgroud) 我用它来为我的自定义主题获取 wordpress 评论:
get_comments( array('status' => 'aprove','order' => 'ASC', 'post_id' => $newpost->ID) );
Run Code Online (Sandbox Code Playgroud)
除了等待审核的评论未被过滤这一事实之外,一切正常。遵循法典:http : //codex.wordpress.org/Function_Reference/get_comment'status' => 'approve'应该过滤掉那些,但这似乎没有发生。
我没有正确使用它吗?
假设您有以下脚本:
# My comment line 1
# My comment line 2
# My comment line 3
echo "My script"
cd $MY_PATH
./anotherScript.ksh
Run Code Online (Sandbox Code Playgroud)
是否有任何命令可以显示:
# My comment line 1
# My comment line 2
# My comment line 3
Run Code Online (Sandbox Code Playgroud)
或者,我可以编写一个脚本来检测第一块注释。
谢谢
我经常看到开源或“专业”python 代码中的注释——比如 webapp2 或 webob,看起来很间隔。评论似乎超过了代码。我注意到个别开发人员也在他们自己的应用程序中这样做。大间距,大量注释,然后是每隔一段时间写几行代码。
我想我喜欢这种风格,它确实感觉更有条理。现在我是用 python 做的更大的项目,我想知道我是否应该像我看到其他人所做的那样,用代码和注释来组织一个大项目。我认为这可能会使它更具可读性和可维护性,并且可能使我成为一个更好的编码员——因为事情会更清楚。
只是想:这个问题在代码审查上更好吗?听就是服从
目前我只是这样评论,例如:
#U - Idempotent. b-atching requests
# which can be PUT, DELETE or GET.
#@control.access.collector_or_owner
def patch(s,*a,**k):
s.resolve(*a,**k)
for mod in s.requested_modifications:
method = mod.get('method') or 'PUT'
point = s.current_point+mod.get('point') or ''
body = mod.get('body') or ''
s.say('Will execute %s on %s for %s\n' % (method,point,body))
# create the in-app request
mod_request = webapp2.Request.blank(point)
mod_request.body = str(body)
mod_request.method = method
mod_request.app = s.app
# then find the handler and report …Run Code Online (Sandbox Code Playgroud) 我正在阅读Google C++ Style Guide以尝试模仿良好的编码实践。当我通读关于如何评论我的代码的部分时,它要求我用license boilerplate开始每个文件。我所能找到的关于这个术语的所有信息都来自Mozilla以及我认为是他们的评论标准。许可证样板注释究竟是什么,它需要采用什么格式?
注意:明确地说,我并不是说 Google C++ 风格指南是遵循良好编码实践的完美指南。我只是用它来获得关于如何改进我的编码风格的新想法。
我习惯于以特定的方式记录C#项目中的代码,以提高团队生产力,从Visual Studio中的Intellisense等中受益.
代码看起来类似于:
/// <summary>
/// Loads a user with a specific id.
/// </summary>
/// <param name="id">The id of the user to search for.</param>
/// <returns>A user with the given id.</returns>
public User GetUserById(string id) {
...
}
Run Code Online (Sandbox Code Playgroud)
用于评论和文档的Typescript是否有类似的约定?甚至是使用这些约定从代码注释(如JavaDoc)生成html文档页面的工具?
显然,这:
def f():
pass
# maybe the function is over
pass # oh wait, it's not
f()
Run Code Online (Sandbox Code Playgroud)
是有效的语法,而这不是:
def f():
pass
''' maybe the function is over '''
pass # oh wait, it's not
f()
Run Code Online (Sandbox Code Playgroud)
这对我来说是一个巨大的惊喜。所以我的问题是:
我正在尝试打印出以下内容:
cout << *pointer1/*pointer2 << endl;
Run Code Online (Sandbox Code Playgroud)
然而,因为/*打开了一个注释块,所有过去的/*都被视为注释。到目前为止,我提出的解决方案是:
int tempPointer = *pointer;
cout << *pointer1/tempPointer << endl;
Run Code Online (Sandbox Code Playgroud)
这有效,但不是很优雅。
有没有办法防止/*在这种情况下创建评论块?
在 bash GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)或任何稳定版本中,您可以使用#或:进行评论
这两个和有用性有什么区别?
我注意到#注释使整行成为注释,而:作用域/效果仅在它到达第一个\n或;字符(在给定行中)之前。
[gigauser@someserver ~]$ # this is a # comment; echo this will not print
[gigauser@someserver ~]$ : this is a : comment; echo this will print
this will print
Run Code Online (Sandbox Code Playgroud)
在下面的代码中,为什么最后 2 条评论没有按预期工作,然后将它们视为评论(尽管::如果它出现在: ?
[gigauser@someserver ~]$ #
[gigauser@someserver ~]$ ##
[gigauser@someserver ~]$ ####
[gigauser@someserver ~]$ ####
[gigauser@someserver ~]$ : : : : : : : : : …Run Code Online (Sandbox Code Playgroud) comments ×10
c++ ×2
command ×2
linux ×2
php ×2
python ×2
wordpress ×2
admin ×1
arrays ×1
bash ×1
boilerplate ×1
c# ×1
coding-style ×1
conventions ×1
filter ×1
indentation ×1
java ×1
shell ×1
typescript ×1
unix ×1
whitespace ×1