Generation

generate functionSat, 28 Jan 2023

The full JS and PHP code is a "subscribe" button with a subscriber counter and sending data to the database for the site on the Wordpress CMS; Make it so that the user can click on the "subscribe to the author" button, data about the subscriber and who they subscribed to is sent to the database, the number of subscribers to this author is displayed on the button. Make a shortcode for displaying a button with a counter

function subscribe($atts) { ob_start(); $author = get_userdata(get_the_author_meta('ID')); $count = $author->subscribers; ?> <div class="subscribe"> <button>Subscribe to <?php echo $author->display_name; ?></button> <span class="count"><?php echo $count; ?></span> </div> <?php return ob_get_clean(); } add_shortcode('subscribe', 'subscribe'); function subscribe_script() { wp_enqueue_script('script', get_stylesheet_directory_uri() . '/js/subscribe.js'); wp_localize_script('script', 'ajaxurl', admin_url('admin-ajax.php')); } add_action('wp_enqueue_scripts', 'subscribe_script');

Questions about programming?Chat with your personal AI assistant