url:
.../wp-admin/admin.php?page=wta_table_admin&action=edit&table=1
چرا پی اچ پی نمیتونه $_GET بگیره
تابع دخیره اطلاعات و گیره آجاکس است handle_requests()
ولی $_GET['action'] && $_GET['table'] دریافت نمیکنه!!!
class WTA_Table_Admin {
private $version;
private $page_slug;
private $page_hook;
private $base_url;
private $db;
function __construct($version, $base_url = false ) {
$this->load_dependencies();
$this->version = $version;
$this->page_slug = 'wta_table_admin';
$this->db = WTA_DB_Table::get_instance();
add_action( 'admin_menu', array($this, 'add_menu_items') );
add_action( 'admin_enqueue_scripts', array($this, 'backend_enqueue') );
add_action( 'admin_init', array($this, 'handle_requests') );
add_action('wp_ajax_handle_requests', array($this, 'handle_requests'));
if(!$base_url)
$this->base_url = plugins_url( '', dirname(__FILE__) );
else
$this->base_url = $base_url;
}
private function load_dependencies(){
require_once 'class-wta-db-table.php';
}
public function add_menu_items() {
$this->page_hook = add_menu_page( __('WooTableAttributes', 'wta-tableplugin'), __('WooTableAttributes', 'wta-tableplugin'), 'manage_options', $this->page_slug, array($this, 'print_page'), $this->base_url . "/img/icon.png" );
}
public function backend_enqueue() {
wp_enqueue_script('wta-sortable', $this->base_url . '/js/admin/sortable.js', array('jquery'), $this->version, false);
}
public function print_page() {
?>
<div class="wrap">
<?php
if(isset($_GET['action']) && $_GET['action'] == 'add'){
echo sprintf( '<h2>%s <a class="add-new-h2" href="%s">%s</a></h2>', __('Add Table', 'wta-tableplugin'), admin_url('admin.php?page='.$this->page_slug), __('View All', 'wta-tableplugin') );
$this->create_ui();
}
elseif(isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['table']) && is_numeric($_GET['table'])){
echo sprintf( '<h2>%s <a class="add-new-h2" href="%s">%s</a></h2>', __('Edit Table', 'wta-tableplugin'), admin_url('admin.php?page='.$this->page_slug), __('View All', 'wta-tableplugin') );
$table = $this->db->get($_GET['table']);
if($table)
$this->create_ui($table);
}
else{
echo sprintf( '<h2>%s <a class="add-new-h2" href="%s">%s</a></h2>', __('Tables', 'wta-tableplugin'), admin_url('admin.php?page='.$this->page_slug.'&action=add'), __('Add New', 'wta-tableplugin') );
$list_table = new WTA_List_Table();
$list_table->show();
}
?>
</div>
<?php
}
private function create_ui($table = false) {
$table_id = $table ? $table['id'] : '';
$name = $table ? $table['name'] : '';
$headcolor = $table ? $table['headcolor'] : '';
$cols = $table ? $table['cols'] : 5;
$subs = $table ? $table['subs'] : '';
$color = $table ? $table['color'] : 'default';
$att_type = $table ? $table['att_type'] : '';
$curr_values = $table ? $table['att_name'] : '';
$col_span = $cols;
$sub_array = explode(',', $subs);
$layout = $data = array();
if (!empty($this->themplate_id)) {
$option = WTA_Options::get_option($this->plugin_name, $this->version);
$forms = $option->get();
if (!empty($forms[$this->themplate_id])) {
$layout = $forms[$this->themplate_id];
$data = $layout['data'];
$layout = $layout['layout'];
}
}
$resultdb = $this->db->get($table_id);
$db_attName = explode( ',', $resultdb['att_name'] );
$db_attType = explode( ',', $resultdb['att_type'] );
for($i=0; $i < count($db_attName); $i++)
{
if(!empty($db_attName[$i]))
$attnt[$db_attType[$i]] = $db_attName[$i];
}
$image = false;
$productname = false;
$price = false;
$quantity = false;
$db_rowfour = explode( ',', $resultdb['rowfour'] );
for($i=0; $i < count($db_rowfour); $i++)
{
switch ($db_rowfour[$i]) {
case "image":
$image = true;
break;
case "productname":
$productname = true;
break;
case "price":
$price = true;
break;
case "quantity":
$quantity = true;
break;
}
}
?>
<div id="tabs" class="ui-tabs ui-corner-all ui-widget ui-widget-content">
<?php $this->wta_settings($table_id, $name); ?>
<div id="wtasave" class="wtasave-1">
<div class="wta-save-bottom">
<div class="container">
<div id="display"></div>
<input type="hidden" id="actsave" value="<?php echo $_GET['action']; ?>" />
<input type="hidden" id="idtable" value="<?php echo $_GET['table']; ?>" />
<div class="wta-save-center">
<input name="wta_save_changes" id="wta_save_changes" class="button button-primary right" value="Save Changes" type="submit">
</div>
</div>
</div>
</div>
</div>
<?php
}
public function wta_settings($table_id, $name) {
?>
<table style="width: 100%; height:100%;" border="1">
<tbody>
<tr>
<td style="width: 10%;">Name Table:</td>
<td style="width: 20%;">
<input type="text" class="wta-comptable-title" placeholder="<?php _e('Table Name', 'wta-tableplugin'); ?>" name="table_name" value="<?php echo esc_attr($name); ?>" required="required" />
</td>
<td style="width: 10%;">Link ShortCut:</td>
<td colspan="2" style="width: 40%;">
[wta_comparison_table id="<?php echo $table_id; ?>" class=""]
</td>
</tr>
</tbody>
</table>
<?php
return;
}
public function handle_requests() {
if($_GET['action'] == 'edit')
{
$this->db->update( $_GET['table'], $_POST['table_name']);
}
}
}
JS File
jQuery(document).ready(function($) {
$('#wta_save_changes').click(function(){
var table_name = jQuery(".wta-comptable-title").val();
var actsave = jQuery("#actsave").val();
var idtable = jQuery("#idtable").val();
var catlist = '11';
var mydata = {
action: "handle_requests",
table_name: table_name,
catlist: catlist,
getaction: actsave,
table: idtable
};
$.ajax({
type: "POST",
url: ajaxurl,
dataType: "json",
data: mydata,
success: function (data, textStatus, jqXHR) {
if(data === true)
$('#display').html('<p>Options Saved!</p>');
else
$('#display').html('<p>Do not Saved!</p>');
},
error: function (errorMessage) {
console.log(errorMessage);
}
});
});
});
لطفا کمک کنید