New answers tagged

0 votes

Redirect customer to login if not logged in when proceeding to checkout

Add the code below to your child's theme functions.php file. function wp_checkout_login_redirect() { if ( ! is_user_logged_in()&& (is_cart() || is_checkout() ) ) { wp_redirect(...
user avatar
0 votes

Conditionally run function based on custom meta value?

Instead of conditionally adding an add_action() call, you can just add it and run the function it hooks to—its callback—conditionally instead. For example: add_action( '...
user avatar
  • 10.4k
0 votes
Accepted

Hook before user is created and make some custom validation

You need to add , 10, 3 after your closure to set the hook priority and (more importantly) the number of accepted arguments - otherwise $user_email and $errors will not be passed. add_action( '...
user avatar
  • 35.6k
0 votes

getEntityRecord without knowing the post type

As of today, you can use the following to get the current post type : import { useSelect } from '@wordpress/data'; const postType = useSelect( (select) => select('core/editor')....
user avatar
1 vote

Is there a JavaScript equivalent of get_post_field?

The @wordpress/hooks package only gives you a JS-like equivalent to the PHP-based hook system in WordPress - they are entirely separate, and don't bring any native WP PHP functions to the table. What ...
user avatar
  • 35.6k
2 votes
Accepted

Append a code when at the current page in wp_list_pages()

I would use a custom walker and then extend the Walker_Page::start_el() method, like so: // Based on Walker_Page for WordPress v6.0 // @link https://github.com/WordPress/wordpress-develop/blob/6.0/src/...
user avatar
  • 32.1k
0 votes

Best possible way to get all options

There is a solution to query all the options that can be set by the plugin, if these are registered settings. I assume you register the settings as follows: register_setting( 'plugin-settings-group', '...
user avatar
1 vote

How to remove js ui library added by default by wordpress

The related library is registered with a function called wp_default_scripts. File location (for Wordpress 6.0): ...wp-includes/script-loader.php remove to remove the relevant script; The add function ...
user avatar
3 votes
Accepted

What is the "correct" way to add hooks or similar PHP behavior to a blocktheme?

I'm not the most experienced in block themes, but from what I've seen of them so far I feel pretty confident in saying that the functionality you describe should be implemented as a block. But it's ...
user avatar
0 votes

Restrict editing of post type to list stored in user meta

Ideally access controls would be implemented via WordPress's Roles and Capabilities system. But in highly-granular cases such as limiting access to a single post to a few users, the map_meta_cap ...
user avatar
  • 5,340

Top 50 recent answers are included