PHP – Delete Special Characters
To effectively remove special characters in a string, just use the preg_replace method. $string = preg_replace(‘/[^a-zA-Z0-9]/s’, ”, $string);
Il n'y a pas de questions bêtes
To effectively remove special characters in a string, just use the preg_replace method. $string = preg_replace(‘/[^a-zA-Z0-9]/s’, ”, $string);
To make queries on WordPress, I’m used to using WP_Query($args). In this example, we want to add a LIKE = “%title%” in our query. Here is a simple request that adds all our posts in the array a_response_array: $args = array( ‘post_status’ => ‘publish’, ); // The Query $query = new WP_Query( $args ); // … Read more
To make all WordPress functions accessible in a PHP script, just include wp-load.php require_once(‘../wp-load.php’); to test, we can for example display the version of WordPress $blog_info = get_bloginfo(‘version’); print_r($blog_info);
Using the getElementsByTagName method to navigate and find the child in question. $number_orders = $image_1->getElementsByTagName(‘number_order’); foreach ($number_orders as $key => $value) { $value->nodeValue = “teaser”; }
To find out if the current user is an administrator in WordPress, i.e. if they have the right to set up options: if ( ! current_user_can( ‘manage_options’ ) ) { echo “You are not admin”; } else { echo “You are an admin”; }
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
To retrieve the value of the selected button: $(‘input[name=radioName]:checked’, ‘#myForm’).val()
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
jQuery-File-Upload How to use the basic solution from jQuery-File-Upload and make it work on every browser, with a special dedication to Internet Explorer. The basic version has the advantage of not being overloaded with libraries, and above all it is much easier to import into a site that already exists. Libraries <script type=”text/javascript” src=”//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js”></script><script type=”text/javascript” … Read more
When it is necessary to have a predefined order in a query, it is possible to change the order of the items by using a CASE in the ORDER BY. In this example id 12 must appear before id 2. SELECT * FROM channel ORDER BY ( CASE WHEN id = 1 THEN 1 WHEN … Read more