core = $core;
parent::__construct( MWAI_PREFIX, MWAI_ENTRY, MWAI_DOMAIN, class_exists( 'MeowPro_MWAI_Core' ) );
if ( is_admin() ) {
$this->contentGeneratorEnabled = $this->core->get_option( 'module_generator_content' );
$this->imagesGeneratorEnabled = $this->core->get_option( 'module_generator_images' );
$this->videosGeneratorEnabled = $this->core->get_option( 'module_generator_videos' );
$this->playgroundEnabled = $this->core->get_option( 'module_playground' );
$can_access_settings = $this->core->can_access_settings();
$can_access_features = $this->core->can_access_features();
if ( $can_access_settings || $can_access_features ) {
add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
}
if ( $can_access_settings ) {
add_action( 'admin_menu', [ $this, 'app_menu' ] );
}
if ( $can_access_features ) {
add_action( 'admin_menu', [ $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_filter( 'page_row_actions', [ $this, 'post_row_actions' ], 10, 2 );
}
if ( $this->imagesGeneratorEnabled ) {
add_filter( 'media_row_actions', [ $this, 'media_row_actions' ], 10, 2 );
}
add_action( 'admin_footer', [ $this, 'admin_footer' ] );
}
}
}
public function admin_menu() {
// Generate New (under Posts)
if ( $this->contentGeneratorEnabled ) {
add_submenu_page(
'edit.php',
'Generate New',
'Generate New',
'read',
'mwai_content_generator',
[ $this, 'ai_content_generator' ],
2
);
}
// In Tools
if ( $this->playgroundEnabled ) {
add_management_page(
'Playground',
__( 'Playground', 'ai-engine' ),
'read',
'mwai_dashboard',
[ $this, 'ai_playground' ]
);
}
if ( $this->contentGeneratorEnabled ) {
add_management_page(
'Generate Content',
'Generate Content',
'read',
'mwai_content_generator',
[ $this, 'ai_content_generator' ]
);
}
if ( $this->imagesGeneratorEnabled ) {
add_management_page(
'Generate Images',
'Generate Images',
'read',
'mwai_images_generator',
[ $this, 'ai_image_generator' ]
);
}
if ( $this->videosGeneratorEnabled ) {
add_management_page(
'Generate Videos',
'Generate Videos',
'read',
'mwai_videos_generator',
[ $this, 'ai_video_generator' ]
);
}
// In the Admin Bar:
add_action( 'admin_bar_menu', [ $this, 'admin_bar_menu' ], 100 );
}
public 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'];
$videos_generator = isset( $admin_bar['videos_generator'] ) && $admin_bar['videos_generator'];
// Workspace is checked by default (a missing key counts as enabled), but
// only appears when the module is on and the Pro class runs it.
$workspace = ( !isset( $admin_bar['workspace'] ) || $admin_bar['workspace'] ) &&
$this->core->get_option( 'module_workspace' ) &&
class_exists( 'Meow_MWAI_Modules_Workspace' ) &&
current_user_can( 'manage_options' );
if ( $settings ) {
$wp_admin_bar->add_node( [
'id' => 'mwai-settings',
'title' => '' . __( 'AI Engine', 'ai-engine' ),
'href' => admin_url( 'admin.php?page=mwai_settings' ),
'meta' => [ 'class' => 'mwai-settings' ],
] );
}
if ( $content_generator ) {
$wp_admin_bar->add_node( [
'id' => 'mwai-content-generator',
'title' => MWAI_IMG_WAND_HTML . __( 'Content', 'ai-engine' ),
'href' => admin_url( 'tools.php?page=mwai_content_generator' ),
'meta' => [ 'class' => 'mwai-content-generator' ],
] );
}
if ( $images_generator ) {
$wp_admin_bar->add_node( [
'id' => 'mwai-image-generator',
'title' => MWAI_IMG_WAND_HTML . __( 'Images', 'ai-engine' ),
'href' => admin_url( 'tools.php?page=mwai_images_generator' ),
'meta' => [ 'class' => 'mwai-images-generator' ],
] );
}
if ( $videos_generator ) {
$wp_admin_bar->add_node( [
'id' => 'mwai-video-generator',
'title' => MWAI_IMG_WAND_HTML . __( 'Videos', 'ai-engine' ),
'href' => admin_url( 'tools.php?page=mwai_videos_generator' ),
'meta' => [ 'class' => 'mwai-videos-generator' ],
] );
}
// The Global Magic Wand
// if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
// $wp_admin_bar->add_node( array(
// 'id' => 'mwai-debug',
// 'title' => MWAI_IMG_WAND_HTML . __( 'Magic Wand', 'ai-engine' ),
// //'href' => admin_url( 'tools.php?page=mwai_debug' ),
// 'meta' => array( 'class' => 'mwai-debug' ),
// ) );
// }
if ( $playground ) {
$wp_admin_bar->add_node( [
'id' => 'mwai-playground',
'title' => MWAI_IMG_WAND_HTML . __( 'Playground', 'ai-engine' ),
'href' => admin_url( 'tools.php?page=mwai_dashboard' ),
'meta' => [ 'class' => 'mwai-playground' ],
] );
}
if ( $workspace ) {
$nyao = "";
$wp_admin_bar->add_node( [
'id' => 'mwai-workspace',
'title' => $nyao . __( 'Workspace', 'ai-engine' ),
'href' => admin_url( 'admin.php?page=mwai_workspace' ),
'meta' => [ 'class' => 'mwai-workspace' ],
] );
}
}
public function ai_playground() {
echo '