Help about AdminAction
Tim4c opened this issue · comments
Hi there,
Can you provide an example on how to create an admin menu page from the AdminAction class?
My goal at the end is to create a CRUD section in the Wordpress admin for an "external" entity (created with sf/doctrine).
Thanks in advance.
Hello @Tim4c , this should works.
<?php
#src/Action/AdminAction.php
namespace App\Action;
use Metabolism\WordpressBundle\Action\AdminAction as BaseAdminAction;
class AdminAction extends BaseAdminAction
{
public function __construct()
{
parent::__construct();
add_action( 'admin_menu', [$this, 'my_admin_menu']);
}
function my_admin_menu() {
add_menu_page(
__( 'Sample page', 'my-textdomain' ),
__( 'Sample menu', 'my-textdomain' ),
'manage_options',
'sample-page',
[$this, 'my_admin_page_contents'],
'dashicons-schedule',
3
);
}
function my_admin_page_contents() {
?>
<h1>
<?php esc_html_e( 'Welcome to my custom admin page.', 'my-plugin-textdomain' ); ?>
</h1>
<?php
}
}
@wearemetabolism Thanks, it works fine. My mistake was to add the add_action in init() method... @++