OK Codice completo:
<?php
//check to see whether the user is an admin or not.
if (is_admin()) {
function wpsc_display_products_seo(){
global $wpdb;
$productList = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_PRODUCT_LIST . " ORDER BY name ASC");
echo get_admin_page_parent();
$path = 'admin.php?page=wpsc_product_seo_details';
$url = admin_url($path);
?>
<h2><?php _e('Products List','wpsc'); ?></h2>
<p>Below is a list of products. Select a product to edit it's SEO properties.</p>
<table>
<tr>
<td></td>
<td>Product Name</td>
<td>Meta Title</td>
<td>Meta Description</td>
<td>Edit</td>
</tr>
</table>
<table>
<?php if($productList) : ?>
<?php foreach($productList as $product) : ?>
<?php $meta = getProductMeta($product->id); ?>
<tr style="background:#fff;">
<td width="200"><?php echo $product->name; ?></td>
<td width="300"><?php getVal($meta, 'meta_title'); ?></td>
<td width="200"><?php getVal($meta, 'meta_description'); ?></td>
<td width="200"><?php getVal($meta, 'meta_keywords'); ?></td>
<td width="200"><a href="<?php echo $url; ?>">Edit</a></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
<?php
}
function wpsc_product_seo_details()
{
echo "<h2>Hello</h2>";
}
function getProductMeta($id)
{
global $wpdb;
$meta = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_PRODUCT_META . " WHERE product_id = $id");
if($meta)
{
return $meta;
} else {
return null;
}
}
function getVal($RS, $key)
{
if($RS)
{
if (property_exists($RS, $key))
{
return $RS->$key;
}
}
return null;
}
function wpsc_add_seo_admin_pages($page_hooks, $base_page) {
$page_hooks[] = add_submenu_page($base_page, __('SEO For Products','wpsc'), __('SEO For Products','wpsc'), 7, 'wpsc-module-seo', 'wpsc_display_products_seo');
return $page_hooks;
}
add_filter('wpsc_additional_pages', 'wpsc_add_seo_admin_pages',10, 2);
}
?>
POST VECCHIO
Ciao ragazzi,
Attualmente sto scrivendo un plugin per il mio cliente in wordpress. Il problema che sto riscontrando è quando un utente fa clic su Modifica per modificare un record. Non sono sicuro di come creare il collegamento di amministrazione per farlo.
vale a dire
<a href="<?php echo get_bloginfo('url'); ?>/wp-admin/admin.php?page=wpsc_product_seo_details">Edit</a>
function wpsc_product_seo_details()
{
echo "<h2>Hello</h2>";
}
So che il mio markup per il tag è probabilmente sbagliato ma stavo solo testando. Devo registrare un hook per farlo.
wpsc_product_seo_details()
? L'hai aggiunto al tuo menu in qualche modo?