Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

erikstainsby on "Custom menu permissions issues"

$
0
0

I have read the docs for add_submenu_page a thousand times. This is getting very old.
I have a custom top-level menu "Site Manager" which I mean to poopulate with half a dozen custom plugins. Only I can't seem to get past hooking up the first child. (The top-level has no direct child menu items, just an information page.)

  1. I hook 'admin_menu' in _init (class-based php file)
  2. I see error_log msgs for _init, then add_ci_submenu, then the returned suffix is logged
  3. at which point the screen dies with the proverbial You do not have sufficient permissions... yada yada
  4. I proceed to rip out my hair

What am I doing wrong? It seems so baldly simple. No?

Here's my code:

class ContactInfo {

	var $suffix;	// menu tag suffix 

	public function __construct() {
		add_action( 'init', array( &$this, '_init' ));
	}

	public function _init() {

		error_log(__FUNCTION__);

		wp_register_sidebar_widget('ci-widget','Contact Information',array(&$this,'ci_widget'));

		if( is_admin()) {
			add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_styles_scripts' ));
			add_action( 'admin_menu', array( &$this,'add_ci_submenu' ));
			add_action( 'wp_ajax_coop-save-ci-change', array( &$this, 'ci_admin_save_changes'));
		}
	}

	public function frontside_enqueue_styles_scripts() {
		error_log(__FUNCTION__);
		wp_enqueue_style( 'coop-ci' );
	//	wp_enqueue_script( 'coop-ci-js' );
	}

	public function admin_enqueue_styles_scripts($hook) {

		error_log(__FUNCTION__);
		error_log($hook);

	//	if( 'toplevel_page_site-manager' !== $hook && $this->suffix !== $hook ) {
	//		return;
	//	}

		wp_register_script( 'coop-ci-admin-js', plugins_url( '/js/ci-admin.js',__FILE__), array('jquery'));
		wp_register_style( 'coop-ci-admin', plugins_url( '/css/ci-admin.css', __FILE__ ), false );

		wp_enqueue_style( 'coop-ci-admin' );
		wp_enqueue_script( 'coop-ci-admin-js' );

	}

	public function add_ci_submenu() {

		error_log(__FUNCTION__);

		$this->suffix = add_submenu_page( 'site-manager', 'Contact Information', 'Contact Information', 'manage_options', 'contact-information', array(&$this,'admin_ci_settings_page'));

		error_log('suffix: '. $this->suffix);
	}

        public function admin_ci_settings_page() {

		error_log(__FUNCTION__);

	//	if( ! current_user_can('manage_local_site') ) die('You do not have required permissions to view this page');

		$out = array();
		$out[] = '<div class="wrap">';
		$out[] = '<div id="icon-options-general" class="icon32">';
		$out[] = '<br>';
		$out[] = '</div>';
		$out[] = '<h2>Contact Information parameters</h2>';

		$out[] = '<p>Contact info used on the front page of the site</p>';

                [snip]

                echo implode("\n",$out);
	}
}
/* end of class */

Yours, franticly,
Erik


Viewing all articles
Browse latest Browse all 8245

Trending Articles