WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WordPress is giving a permissions error on plugin submission (2 posts)

  1. David Powell
    Member
    Posted 1 year ago #

    I'm creating a new plugin (based on a previous plugin I created that works). The options pages show up fine but when I submit I get the "You do not have sufficient permissions to access this page." error.

    The plugin it's based on works and submits fine. I'm not sure why this is having an issue though.

    Below is the script that creates the plugin, it's pages, and the code that creates the new item on submit.

    add_action( 'wp_enqueue_scripts', 'add_product_focus_styles' );
        	add_action( 'wp_enqueue_scripts', 'add_product_focus_scripts' );
    
            function add_product_focus_styles() {
            	wp_register_style( 'pfstyles', plugins_url('/css/product-focus.css', __FILE__));
               	wp_enqueue_style( 'pfstyles' );
            }
    
            function add_product_focus_scripts() {
               	//wp_register_script('rpjs',plugins_url('/js/productfocus.js', __FILE__),'','',true);
            	//wp_enqueue_script('rpjs');
            }
    
            register_activation_hook(__FILE__, 'product_focus_activate');
    
        	// activating the default values
        	function product_focus_activate(){
        		product_focus_start();
        	}
    
        	function product_focus_start() {
        		global $wpdb;
        		/*
                          code that creates my table
                        */
        	}
        	 /**
             * Add the menu items to the WordPress menu bar
             */
             add_action('admin_menu', 'create_product_focus_menu_page');
    
        	function create_product_focus_menu_page() {
        	   add_menu_page('Add Focus', 'Add Focus', 'administrator', 'productfocus/product-focus-create.php','',   plugins_url('productfocus/images/icon.png'));
        	   add_submenu_page('productfocus/product-focus-create.php', 'Edit Focus', 'Edit Focus', 'administrator', 'productfocus/product-focus-edit.php');
    
        		add_action( 'admin_init', 'add_product_focus_styles' );
        		add_action( 'admin_init', 'add_product_focus_scripts' );
        	}
    
        	if(isset($_POST['createFocus'])){
        		global $wpdb;
        		$table_name = $wpdb->prefix."productfocus";
    
        		$pfname = $_POST['pfname'];
        		$pfdate = $_POST['pfdate'];
        		$return = $_SERVER['HTTP_REFERER'];
    
        		$q = $wpdb->prepare("INSERT INTO $table_name (pfname,pfdate) VALUES (%s,$d,)",$pfname,$pfdate);
        		$wpdb ->query($q);
    
        		header("location: ".$_SERVER['PHP_SELF']."?page=productfocus/product-focus-create.php");
        		exit;
        	}

    any clues why the "create" page will show but I get the error when I try to submit the form?

  2. David Powell
    Member
    Posted 1 year ago #

    Turns out the name of the button used to submit the page didn't match in the submit function.

Topic Closed

This topic has been closed to new replies.

About this Topic