本文整理汇总了PHP中wp_allow_comment函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_allow_comment函数的具体用法?PHP wp_allow_comment怎么用?PHP wp_allow_comment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_allow_comment函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wp_new_comment
function wp_new_comment($commentdata)
{
$commentdata = apply_filters('preprocess_comment', $commentdata);
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
$commentdata['user_ID'] = (int) $commentdata['user_ID'];
$commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
$commentdata['comment_agent'] = $_SERVER['HTTP_USER_AGENT'];
$commentdata['comment_date'] = current_time('mysql');
$commentdata['comment_date_gmt'] = current_time('mysql', 1);
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
$comment_ID = wp_insert_comment($commentdata);
do_action('comment_post', $comment_ID, $commentdata['comment_approved']);
if ('spam' !== $commentdata['comment_approved']) {
// If it's spam save it silently for later crunching
if ('0' == $commentdata['comment_approved']) {
wp_notify_moderator($comment_ID);
}
$post =& get_post($commentdata['comment_post_ID']);
// Don't notify if it's your own comment
if (get_settings('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID']) {
wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
}
}
return $comment_ID;
}
示例2: wp_new_comment
/**
* Adds a new comment to the database.
*
* Filters new comment to ensure that the fields are sanitized and valid before
* inserting comment into database. Calls 'comment_post' action with comment ID
* and whether comment is approved by WordPress. Also has 'preprocess_comment'
* filter for processing the comment data before the function handles it.
*
* We use REMOTE_ADDR here directly. If you are behind a proxy, you should ensure
* that it is properly set, such as in wp-config.php, for your environment.
* See {@link https://core.trac.wordpress.org/ticket/9235}
*
* @since 1.5.0
* @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`.
*
* @see wp_insert_comment()
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param array $commentdata {
* Comment data.
*
* @type string $comment_author The name of the comment author.
* @type string $comment_author_email The comment author email address.
* @type string $comment_author_url The comment author URL.
* @type string $comment_content The content of the comment.
* @type string $comment_date The date the comment was submitted. Default is the current time.
* @type string $comment_date_gmt The date the comment was submitted in the GMT timezone.
* Default is `$comment_date` in the GMT timezone.
* @type int $comment_parent The ID of this comment's parent, if any. Default 0.
* @type int $comment_post_ID The ID of the post that relates to the comment.
* @type int $user_id The ID of the user who submitted the comment. Default 0.
* @type int $user_ID Kept for backward-compatibility. Use `$user_id` instead.
* @type string $comment_agent Comment author user agent. Default is the value of 'HTTP_USER_AGENT'
* in the `$_SERVER` superglobal sent in the original request.
* @type string $comment_author_IP Comment author IP address in IPv4 format. Default is the value of
* 'REMOTE_ADDR' in the `$_SERVER` superglobal sent in the original request.
* }
* @return int|false The ID of the comment on success, false on failure.
*/
function wp_new_comment($commentdata)
{
global $wpdb;
if (isset($commentdata['user_ID'])) {
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
}
$prefiltered_user_id = isset($commentdata['user_id']) ? (int) $commentdata['user_id'] : 0;
/**
* Filter a comment's data before it is sanitized and inserted into the database.
*
* @since 1.5.0
*
* @param array $commentdata Comment data.
*/
$commentdata = apply_filters('preprocess_comment', $commentdata);
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
if (isset($commentdata['user_ID']) && $prefiltered_user_id !== (int) $commentdata['user_ID']) {
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
} elseif (isset($commentdata['user_id'])) {
$commentdata['user_id'] = (int) $commentdata['user_id'];
}
$commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
$parent_status = 0 < $commentdata['comment_parent'] ? wp_get_comment_status($commentdata['comment_parent']) : '';
$commentdata['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $commentdata['comment_parent'] : 0;
if (!isset($commentdata['comment_author_IP'])) {
$commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
}
$commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP']);
if (!isset($commentdata['comment_agent'])) {
$commentdata['comment_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
}
$commentdata['comment_agent'] = substr($commentdata['comment_agent'], 0, 254);
if (empty($commentdata['comment_date'])) {
$commentdata['comment_date'] = current_time('mysql');
}
if (empty($commentdata['comment_date_gmt'])) {
$commentdata['comment_date_gmt'] = current_time('mysql', 1);
}
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
$comment_ID = wp_insert_comment($commentdata);
if (!$comment_ID) {
$fields = array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_content');
foreach ($fields as $field) {
if (isset($commentdata[$field])) {
$commentdata[$field] = $wpdb->strip_invalid_text_for_column($wpdb->comments, $field, $commentdata[$field]);
}
}
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
$comment_ID = wp_insert_comment($commentdata);
if (!$comment_ID) {
return false;
}
}
/**
* Fires immediately after a comment is inserted into the database.
*
* @since 1.2.0
*
* @param int $comment_ID The comment ID.
//.........这里部分代码省略.........
示例3: wp_new_comment
/**
* Adds a new comment to the database.
*
* Filters new comment to ensure that the fields are sanitized and valid before
* inserting comment into database. Calls 'comment_post' action with comment ID
* and whether comment is approved by WordPress. Also has 'preprocess_comment'
* filter for processing the comment data before the function handles it.
*
* We use REMOTE_ADDR here directly. If you are behind a proxy, you should ensure
* that it is properly set, such as in wp-config.php, for your environment.
* See {@link https://core.trac.wordpress.org/ticket/9235}
*
* @since 1.5.0
* @since 4.3.0 'comment_agent' and 'comment_author_IP' can be set via `$commentdata`.
*
* @see wp_insert_comment()
*
* @global wpdb $wpdb
*
* @param array $commentdata {
* Comment data.
*
* @type string $comment_author The name of the comment author.
* @type string $comment_author_email The comment author email address.
* @type string $comment_author_url The comment author URL.
* @type string $comment_content The content of the comment.
* @type string $comment_date The date the comment was submitted. Default is the current time.
* @type string $comment_date_gmt The date the comment was submitted in the GMT timezone.
* Default is `$comment_date` in the GMT timezone.
* @type int $comment_parent The ID of this comment's parent, if any. Default 0.
* @type int $comment_post_ID The ID of the post that relates to the comment.
* @type int $user_id The ID of the user who submitted the comment. Default 0.
* @type int $user_ID Kept for backward-compatibility. Use `$user_id` instead.
* @type string $comment_agent Comment author user agent. Default is the value of 'HTTP_USER_AGENT'
* in the `$_SERVER` superglobal sent in the original request.
* @type string $comment_author_IP Comment author IP address in IPv4 format. Default is the value of
* 'REMOTE_ADDR' in the `$_SERVER` superglobal sent in the original request.
* }
* @return int|false The ID of the comment on success, false on failure.
*/
function wp_new_comment($commentdata)
{
global $wpdb;
if (isset($commentdata['user_ID'])) {
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
}
$prefiltered_user_id = isset($commentdata['user_id']) ? (int) $commentdata['user_id'] : 0;
/**
* Filter a comment's data before it is sanitized and inserted into the database.
*
* @since 1.5.0
*
* @param array $commentdata Comment data.
*/
$commentdata = apply_filters('preprocess_comment', $commentdata);
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
if (isset($commentdata['user_ID']) && $prefiltered_user_id !== (int) $commentdata['user_ID']) {
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
} elseif (isset($commentdata['user_id'])) {
$commentdata['user_id'] = (int) $commentdata['user_id'];
}
$commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
$parent_status = 0 < $commentdata['comment_parent'] ? wp_get_comment_status($commentdata['comment_parent']) : '';
$commentdata['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $commentdata['comment_parent'] : 0;
if (!isset($commentdata['comment_author_IP'])) {
$commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
}
$commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $commentdata['comment_author_IP']);
if (!isset($commentdata['comment_agent'])) {
$commentdata['comment_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
}
$commentdata['comment_agent'] = substr($commentdata['comment_agent'], 0, 254);
if (empty($commentdata['comment_date'])) {
$commentdata['comment_date'] = current_time('mysql');
}
if (empty($commentdata['comment_date_gmt'])) {
$commentdata['comment_date_gmt'] = current_time('mysql', 1);
}
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
$comment_ID = wp_insert_comment($commentdata);
if (!$comment_ID) {
$fields = array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_content');
foreach ($fields as $field) {
if (isset($commentdata[$field])) {
$commentdata[$field] = $wpdb->strip_invalid_text_for_column($wpdb->comments, $field, $commentdata[$field]);
}
}
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
$comment_ID = wp_insert_comment($commentdata);
if (!$comment_ID) {
return false;
}
}
/**
* Fires immediately after a comment is inserted into the database.
*
* @since 1.2.0
*
//.........这里部分代码省略.........
示例4: create_item
/**
* Create a comment.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function create_item($request)
{
if (!empty($request['id'])) {
return new WP_Error('rest_comment_exists', __('Cannot create existing comment.'), array('status' => 400));
}
$post = get_post($request['post']);
if (empty($post)) {
return new WP_Error('rest_post_invalid_id', __('Invalid post id.'), array('status' => 404));
}
$prepared_comment = $this->prepare_item_for_database($request);
// Setting remaining values before wp_insert_comment so we can
// use wp_allow_comment().
if (!isset($prepared_comment['comment_date_gmt'])) {
$prepared_comment['comment_date_gmt'] = current_time('mysql', true);
}
// Set author data if the user's logged in
$missing_author = empty($prepared_comment['user_id']) && empty($prepared_comment['comment_author']) && empty($prepared_comment['comment_author_email']) && empty($prepared_comment['comment_author_url']);
if (is_user_logged_in() && $missing_author) {
$user = wp_get_current_user();
$prepared_comment['user_id'] = $user->ID;
$prepared_comment['comment_author'] = $user->display_name;
$prepared_comment['comment_author_email'] = $user->user_email;
$prepared_comment['comment_author_url'] = $user->user_url;
}
if (!isset($prepared_comment['comment_author_email'])) {
$prepared_comment['comment_author_email'] = '';
}
if (!isset($prepared_comment['comment_author_url'])) {
$prepared_comment['comment_author_url'] = '';
}
$prepared_comment['comment_author_IP'] = '127.0.0.1';
$prepared_comment['comment_agent'] = '';
$prepared_comment['comment_approved'] = wp_allow_comment($prepared_comment);
/**
* Filter a comment before it is inserted via the REST API.
*
* Allows modification of the comment right before it is inserted via `wp_insert_comment`.
*
* @param array $prepared_comment The prepared comment data for `wp_insert_comment`.
* @param WP_REST_Request $request Request used to insert the comment.
*/
$prepared_comment = apply_filters('rest_pre_insert_comment', $prepared_comment, $request);
$comment_id = wp_insert_comment($prepared_comment);
if (!$comment_id) {
return new WP_Error('rest_comment_failed_create', __('Creating comment failed.'), array('status' => 500));
}
if (isset($request['status'])) {
$comment = get_comment($comment_id);
$this->handle_status_param($request['status'], $comment);
}
$this->update_additional_fields_for_object(get_comment($comment_id), $request);
$context = current_user_can('moderate_comments') ? 'edit' : 'view';
$response = $this->get_item(array('id' => $comment_id, 'context' => $context));
$response = rest_ensure_response($response);
if (is_wp_error($response)) {
return $response;
}
$response->set_status(201);
$response->header('Location', rest_url('/wp/v2/comments/' . $comment_id));
/**
* Fires after a comment is created or updated via the REST API.
*
* @param array $prepared_comment Inserted comment data.
* @param WP_REST_Request $request The request sent to the API.
* @param bool $creating True when creating a comment, false when updating.
*/
do_action('rest_insert_comment', $prepared_comment, $request, true);
return $response;
}
示例5: wp_new_comment
/**
* Adds a new comment to the database.
*
* Filters new comment to ensure that the fields are sanitized and valid before
* inserting comment into database. Calls 'comment_post' action with comment ID
* and whether comment is approved by WordPress. Also has 'preprocess_comment'
* filter for processing the comment data before the function handles it.
*
* We use REMOTE_ADDR here directly. If you are behind a proxy, you should ensure
* that it is properly set, such as in wp-config.php, for your environment.
* See {@link http://core.trac.wordpress.org/ticket/9235}
*
* @since 1.5.0
* @uses apply_filters() Calls 'preprocess_comment' hook on $commentdata parameter array before processing
* @uses do_action() Calls 'comment_post' hook on $comment_ID returned from adding the comment and if the comment was approved.
* @uses wp_filter_comment() Used to filter comment before adding comment.
* @uses wp_allow_comment() checks to see if comment is approved.
* @uses wp_insert_comment() Does the actual comment insertion to the database.
*
* @param array $commentdata Contains information on the comment.
* @return int The ID of the comment after adding.
*/
function wp_new_comment($commentdata)
{
$commentdata = apply_filters('preprocess_comment', $commentdata);
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
if (isset($commentdata['user_ID'])) {
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
} elseif (isset($commentdata['user_id'])) {
$commentdata['user_id'] = (int) $commentdata['user_id'];
}
$commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
$parent_status = 0 < $commentdata['comment_parent'] ? wp_get_comment_status($commentdata['comment_parent']) : '';
$commentdata['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $commentdata['comment_parent'] : 0;
$commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']);
$commentdata['comment_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? substr($_SERVER['HTTP_USER_AGENT'], 0, 254) : '';
$commentdata['comment_date'] = current_time('mysql');
$commentdata['comment_date_gmt'] = current_time('mysql', 1);
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
$comment_ID = wp_insert_comment($commentdata);
do_action('comment_post', $comment_ID, $commentdata['comment_approved']);
if ('spam' !== $commentdata['comment_approved']) {
// If it's spam save it silently for later crunching
if ('0' == $commentdata['comment_approved']) {
wp_notify_moderator($comment_ID);
}
$post = get_post($commentdata['comment_post_ID']);
// Don't notify if it's your own comment
if (get_option('comments_notify') && $commentdata['comment_approved'] && (!isset($commentdata['user_id']) || $post->post_author != $commentdata['user_id'])) {
wp_notify_postauthor($comment_ID, isset($commentdata['comment_type']) ? $commentdata['comment_type'] : '');
}
}
return $comment_ID;
}
示例6: newThread
public static function newThread($data = array())
{
$userId = CMA::getPostingUserId();
$user = get_userdata($userId);
if (empty($userId) or empty($user)) {
throw new Exception(CMA::__('Invalid user.'));
}
$title = self::titleFilter($data['title']);
$content = self::contentFilter($data['content'], $userId);
self::validateTitle($title, $editId = false, $errors);
if (!CMA_Settings::getOption(CMA_Settings::OPTION_QUESTION_DESCRIPTION_OPTIONAL) && empty($content)) {
$errors[] = __('Content cannot be empty', 'cm-answers-pro');
}
if (($badWord = CMA_BadWords::filterIfEnabled($content)) !== false) {
$errors[] = sprintf(CMA_Labels::getLocalized('msg_content_includes_bad_word'), $badWord);
}
if (!empty($_FILES) and !self::areQuestionAttachmentsAllowed()) {
$errors[] = __('Upload is not allowed.', 'cm-answers-pro');
} elseif (!self::validateUploadSize()) {
$errors[] = __('The file you uploaded is too big', 'cm-answers-pro');
} elseif (!self::validateUploadNames()) {
$errors[] = __('The file you uploaded is not allowed', 'cm-answers-pro');
}
if (!empty($data['category']) && $data['category'] > 0) {
if ($category = CMA_Category::getInstance($data['category'])) {
if (!$category->isVisible()) {
$errors[] = CMA::__('You have no permission to post this question.');
}
} else {
$errors[] = CMA::__('Choose a valid category.');
}
} else {
if (CMA_Settings::getOption(CMA_Settings::OPTION_QUESTION_REQUIRE_CATEGORY)) {
$errors[] = CMA::__('Choose a category.');
}
}
if (!empty($errors)) {
throw new Exception(serialize($errors));
}
if (CMA_Settings::getOption(CMA_Settings::OPTION_QUESTION_AUTO_APPROVE) || self::isAuthorAutoApproved($userId)) {
$status = 'publish';
} else {
$status = 'draft';
if (self::getSpamFilter() || CMA_Settings::getOption(CMA_Settings::OPTION_SIMULATE_COMMENT)) {
/** Hack, simulate comment adding to trigger spam filters * */
$commentdata = array('comment_post_ID' => 0, 'comment_author' => $user->first_name, 'comment_author_email' => $user->user_email, 'comment_author_url' => '', 'comment_content' => $title . ' ' . $content, 'comment_type' => self::POST_TYPE, 'user_ID' => $userId, 'comment_parent' => 0, 'comment_author_IP' => preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']), 'comment_date' => current_time('mysql'), 'comment_date_gmt' => current_time('mysql', 1), 'comment_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? substr($_SERVER['HTTP_USER_AGENT'], 0, 254) : '');
if (CMA_Settings::getOption(CMA_Settings::OPTION_SIMULATE_COMMENT)) {
// Simulate comment to detect flood and so on.
if (wp_allow_comment($commentdata) == 'spam') {
$status = 'draft';
}
}
}
}
$postData = array('post_status' => $status, 'post_type' => self::POST_TYPE, 'post_title' => $title, 'post_content' => $content, 'post_name' => urldecode(sanitize_title_with_dashes(remove_accents($title))), 'post_author' => $userId);
do_action('cma_question_post_before', $postData);
$id = wp_insert_post($postData);
if ($id instanceof WP_Error) {
return $id->get_error_message();
} else {
$instance = self::getInstance($id);
$instance->setUpdated()->setResolved(false)->setAuthorIP()->checkGeolocation();
if (!empty($data['notify']) and $data['notify'] == 1) {
$instance->getFollowersEngine()->addFollower();
}
$instance->savePostMeta(array(self::$_meta['views'] => 0));
$instance->savePostMeta(array(self::$_meta['votes_answers'] => 0));
$instance->savePostMeta(array(self::$_meta['votes_question'] => 0));
$instance->savePostMeta(array(self::$_meta['votes_question_answers'] => 0));
$instance->savePostMeta(array(self::$_meta['highestRatedAnswer'] => 0));
$instance->savePostMeta(array(self::$_meta['stickyPost'] => 0));
if (!empty($data['category'])) {
$r = wp_set_post_terms($id, array($data['category']), CMA_Category::TAXONOMY, true);
}
if (isset($data['tags'])) {
$r = wp_set_post_tags($id, $data["tags"], true);
}
if (CMA_Settings::getOption(CMA_Settings::OPTION_USER_RELATED_QUESTIONS_ENABLE) and !empty($data['userRelatedQuestions'])) {
$instance->setUserRelatedQuestions(CMA_UserRelatedQuestions::getIdsFromRaw($data['userRelatedQuestions']));
}
$instance->savePost();
$attachmentsIds = CMA_QuestionAttachment::handleUpload($instance->getId());
if (!empty($_POST['attached']) && is_array($_POST['attached'])) {
$attachmentsIds = array_merge($attachmentsIds, $_POST['attached']);
}
foreach ($attachmentsIds as $attachmentId) {
if (!empty($attachmentId)) {
$instance->addAttachment($attachmentId);
}
}
if (CMA_Settings::getOption(CMA_Settings::OPTION_NEW_QUESTION_EVERYBODY_FOLLOW_ENABLED)) {
$instance->makeEverybodyFollowers();
}
if ($status == 'draft') {
$instance->notifyModerator();
} else {
self::updateQA($userId);
$instance->notifyAboutNewQuestion();
}
if (CMA_Settings::getOption(CMA_Settings::OPTION_LOGS_ENABLED)) {
//.........这里部分代码省略.........
示例7: nxs_postNewComment
function nxs_postNewComment($cmnt, $aa = false)
{
$cmnt['comment_post_ID'] = (int) $cmnt['comment_post_ID'];
$cmnt['comment_parent'] = isset($cmnt['comment_parent']) ? absint($cmnt['comment_parent']) : 0;
$parent_status = 0 < $cmnt['comment_parent'] ? wp_get_comment_status($cmnt['comment_parent']) : '';
$cmnt['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $cmnt['comment_parent'] : 0;
$cmnt['comment_author_IP'] = '';
$cmnt['comment_agent'] = 'SNAP';
$cmnt['comment_date'] = get_date_from_gmt($cmnt['comment_date_gmt']);
$cmnt = wp_filter_comment($cmnt);
if ($aa) {
$cmnt['comment_approved'] = 1;
} else {
$cmnt['comment_approved'] = wp_allow_comment($cmnt);
}
$cmntID = wp_insert_comment($cmnt);
if ('spam' !== $cmnt['comment_approved']) {
if ('0' == $cmnt['comment_approved']) {
wp_notify_moderator($cmntID);
}
$post =& get_post($cmnt['comment_post_ID']);
if (get_option('comments_notify') && $cmnt['comment_approved'] && (!isset($cmnt['user_id']) || $post->post_author != $cmnt['user_id'])) {
wp_notify_postauthor($cmntID, isset($cmnt['comment_type']) ? $cmnt['comment_type'] : '');
}
global $wpdb, $dsq_api;
if (isset($dsq_api)) {
$plugins_url = str_replace('social-networks-auto-poster-facebook-twitter-g/', '', plugin_dir_path(__FILE__));
require_once $plugins_url . 'disqus-comment-system/export.php';
if (function_exists('dsq_export_wp')) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = " . $cmntID));
// prr($comments);
$wxr = dsq_export_wp($post, $comments);
$response = $dsq_api->import_wordpress_comments($wxr, time());
// prr($response);
}
}
}
return $cmntID;
}
示例8: post_comment
/**
* If the blog post is cross-posted, and comments are redirected from phpBB,
* this catches posted comments and sends them to the forum
*/
function post_comment($postID)
{
global $phpbb_root_path, $phpEx, $phpbbForum, $auth, $user, $db;
if (!$this->is_working()) {
return;
}
$wpUserID = 0;
if ($wpUser = wp_get_current_user()) {
$wpUserID = $u->ID;
}
$requireNameEmail = get_option('require_name_email');
$fStateChanged = $phpbbForum->foreground();
$dets = $this->get_xposted_details($postID);
if (!$dets) {
$phpbbForum->restore_state($fStateChanged);
return;
}
$isValidEmail = true;
$guestPosting = false;
if ($phpbbForum->user_logged_in()) {
$username = $phpbbForum->get_username();
$website = $phpbbForum->get_userdata('user_website');
$email = $phpbbForum->get_userdata('user_email');
} else {
$guestPosting = true;
$username = strip_tags(stripslashes(request_var('author', 'Anonymous')));
$website = request_var('url', '');
$email = request_var('email', '');
if ($email) {
// use wordpress to sanitize email
$phpbbForum->background();
$isValidEmail = is_email($email);
$phpbbForum->foreground();
}
$username = wpu_find_next_avail_name($username, 'phpbb');
}
if (empty($dets['topic_approved'])) {
$phpbbForum->restore_state($fStateChanged);
wp_die($phpbbForum->lang['ITEM_LOCKED']);
}
if ($dets['topic_status'] == ITEM_LOCKED) {
$phpbbForum->restore_state($fStateChanged);
wp_die($phpbbForum->lang['TOPIC_LOCKED']);
}
if ($dets['forum_id'] == 0) {
// global announcement
if (!$auth->acl_getf_global('f_wpu_xpost_comment')) {
$phpbbForum->restore_state($fStateChanged);
wp_die(__('You do not have permission to respond to this announcement', 'wp-united'));
}
} else {
if (!$auth->acl_get('f_wpu_xpost_comment', $dets['forum_id'])) {
$phpbbForum->restore_state($fStateChanged);
wp_die(__('You do not have permission to comment in this forum', 'wp-united'));
}
}
$content = isset($_POST['comment']) ? trim($_POST['comment']) : null;
if (empty($content)) {
$phpbbForum->restore_state($fStateChanged);
wp_die(__('Error: Please type a comment!', 'wp-united'));
}
// taken from wp-comment-post.php, native WP translation of strings
if ($requireNameEmail && $guestPosting) {
if (6 > strlen($email) || '' == $username) {
wp_die(__('<strong>ERROR</strong>: please fill in the required fields (name, email).', 'wp-united'));
} elseif (!$isValidEmail) {
wp_die(__('<strong>ERROR</strong>: please enter a valid email address.', 'wp-united'));
}
}
$commentParent = (int) request_var('comment_parent', 0);
// create a wordpress comment and run some checks on it
// send comment thru akismet, other spam filtering, if user is logged out
$phpbbForum->background();
$commentData = array('comment_post_ID' => $postID, 'comment_author' => $username, 'comment_author_email' => $email, 'comment_author_url' => $website, 'comment_parent' => $commentParent, 'comment_type' => '', 'user_ID' => $wpUserID);
$checkSpam = $this->get_setting('xpostspam');
$checkSpam = !empty($checkSpam);
if ($guestPosting && $checkSpam) {
$commentData = apply_filters('preprocess_comment', $commentData);
}
$commentData = array_merge($commentData, array('comment_author_IP' => preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']), 'comment_agent' => substr($_SERVER['HTTP_USER_AGENT'], 0, 254), 'comment_date' => current_time('mysql'), 'comment_date_gmt' => current_time('mysql', 1), 'comment_karma' => 0));
$forceModeration = false;
$overrideApproval = false;
if ($guestPosting && $checkSpam) {
$commentData['comment_approved'] = wp_allow_comment($commentData);
if (!$commentData['comment_approved'] || $commentData['comment_approved'] == 'spam') {
$forceModeration = true;
} else {
// if the comment has passed checks, and we are overriding phpBB approval settings
if ($this->get_setting('xpostspam') == 'all') {
$overrideApproval = true;
}
}
}
$phpbbForum->foreground();
wpu_html_to_bbcode($content);
$content = utf8_normalize_nfc($content);
//.........这里部分代码省略.........
示例9: create_item
/**
* Creates a comment.
*
* @since 4.7.0
* @access public
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response Response object on success, or error object on failure.
*/
public function create_item($request)
{
if (!empty($request['id'])) {
return new WP_Error('rest_comment_exists', __('Cannot create existing comment.'), array('status' => 400));
}
// Do not allow comments to be created with a non-default type.
if (!empty($request['type']) && 'comment' !== $request['type']) {
return new WP_Error('rest_invalid_comment_type', __('Cannot create a comment with that type.'), array('status' => 400));
}
$prepared_comment = $this->prepare_item_for_database($request);
if (is_wp_error($prepared_comment)) {
return $prepared_comment;
}
$prepared_comment['comment_type'] = '';
/*
* Do not allow a comment to be created with missing or empty
* comment_content. See wp_handle_comment_submission().
*/
if (empty($prepared_comment['comment_content'])) {
return new WP_Error('rest_comment_content_invalid', __('Invalid comment content.'), array('status' => 400));
}
// Setting remaining values before wp_insert_comment so we can use wp_allow_comment().
if (!isset($prepared_comment['comment_date_gmt'])) {
$prepared_comment['comment_date_gmt'] = current_time('mysql', true);
}
// Set author data if the user's logged in.
$missing_author = empty($prepared_comment['user_id']) && empty($prepared_comment['comment_author']) && empty($prepared_comment['comment_author_email']) && empty($prepared_comment['comment_author_url']);
if (is_user_logged_in() && $missing_author) {
$user = wp_get_current_user();
$prepared_comment['user_id'] = $user->ID;
$prepared_comment['comment_author'] = $user->display_name;
$prepared_comment['comment_author_email'] = $user->user_email;
$prepared_comment['comment_author_url'] = $user->user_url;
}
// Honor the discussion setting that requires a name and email address of the comment author.
if (get_option('require_name_email')) {
if (empty($prepared_comment['comment_author']) || empty($prepared_comment['comment_author_email'])) {
return new WP_Error('rest_comment_author_data_required', __('Creating a comment requires valid author name and email values.'), array('status' => 400));
}
}
if (!isset($prepared_comment['comment_author_email'])) {
$prepared_comment['comment_author_email'] = '';
}
if (!isset($prepared_comment['comment_author_url'])) {
$prepared_comment['comment_author_url'] = '';
}
if (!isset($prepared_comment['comment_agent'])) {
$prepared_comment['comment_agent'] = '';
}
$check_comment_lengths = wp_check_comment_data_max_lengths($prepared_comment);
if (is_wp_error($check_comment_lengths)) {
$error_code = $check_comment_lengths->get_error_code();
return new WP_Error($error_code, __('Comment field exceeds maximum length allowed.'), array('status' => 400));
}
$prepared_comment['comment_approved'] = wp_allow_comment($prepared_comment, true);
if (is_wp_error($prepared_comment['comment_approved'])) {
$error_code = $prepared_comment['comment_approved']->get_error_code();
$error_message = $prepared_comment['comment_approved']->get_error_message();
if ('comment_duplicate' === $error_code) {
return new WP_Error($error_code, $error_message, array('status' => 409));
}
if ('comment_flood' === $error_code) {
return new WP_Error($error_code, $error_message, array('status' => 400));
}
return $prepared_comment['comment_approved'];
}
/**
* Filters a comment before it is inserted via the REST API.
*
* Allows modification of the comment right before it is inserted via wp_insert_comment().
*
* @since 4.7.0
*
* @param array $prepared_comment The prepared comment data for wp_insert_comment().
* @param WP_REST_Request $request Request used to insert the comment.
*/
$prepared_comment = apply_filters('rest_pre_insert_comment', $prepared_comment, $request);
$comment_id = wp_insert_comment(wp_filter_comment(wp_slash((array) $prepared_comment)));
if (!$comment_id) {
return new WP_Error('rest_comment_failed_create', __('Creating comment failed.'), array('status' => 500));
}
if (isset($request['status'])) {
$this->handle_status_param($request['status'], $comment_id);
}
$comment = get_comment($comment_id);
/**
* Fires after a comment is created or updated via the REST API.
*
* @since 4.7.0
*
* @param WP_Comment $comment Inserted or updated comment object.
//.........这里部分代码省略.........
示例10: allow_comment
/**
* Checks to see if the comment is allowed.
*
* [!!] Handles the exception for duplicate comments.
*
* @param array $commentdata
* @param int $result_id
* @param object $post
* @return array|bool
*/
public function allow_comment(array $commentdata, $result_id, &$post)
{
try {
add_filter('wp_die_handler', array('Social', 'wp_die_handler'));
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
remove_filter('wp_die_handler', array('Social', 'wp_die_handler'));
return $commentdata;
} catch (Exception $e) {
remove_filter('wp_die_handler', array('Social', 'wp_die_handler'));
if ($e->getMessage() == Social::$duplicate_comment_message) {
// Remove the aggregation ID from the stack
unset($post->results[$this->_key][$result_id]);
$aggregated_ids = array();
foreach ($post->aggregated_ids[$this->_key] as $id) {
if ($id != $result_id) {
$aggregated_ids[] = $id;
}
}
$post->aggregated_ids[$this->_key] = $aggregated_ids;
// Mark the result as ignored
Social_Aggregation_Log::instance($post->ID)->ignore($result_id);
}
}
return false;
}
示例11: Comments_array
function Comments_array($comments, $post_ID)
{
$post = get_post($post_ID);
$user_ID = self::Get_user_ID($post);
update_option(c_al2fb_log_importing, true);
// Integration?
if ($user_ID && !self::Is_excluded($post) && $post->post_type != 'reply' && !get_post_meta($post->ID, c_al2fb_meta_nointegrate, true) && $post->comment_status == 'open') {
// Get time zone offset
$tz_off = get_option('gmt_offset');
if (empty($tz_off)) {
$tz_off = 0;
}
$tz_off = apply_filters('al2fb_gmt_offset', $tz_off);
$tz_off = $tz_off * 3600;
// Get Facebook comments
if (self::Is_recent($post) && get_user_meta($user_ID, c_al2fb_meta_fb_comments, true)) {
$fb_comments = WPAL2Int::Get_comments_or_likes($post, false);
if ($fb_comments && $fb_comments->data) {
// Get WordPress comments
$stored_comments = get_comments('post_id=' . $post->ID);
$stored_comments = array_merge($stored_comments, get_comments('status=spam&post_id=' . $post->ID));
$stored_comments = array_merge($stored_comments, get_comments('status=trash&post_id=' . $post->ID));
$stored_comments = array_merge($stored_comments, get_comments('status=hold&post_id=' . $post->ID));
$deleted_fb_comment_ids = get_post_meta($post->ID, c_al2fb_meta_fb_comment_id, false);
foreach ($fb_comments->data as $fb_comment) {
if (!empty($fb_comment->id)) {
$search_comment_id = end(explode('_', $fb_comment->id));
// Check if stored comment
$stored = false;
if ($stored_comments) {
foreach ($stored_comments as $comment) {
$fb_comment_id = get_comment_meta($comment->comment_ID, c_al2fb_meta_fb_comment_id, true);
if ($search_comment_id == end(explode('_', $fb_comment_id))) {
$stored = true;
break;
}
}
}
// Check if deleted comment
if (!$stored && $deleted_fb_comment_ids) {
foreach ($deleted_fb_comment_ids as $deleted_fb_comment_id) {
if ($search_comment_id == end(explode('_', $deleted_fb_comment_id))) {
$stored = true;
break;
}
}
}
// Create new comment
if (!$stored) {
$name = $fb_comment->from->name . ' ' . __('on Facebook', c_al2fb_text_domain);
if ($post->post_type == 'topic') {
// bbPress
$reply_id = bbp_insert_reply(array('post_parent' => $post_ID, 'post_content' => $fb_comment->message, 'post_status' => 'draft'), array('forum_id' => bbp_get_topic_forum_id($post_ID), 'topic_id' => $post_ID, 'anonymous_name' => $name));
// Add data
add_post_meta($reply_id, c_al2fb_meta_link_id, $fb_comment->id);
add_post_meta($post_ID, c_al2fb_meta_fb_comment_id, $fb_comment->id);
// Publish
$reply = array();
$reply['ID'] = $reply_id;
$reply['post_status'] = 'publish';
wp_update_post($reply);
} else {
$comment_ID = $fb_comment->id;
$commentdata = array('comment_post_ID' => $post_ID, 'comment_author' => $name, 'comment_author_email' => $fb_comment->from->id . '@facebook.com', 'comment_author_url' => WPAL2Int::Get_fb_profilelink($fb_comment->from->id), 'comment_author_IP' => '', 'comment_date' => date('Y-m-d H:i:s', strtotime($fb_comment->created_time) + $tz_off), 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime($fb_comment->created_time)), 'comment_content' => $fb_comment->message, 'comment_karma' => 0, 'comment_approved' => 1, 'comment_agent' => 'AL2FB', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => 0);
// Assign parent comment id
if (!empty($fb_comment->parent->id)) {
$parent_args = array('post_id' => $post_ID, 'meta_query' => array(array('key' => c_al2fb_meta_fb_comment_id, 'value' => $fb_comment->parent->id)));
$parent_comments_query = new WP_Comment_Query();
$parent_comments = $parent_comments_query->query($parent_args);
if (isset($parent_comments) && count($parent_comments) == 1) {
$commentdata['comment_parent'] = $parent_comments[0]->comment_ID;
}
}
$commentdata = apply_filters('al2fb_preprocess_comment', $commentdata, $post);
// Copy Facebook comment to WordPress database
if (get_user_meta($user_ID, c_al2fb_meta_fb_comments_copy, true)) {
// Apply filters
if (get_option(c_al2fb_option_nofilter_comments)) {
$commentdata['comment_approved'] = '1';
} else {
$commentdata = apply_filters('preprocess_comment', $commentdata);
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
}
// Insert comment in database
$comment_ID = wp_insert_comment($commentdata);
add_comment_meta($comment_ID, c_al2fb_meta_fb_comment_id, $fb_comment->id);
do_action('comment_post', $comment_ID, $commentdata['comment_approved']);
// Notify
if ('spam' !== $commentdata['comment_approved']) {
if ('0' == $commentdata['comment_approved']) {
wp_notify_moderator($comment_ID);
}
if (get_option('comments_notify') && $commentdata['comment_approved']) {
wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
}
}
} else {
$commentdata['comment_approved'] = '1';
}
//.........这里部分代码省略.........
示例12: create
public static function create($service_answer, $data, $app_id)
{
$service_answer = array();
$service_answer['comment_ok'] = 0;
if (!empty($data['comment'])) {
$comment = $data['comment'];
//Check authentication
if (!empty($data['auth'])) {
if (is_array($comment)) {
$comment_content = trim(base64_decode($comment['content']));
if (!empty($comment_content)) {
$to_check = array($comment['content'], $comment['post']);
//TODO we could add a filter on this to add more comment data to control field
//(and same must be applied on app side).
$result = WpakUserLogin::log_user_from_authenticated_action($app_id, "comment-POST", $data['auth'], $to_check);
if ($result['ok']) {
if (empty($comment['id'])) {
if (!empty($comment['post'])) {
$post = get_post($comment['post']);
if (!empty($post)) {
if ($post->post_status === 'publish') {
//Comments must be open for the given post:
if (comments_open($post->ID)) {
$post_type = get_post_type_object($post->post_type);
//The logged in user must be able to read the post he's commenting on :
if (current_user_can($post_type->cap->read_post, $post->ID)) {
$comment['content'] = $comment_content;
$logged_in_user = WpakUserLogin::get_current_user();
$comment['author'] = $logged_in_user->ID;
$comment['author_name'] = $logged_in_user->user_login;
$comment['author_email'] = $logged_in_user->user_email;
$comment['author_url'] = $logged_in_user->user_url;
//The following comment insertion is inspired from the WP API v2 :)
$prepared_comment = self::prepare_comment_for_database($comment);
if (is_array($prepared_comment)) {
//Don't post the same comment twice :
if (!self::is_duplicate($prepared_comment)) {
$prepared_comment['comment_approved'] = wp_allow_comment($prepared_comment);
/**
* Use this filter to edit the comment fields before inserting it to database.
*
* @param array $prepared_comment Comment that is going to be inserted into db
* @param WP_User $logged_in_user Currently logged in user
* @param int $app_id Id of the current app
*/
$prepared_comment = apply_filters('wpak_comments_before_insert', $prepared_comment, $logged_in_user, $app_id);
$comment_id = wp_insert_comment($prepared_comment);
if ($comment_id) {
$inserted_comment = get_comment($comment_id);
if ($inserted_comment->comment_approved) {
$comment_tree = self::get_post_comments($post->ID, $app_id);
if (!empty($comment_tree[$comment_id])) {
$service_answer['comment'] = self::get_comment_web_service_data($comment_tree[$comment_id]);
$service_answer['comments'] = self::read_one(array(), $post->ID, $app_id);
$service_answer['comment_ok'] = 1;
$service_answer['waiting_approval'] = 0;
} else {
$service_answer['comment_error'] = 'wrong-comment-tree';
}
} else {
$comment_tree = self::get_post_comments($post->ID, $app_id, false);
//false to get non approved comments too
if (!empty($comment_tree[$comment_id])) {
$service_answer['comment'] = self::get_comment_web_service_data($comment_tree[$comment_id]);
$service_answer['comments'] = self::read_one(array(), $post->ID, $app_id);
//Note : $service_answer['comments'] will not contain the inserted comment as
//it is waiting for approval.
$service_answer['comment_ok'] = 1;
$service_answer['waiting_approval'] = 1;
} else {
$service_answer['comment_error'] = 'wrong-comment-tree';
}
}
} else {
$service_answer['comment_error'] = 'wp-insert-comment-failed';
}
} else {
$service_answer['comment_error'] = 'already-said-that';
}
} else {
$service_answer['comment_error'] = $prepared_comment;
//Contains error string
}
} else {
$service_answer['comment_error'] = 'user-cant-comment-this-post';
}
} else {
$service_answer['comment_error'] = 'comments-closed';
}
} else {
$service_answer['comment_error'] = 'post-not-published';
}
} else {
$service_answer['comment_error'] = 'comment-post-not-found';
}
} else {
$service_answer['comment_error'] = 'no-comment-post';
}
} else {
$service_answer['comment_error'] = 'comment-already-exists';
//.........这里部分代码省略.........
示例13: create_item
/**
* Create a comment.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function create_item($request)
{
if (!empty($request['id'])) {
return new WP_Error('rest_comment_exists', __('Cannot create existing comment.'), array('status' => 400));
}
$post = get_post($request['post']);
if (empty($post)) {
return new WP_Error('rest_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
}
$prepared_comment = $this->prepare_item_for_database($request);
// Setting remaining values before wp_insert_comment so we can
// use wp_allow_comment().
if (!isset($prepared_comment['comment_date_gmt'])) {
$prepared_comment['comment_date_gmt'] = current_time('mysql', true);
}
if (!isset($prepared_comment['comment_author_email'])) {
$prepared_comment['comment_author_email'] = '';
}
if (!isset($prepared_comment['comment_author_url'])) {
$prepared_comment['comment_author_url'] = '';
}
$prepared_comment['comment_author_IP'] = '127.0.0.1';
$prepared_comment['comment_agent'] = '';
$prepared_comment['comment_approved'] = wp_allow_comment($prepared_comment);
$prepared_comment = apply_filters('rest_pre_insert_comment', $prepared_comment, $request);
$comment_id = wp_insert_comment($prepared_comment);
if (!$comment_id) {
return new WP_Error('rest_comment_failed_create', __('Creating comment failed.'), array('status' => 500));
}
if (isset($request['status'])) {
$comment = get_comment($comment_id);
$this->handle_status_param($request['status'], $comment);
}
$this->update_additional_fields_for_object(get_comment($comment_id), $request);
$context = current_user_can('moderate_comments') ? 'edit' : 'view';
$response = $this->get_item(array('id' => $comment_id, 'context' => $context));
$response = rest_ensure_response($response);
if (is_wp_error($response)) {
return $response;
}
$response->set_status(201);
$response->header('Location', rest_url('/wp/v2/comments/' . $comment_id));
return $response;
}
示例14: test_die_as_duplicate_if_comment_author_name_and_emails_match
/**
* @expectedException WPDieException
*/
public function test_die_as_duplicate_if_comment_author_name_and_emails_match()
{
$now = time();
$comment_data = array('comment_post_ID' => self::$post_id, 'comment_author' => 'Bob', 'comment_author_email' => 'bobthebuilder@example.com', 'comment_author_url' => 'http://example.com', 'comment_content' => 'Yes, we can!', 'comment_author_IP' => '192.168.0.1', 'comment_parent' => 0, 'comment_date_gmt' => date('Y-m-d H:i:s', $now), 'comment_agent' => 'Bobbot/2.1', 'comment_type' => '');
$result = wp_allow_comment($comment_data);
}