1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

Dasar2 Pembuatan Wordpress Plugins

Discussion in 'Wordpress' started by ewwink, Jan 24, 2011.

  1. ewwink

    ewwink Super Hero

    Joined:
    Apr 27, 2006
    Messages:
    2,836
    Likes Received:
    1,100
    Location:
    Tasikmalaya, Sunda, Indonesia
    kadangkala untuk memodif wordpress biasanya kita edit2 themenya terutama yg sering di edit adalah functions.php nah daripada klo nanti themenya di ganti trus themenya di otak atik lagi mending kita bikin pluginnya aja.

    dalam contoh kali ini ane akan bikin "List Tags tanpa link" karena kmren2 SEO booster Pro disalah satu post ane ngasilin tags sampai ribuan dan ini ga baik bs menyebabkan penalti google makanya linknya harus dihapus, biasanya klo manual tinggal replace <?php the_tags(); ?> dengan kode di bawah ke single.php atau bisa juga di index.php atau archieve.php
    PHP:
    <?php
    $articletags 
    strip_tags(get_the_tag_list('',', ',''));
    echo 
    $articletags;
    ?>
    tapi klo untuk dibuat plugin wordpress buat file berekstensi php dan masukan identifikasi dibawah ini tepat dibawah kode <?php

    PHP:
    /*
    Plugin Name: List Tags tanpa link
    Plugin URI: http://www.adsense-id.com/forums/showthread.php/64628
    Description: Menampilkan list tags tanpa link jika ada fungsi the_tags (single.php, index.php)
    Author: ewwink
    Version: 0.1
    Author URI: http://www.tasikmalaya.info
    */
    kemudian masukan kode
    Code:
    add_action('the_tags','strip_tags');
    strip_tags diatas adalah fungsi php untuk menghilangkan kode html temasuk link dan komplit kodenya
    PHP:
    <?php
    /*
    Plugin Name: List Tags tanpa link
    Plugin URI: http://www.adsense-id.com/forums/showthread.php/64628
    Description: Menampilkan list tags tanpa link jika ada fungsi the_tags (single.php, index.php)
    Author: ewwink
    Version: 0.1
    Author URI: http://www.tasikmalaya.info
    */
    add_action('the_tags','strip_tags');
    ?>
    save, zip, upload and activate
    sedangkan jika theme nya tidak mempunyai fungsi <?php the_tags(); ?> dan dan ingin otomatis menampilkan tags tanpa link tulis kode
    Code:
    function list_tag_tanpa_link(){
    $articletags = strip_tags(get_the_tag_list('',', ',''));
    echo get_the_content().'<p>'.$articletags.'<p>'; 
    }
    add_action('the_content','list_tag_tanpa_link');
    dari contoh diatas add_action berarti akan mereplace fungsi the_content dengan fungsi list_tag_tanpa_link yg menghasilkan output get_the_content() dan $articletags

    dan berikut komplit kodenya, save, upload & activate
    PHP:
    <?php
    /*
    Plugin Name: List Tags tanpa link
    Plugin URI: http://www.adsense-id.com/forums/showthread.php/64628
    Description: Menampilkan list tags tanpa link jika ada fungsi the_content (single.php, index.php)
    Author: ewwink
    Version: 0.1
    Author URI: http://www.tasikmalaya.info
    */
    function list_tag_tanpa_link(){
    $articletags strip_tags(get_the_tag_list('',', ',''));
    echo 
    get_the_content().'<p>'.$articletags.'<p>';
    }
    add_action('the_content','list_tag_tanpa_link');
    ?>
    ane yakin di adsense-id banyak yg lebih jago dengan plugins ayo share disini dan berkreasi bersama.
    contoh plugin lainnya
    - Related Postku
    - Bot Access Notification
    - Limit Tag Display
    resources:
    _http://codex.wordpress.org/Writing_a_Plugin
    _http://www.adsense-id.com/forums/forumdisplay.php/101-Wordpress

    makasih,

    ewwink
     
    Last edited: Jan 28, 2011
  2. hadie87

    hadie87 Densus 99

    Joined:
    Sep 10, 2009
    Messages:
    5,920
    Likes Received:
    3,046
    Location:
    Baturaja, Indonesia
    akhirnya di share juga. mantab om momod

    apakah ini yang kita bicarakan kemarin om momod?
    ane izin memakai dan mencoba plugin buatan om momod ya:D
    Btw ane pertamax di sticky nya momod :senyum:
     
    ewwink likes this.
  3. ewwink

    ewwink Super Hero

    Joined:
    Apr 27, 2006
    Messages:
    2,836
    Likes Received:
    1,100
    Location:
    Tasikmalaya, Sunda, Indonesia
    bukan om ini hanya dasar2nya aja biar ga lupa dan kampanye klo modif atau bikin plugins itu tidak selalu susah, klo yg kmren2 yg dibicarakan nnti klo udah berhasil ane share hehe
     
  4. yuniico

    yuniico Super Hero

    Joined:
    Oct 26, 2009
    Messages:
    1,925
    Likes Received:
    374
    Location:
    F*CKGINA
    ini yang ane cari :senyum:

    ijin bookmark terus di tes di localhost dulu . . .

    Thanks om. . .
     
  5. ewwink

    ewwink Super Hero

    Joined:
    Apr 27, 2006
    Messages:
    2,836
    Likes Received:
    1,100
    Location:
    Tasikmalaya, Sunda, Indonesia
    Contoh lain Wordpress Plugins: Related Posts

    contoh lain misal ada satu kode "related posts" di
    _blog.web6.org/wordpress-related-posts-without-plugin/
    Code:
    //related post shortcode
    function related_posts_shortcode( $atts ) {
    
        extract(shortcode_atts(array(
            'limit' => '5',
        ), $atts));
    
        global $wpdb, $post, $table_prefix;
    
        if ($post->ID) {
    
            $retval = '
    <ul>';
    
            // Get tags
            $tags = wp_get_post_tags($post->ID);
            $tagsarray = array();
            foreach ($tags as $tag) {
                $tagsarray[] = $tag->term_id;
            }
            $tagslist = implode(',', $tagsarray);
    
            // Do the query
            $q = "
                SELECT p.*, count(tr.object_id) as count
                FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p
                WHERE tt.taxonomy ='post_tag'
                    AND tt.term_taxonomy_id = tr.term_taxonomy_id
                    AND tr.object_id  = p.ID
                    AND tt.term_id IN ($tagslist)
                    AND p.ID != $post->ID
                    AND p.post_status = 'publish'
                    AND p.post_date_gmt < NOW()
                GROUP BY tr.object_id
                ORDER BY count DESC, p.post_date_gmt DESC
                LIMIT $limit;";
    
            $related = $wpdb->get_results($q);
    
            if ( $related ) {
                foreach($related as $r) {
                    $retval .= '
        <li><a title="'.wptexturize($r->post_title).'" href="'.get_permalink($r->ID).'">'.wptexturize($r->post_title).'</a></li>
    ';
                }
            } else {
                $retval .= '
        <li>No related posts found</li>
    ';
            }
            $retval .= '</ul>
    ';
            return $retval;
        }
        return;
    }
    add_shortcode('related_posts', 'related_posts_shortcode');
    
    dan kita ingin itu dibuat plugin tinggal modif jadi
    PHP:
    <?php
    /*
    Plugin Name: Related Postku
    Plugin URI: http://www.adsense-id.com/forums/showthread.php/64628
    Description: Menampilkan Related Post di Single.php
    Author: ewwink
    Version: 0.1
    Author URI: http://www.tasikmalaya.info
    */
    //related post shortcode
    function related_posts_shortcode$atts ) {    extract(shortcode_atts(array('limit' => '5',
        ), 
    $atts));

        global 
    $wpdb$post$table_prefix;

        if (
    $post->ID) {

            
    $retval '
    <ul>'
    ;

            
    // Get tags
            
    $tags wp_get_post_tags($post->ID);
            
    $tagsarray = array();
            foreach (
    $tags as $tag) {
                
    $tagsarray[] = $tag->term_id;
            }
            
    $tagslist implode(','$tagsarray);

            
    // Do the query
            
    $q "
                SELECT p.*, count(tr.object_id) as count
                FROM 
    $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p
                WHERE tt.taxonomy ='post_tag'
                    AND tt.term_taxonomy_id = tr.term_taxonomy_id
                    AND tr.object_id  = p.ID
                    AND tt.term_id IN (
    $tagslist)
                    AND p.ID != 
    $post->ID
                    AND p.post_status = 'publish'
                    AND p.post_date_gmt < NOW()
                GROUP BY tr.object_id
                ORDER BY count DESC, p.post_date_gmt DESC
                LIMIT 
    $limit;";

            
    $related $wpdb->get_results($q);

            if ( 
    $related ) {
                foreach(
    $related as $r) {
                    
    $retval .= '
        <li><a title="'
    .wptexturize($r->post_title).'" href="'.get_permalink($r->ID).'">'.wptexturize($r->post_title).'</a></li>
    '
    ;
                }
            } else {
                
    $retval .= '
        <li>No related posts found</li>
    '
    ;
            }
            
    $retval .= '</ul>
    '
    ;
            return 
    get_the_content().'<div id="relatedpost"><h3>Related Posts:</h3>'.$retval.'</div>';// menambah get_the_content() dan format html
        
    }
        return;
    }
    add_action('the_content','related_posts_shortcode');
    ?>
    dari kode diatas yg di modif hanya menambahkan identifikasi, merubah
    PHP:
    return $retval;
    jadi
    PHP:
    return get_the_content().'<div id="relatedpost"><h3>Related Posts:</h3>'.$retval.'</div>'// menambah get_the_content() dan format html
    dan menambahkan kode dibawah untuk memodifikasi the_content
    PHP:
    add_action('the_content','related_posts_shortcode');
     
  6. sariful

    sariful Super Hero

    Joined:
    Aug 22, 2009
    Messages:
    874
    Likes Received:
    54
    Location:
    Belakang ITC Cibinong
    Mudah-mudahan ada inspirasi bikin plugin sendiri... amin... thank om momod share nya :)
     
  7. ciduh.com

    ciduh.com Ads.id Fan

    Joined:
    Nov 28, 2010
    Messages:
    224
    Likes Received:
    5
    Location:
    Subang, Indonesia
    nice info gan, tar ane praktekin dah..
     
  8. surv1

    surv1 Newbie

    Joined:
    Oct 9, 2010
    Messages:
    4
    Likes Received:
    0
    Location:
    bandung
    ni ce in fo th an k
     
  9. asep hermawan

    asep hermawan Ads.id Pro

    Joined:
    May 25, 2010
    Messages:
    353
    Likes Received:
    2
    di bukmark dl om :|
     
  10. BruceLee

    BruceLee Super Hero

    Joined:
    Nov 15, 2010
    Messages:
    2,164
    Likes Received:
    227
    Location:
    Kangean
    mantabb om.. udah lama ane cari tutorialnya om..
    alhmdllh akhrnya om momod turun tangan..
     
    neil04 likes this.
  11. D'Harisy

    D'Harisy Super Hero

    Joined:
    Jun 18, 2010
    Messages:
    1,153
    Likes Received:
    43
    Location:
    Di bawah telapak kaki ibu
    Hatur nuhun kang Momod Ewink..bookmark heula ah..can pati ngarti..nanti pasti perlu...
     
  12. ewwink

    ewwink Super Hero

    Joined:
    Apr 27, 2006
    Messages:
    2,836
    Likes Received:
    1,100
    Location:
    Tasikmalaya, Sunda, Indonesia
    Plugin Wordpress: Bot Access Notification

    contoh lain
    Plugin Wordpress: Bot Access Notification

    deskripsi: memberikan notifikasi lewat email jika googlebot, yahoo! slurp, msnbot mengakses situs ente.

    kode mentahnya: _http://goo.gl/jUBoT
    PHP:
    <?php
    $email 
    "[email protected]";

    if(
    eregi("yahoo! Slurp",$_SERVER['HTTP_USER_AGENT']))
    {
    mail($email"The Yahoo bot came to call yoursite",
    "Yahoo has visited: ".$_SERVER['REQUEST_URI']);
    }
    if(
    eregi("googlebot",$_SERVER['HTTP_USER_AGENT']))
    {
    mail($email"The Googlebot came to call your site",
    "Google has visited: ".$_SERVER['REQUEST_URI']);
    }
    ?> 
    setelah dibikin plugin
    PHP:
    <?php
    /*
    Plugin Name: Bot Access Notification
    Plugin URI: http://www.adsense-id.com/forums/showthread.php/64628
    Description: Give notification by email if bot such as GoogleBot, Yahoo! Slurp and Msnbot access your website
    Author: ewwink
    Version: 0.1
    Author URI: http://www.tasikmalaya.info
    */
    $email "[email protected]";
    $pesan "\n email notifikasi ini dikirim oleh \"Bot Access Notification\" \n by: ewwink, http://goo.gl/tUmFX";

    if(
    eregi("yahoo! Slurp",$_SERVER['HTTP_USER_AGENT']))
    {
    mail($email"Yahoo bot  telah mengunjungi ".$_SERVER['HTTP_HOST'],
    "Yahoo has visited: ".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$pesan);
    }
    if(
    eregi("googlebot",$_SERVER['HTTP_USER_AGENT']))
    {
    mail($email"Googlebot telah mengunjungi ".$_SERVER['HTTP_HOST'],
    "Google has visited: ".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$pesan);
    }
    if(
    eregi("msnbot",$_SERVER['HTTP_USER_AGENT']))
    {
    mail($email"MSNbot telah mengunjungi ".$_SERVER['HTTP_HOST'],
    "Google has visited: ".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$pesan);
    }
    ?>
    jangan lupa edit [email protected]
     
    Last edited: Jan 24, 2011
    gokkri likes this.
  13. kuudo

    kuudo Super Hero

    Joined:
    Jul 18, 2009
    Messages:
    1,259
    Likes Received:
    50
    Location:
    Kota tahu
    Klo untuk membatasi jumlah tag yang tampil di single gimana kang :hmm:
     
  14. ooND

    ooND Super Hero

    Joined:
    Jul 24, 2010
    Messages:
    5,707
    Likes Received:
    1,118
    Location:
    Wonosobo, Jawa Tengah, Indonesia, Indonesia
    om kalo mau bikin plugin agc gmn ya... :hmm:
    agc kan kode2 nya ga urut,,,
     
  15. gokkri

    gokkri Ads.id Pro

    Joined:
    Oct 25, 2010
    Messages:
    477
    Likes Received:
    4
    Location:
    LA Mania
    mantab nie,,bungkus dulu ah
     
  16. ewwink

    ewwink Super Hero

    Joined:
    Apr 27, 2006
    Messages:
    2,836
    Likes Received:
    1,100
    Location:
    Tasikmalaya, Sunda, Indonesia
    ini neeh
    PHP:
    <?php
    /*
    Plugin Name: limit tag
    Plugin URI: http://www.adsense-id.com/forums/showthread.php/64628-Dasar2-Pembuatan-Wordpress-Plugins/page2
    Description: Tampilkan tags secara terbatas
    Author: ewwink
    Version: 0.1
    Author URI: http://www.erwin.im
    */
    function my_limit_tags(){
    $posttags get_the_tags();
    echo 
    'Tags: ';
    $count=0;
    if (
    $posttags) {
        foreach(
    $posttags as $tag) {
            
    $count++;
            echo 
    '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>, ';
            if( 
    $count == ) break;
        }
    }
    }
    add_action('the_tags','my_limit_tags');
    ?>
    dan ganti nomor dibawah sesuai dengan nomor tag yg ingin ente tampilkan
    PHP:
    if( $count == ) break;
    klo itu rada rumit ente harus paham dulu scraping
     
  17. heripu

    heripu Super Hero

    Joined:
    Dec 14, 2010
    Messages:
    1,898
    Likes Received:
    421
    Location:
    Plembang
    wedew gak nyampai nih,,,
    tapi boorkmark dulu ah,, buat belajar,,
     
  18. teguhaditya

    teguhaditya Super Hero

    Joined:
    Jan 23, 2008
    Messages:
    7,503
    Likes Received:
    1,418
    Location:
    _ ▂ ▃ ▅ ▆ █
    Re: Plugin Wordpress: Bot Access Notification

    barusan coba lumayan bagus hasilnya, cuma hati hati aja kalau pake plugin ini, ntar kaget inbox penuh :lol:
    mesti di oprek lagi pluginnya nih
     
  19. ewwink

    ewwink Super Hero

    Joined:
    Apr 27, 2006
    Messages:
    2,836
    Likes Received:
    1,100
    Location:
    Tasikmalaya, Sunda, Indonesia
    Re: Plugin Wordpress: Bot Access Notification

    :lol:
    iya otak2 atik lagi aja supaya ngirimnya sekali email per-bot dalam jangka waktu tertentu
     
  20. aleydoank

    aleydoank Super Hero

    Joined:
    Jun 6, 2009
    Messages:
    1,897
    Likes Received:
    43
    Location:
    Bandung
    oh, ternyata seperti ini ya buat plugin, script nya di bundel dalam satu file..
    baru mudeng ane, hehe.. iya kan plugin itu tambahan script ya..
    :lol:
    Makasi banyak Kang momod. :p
     

Share This Page