New answers tagged

0

I have written a function that will convert the qtranslate-x string into array of language and based on that you can use a particular language. /** * This function breaks q-translate string into array per language. * * @param - {string}$content - the q-translate string Eg : [:en]Title in English[:fr]Title in French * @return {array/bool} $lang - an ...


2

If you change manage_edit-post_columns to manage_posts_columns in your code snippet, then it should hide the comment column for all post types (appart from the page post type) within the WP_Posts_List_Table src. You might want to check if the column array key isset first, before unsetting it.


2

I got an alternative : This will not just hiding but disabling also function disable_comments() { $post_types = get_post_types(); foreach ($post_types as $post_type) { if(post_type_supports($post_type,'comments')) { remove_post_type_support($post_type,'comments'); remove_post_type_support($post_type,'trackbacks'); ...


0

I found out the issue. It was something like jQuery/AJAX code for it is not being able to hook itself when I reload the form with .load(), therefore the second time I submit a new comment, or when I clicked the reload button for the comment list/form (making the .load() run once), the new form would still submit the comment but since the jQuery/AJAX is not ...


0

It was about calling the fields value containers which are arrays, so: get_comment_author() should change to something like this: $commenter['comment_author']


1

This quite rare setup so it is hard to recommend one way or another. Having worked with comments before I would recommend to stick with WordPress API functions (wp_insert_comment() and so on) for manipulating them. While DB structure is indeed simple you don't account for all the hooks firing and other things that might be happening. For example once in ...


0

This notice comes because object $comments is null. So the have_comments() must wrap all the thing to be sure there are comments before using any property. in your case : <?php if ( have_comments() ) : /* the code */ endif; ?>


0

Unfortunately the hooks: manage_{$this->screen->id}_columns manage_{$this->screen->id}_sortable_columns manage_comments_custom_column are not available for the post-comments list table, constructed within the wp_ajax_get-comments call. That table consists only of two columns: author and comment. The data for author, avatar, email, url and IP ...


0

For comment approved, you can review this question Approve comment hook? For comment submitted, you can hook into the comment_post hook, like function show_message_function( $comment_ID, $comment_approved ) { if( 0 === $comment_approved ){ //function logic goes here } } add_action( 'comment_post', 'show_message_function', 10, 2 ); Code ...


0

I have tried this in the following way, you can try this .... put the following code in functions.php function hide_comment_form_function( $comment_ID, $comment_approved ){ $commentData = get_comment( $comment_ID ); $postTitle = get_the_title($commentData->comment_post_ID); $url = get_site_url() ."/" .$postTitle . "/?status=cmt_post"; header("Location:...


0

Wordpress adds hashtag to URL if comment was successfully submitted. The easiest way to hide comment form or display some info is to check if hash exists with Javascript. hash = window.location.hash; if(hash){ $('#commentform').hide(); }


0

The following example uses the comment_post hook to run a function immediately after a comment is posted. The function checks whether the comment is approved and, if so, executes the code specified. function show_message_function( $comment_ID, $comment_approved ) { if( 1 === $comment_approved ){ //function logic goes here }}add_action( 'comment_post', '...


0

You got this action comment_post which fires just after comment is inserted in database


0

Demo - Setup Here's a demo how we could control the display of comment fields and their order: Let's create a custom class: $mycf = new MyCommentFields; Then we define our extra fields: $myfields = []; $myfields['myaddress'] = sprintf( '<p class="comment-form-myaddress"> <label for="myaddress">%s <span class="required">*&...


1

It looks like the first time the core calls wp_get_current_user() is within the WP::init() method. To better understand the context, we see that it's right after the after_setup_theme hook and just before the init hook src: do_action( 'after_setup_theme' ); // Set up current user. $GLOBALS['wp']->init(); do_action( 'init' ); where WP::init() is ...


0

I suggest adding a snippet to the theme file where the comments form is loaded that checks to make sure there is a logged in user and then, if that user a Subscriber, then show the comments form to them. The examples below use the Twenty Sixteen theme: In comments.php: // First, get the current user and check their role $user = wp_get_current_user(); if ( ...


-1

The below code check if user is not subscriber then comment form will not display. Comment form only show when user is login and and user role is subscriber. add_filter( 'init', 'manage_comment'); function manage_comment() { global $current_user; $user_roles = $current_user->roles; $user_role = array_shift($user_roles); if (...


3

I wonder if you mean this kind of approach: add_filter( 'init', function() { $u = wp_get_current_user(); if( $u->exists() && in_array( 'banned', $u->roles, true ) ) add_filter( 'comments_open', '__return_false' ); } ); where we check if the current user has the custom banned role. If that's the case then we force all ...


0

To list the most recent (5) comments you can use this code : $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,50) // NUMBER OF CHARACTERS AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->...


0

You should consider removing the average_ratingfn() function definition out of there and call it with an input argument for the post ID. You can try to fetch the comment object with (untested): $comment = get_comment( $comment_ID ); and then make sure it's not null or you have an actual comment object with: if( $comment instanceof \WP_Comment ) $...


-2

Have you tried paginate_comments_links();? <div class="navigation"> <?php paginate_comments_links(); ?> </div>


0

Sadly there are no hooks or filters that you could use in edit-comments.php. You'd have to build your own admin page with a custom button and use wp_set_comment_status( $comment, 'approve' ); to approve comment and do whatever you need to do... EDIT: I was wrong - there's the wp_set_comment_status action inside wp_set_comment_status function https://wpseek....


1

Just some additional info for the main comment query: Since you mentioned the global $wp_query object, we can see that it stores: $wp_query->max_num_comment_pages = $comment_query->max_num_pages; in the main comment query in the comments template. There exists a wrapper for this, namely: get_comment_pages_count(); that's available after the ...


1

One approach is to use the cpage query variable: if ( ! empty( get_query_var( 'cpage' ) ) ) { // There is more than one page of comments. }


1

Try this, get_option( 'page_comments' ) will check if pagination is checked in options > discussion, then we compare comments per page (get_query_var( 'comments_per_page' )) to the current post's total comments found (count): function wpse231229_is_paginate_comments( $post_id = 0 ) { return get_option( 'page_comments' ) && ( $pagi = (int) ...


0

There's this built-in function for querying comments get_comments and here's something that would help in your template: $comments = get_comments( array( 'number' => 10 ) ); if ( !empty( $comments ) ) { ?> <ul> <?php foreach ( $comments as $comment ) : ?> <li><?php echo sprintf( "<strong>...


0

Add bellow code in your functions.php file. } add_filter('comment_form_default_fields','remove_comment_fields'); function remove_comment_fields($fields) { unset($fields['url']); return $fields; } add_filter('comment_form_default_fields','remove_comment_fields'); Refference url


0

Seems pretty much simple: add_filter( 'get_comment_author_link', 'attach_city_to_author' ); function attach_city_to_author( $author ) { $city = get_comment_meta( get_comment_ID(), 'city', true ); if ( $city ) $author = $city; return $author; } Unless if you are adding the city name somewhere else and wanted to remove comment author name then ...


1

As discussed in the comments, your database prefix settings are off-kilter. Check the database prefix actually in use in your database, and make sure it's the same as the one in wp-config.php. Also make sure all of your WordPress-related tables have the same prefix. You'll also need to search through your database, particularly in the _options table, as ...


2

There is no use for converting an integer to a string when you just need to display the result or for simple checking against a hardcoded known datatype value. Converting datatypes is only useful when you need to validate values strickly against a certain specific datatype. Your issue is that you do not exactly know how to test your values. 0, either an an ...



Top 50 recent answers are included