Passing the name of selected color from the custom component to `render_callback`

If you just want to get the selected color name, then you can use the getColorObjectByColorValue() function in the @wordpress/block-editor package, which is wp.blockEditor.getColorObjectByColorValue in the browser. The function accepts two parameters: a color list (each is an object with color and name as the properties), and the color (a HEX code, e.g. #17a2b8) that … Read more

WordPress shortcode returns the data before

Change form.php <form action=”<?= $_SERVER[“REQUEST_URI”]; ?>” method=”post”> <input type=”hidden” name=”form_submit_nonce” value=”<?php echo wp_create_nonce(‘form-submit-nonce’); ?>”/> <label for=”id”>ID</label> <input id=”id” name=”id” type=”text” value=”” required /> <input type=”submit” name=”submitid” value=”Submit”> </form> Change plugin file function form_shortcode(){ if ( isset( $_POST[“submitid”] ) && isset($_POST[‘form_submit_nonce’]) && wp_verify_nonce($_POST[‘form_submit_nonce’], ‘form-submit-nonce’) ) { echo “<p>OK</p>”; } else { include “form.php”; } } add_shortcode( … Read more

How to create a field in customize and show that in header.php?

add_action( ‘customize_register’, ‘theme_customize_register’ ); /** * Register individual settings through customizer’s API. * * @param WP_Customize_Manager $wp_customize Customizer reference. */ function theme_customize_register( $wp_customize ) { // You can first start by adding a section $wp_customize->add_section( ‘theme_options’, array( ‘title’ => __( ‘Title of your section’, ‘domain’ ), ‘capability’ => ‘edit_theme_options’, ‘description’ => __( ‘Some description’, ‘domain’ … Read more

How to relocate paypal button gateway on checkout page in woocommerce

Have you tried this? E.g. the paypal button function name is woo_custom_paypal_button. Then add action like this into your function.php or specific plugin: add_action( ‘woocommerce_checkout_before_customer_details’, ‘woo_custom_paypal_button’ ); Or if there’s something that’s already displayed there, and you might want to remove it, first find the function name and then try like this: remove_action( ‘woocommerce_checkout_before_customer_details’, ‘woo_function_to_remove’ … Read more

Correct PHP to output a single result of a Function with SQL Query

Solved it! Amazing what a good nights sleep does! Function: function get_all_rating_criteria_travel6(){ global $wpdb; $rating6 = $wpdb->get_var( ‘SELECT RatingCriteriaText from ratingcriteria WHERE NicheID=1 AND StarRatingID=5;’); echo $rating6; } Code to display: <?php get_all_rating_criteria_travel6(); ?>

Simple WordPress endpoint route doesn’t work

Exact namespace prefix and non-empty endpoint name helped me: add_action(‘rest_api_init’, function () { register_rest_route(‘vku/notifications’, ‘test’, [ ‘methods’ => ‘GET’, ‘callback’ => function (WP_REST_Request $request) { error_log(‘Route “notifications” works’); return new WP_REST_Response(true, 200); }, ]); });

how to serialize() mysql update data

You should not use raw SQL to modify roles and capabilities, it is very bad practice, and unnecessary. Instead, use the roles API, e.g. $role = get_role( ‘subscriber’ ); $role->add_cap( ‘read’ ); Or to add it to a specific user: $user = new WP_User( $user_id ); $user->add_cap( ‘read’ ); Likewise you can remove a capability … Read more

malware undetectable by multiple scans

There are many ways to infect a site – and many ways to hide that infection from the ‘popular’ security plugins. One way to detect malicious code is via a file-hash-compare function. You may need to write your own though (I did, but it’s not perfect). That function would compare each file’s hash with a … Read more