I want to highlight author comments in admin panel of WordPress engine. I have many comments on my blog every day, and it's hard sometimes in admin panel to find my own comment.
This can be achieved with a targeted action hook and a bit of CSS:
add_action( 'admin_head-edit-comments.php', 'colored_comments_so_15232115' );
function colored_comments_so_15232115()
{
?>
<style>.comment-author-USER_LOGIN { background-color: #DFDB83 }</style>
<?php
}
Replace USER_LOGIN with your login name. And surely, you could add as many users/background-colors as needed.
This CSS is only printed in the Comments page (/wp-admin/edit-comments.php) by using the hook admin_head-$hook_suffix.
You can also use a plugin: Comment Moderation Highlights
note: I'm the plugin developer.
Set it so that it looks for your email addresss, pick a color and save. All your comments will be Highlighted within the comments admin.
Related
I want to allow user only one comment in a post.
I check/validate my user comments with preprocess_comment filter hook. And stop for multiple comments.
But I can not hide the comment form box after user make the comment.
when a user comment in a post then the comment box will disable/hide from the page.
Help please
You may create your custom comment.php template of course comment form also in your theme.
Check this link
https://developer.wordpress.org/themes/template-files-section/partial-and-miscellaneous-template-files/comment-template/
End of the page:
https://developer.wordpress.org/themes/template-files-section/partial-and-miscellaneous-template-files/comment-template/#the-end
<?php
if( YOUR_CONDITION_FUNCTION_OR_LOGIC() ){
comment_form();
}
?>
Hope it helps you.
I have very beginner level understanding of wordpress, woocommerce and elementor. I am still learning a lot of things. I believe that the best way to learn is to imitate. So, I go through various themes and try to imitate their behaviour and appearance using Elementor. But, this particular theme caught my eye. The Add to cart button appears when someone hovers over the product image instead of always being there. Can you guys please help me figure this out or atleast point me in the right direction?
This is how it should look when someone hovers over the images
This is how it looks when the mouse pointer is away
More info
<?php if($available) {?>
Buy now
<?php } ?>
This code solves my problem as expected.
WooCommerce documentation reference
Solution: Add code in your theme's function.php file.
add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 30 );
function my_extra_button_on_product_page() {
global $product;
echo 'Add to cart';
}
Solution: Install Custom WooCommerce Add to Cart plugin
Custom WooCommerce Add to Cart Plugin
Solution: You can use hooks with shortcodes:
custom add to cart button
Or create overrides for WooCommerce files in your own template
I have a wp-network installed with users that can create pages in each site.
Each of those pages get a place in the primary menu, and only one user have permission to create all this menu.
I want to create a user only to be able to edit the content of the pages, but not the title.
How can I disable the title of the page to be edited from the admin menu for a specific user, or (far better) for a capability?
I thought only a possibility, that's editing admin css to hide the title textbox, but I have two problems:
I don't like to css-hide things.
I don't know where is the admin css.
I know php, but don't know how to add a css hide to an element for a capability.
You should definitely use CSS to hide the div#titlediv. You'll want the title to show in the markup so the form submission, validation, etc continues to operate smoothly.
Some elements you'll need to know to implement this solution:
current_user_can() is a boolean function that tests if the current logged in user has a capability or role.
You can add style in line via the admin_head action, or using wp_enqueue_style if you'd like to store it in a separate CSS file.
Here is a code snippet that will do the job, place it where you find fit, functions.php in your theme works. I'd put it inside a network activated plugin if you're using different themes in your network:
<?php
add_action('admin_head', 'maybe_modify_admin_css');
function maybe_modify_admin_css() {
if (current_user_can('specific_capability')) {
?>
<style>
div#titlediv {
display: none;
}
</style>
<?php
}
}
?>
I resolved the problem, just if someone comes here using a search engine, I post the solution.
Doing some research, I found the part of the code where the title textbox gets inserted, and I found a function to know if a user has a certain capability.
The file where the title textbox gets added is /wp-admin/edit-form-advanced.php. This is the line before the textbox
if ( post_type_supports($post_type, 'title') )
I changed it to this
if ( post_type_supports($post_type, 'title') and current_user_can('edit_title') )
That way, the textbox is only added when the user has the capability called "edit_title"
When this IF block ends few lines after, I added:
else echo "<h2>".esc_attr( htmlspecialchars( $post->post_title ) )."</h2>";
To see the page title but not to edit it, when the user hasn't got "edit_title" capability.
Then I had already installed a plugin to edit user capabilities and roles, wich help me to create a new capability (edit_title) and assign it to the role I want.
I have modified the buddypress admin bar by creating the following plugin which adds a simple text link to the bar:
function bp_adminbar_currentsite_menu() {
global $bp;
?>
<li>
<!-- Insert your link url or relative url, and your link text below -->
EXAMPLE LINK TEXT
</li>
<?php
}
// Call The Function Above
add_action('bp_adminbar_menus', 'bp_adminbar_currentsite_menu', 999);
However, I do NOT want the above link to be shown when logged into the wordpress admin backend (so for example when an admin is editing a post). I thought about just doing a php_self check to see if it contained "/wp-admin/" but figured that there has to be a more elegant wordpress/buddypress hook here.
How can I get the above code to only show when you are viewing a normal blog page, NOT in the admin area?
Thanks
using is_admin() is the answer. It is a wordpress function that checks to see if you are looking at admin pages or not.
In Drupal 7 comments, how can I hide/disable homepage field for anonymous commenters?
Whilst there are lots of answers here none of them provide all of the code in one easy to copy and paste block:
/**
* Implements hook_form_FORM_ID_alter().
*
* Remove homepage field from comments form.
*/
function THEMENAME_form_comment_form_alter(&$form, &$form_state) {
$form['author']['homepage']['#access'] = FALSE;
}
Put this code in your themes template.php replacing THEMENAME with the name of your theme.
Open the file themes/<your_theme>/templates/comment-wrapper.tpl.php in your drupal installation folder, and add this line before the HTML code:
<?php $content['comment_form']['author']['homepage'] = null; ?>
or at least before
<?php print render($content['comment_form']); ?>
With that you're deactivating the homepage field in the form that is displayed to the user.
You can also do what #Robert says and choose "Anonymous posters may not leave their contact info", but you'd be allowing comments without email information as well. If you just want to hide the homepage field from the form and keep the email (for example, to use Gravatar), this bit of hacking should do the trick. If your website has more than one theme, make sure you do it in every theme that displays the comments form.
In a suitable form_alter() hook, do this:
$form['author']['homepage']['#access'] = FALSE;
This is better than using unset() or setting $form['author']['homepage'] to null as described in other answers, because the comment_form_validate() function throws ugly errors.
All credit to Art Williams
Administration » Structure » Content types » (Your content type) » Comment Settings » Anonymous commenting » Anonymous posters may not / may /must leave their contact info.
Here's the three-line custom module solution. I usually keep a custom_site_tweaks module for this type of thing per site.
function CUSTOM_form_comment_node_blog_post_form_alter(&$form, &$form_state, $form_id) {
unset($form['author']['homepage']);
}
BTW: This is a great way to de-incentivize spam posts.