Is this shortcode safe?

[ad_1]

I used chatgpt to create a shortcode to get the product name of a WooCommerce product by id, this is what I got:

function get_woocommerce_product_name_by_id($atts) {
// Extract the attributes from the shortcode
$atts = shortcode_atts(array(
‘id’ => ”,
), $atts);

if (empty($atts[‘id’])) {
return ‘Please provide a product ID.’;
}

$product = wc_get_product($atts[‘id’]);

if (!$product) {
return ‘Product not found.’;
}

return $product->get_name();
}
add_shortcode(‘product_name’, ‘get_woocommerce_product_name_by_id’);

​

Could someone please tell me if the code is safe? does it have something that could break my site?

Thanks!

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer