25 April 2014

Membuat Plugin Sederhana di Wordpress (4)




Form tambah / edit ditampilkan ketika fungsi gfaq_sesi dijalankan, dengan variabel $_GET. Dan data baru disimpan / diupdate ketika ada variabel $_POST.

function gfaq_sesi()
{
if( ! empty($_POST['action'])){      
        // tambah record
        if('new' == $_POST['action']){
            gfaq_insert_sesi($_POST);
        }
        // update record
        else if('update' == $_POST['action']){
            if(! empty($_POST['section_name'])){
                if( ! empty ($_POST['section_name'])){
                    gfaq_update_sesi($_POST);                  
                }
            }
        }
        // Hapus semua item terpilih      
        else if('delete' === $_POST['action']){
            gfaq_bulk_delete_sesi($_POST['sesi']);
        }
    }
  
    // hapus record
    if( ! empty( $_GET['delete'] )){
        gfaq_delete_sesi($_GET['delete']);
    }
    // tampilkan form tambah record
    elseif('new' === $_GET['form']){
        gfaq_form_sesi();
    }
    // tampilkan form perbaharui record
    elseif( ! empty( $_GET['update'] ))
    {
        gfaq_form_sesi($_GET['update']);
    }  
    // tampilkan tabel record
    else
    {
        gfaq_table();
    }}
/** Form Tambah / Edit record **/
function gfaq_form_sesi($id = null){
    $section_name = null;
    $section_description = null;
    $form_title = 'Tambah Sesi';
    $section_name = null;
    $section_description = null;
    $input_hidden = '';
    if(!empty($id)){
        $form_title = 'Edit Sesi';
        global $wpdb;
        $id = absint($id);
        $row = $wpdb->get_row("SELECT id, name, description FROM " . $wpdb->prefix . "gfaq_sesi WHERE id = " . $id, ARRAY_A);
        $section_name = $row['name'];
        $section_description = $row['description'];
        $input_hidden = '
                         ';
    }  
?>
  

      


      
      
        echo $input_hidden;
?>
          

                
                  
                  
              
                
                                      
                  
            
Nama Sesi
Deskripsi
                    'section_description',  'media_buttons'=>false) );?>
                    

    submit_button();
    ?>  
        

    

}


0 komentar:

Posting Komentar