WordPress – Character counter for the caption field of an image

MacBook avec code sur un bureau

For every WordPress image, we can add a caption or a title. It may be useful to add a counter. To do this, you must use both hooks admin_head-post.php and admin_head-post-new.php function cf_caption_count_js() { echo ‘<script type=”text/javascript”> jQuery(document).ready(function() { jQuery(“#attachment_caption”).wrap(“<div></div>”); jQuery(“#attachment_caption”).parent().css(“display”, “table”); jQuery(“#attachment_caption”).parent().css(“width”, “100%”); jQuery(“#attachment_caption”).after(“<span id=\’cf_caption_count\’ style=\’display:table-cell; width: 30px; margin-left: 5px; text-align: right;\’></span>”); jQuery(“#cf_caption_count”).html(jQuery(“#attachment_caption”).val().length); jQuery(“#attachment_caption”).keyup(function() … Read more

PHP – CURL Authentication

MacBook avec code sur un bureau

To authenticate a cURL request in PHP, the option to know is CURLOPT_USERPWD. It sends a username / password pair in the user:password format. Basic authentication $ch = curl_init(‘https://exemple.com/api’); curl_setopt($ch, CURLOPT_USERPWD, ‘utilisateur:motdepasse’); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $reponse = curl_exec($ch); if ($reponse === false) { throw new RuntimeException(curl_error($ch)); } curl_close($ch); Setting … Read more

Categories PHP