Removing comment form consent from Wordpress - wordpress

In order to remove the consent field from the comment form on blog posts the following filter is added to my child themes function.php:
add_filter('comment_form_default_fields', 'unset_consent_field');
function unset_consent_field($fields){
if(isset($fields['cookies']))
unset($fields['cookies']);
return $fields;
}
The consent field remains however. Replacing 'cookies' with 'url' successfully removes the URL field so im not sure why its not working for the cookies field.
Any ideas what could be causing this and what the solution is?

The checkbox can be removed under Wordpress Settings -> Privacy

Related

ERROR: please fill the required fields (name, email). in Wordpress Comment

I have a problem submitting comment form for not signed in users. When I try to submit the forms, it is giving me an error -
ERROR: please fill the required fields (name, email).
I am using default template for WordPress. I have tried to deactivate the plugins one by one to make sure that if this is not a conflict, but then it is also not working. However, It's working fine for logged in users.
You can just make the email and name fields not required, To achieve this, go to Dashboard > Settings > Discussion and uncheck the Comment author must fill out name and email.
Edit:
Read the comments for actual solution ...
I had the same issue. Check the code below within your theme and remove 'comment-form' and 'comment-list'.
add_theme_support(
'html5',
array(
'search-form',
//'comment-form',
//'comment-list',
'gallery',
'caption',
)
);
Note this question should be on WordPress stackoverflow.

How to remove woocommerce check out page's default email address text

By default email field is showing email address from wordpress general settings , I want to show a custom text like 'example#example.com' in this field as a place holder value. Please advise
None of the answers solved my problem either...
Took me a while to work this out, really simple in the end, just put this at the end of your functions.php file and change the value to whatever you want.
function woocommerce_change_checkout_field_value() {
echo "<script>document.getElementById('billing_email').value = 'Your value here';</script>";
}
add_action( 'woocommerce_after_checkout_form', 'woocommerce_change_checkout_field_value');
Go to your dashboard -> Woocommerce -> Settings -> Emails -> Email options, you will see ""From" Name" and ""From" Email Address", change those and it should change it on the email.
More information about configuring some of the basic options on woocommerce you can visit this page.
You need to implement checkout field customization hook for doing this. Its correct way of doing it.
Please refer to this : https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
get WooCommerce Checkout Manager
then complete Replace Placeholder Name of your field.

How to set custom post type as parent of page?

I've found plenty of info on how to set a page as the parent of a custom post type, but not the other way round - I want to set a custom post type as the parent of my page.
I've found the following hook, originally intended to add drafts to the list of available parents for a page. It works for adding drafts, but if I use it to chaneg the retrieved post type, the parent pulldown on the page edit screen disappears. Any ideas?
add_filter( 'page_attributes_dropdown_pages_args', 'so_3538267_enable_drafts_parents' );
add_filter( 'quick_edit_dropdown_pages_args', 'so_3538267_enable_drafts_parents' );
function so_3538267_enable_drafts_parents( $args )
{
//$args['post_status'] = 'draft,publish,pending';//works
$args['post_type'] = 'campaign';//custom post type name - doesn't work
return $args;
}
I've got it working. The code above is good, I just needed to set my custom post type to be hierarchical.
Edit:
I spoke too soon. The above change allowed me to select the custom post type as the parent of the page, but now the child page is inaccessible on the frontend. I get a 404 error. I've tried flushing permalinks as usual.
The URL it's trying to use for the page:
http://www.example.com/sample-campaign-6/about-campaign/
the first part is the slug for the parent custom post type.
Can anyone tell me how to get this working?
Thanks.

wp auto insert tag in posts

when I edit a post in wp sometimes I don't assign a tag , is it a good Idea to auto insert a tag like the category name or my site name instead of no tag at all?
and if its better to input a tag then I need help writing a function that check if the post has no tag then it will insert lets say my sitename.
all what I have is
wp_set_post_tags( 42, 'mepanorama', true );
but this will work only on specific post and does not check if there is a tag already.
This will return the number of tags:
count(wp_get_post_terms($post_id, 'post_tag', array("fields" => "names")));
I made a plugin that adds tags to posts automatically, it is called Automatic Post Tagger. Check it out, it might be useful for you. :)

WordPress add a new page to admin section

I have already developed my plugin for WordPress and I can manage it from admin. I have passed the access to the plugin file using add_submenu_page. The problem is that the plugin is extending and I want to use another file that is linked from the main file. For example I have second_page.php?id=3. When I try to access this link, I get a
You do not have sufficient permissions to access this page.
message. I want to "validate" this page also for using with this script and I don't know how. Ideas?
When you add a page with add_submenu_page(), the url should be something like:
wp-admin/admin.php?page=<your_page_handle>
Your page is actually loaded from admin.php (typically). You can add parameters to your links by appending something like &id=3 and then have your main plugin page-loading logic determine which file to include based on the parameter.
For instance
if (isset($_GET['id']) && ((int) $_GET['id']) == 3) {
include 'second_page.php';
} else {
include 'first_page.php';
}
Edit:
I found a trick that may be easier for you, though I haven't thoroughly tested it. Let's say that you have two pages: my_one and my_two. Just call add_submenu_page twice, and set the second page's parent as the first page. This will cause Wordpress to not add a link to the navigation bar, but you can still access your page by navigating to admin.php?page=my_two.
Example:
add_submenu_page(
'my_toplevel_link'
, 'Page Title'
, 'Link Name'
, 'administrator'
, 'my_one' // here's the page handle for page one
, 'my_one_callback'
);
add_submenu_page(
'my_one' // set the parent to your first page and it wont appear
, 'Page Title'
, 'Link Name' // unused
, 'administrator'
, 'my_two'
, 'my_two_callback'
);
Since WP natively supports URLs like wp-admin/admin.php?page=<your_page_handle> you can do sub pages with something like:
wp-admin/admin.php?page=yourpage
wp-admin/admin.php?page=yourpage&sub=2
wp-admin/admin.php?page=yourpage&sub=3
Then in the code that handles wp-admin/admin.php?page=<your_page_handle> you just look at the $_GET and pull up the main page or a sub-page as needed.
I've definitely seen plugins where the admin page has a little row of links across the top linking the various sub-pages.

Resources