core = $core;
parent::__construct( MWAI_PREFIX, MWAI_ENTRY, MWAI_DOMAIN, class_exists( 'MeowPro_MWAI_Core' ) );
if ( is_admin() ) {
$this->imgWand = "";
$this->contentGeneratorEnabled = $this->core->get_option( 'module_generator_content' );
$this->imagesGeneratorEnabled = $this->core->get_option( 'module_generator_images' );
$this->playgroundEnabled = $this->core->get_option( 'module_playground' );
if ( $this->core->can_access_settings() ) {
add_action( 'admin_menu', array( $this, 'app_menu' ) );
}
if ( $this->core->can_access_features() ) {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
// Only if the Suggestions are enabled.
$this->suggestionsEnabled = $this->core->get_option( 'module_suggestions' );
if ( $this->suggestionsEnabled ) {
add_filter( 'post_row_actions', [ $this, 'post_row_actions' ], 10, 2 );
}
add_action( 'admin_footer', [ $this, 'admin_footer' ] );
}
}
}
function admin_menu() {
// Generate New (under Posts)
if ( $this->contentGeneratorEnabled) {
add_submenu_page( 'edit.php', 'Generate New', 'Generate New', 'read', 'mwai_content_generator',
array( $this, 'ai_content_generator' ), 2 );
}
// In Tools
if ( $this->playgroundEnabled ) {
add_management_page( 'Playground', __( 'Playground', 'ai-engine' ), 'read',
'mwai_dashboard', array( $this, 'ai_playground' ) );
}
if ( $this->contentGeneratorEnabled ) {
add_management_page( 'Generate Content', 'Generate Content', 'read', 'mwai_content_generator',
array( $this, 'ai_content_generator' ) );
}
if ( $this->imagesGeneratorEnabled ) {
add_management_page( 'Generate Images', 'Generate Images', 'read', 'mwai_images_generator',
array( $this, 'ai_image_generator' ) );
}
// In the Admin Bar:
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 100 );
}
function admin_bar_menu( $wp_admin_bar ) {
$admin_bar = $this->core->get_option( 'admin_bar' );
$settings = isset( $admin_bar['settings'] ) && $admin_bar['settings'];
$playground = isset( $admin_bar['playground'] ) && $admin_bar['playground'];
$content_generator = isset( $admin_bar['content_generator'] ) && $admin_bar['content_generator'];
$images_generator = isset( $admin_bar['images_generator'] ) && $admin_bar['images_generator'];
if ( $settings ) {
$wp_admin_bar->add_node( array(
'id' => 'mwai-settings',
'title' => '' . __( 'AI Engine', 'ai-engine' ),
'href' => admin_url( 'admin.php?page=mwai_settings' ),
'meta' => array( 'class' => 'mwai-settings' ),
) );
}
if ( $content_generator ) {
$wp_admin_bar->add_node( array(
'id' => 'mwai-content-generator',
'title' => $this->imgWand . __( 'Content', 'ai-engine' ),
'href' => admin_url( 'tools.php?page=mwai_content_generator' ),
'meta' => array( 'class' => 'mwai-content-generator' ),
) );
}
if ( $images_generator ) {
$wp_admin_bar->add_node( array(
'id' => 'mwai-image-generator',
'title' => $this->imgWand . __( 'Images', 'ai-engine' ),
'href' => admin_url( 'tools.php?page=mwai_images_generator' ),
'meta' => array( 'class' => 'mwai-images-generator' ),
) );
}
// If it's WP_DEBUG then let's add a menu
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$wp_admin_bar->add_node( array(
'id' => 'mwai-debug',
'title' => $this->imgWand . __( 'Magic Wand', 'ai-engine' ),
//'href' => admin_url( 'tools.php?page=mwai_debug' ),
'meta' => array( 'class' => 'mwai-debug' ),
) );
}
if ( $playground ) {
$wp_admin_bar->add_node( array(
'id' => 'mwai-playground',
'title' => $this->imgWand . __( 'Playground', 'ai-engine' ),
'href' => admin_url( 'tools.php?page=mwai_dashboard' ),
'meta' => array( 'class' => 'mwai-playground' ),
) );
}
}
public function ai_playground() {
echo '