Check condition before changing post status in wordpress - wordpress

I have a form in the front end which enables users to submit posts. These posts are by default saved as pending. It can only set to publish by the admin. Before publishing certain conditions are to be checked before its set as published.
If the condition is true set post status as publish. If not set it as pending. What is the appropriate action hook to achieve this?

look here, there is 6 hooks than you can use for that :
https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/post.php#L4058
just take care that the values that you use in your condition can also be change on this hooks then you have to test where you have the values you need.

Related

WooCommerce API List all products with a specific attribute

Using the WooCommerce API I want to send an HTTP GET request to download all products with a specific attribute.
The documentation says the URL to do this with is this
/wp-json/wc/v3/products
And I can add parameters to the URL in order to filter the products.
I have successfully added filters for page and page count:
wp-json/wc/v3/products?per_page=100&page=10
I have also managed to get only available products with this parameter:
wp-json/wc/v3/products?&stock_status=instock
However, I cannot manage to add a filter for the attributes. I have tried the following ways to write the URL and non of them work
wp-json/wc/v3/products/?attribute=1
wp-json/wc/v3/products/?
wp-json/wc/v3/products/?attribute_pa_емаг=Да
wp-json/wc/v3/products/?filter[pa_емаг]=10
What would be the correct way to write the URL?
(Note: The attribute is pa_емаг and its value is Да)
The correct call would be:
/wp-json/wc/v3/products?attribute={attribute-taxonomy}&attribute_term={term-id/tag_ID}
Where attribute-taxonomy would be full slug in your case "pa_емаг", and term-id/tag_ID the id of "Да".

Show all Available Bookable Product in "WooCommerce Bookings" extension

User select date, time and then search
After click "Search Availability", it is needs to show all the available product within the provided date and time slot.
Using "WooCommerce Bookings" extension, how to do it?
I have customized both WooCommerce & Booking Extension:
To save bookable product :
woocommerce-bookings/includes/class-wc-bookings-admin.php
Method executes saving :
save_product_data( $post_id ) at line 434
File for searching listing page:
woocommerce/templates/archive-product.php
Skip loading boooking:
/wp-content/plugins/woocommerce-bookings/includes/booking-form/class-wc-booking-form.php
skip loading date time:
/wp-content/plugins/woocommerce-bookings/assets/js/booking-form.js
/templates/single-product/add-to-cart/booking.php
I tried to solve it as database driven solution first but data seems like unstructured. Also without identifying the Property and Method at the Code, you won't be able to make any customization. Doing customization the plugin and extension is easy but he hard part is understand the code structure and flow. Once you get it, you may do any level of customization.
There are lots of files (.PHP,JS) you needs to check but I have made it narrow for you. You only check the mentioned file above and can do your modification most of the case.

wp_delete_post() force deleting post, override ignored

I have set up a custom post type with a way to manage the posts on the front end of the site. On the front end users have the option to edit or delete posts.
When the user clicks delete, I run the wp_delete_post() function, to send the post to the trash. I don't want the post to bypass the trash, I would actually like the post to be sent to the trashcan.
The second parameter of the wp_delete_post is a boolean, true/false , which is supposed to dicate weather or not to bypass the trash.
The first is the ID of the post you'd like to delete.
http://codex.wordpress.org/Function_Reference/wp_delete_post
Here is my function:
wp_delete_post( $cpt_id, false );
As you can see, I've set the second parameter to false, but it still bypasses the trash and gets deleted from the server.
Is this a bug that I should report to core, or am I missing something simple?
Thanks!
Since you never want to delete and always want to trash, you could use wp_trash_post() instead. (http://codex.wordpress.org/Function_Reference/wp_trash_post)
However, that simply calls wp_delete_post() for you.
If none of your deletes are going to the trash, make sure that EMPTY_TRASH_DAYS is not set to 0 somewhere. (e.g. your wp-config.php) (http://codex.wordpress.org/Editing_wp-config.php)
HTH,
=C=

Run checks on drupal_goto function

I have a strange issue with a drupal site and a custom form. I have a custom module that puts a form as a block...simple input field that posts a search query to a store locator.
The form keeps getting overridden and the action/url changes randomly at random times. I need a quick solution to this whilst we debug the real issue that's causing this.
I need to write an if statement that checks the drupal_goto function that goes along the lines of if drupal_goto == /store-locator then run else change the drupal_goto action to /store-locator.
Any help would be appreciated.

trying to find the comment hook I need for wordpress?

I'm writing a wordpress plugin that will execute a certain function when a user submits a comment. The only issue is I'm using the hook "comment_post" which works but if that comment gets stopped by akismet I'm still logging that comment but now my numbers are off from what's on the actual site. Is there a comment_approved type hook I should be using instead?
this is something I was looking at not too long ago,
Only thing is the admin has to approve/edit the comment before the function would run..
using the wordpress admin hook:
wp_set_comment_status()
This function is run after changing the status of the comment by the admin..,
this looks for the status from 4 options
status ("delete", "approve", "spam", "hold").
You can check for the status approve?
do your caculation from there?

Resources