antispambot()
      ...
  zeroize()
$ whoami
Yoav Farhi
Developer
blog.yoavfarhi.com
@yoavf
$ pwd
//antispambot()

/**
 * Converts email addresses characters to HTML entities
 * to block spam bots.
 *
 * @return string Converted email address.
 */
function antispambot($emailaddy, $mailto=0)
?>


Email me at:
<?php echo antispambot('yoav@farhi.org'); ?>

Email me at:
yo&#97;v&#64;&#102;a&#114;&#104;&#105;&#46;org
//checked(), selected(), disabled()

/**
 * Outputs the html checked attribute.
 *
 * Compares the first two arguments and if identical
 * marks as checked
 *
 * @return string html attribute or empty string
 */
function checked( $checked, $current = true, $echo = true )

?>

<input type='checkbox' name='postlink' value='1' <?php if
( 1 == $postlink ) echo 'checked="checked"'; ?> />

<input type="checkbox" name="postlink" value="1" <?php
checked( $postlink, 1 ); ?> />
//human_time_diff()

/**
 * Determines the difference between two timestamps.
 *
 * The difference is returned in a human readable
 * format such as "1 hour", * "5 mins", "2 days".
 * @return string Human readable time difference.
*/
function human_time_diff( $from, $to )
?>

<?php echo human_time_diff(get_comment_time('U')).' ago';?>

//2 days ago
//wp_list_pluck()

/**
 * Pluck a certain field out of each object in a list.
 * @return array
 */
function wp_list_pluck( $list, $field );

$foods = array(
! array(
! ! 'name' =>     'Banana',
! ! 'color' =>    'Yellow',
! ),
! array(
! ! 'name' =>     'Apple',
! ! 'color' =>    'Red',
! ),
);

$foods_names = wp_list_pluck( $foods, 'name' );
//$foods_names = array( 'Banana','Apple' );

$color_names = wp_list_pluck( $foods, 'color' );
//$color_names = array( 'Yellow','Red' );
//wp_localize_script()




  //wordcamp.js

  jQuery(document).ready(function($){
    alert('Welcome to WordCamp Jerusalem 2013');
    });
  });
//wp_localize_script()

/**
 * Used to localizes a script.
 *
 * @return bool Whether the localization was
 * added successfully.
 */
function wp_localize_script( $handle, $object_name, $l10n );
?>

<?php
wp_enqueue_script( 'wordcamp-jeruslaem', 'wordcamp.js' );
$translation_array = array(
 'welcome' => __( 'Welcome to WordCamp Jerusalem 2013' )
);
wp_localize_script( 'wordcamp-jeruslaem', 'wc_strings',
                   $translation_array );
?>

<script>
  var wc_strings = {
     welcome: '2013 ‫,'ברוכים הבאים לוורדקמפ ירושלים‬
  };
</script>
//wp_localize_script()




  // WordCamp.js

  jQuery(document).ready(function($){
    alert( wc_strings.welcome );
    });
  });
Let’s get to work


                       cc-by galato901
                    http://yoav.fr/towork
//wp_kses()

/**
 * Filters content and keeps only allowable HTML elements.
 *
 * @return string Filtered content with only
 * allowed HTML elements
 */

function wp_kses($string, $allowed_html, $allowed_protocols);

$tags = array(
    'em' => array(),
    'strong' => array()
);

$html = <<<EOT
<p>
! <b>BOLD</b> is different than <em>italics</em>
</p>
EOT;

echo wp_kses( $html, $tags );
//BOLD is different than <em>italics</em>
//wp_mail()

/**
 * Send mail, similar to PHP's mail
 *
 * @return bool Whether the email contents were sent
 * successfully.
 */

function wp_mail( $to, $subject, $message, $headers =
'', $attachments = array() );

$to = 'yoav@farhi.org';
$subject = 'I love WordPres';
$message = 'WordPress is The Awesome!!!1';

$mail = wp_mail( $to, $subject, $message );

if( $mail )
! echo 'Mail sent';
//wp_remote_get()

/**
 * Retrieve the raw response from the HTTP
 * request using the GET method.
 *
 * @return WP_Error|array The response or
 *         WP_Error on failure.
 */
function wp_remote_get( $url, $args = array() );

$url = 'http://nominatim.openstreetmap.org/search?
q=Netanya&format=json';

$response = wp_remote_get( $url );

if ( ! is_wp_error( $response ) )
! //Do something
//wp_trim_words()

/**
 * Trims text to a certain number of words.
 *
 * @return string Trimmed text.
 */

function wp_trim_words( $text, $num_words = 55, $more = null );

$text = "I love WordPress and Joomla";
echo wp_trim_words( $text, 3 );

// I Love WordPress
//zeroise()

/**
 * Add leading zeros when necessary.
 *
 * @return string Adds leading zeros to number if needed.
 */
function zeroise($number, $threshold);

$comno = get_comments_number();
// $comno = '2'
$zeroed = zeroise($comno, 2);
// $zeroed = '02'
cc by-nc-nd anarosaphotography
           http://yoav.fr/happy




Happy
questions ?
How can I get involved
with the WordPress.org
      community?

WordPress: From Antispambot to Zeroize

  • 1.
    antispambot() ... zeroize()
  • 2.
  • 3.
  • 4.
  • 6.
    //antispambot() /** * Convertsemail addresses characters to HTML entities * to block spam bots. * * @return string Converted email address. */ function antispambot($emailaddy, $mailto=0) ?> Email me at: <?php echo antispambot('[email protected]'); ?> Email me at: yo&#97;v&#64;&#102;a&#114;&#104;&#105;&#46;org
  • 7.
    //checked(), selected(), disabled() /** * Outputs the html checked attribute. * * Compares the first two arguments and if identical * marks as checked * * @return string html attribute or empty string */ function checked( $checked, $current = true, $echo = true ) ?> <input type='checkbox' name='postlink' value='1' <?php if ( 1 == $postlink ) echo 'checked="checked"'; ?> /> <input type="checkbox" name="postlink" value="1" <?php checked( $postlink, 1 ); ?> />
  • 8.
    //human_time_diff() /** * Determinesthe difference between two timestamps. * * The difference is returned in a human readable * format such as "1 hour", * "5 mins", "2 days". * @return string Human readable time difference. */ function human_time_diff( $from, $to ) ?> <?php echo human_time_diff(get_comment_time('U')).' ago';?> //2 days ago
  • 9.
    //wp_list_pluck() /** * Plucka certain field out of each object in a list. * @return array */ function wp_list_pluck( $list, $field ); $foods = array( ! array( ! ! 'name' => 'Banana', ! ! 'color' => 'Yellow', ! ), ! array( ! ! 'name' => 'Apple', ! ! 'color' => 'Red', ! ), ); $foods_names = wp_list_pluck( $foods, 'name' ); //$foods_names = array( 'Banana','Apple' ); $color_names = wp_list_pluck( $foods, 'color' ); //$color_names = array( 'Yellow','Red' );
  • 10.
    //wp_localize_script() //wordcamp.js jQuery(document).ready(function($){ alert('Welcome to WordCamp Jerusalem 2013'); }); });
  • 11.
    //wp_localize_script() /** * Usedto localizes a script. * * @return bool Whether the localization was * added successfully. */ function wp_localize_script( $handle, $object_name, $l10n ); ?> <?php wp_enqueue_script( 'wordcamp-jeruslaem', 'wordcamp.js' ); $translation_array = array( 'welcome' => __( 'Welcome to WordCamp Jerusalem 2013' ) ); wp_localize_script( 'wordcamp-jeruslaem', 'wc_strings', $translation_array ); ?> <script> var wc_strings = { welcome: '2013 ‫,'ברוכים הבאים לוורדקמפ ירושלים‬ }; </script>
  • 12.
    //wp_localize_script() //WordCamp.js jQuery(document).ready(function($){ alert( wc_strings.welcome ); }); });
  • 13.
    Let’s get towork cc-by galato901 http://yoav.fr/towork
  • 14.
    //wp_kses() /** * Filterscontent and keeps only allowable HTML elements. * * @return string Filtered content with only * allowed HTML elements */ function wp_kses($string, $allowed_html, $allowed_protocols); $tags = array( 'em' => array(), 'strong' => array() ); $html = <<<EOT <p> ! <b>BOLD</b> is different than <em>italics</em> </p> EOT; echo wp_kses( $html, $tags ); //BOLD is different than <em>italics</em>
  • 15.
    //wp_mail() /** * Sendmail, similar to PHP's mail * * @return bool Whether the email contents were sent * successfully. */ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ); $to = '[email protected]'; $subject = 'I love WordPres'; $message = 'WordPress is The Awesome!!!1'; $mail = wp_mail( $to, $subject, $message ); if( $mail ) ! echo 'Mail sent';
  • 16.
    //wp_remote_get() /** * Retrievethe raw response from the HTTP * request using the GET method. * * @return WP_Error|array The response or * WP_Error on failure. */ function wp_remote_get( $url, $args = array() ); $url = 'http://nominatim.openstreetmap.org/search? q=Netanya&format=json'; $response = wp_remote_get( $url ); if ( ! is_wp_error( $response ) ) ! //Do something
  • 17.
    //wp_trim_words() /** * Trimstext to a certain number of words. * * @return string Trimmed text. */ function wp_trim_words( $text, $num_words = 55, $more = null ); $text = "I love WordPress and Joomla"; echo wp_trim_words( $text, 3 ); // I Love WordPress
  • 18.
    //zeroise() /** * Addleading zeros when necessary. * * @return string Adds leading zeros to number if needed. */ function zeroise($number, $threshold); $comno = get_comments_number(); // $comno = '2' $zeroed = zeroise($comno, 2); // $zeroed = '02'
  • 19.
    cc by-nc-nd anarosaphotography http://yoav.fr/happy Happy
  • 20.
  • 21.
    How can Iget involved with the WordPress.org community?