Today I Learned - Rocky Kev

TIL Default Params in PHP

POSTED ON:

TAGS:

In your markup file:

<?php //echo do_shortcode('[rockyShortcode color="red"]' . "BLAH BLAH BLAH" . "[/rockyShortcode]"); ?>

In your PHP file:

add_shortcode('rockyShortcode', 'rockysFunction'); // Place [html5_shortcode_demo_2] in Pages, Posts now.

// Throwaway function
function rockysFunction($atts, $content = null)
{

    $atts = shortcode_atts(array(
        'color'  => 'blue',
        'size' => '24px'
    ), $atts);

    $textColor = 'color: ' . esc_attr($atts['color']) . ';';
    $textSize = 'font-size: ' . esc_attr($atts['size']) . ';';

    $element = '<div class="custom-class" style="' . $textColor . $textSize .  '">';
    $element .= $content;
    $element .= '</div>';

    return $element;

}

Related TILs

Tagged:

TIL how NGINX knows to look for index.html vs index.php

What happens when visitor hits /foo/bar URL?

TIL php-fpm

PHP runs as a separated service when using PHP-FPM. By using this PHP version as language interpreter, requests are processed through a TCP/IP socket; so that the Nginx web server only handles the HTTP requests and PHP-FPM interprets the PHP code. The fact of having two separate services is key for increasing efficiency.

TIL the difference between single-threaded & multi-threaded architecture

For web dev, we don't need it. We're not bottle-necked by the processing power. We're instead bottlenecked by the ability to read files/databases. We can simulate multi-threading (and improve our app's performance) using async/await.