SlideShare ist ein Scribd-Unternehmen logo
1 von 76
‫התוסף הראשון שלי‬
   ‫יואב פרחי, ‪yoav@farhi.org‬‬
‫התוסף הראשון שלי‬
   ‫יואב פרחי, ‪yoav@farhi.org‬‬
‫התוסף הראשון שלי‬
RTL Tester
<?php

/*
Plugin Name: RTL Tester
Plugin URI: http://wordpress.org/extend/plugins/rtl-tester/
Description: This plugin can be used to test WordPress themes
and plugins with Right To Left (RTL) text direction. Simply
activate this plugin to enable RTL and deactivate to return to
normal operation. Yes, this is simplest plugin in the world.
Author: <a href="http://blog.yoavfarhi.com">Yoav Farhi</a>, <a
href="http://automattic.com">Automattic</a>
Version: 0.2
*/

$text_direction = 'rtl';
‫תשתית‬
class RTLTester {

    function __construct() {

        load_plugin_textdomain( 'rtl-tester' );

        // Hooks and filters
    }

}

new RTLTester;
‫תשתית‬
class RTLTester {

    function __construct() {

        load_plugin_textdomain( 'rtl-tester' );

        // Hooks and filters
    }

}

new RTLTester;
‫ווים‬
hooks
<?php wp_footer(); ?>

</body>
</html>
function wp_footer() {
    do_action('wp_footer');
}
add_action( 'wp_footer', 'my_add_credit' );
add_action( 'wp_footer', 'my_add_credit' );

function my_add_credit() {
    echo "I did this!";
}
‫פילטרים‬
‫‪filters‬‬
function the_content($more_link_text = null, $stripteaser = 0) {

    $content = get_the_content($more_link_text, $stripteaser);

    $content = apply_filters('the_content', $content);
    echo $content;
}
function the_content($more_link_text = null, $stripteaser = 0) {

    $content = get_the_content($more_link_text, $stripteaser);

    $content = apply_filters('the_content', $content);
    echo $content;
}
function the_content($more_link_text = null, $stripteaser = 0) {

    $content = get_the_content($more_link_text, $stripteaser);

    $content = apply_filters('the_content', $content);
    echo $content;
}



add_filter( 'the_content', 'my_wordpress_link' );
function the_content($more_link_text = null, $stripteaser = 0) {

    $content = get_the_content($more_link_text, $stripteaser);

    $content = apply_filters('the_content', $content);
    echo $content;
}



add_filter( 'the_content', 'my_wordpress_link' );

function my_wordpress_link( $content ){




}
function the_content($more_link_text = null, $stripteaser = 0) {

    $content = get_the_content($more_link_text, $stripteaser);

    $content = apply_filters('the_content', $content);
    echo $content;
}



add_filter( 'the_content', 'my_wordpress_link' );

function my_wordpress_link( $content ){

    $content = str_replace( 'WordPress', '<a href="http://
wordpress.org">WordPress</a>', $content );
    return $content


}
‫ביצוע פעולה‬   ‫פעולה על משתנה‬


 add_action      add_filter

 do_action      apply_filters
‫תשתית‬
class RTLTester {

    function __construct() {

        load_plugin_textdomain( 'rtl-tester' );

        // Hooks and filters
    }




}

new RTLTester;
‫פונקציות עזר‬
class RTLTester {

    function __construct() { . . .




}

new RTLTester;
‫פונקציות עזר‬
class RTLTester {

    function __construct() { . . .

    function get_direction() {
        if ( is_rtl() )
             $direction = 'rtl';
        else
             $direction = 'ltr';
        return $direction;
    }

}

new RTLTester;
‫פונקציות עזר‬
class RTLTester {

    function __construct() { . . .

    function get_direction() {
        $direction = is_rtl() ? 'rtl' : 'ltr';
        return $direction;
    }




}

new RTLTester;
function admin_bar_rtl_switcher() {
function admin_bar_rtl_switcher() {
    global $wp_admin_bar;
function admin_bar_rtl_switcher() {
    global $wp_admin_bar;

   if ( !is_super_admin() || !is_admin_bar_showing() )
     return;
function admin_bar_rtl_switcher() {
    global $wp_admin_bar;

   if ( !is_super_admin() || !is_admin_bar_showing() )
     return;

   $direction = $this->get_direction();
function admin_bar_rtl_switcher() {
    global $wp_admin_bar;

   if ( !is_super_admin() || !is_admin_bar_showing() )
     return;

   $direction = $this->get_direction();
   $direction = ( $direction == 'rtl' ) ? 'ltr' : 'rtl';
function admin_bar_rtl_switcher() {
    global $wp_admin_bar;

   if ( !is_super_admin() || !is_admin_bar_showing() )
     return;

   $direction = $this->get_direction();
   $direction = ( $direction == 'rtl' ) ? 'ltr' : 'rtl';

   $wp_admin_bar->add_menu(array(
function admin_bar_rtl_switcher() {
    global $wp_admin_bar;

   if ( !is_super_admin() || !is_admin_bar_showing() )
     return;

   $direction = $this->get_direction();
   $direction = ( $direction == 'rtl' ) ? 'ltr' : 'rtl';

   $wp_admin_bar->add_menu(array(
     'id' => 'RTL',
function admin_bar_rtl_switcher() {
        global $wp_admin_bar;

       if ( !is_super_admin() || !is_admin_bar_showing() )
         return;

       $direction = $this->get_direction();
       $direction = ( $direction == 'rtl' ) ? 'ltr' : 'rtl';

        $wp_admin_bar->add_menu(array(
          'id' => 'RTL',
          'title' => sprintf( __('Switch to %s', 'rtl-
tester'), strtoupper( $direction ) ),
function admin_bar_rtl_switcher() {
        global $wp_admin_bar;

       if ( !is_super_admin() || !is_admin_bar_showing() )
         return;

       $direction = $this->get_direction();
       $direction = $direction == 'rtl' ? 'ltr' : 'rtl';

        $wp_admin_bar->add_menu(array(
          'id' => 'RTL',
          'title' => sprintf( __('Switch to %s', 'rtl-
tester'), strtoupper( $direction ) ),
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) );
          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;

          $direction = $this->get_direction();
          $direction = $direction == 'rtl' ? 'ltr' : 'rtl';

          $wp_admin_bar->add_menu(array(
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
  tester'), strtoupper( $direction ) ),
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) );
          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;
$translation = __('Switch to %s', 'rtl-tester');
          $direction = $this->get_direction();
          $direction = $direction == 'rtl' ? 'ltr' : 'rtl';

          $wp_admin_bar->add_menu(array(
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
  tester'), strtoupper( $direction ) ),
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) );
          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;
$translation = __('Switch to %s', 'rtl-tester');
// $translation = "-‫% לעבור ל‬s"
          $direction = $this->get_direction();
          $direction = $direction == 'rtl' ? 'ltr' : 'rtl';

          $wp_admin_bar->add_menu(array(
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
  tester'), strtoupper( $direction ) ),
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) );
          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;
$translation = __('Switch to %s', 'rtl-tester');
// $translation = "-‫% לעבור ל‬s"
          $direction = $this->get_direction();
          $direction = $direction == 'rtl' ? 'ltr' : 'rtl';
$direction = 'ltr';
          $wp_admin_bar->add_menu(array(
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
  tester'), strtoupper( $direction ) ),
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) );
          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;
$translation = __('Switch to %s', 'rtl-tester');
// $translation = "-‫% לעבור ל‬s"
          $direction = $this->get_direction();
          $direction = $direction == 'rtl' ? 'ltr' : 'rtl';
$direction = 'ltr';
$direction = strtoupper( $direction );
          $wp_admin_bar->add_menu(array(
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
  tester'), strtoupper( $direction ) ),
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) );
          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;
$translation = __('Switch to %s', 'rtl-tester');
// $translation = "-‫% לעבור ל‬s"
          $direction = $this->get_direction();
          $direction = $direction == 'rtl' ? 'ltr' : 'rtl';
$direction = 'ltr';
$direction = strtoupper( $direction );
          $wp_admin_bar->add_menu(array(
// $direction = LTR
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
  tester'), strtoupper( $direction ) ),
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) );
          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;
$translation = __('Switch to %s', 'rtl-tester');
// $translation = "-‫% לעבור ל‬s"
          $direction = $this->get_direction();
          $direction = $direction == 'rtl' ? 'ltr' : 'rtl';
$direction = 'ltr';
$direction = strtoupper( $direction );
          $wp_admin_bar->add_menu(array(
// $direction = LTR
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
$title = sprintf( $translation, $direction )
  tester'), strtoupper( $direction ) ),
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) );
          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;
$translation = __('Switch to %s', 'rtl-tester');
// $translation = "-‫% לעבור ל‬s"
          $direction = $this->get_direction();
          $direction = $direction == 'rtl' ? 'ltr' : 'rtl';
$direction = 'ltr';
$direction = strtoupper( $direction );
          $wp_admin_bar->add_menu(array(
// $direction = LTR
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
$title = sprintf( $translation, $direction )
  tester'), strtoupper( $direction ) ),
// $title = "-‫ לעבור ל‬LTR"
function admin_bar_rtl_switcher() {
        global $wp_admin_bar;

       if ( !is_super_admin() || !is_admin_bar_showing() )
         return;

       $direction = $this->get_direction();
       $direction = $direction == 'rtl' ? 'ltr' : 'rtl';

        $wp_admin_bar->add_menu(array(
          'id' => 'RTL',
          'title' => sprintf( __('Switch to %s', 'rtl-
tester'), strtoupper( $direction ) ),

       ) );
   }
function admin_bar_rtl_switcher() {
       global $wp_admin_bar;

       if ( !is_super_admin() || !is_admin_bar_showing() )
         return;

       $direction = $this->get_direction();
       $direction = $direction == 'rtl' ? 'ltr' : 'rtl';

        $wp_admin_bar->add_menu(array(
          'id' => 'RTL',
          'title' => sprintf( __('Switch to %s', 'rtl-
tester'), strtoupper( $direction ) ),
          'href' => add_query_arg( array( 'd' => $direction ) )
        ) );
    }
function admin_bar_rtl_switcher() {
       global $wp_admin_bar;

       if ( !is_super_admin() || !is_admin_bar_showing() )
         return;

       $direction = $this->get_direction();
       $direction = $direction == 'rtl' ? 'ltr' : 'rtl';

        $wp_admin_bar->add_menu(array(
          'id' => 'RTL',
          'title' => sprintf( __('Switch to %s', 'rtl-
tester'), strtoupper( $direction ) ),
          'href' => add_query_arg( array( 'd' => $direction ) )
        ) );
    }
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;

          $direction = $this->get_direction();
$url = 'http://mysite.com'
          $direction = $direction == 'rtl' ? 'ltr' : 'rtl';

          $wp_admin_bar->add_menu(array(
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
  tester'), strtoupper( $direction ) ),
            'href' => add_query_arg( array( 'd' => $direction ) )
          ) );
      }
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;

          $direction = $this->get_direction();
$url = 'http://mysite.com'
add_query_arg( array( ='d' => 'rtl'), $url ) ? 'ltr' : 'rtl';
          $direction    $direction == 'rtl'

          $wp_admin_bar->add_menu(array(
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
  tester'), strtoupper( $direction ) ),
            'href' => add_query_arg( array( 'd' => $direction ) )
          ) );
      }
function admin_bar_rtl_switcher() {
          global $wp_admin_bar;

          if ( !is_super_admin() || !is_admin_bar_showing() )
            return;

          $direction = $this->get_direction();
$url = 'http://mysite.com'
add_query_arg( array( ='d' => 'rtl'), $url ) ? 'ltr' : 'rtl';
          $direction    $direction == 'rtl'

          $wp_admin_bar->add_menu(array(
// $url = 'http://mysite.com/?d=rtl'
            'id' => 'RTL',
            'title' => sprintf( __('Switch to %s', 'rtl-
  tester'), strtoupper( $direction ) ),
             'href' => add_query_arg( array( 'd' => $direction ) )
          ) );
      }
function admin_bar_rtl_switcher() {
       global $wp_admin_bar;

       if ( !is_super_admin() || !is_admin_bar_showing() )
         return;

       $direction = $this->get_direction();
       $direction = $direction == 'rtl' ? 'ltr' : 'rtl';

        $wp_admin_bar->add_menu(array(
          'id' => 'RTL',
          'title' => sprintf( __('Switch to %s', 'rtl-
tester'), strtoupper( $direction ) ),
          'href' => add_query_arg( array( 'd' => $direction ) )
        ) );
    }
‫קריאה לפונקציה‬
class RTLTester {

    function __construct() {



    }

    function admin_bar_rtl_switcher() {   ...

    function get_direction() {   ...
}

new RTLTester;
‫קריאה לפונקציה‬
class RTLTester {

    function __construct() {
            add_action( 'admin_bar_menu', array( $this,
    'admin_bar_rtl_switcher' ), 999 );
    }

    function admin_bar_rtl_switcher() {   ...

    function get_direction() {   ...
}

new RTLTester;
function set_direction() {
function set_direction() {
    global $wp_locale;
function set_direction() {
    global $wp_locale;

   $_user_id = get_current_user_id();
function set_direction() {
    global $wp_locale;

   $_user_id = get_current_user_id();

   if ( isset( $_GET['d'] ) ) {
function set_direction() {
    global $wp_locale;

   $_user_id = get_current_user_id();

   if ( isset( $_GET['d'] ) ) {
      $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr';
function set_direction() {
    global $wp_locale;

   $_user_id = get_current_user_id();

   if ( isset( $_GET['d'] ) ) {
      $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr';
      update_user_meta( $_user_id, 'rtladminbar', $direction );
function set_direction() {
    global $wp_locale;

   $_user_id = get_current_user_id();

   if ( isset( $_GET['d'] ) ) {
      $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr';
      update_user_meta( $_user_id, 'rtladminbar', $direction );
   } else {
function set_direction() {
    global $wp_locale;

   $_user_id = get_current_user_id();

   if ( isset( $_GET['d'] ) ) {
      $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr';
      update_user_meta( $_user_id, 'rtladminbar', $direction );
   } else {
     $direction = get_user_meta($_user_id, 'rtladminbar', true);
function set_direction() {
    global $wp_locale;

   $_user_id = get_current_user_id();

   if ( isset( $_GET['d'] ) ) {
      $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr';
      update_user_meta( $_user_id, 'rtladminbar', $direction );
   } else {
     $direction = get_user_meta($_user_id, 'rtladminbar', true);
     if ( false === $direction )
function set_direction() {
    global $wp_locale;

   $_user_id = get_current_user_id();

   if ( isset( $_GET['d'] ) ) {
      $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr';
      update_user_meta( $_user_id, 'rtladminbar', $direction );
   } else {
     $direction = get_user_meta($_user_id, 'rtladminbar', true);
     if ( false === $direction )
         $direction = $wp_locale->text_direction;
   }
function set_direction() {
    global $wp_locale;

    $_user_id = get_current_user_id();

    if ( isset( $_GET['d'] ) ) {
       $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr';
       update_user_meta( $_user_id, 'rtladminbar', $direction );
    } else {
      $direction = get_user_meta($_user_id, 'rtladminbar', true);
      if ( false === $direction )
          $direction = $wp_locale->text_direction;
    }

    $wp_locale->text_direction = $direction;

}
‫קריאה לפונקציה‬
class RTLTester {

    function __construct() {
        add_action( 'admin_bar_menu', array( $this,
'admin_bar_rtl_switcher' ), 999 );

    }

    function admin_bar_rtl_switcher() {
                                          ...
    function set_direction() {
                                 ...
    function get_direction() {
}

new RTLTester;
‫קריאה לפונקציה‬
class RTLTester {

    function __construct() {
        add_action( 'admin_bar_menu', array( $this,
'admin_bar_rtl_switcher' ), 999 );
        add_action( 'init', array( $this, 'set_direction' ) );
    }

    function admin_bar_rtl_switcher() {
                                          ...
    function set_direction() {
                                 ...
    function get_direction() {
}

new RTLTester;
One last thing...
class RTLTester {

    function __construct() {


        add_action( 'admin_bar_menu', array( $this,
'admin_bar_rtl_switcher' ), 999 );
        add_action( 'init', array( $this, 'set_direction' ) );
    }

    function admin_bar_rtl_switcher() {   ...

    function set_direction() {   ...

    function get_direction() {   ...
}

new RTLTester;
One last thing...
class RTLTester {

    function __construct() {
       load_plugin_textdomain( 'rtl-tester' );
        add_action( 'admin_bar_menu', array( $this,
'admin_bar_rtl_switcher' ), 999 );
        add_action( 'init', array( $this, 'set_direction' ) );
    }

    function admin_bar_rtl_switcher() {   ...

    function set_direction() {   ...

    function get_direction() {   ...
}

new RTLTester;
http://wordpress.org/extend/plugins/about/
? ‫שאלות‬
      yoav@farhi.org
          @yoavf
http://yoav.wordpress.com

Weitere ähnliche Inhalte

Was ist angesagt?

Pimp your site with jQuery!
Pimp your site with jQuery!Pimp your site with jQuery!
Pimp your site with jQuery!Elliott Kember
 
Drupal Cms Prezentace
Drupal Cms PrezentaceDrupal Cms Prezentace
Drupal Cms PrezentaceTomáš Kafka
 
Юнит тестирование в Zend Framework 2.0
Юнит тестирование в Zend Framework 2.0Юнит тестирование в Zend Framework 2.0
Юнит тестирование в Zend Framework 2.0zfconfua
 
Twig, los mejores trucos y técnicas avanzadas
Twig, los mejores trucos y técnicas avanzadasTwig, los mejores trucos y técnicas avanzadas
Twig, los mejores trucos y técnicas avanzadasJavier Eguiluz
 
jQuery sans jQuery
jQuery sans jQueryjQuery sans jQuery
jQuery sans jQuerygoldoraf
 
Migrating Legacy Web Applications to AngularJS
Migrating Legacy Web Applications to AngularJSMigrating Legacy Web Applications to AngularJS
Migrating Legacy Web Applications to AngularJSBTI360
 
Documentacion edderson callpa_ortiz
Documentacion edderson callpa_ortizDocumentacion edderson callpa_ortiz
Documentacion edderson callpa_ortizEdderson J. Ortiz
 

Was ist angesagt? (15)

Pimp your site with jQuery!
Pimp your site with jQuery!Pimp your site with jQuery!
Pimp your site with jQuery!
 
Index2
Index2Index2
Index2
 
Sis quiz
Sis quizSis quiz
Sis quiz
 
Jquery2
Jquery2Jquery2
Jquery2
 
Drupal Cms Prezentace
Drupal Cms PrezentaceDrupal Cms Prezentace
Drupal Cms Prezentace
 
Dwr实战
Dwr实战Dwr实战
Dwr实战
 
Юнит тестирование в Zend Framework 2.0
Юнит тестирование в Zend Framework 2.0Юнит тестирование в Zend Framework 2.0
Юнит тестирование в Zend Framework 2.0
 
Index1
Index1Index1
Index1
 
Silex al límite
Silex al límiteSilex al límite
Silex al límite
 
Twig, los mejores trucos y técnicas avanzadas
Twig, los mejores trucos y técnicas avanzadasTwig, los mejores trucos y técnicas avanzadas
Twig, los mejores trucos y técnicas avanzadas
 
jQuery sans jQuery
jQuery sans jQueryjQuery sans jQuery
jQuery sans jQuery
 
Migrating Legacy Web Applications to AngularJS
Migrating Legacy Web Applications to AngularJSMigrating Legacy Web Applications to AngularJS
Migrating Legacy Web Applications to AngularJS
 
Introducción a Bolt
Introducción a BoltIntroducción a Bolt
Introducción a Bolt
 
Cbgapi
CbgapiCbgapi
Cbgapi
 
Documentacion edderson callpa_ortiz
Documentacion edderson callpa_ortizDocumentacion edderson callpa_ortiz
Documentacion edderson callpa_ortiz
 

Mehr von Yoav Farhi

Your First Gutenberg Block
Your First Gutenberg BlockYour First Gutenberg Block
Your First Gutenberg BlockYoav Farhi
 
[Atelier] Comment traduire un thème (ou une extension) WordPress
[Atelier] Comment traduire un thème (ou une extension) WordPress[Atelier] Comment traduire un thème (ou une extension) WordPress
[Atelier] Comment traduire un thème (ou une extension) WordPressYoav Farhi
 
Gender-fair WordPress: Fixing translation inequality at the core
Gender-fair WordPress: Fixing translation inequality at the coreGender-fair WordPress: Fixing translation inequality at the core
Gender-fair WordPress: Fixing translation inequality at the coreYoav Farhi
 
Right To Left Languages Support – The Right Way
Right To Left Languages Support – The Right WayRight To Left Languages Support – The Right Way
Right To Left Languages Support – The Right WayYoav Farhi
 
Localization: beyond translation
Localization: beyond translationLocalization: beyond translation
Localization: beyond translationYoav Farhi
 
WordPress in NOT English - WordCamp Hamburg 2014
WordPress in NOT English - WordCamp Hamburg 2014WordPress in NOT English - WordCamp Hamburg 2014
WordPress in NOT English - WordCamp Hamburg 2014Yoav Farhi
 
Contributing to WordPress (Hebrew)
Contributing to WordPress (Hebrew)Contributing to WordPress (Hebrew)
Contributing to WordPress (Hebrew)Yoav Farhi
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeYoav Farhi
 
Distributed: Reinventing the Workplace
Distributed: Reinventing the WorkplaceDistributed: Reinventing the Workplace
Distributed: Reinventing the WorkplaceYoav Farhi
 
וורדפרס.קום - אתרי וורדפרס בקלות
וורדפרס.קום - אתרי וורדפרס בקלותוורדפרס.קום - אתרי וורדפרס בקלות
וורדפרס.קום - אתרי וורדפרס בקלותYoav Farhi
 
WordCamp Jerusalem - Doing it Wrong
WordCamp Jerusalem - Doing it WrongWordCamp Jerusalem - Doing it Wrong
WordCamp Jerusalem - Doing it WrongYoav Farhi
 
WordPress theme translation
WordPress theme translationWordPress theme translation
WordPress theme translationYoav Farhi
 
WordPress RTL
WordPress RTL WordPress RTL
WordPress RTL Yoav Farhi
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1Yoav Farhi
 

Mehr von Yoav Farhi (14)

Your First Gutenberg Block
Your First Gutenberg BlockYour First Gutenberg Block
Your First Gutenberg Block
 
[Atelier] Comment traduire un thème (ou une extension) WordPress
[Atelier] Comment traduire un thème (ou une extension) WordPress[Atelier] Comment traduire un thème (ou une extension) WordPress
[Atelier] Comment traduire un thème (ou une extension) WordPress
 
Gender-fair WordPress: Fixing translation inequality at the core
Gender-fair WordPress: Fixing translation inequality at the coreGender-fair WordPress: Fixing translation inequality at the core
Gender-fair WordPress: Fixing translation inequality at the core
 
Right To Left Languages Support – The Right Way
Right To Left Languages Support – The Right WayRight To Left Languages Support – The Right Way
Right To Left Languages Support – The Right Way
 
Localization: beyond translation
Localization: beyond translationLocalization: beyond translation
Localization: beyond translation
 
WordPress in NOT English - WordCamp Hamburg 2014
WordPress in NOT English - WordCamp Hamburg 2014WordPress in NOT English - WordCamp Hamburg 2014
WordPress in NOT English - WordCamp Hamburg 2014
 
Contributing to WordPress (Hebrew)
Contributing to WordPress (Hebrew)Contributing to WordPress (Hebrew)
Contributing to WordPress (Hebrew)
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to Zeroize
 
Distributed: Reinventing the Workplace
Distributed: Reinventing the WorkplaceDistributed: Reinventing the Workplace
Distributed: Reinventing the Workplace
 
וורדפרס.קום - אתרי וורדפרס בקלות
וורדפרס.קום - אתרי וורדפרס בקלותוורדפרס.קום - אתרי וורדפרס בקלות
וורדפרס.קום - אתרי וורדפרס בקלות
 
WordCamp Jerusalem - Doing it Wrong
WordCamp Jerusalem - Doing it WrongWordCamp Jerusalem - Doing it Wrong
WordCamp Jerusalem - Doing it Wrong
 
WordPress theme translation
WordPress theme translationWordPress theme translation
WordPress theme translation
 
WordPress RTL
WordPress RTL WordPress RTL
WordPress RTL
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 

התוסף הראשון שלי - וורדפרס

  • 1. ‫התוסף הראשון שלי‬ ‫יואב פרחי, ‪yoav@farhi.org‬‬
  • 2. ‫התוסף הראשון שלי‬ ‫יואב פרחי, ‪yoav@farhi.org‬‬
  • 3.
  • 4.
  • 6. RTL Tester <?php /* Plugin Name: RTL Tester Plugin URI: http://wordpress.org/extend/plugins/rtl-tester/ Description: This plugin can be used to test WordPress themes and plugins with Right To Left (RTL) text direction. Simply activate this plugin to enable RTL and deactivate to return to normal operation. Yes, this is simplest plugin in the world. Author: <a href="http://blog.yoavfarhi.com">Yoav Farhi</a>, <a href="http://automattic.com">Automattic</a> Version: 0.2 */ $text_direction = 'rtl';
  • 7. ‫תשתית‬ class RTLTester { function __construct() { load_plugin_textdomain( 'rtl-tester' ); // Hooks and filters } } new RTLTester;
  • 8. ‫תשתית‬ class RTLTester { function __construct() { load_plugin_textdomain( 'rtl-tester' ); // Hooks and filters } } new RTLTester;
  • 11. function wp_footer() { do_action('wp_footer'); }
  • 12.
  • 14. add_action( 'wp_footer', 'my_add_credit' ); function my_add_credit() { echo "I did this!"; }
  • 15.
  • 17. function the_content($more_link_text = null, $stripteaser = 0) { $content = get_the_content($more_link_text, $stripteaser); $content = apply_filters('the_content', $content); echo $content; }
  • 18. function the_content($more_link_text = null, $stripteaser = 0) { $content = get_the_content($more_link_text, $stripteaser); $content = apply_filters('the_content', $content); echo $content; }
  • 19. function the_content($more_link_text = null, $stripteaser = 0) { $content = get_the_content($more_link_text, $stripteaser); $content = apply_filters('the_content', $content); echo $content; } add_filter( 'the_content', 'my_wordpress_link' );
  • 20. function the_content($more_link_text = null, $stripteaser = 0) { $content = get_the_content($more_link_text, $stripteaser); $content = apply_filters('the_content', $content); echo $content; } add_filter( 'the_content', 'my_wordpress_link' ); function my_wordpress_link( $content ){ }
  • 21. function the_content($more_link_text = null, $stripteaser = 0) { $content = get_the_content($more_link_text, $stripteaser); $content = apply_filters('the_content', $content); echo $content; } add_filter( 'the_content', 'my_wordpress_link' ); function my_wordpress_link( $content ){ $content = str_replace( 'WordPress', '<a href="http:// wordpress.org">WordPress</a>', $content ); return $content }
  • 22.
  • 23.
  • 24. ‫ביצוע פעולה‬ ‫פעולה על משתנה‬ add_action add_filter do_action apply_filters
  • 25. ‫תשתית‬ class RTLTester { function __construct() { load_plugin_textdomain( 'rtl-tester' ); // Hooks and filters } } new RTLTester;
  • 26. ‫פונקציות עזר‬ class RTLTester { function __construct() { . . . } new RTLTester;
  • 27. ‫פונקציות עזר‬ class RTLTester { function __construct() { . . . function get_direction() { if ( is_rtl() ) $direction = 'rtl'; else $direction = 'ltr'; return $direction; } } new RTLTester;
  • 28. ‫פונקציות עזר‬ class RTLTester { function __construct() { . . . function get_direction() { $direction = is_rtl() ? 'rtl' : 'ltr'; return $direction; } } new RTLTester;
  • 29.
  • 31. function admin_bar_rtl_switcher() { global $wp_admin_bar;
  • 32. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return;
  • 33. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction();
  • 34. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = ( $direction == 'rtl' ) ? 'ltr' : 'rtl';
  • 35. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = ( $direction == 'rtl' ) ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array(
  • 36. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = ( $direction == 'rtl' ) ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL',
  • 37. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = ( $direction == 'rtl' ) ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ),
  • 38. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ),
  • 39. function admin_bar_rtl_switcher() { global $wp_admin_bar; sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) ); if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ),
  • 40. function admin_bar_rtl_switcher() { global $wp_admin_bar; sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) ); if ( !is_super_admin() || !is_admin_bar_showing() ) return; $translation = __('Switch to %s', 'rtl-tester'); $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ),
  • 41. function admin_bar_rtl_switcher() { global $wp_admin_bar; sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) ); if ( !is_super_admin() || !is_admin_bar_showing() ) return; $translation = __('Switch to %s', 'rtl-tester'); // $translation = "-‫% לעבור ל‬s" $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ),
  • 42. function admin_bar_rtl_switcher() { global $wp_admin_bar; sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) ); if ( !is_super_admin() || !is_admin_bar_showing() ) return; $translation = __('Switch to %s', 'rtl-tester'); // $translation = "-‫% לעבור ל‬s" $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $direction = 'ltr'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ),
  • 43. function admin_bar_rtl_switcher() { global $wp_admin_bar; sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) ); if ( !is_super_admin() || !is_admin_bar_showing() ) return; $translation = __('Switch to %s', 'rtl-tester'); // $translation = "-‫% לעבור ל‬s" $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $direction = 'ltr'; $direction = strtoupper( $direction ); $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ),
  • 44. function admin_bar_rtl_switcher() { global $wp_admin_bar; sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) ); if ( !is_super_admin() || !is_admin_bar_showing() ) return; $translation = __('Switch to %s', 'rtl-tester'); // $translation = "-‫% לעבור ל‬s" $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $direction = 'ltr'; $direction = strtoupper( $direction ); $wp_admin_bar->add_menu(array( // $direction = LTR 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ),
  • 45. function admin_bar_rtl_switcher() { global $wp_admin_bar; sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) ); if ( !is_super_admin() || !is_admin_bar_showing() ) return; $translation = __('Switch to %s', 'rtl-tester'); // $translation = "-‫% לעבור ל‬s" $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $direction = 'ltr'; $direction = strtoupper( $direction ); $wp_admin_bar->add_menu(array( // $direction = LTR 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- $title = sprintf( $translation, $direction ) tester'), strtoupper( $direction ) ),
  • 46. function admin_bar_rtl_switcher() { global $wp_admin_bar; sprintf( __('Switch to %s', 'rtl-tester'), strtoupper($direction) ); if ( !is_super_admin() || !is_admin_bar_showing() ) return; $translation = __('Switch to %s', 'rtl-tester'); // $translation = "-‫% לעבור ל‬s" $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $direction = 'ltr'; $direction = strtoupper( $direction ); $wp_admin_bar->add_menu(array( // $direction = LTR 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- $title = sprintf( $translation, $direction ) tester'), strtoupper( $direction ) ), // $title = "-‫ לעבור ל‬LTR"
  • 47. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ), ) ); }
  • 48. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ), 'href' => add_query_arg( array( 'd' => $direction ) ) ) ); }
  • 49. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ), 'href' => add_query_arg( array( 'd' => $direction ) ) ) ); }
  • 50. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $url = 'http://mysite.com' $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ), 'href' => add_query_arg( array( 'd' => $direction ) ) ) ); }
  • 51. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $url = 'http://mysite.com' add_query_arg( array( ='d' => 'rtl'), $url ) ? 'ltr' : 'rtl'; $direction $direction == 'rtl' $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ), 'href' => add_query_arg( array( 'd' => $direction ) ) ) ); }
  • 52. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $url = 'http://mysite.com' add_query_arg( array( ='d' => 'rtl'), $url ) ? 'ltr' : 'rtl'; $direction $direction == 'rtl' $wp_admin_bar->add_menu(array( // $url = 'http://mysite.com/?d=rtl' 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ), 'href' => add_query_arg( array( 'd' => $direction ) ) ) ); }
  • 53. function admin_bar_rtl_switcher() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $direction = $this->get_direction(); $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; $wp_admin_bar->add_menu(array( 'id' => 'RTL', 'title' => sprintf( __('Switch to %s', 'rtl- tester'), strtoupper( $direction ) ), 'href' => add_query_arg( array( 'd' => $direction ) ) ) ); }
  • 54. ‫קריאה לפונקציה‬ class RTLTester { function __construct() { } function admin_bar_rtl_switcher() { ... function get_direction() { ... } new RTLTester;
  • 55. ‫קריאה לפונקציה‬ class RTLTester { function __construct() { add_action( 'admin_bar_menu', array( $this, 'admin_bar_rtl_switcher' ), 999 ); } function admin_bar_rtl_switcher() { ... function get_direction() { ... } new RTLTester;
  • 56.
  • 57.
  • 59. function set_direction() { global $wp_locale;
  • 60. function set_direction() { global $wp_locale; $_user_id = get_current_user_id();
  • 61. function set_direction() { global $wp_locale; $_user_id = get_current_user_id(); if ( isset( $_GET['d'] ) ) {
  • 62. function set_direction() { global $wp_locale; $_user_id = get_current_user_id(); if ( isset( $_GET['d'] ) ) { $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr';
  • 63. function set_direction() { global $wp_locale; $_user_id = get_current_user_id(); if ( isset( $_GET['d'] ) ) { $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr'; update_user_meta( $_user_id, 'rtladminbar', $direction );
  • 64. function set_direction() { global $wp_locale; $_user_id = get_current_user_id(); if ( isset( $_GET['d'] ) ) { $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr'; update_user_meta( $_user_id, 'rtladminbar', $direction ); } else {
  • 65. function set_direction() { global $wp_locale; $_user_id = get_current_user_id(); if ( isset( $_GET['d'] ) ) { $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr'; update_user_meta( $_user_id, 'rtladminbar', $direction ); } else { $direction = get_user_meta($_user_id, 'rtladminbar', true);
  • 66. function set_direction() { global $wp_locale; $_user_id = get_current_user_id(); if ( isset( $_GET['d'] ) ) { $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr'; update_user_meta( $_user_id, 'rtladminbar', $direction ); } else { $direction = get_user_meta($_user_id, 'rtladminbar', true); if ( false === $direction )
  • 67. function set_direction() { global $wp_locale; $_user_id = get_current_user_id(); if ( isset( $_GET['d'] ) ) { $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr'; update_user_meta( $_user_id, 'rtladminbar', $direction ); } else { $direction = get_user_meta($_user_id, 'rtladminbar', true); if ( false === $direction ) $direction = $wp_locale->text_direction; }
  • 68. function set_direction() { global $wp_locale; $_user_id = get_current_user_id(); if ( isset( $_GET['d'] ) ) { $direction = ( $_GET['d'] == 'rtl' ) ? 'rtl' : 'ltr'; update_user_meta( $_user_id, 'rtladminbar', $direction ); } else { $direction = get_user_meta($_user_id, 'rtladminbar', true); if ( false === $direction ) $direction = $wp_locale->text_direction; } $wp_locale->text_direction = $direction; }
  • 69. ‫קריאה לפונקציה‬ class RTLTester { function __construct() { add_action( 'admin_bar_menu', array( $this, 'admin_bar_rtl_switcher' ), 999 ); } function admin_bar_rtl_switcher() { ... function set_direction() { ... function get_direction() { } new RTLTester;
  • 70. ‫קריאה לפונקציה‬ class RTLTester { function __construct() { add_action( 'admin_bar_menu', array( $this, 'admin_bar_rtl_switcher' ), 999 ); add_action( 'init', array( $this, 'set_direction' ) ); } function admin_bar_rtl_switcher() { ... function set_direction() { ... function get_direction() { } new RTLTester;
  • 71.
  • 72.
  • 73. One last thing... class RTLTester { function __construct() { add_action( 'admin_bar_menu', array( $this, 'admin_bar_rtl_switcher' ), 999 ); add_action( 'init', array( $this, 'set_direction' ) ); } function admin_bar_rtl_switcher() { ... function set_direction() { ... function get_direction() { ... } new RTLTester;
  • 74. One last thing... class RTLTester { function __construct() { load_plugin_textdomain( 'rtl-tester' ); add_action( 'admin_bar_menu', array( $this, 'admin_bar_rtl_switcher' ), 999 ); add_action( 'init', array( $this, 'set_direction' ) ); } function admin_bar_rtl_switcher() { ... function set_direction() { ... function get_direction() { ... } new RTLTester;
  • 76. ? ‫שאלות‬ yoav@farhi.org @yoavf http://yoav.wordpress.com