Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter pipo5000

    (@pipo5000)

    I am looking for a way to clean up my code. I’ve read about extensible plugins and I’d like mine to be. I want to be able to create new features for my plugin without having to edit 20 files every time.

    What I’ve tried is to leave all the options I might want to change out of the function that actually creates it. What is was wondering is if there are any other (easier but mainly better) ways of doing this.

    Thread Starter pipo5000

    (@pipo5000)

    Still no luck..

    What I’ve done so far:

    add_action('admin_menu', 'tm_plugin_menu_create');
    function tm_plugin_menu_create() {
    
    	/* define parent menu */
    	$tm_plugin_menu_parent = __('Terpstra Media', 'tm-plugin');
    
    	/* rename or create new submenu items */
    	$tm_plugin_menu_child = array(
    		__('General Settings', 'tm-plugin'),
    		__('Widgets', 'tm-plugin'),
    		__('Shortcodes', 'tm-plugin')
    	);
    
    	/* general plugin menu settings */
    	$tm_plugin_menu_general = array(
    		'icon_url'	=>	'dashicons-sos',
    		'position'	=>	'2.1',
    		'capability'	=>	'manage_options',
    		'slug_prefix'	=>	'tm-plugin-',
    		'func_prefix'	=>	'tm_plugin_',
    		'slug_suffix'	=>	'.php'
    	);
    
    	if ( function_exists('add_menu_page') ) {
    		add_menu_page(
    			$tm_plugin_menu_parent,
    			$tm_plugin_menu_parent,
    			$tm_plugin_menu_general['capability'],
    			$tm_plugin_menu_general['slug_prefix'] . $tm_plugin_menu_parent . $tm_plugin_menu_general['slug_suffix'],
    			$tm_plugin_menu_general['func_prefix'] . $tm_plugin_menu_parent,
    			$tm_plugin_menu_general['icon_url'],
    			$tm_plugin_menu_general['position']
    		);
    	}
    	if ( function_exists('add_submenu_page') ) {
    		foreach ($tm_plugin_menu_child as $page) {
    			add_submenu_page(
    				$tm_plugin_menu_general['slug_prefix'] . $tm_plugin_menu_parent,
    				$page,
    				$page,
    				$tm_plugin_menu_general['capability'],
    				$tm_plugin_menu_general['slug_prefix'] . $page . $tm_plugin_menu_general['slug_suffix'],
    				$tm_plugin_menu_general['func_prefix'] . $page
    			);
    		}
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)