Eli
Eli

Reputation: 1276

Wordpress text link when click returns "you do not have sufficient permissions to access this page."

I am new with wordpress and I really appreciate this cms application. I have been working in creating my own plugin and I was stuck in this particular problem. I have created a text link that points to one my function I have created. But whenever I click this link "Add Category" it returns the "you do not have sufficient permissions to access this page." instead of a simple text "hello" text to be printed. What is the problem with this? I need somebody to help me. Here are my codes

product_category.php

<?php
/**
* Plugin Name: Categorized Product Plugin
* Plugin URI: 
* Description: A plugin for categorizing products
* Author: 
* Author URI: 
* License: A "Slug" license name e.g. GPL2
*/
add_action('admin_menu',array('my_product','myplugin_menu'));
register_activation_hook( __FILE__, array('my_product','jal_install'));

global $jal_db_version;
$jal_db_version = "1.0";

class my_product{

function myplugin_menu(){
 if( function_exists('add_management_page')){
     $page = add_menu_page('product_zone','product Zone','administrator','myplugin_menu_display',array('my_product','category_adding_form'),plugins_url("img/logo_product.png", __FILE__));
 }
}

function category_adding_form(){
 include('categorized_product_form.php');         
}

function test_link(){
echo "hello";
}

 ?>

add_form_link.php

 <div class="wrap">
 <?php
 $path = 'admin.php?page=test_link';
 $url = admin_url($path);
 $link = "<a href='{$url}'>Add Category</a>";
 echo $link;   

 echo "<h1>Product Zone</h1>";
 ?>

Upvotes: 1

Views: 274

Answers (1)

brasofilo
brasofilo

Reputation: 26055

This

?page=test_link

does not have relation with

function test_link()

What you can do is reuse the same page. Put this code in your categorized_product_form.php file:

<div class="wrap">
<?php
$path = 'admin.php?page=myplugin_menu_display';
$url1 = admin_url( $path. '&test_link=true' );
$url2 = admin_url( $path );

if( isset( $_GET['test_link'] ) )
{
    echo '<h1>hello world</h1>';
    echo "<a href='{$url2}'>back</a>";
}
else
{
    echo "<h1>Product Zone</h1>";
    echo "<a href='{$url1}'>Add Category</a>";
}

Related: How to enable additional page in WordPress custom plugin?

Upvotes: 1

Related Questions