';
}
if ($column === 'status_col') {
$status = get_post_meta($post_id, 'status_label', true);
if ($status === 'Active') {
echo '● Active';
} else {
echo '● Inactive';
}
}
if ($column === 'block_type') {
$block_type = get_post_meta($post_id, 'block_type', true);
if ($block_type === 'Logged In') {
echo 'Logged In';
} else {
echo 'Non Logged In';
}
}
if ($column === 'updated') {
$modified = get_post_modified_time('M j, Y g:i A', false, $post_id);
echo esc_html($modified);
}
}
/**
* Enqueue admin scripts
*/
public function enqueue_admin_scripts($hook)
{
// Only load on blocks post type pages
$screen = get_current_screen();
if ($screen && $screen->post_type === 'fma_blocks') {
// Enqueue jQuery if not already loaded
wp_enqueue_script('jquery');
// Use the same select2 handle that's registered in class_fma_main
// This ensures select2 is available before afm-scripts.js loads
wp_enqueue_style('afm-jquery.select2', FMA_PLUGIN_URL . 'application/assets/css/select2/jquery.select2.min.css', array(), FMA_VERSION, 'all');
wp_enqueue_script('afm-jquery.select2', FMA_PLUGIN_URL . 'application/assets/js/select2/jquery.select2.min.js', array('jquery'), FMA_VERSION, false);
// Enqueue admin scripts that contain popup function
// Use same handle as class_fma_main for consistency
wp_enqueue_style('afm-admin', FMA_PLUGIN_URL . 'application/assets/css/afm-styles.css', array('afm-jquery.select2'), FMA_VERSION, 'all');
wp_enqueue_script('afm-admin', FMA_PLUGIN_URL . 'application/assets/js/afm-scripts.js', array('afm-jquery.select2'), FMA_VERSION, false);
// Localize script with admin URL (same as class_fma_main)
wp_localize_script('afm-admin', 'afmAdmin', array(
'assetsURL' => FMA_PLUGIN_URL . 'application/assets/',
'jsonURL' => rest_url(),
));
}
}
/**
* Register Blocks Post Type
*/
public function register_blocks_post_type()
{
// Only register if pro plugin is not active
if (class_exists('file_manager_advanced_shortcode')) {
return;
}
$labels = array(
'name' => _x('Blocks', 'Post type general name', 'file-manager-advanced'),
'singular_name' => _x('Block', 'Post type singular name', 'file-manager-advanced'),
'menu_name' => _x('File Managers', 'Admin Menu text', 'file-manager-advanced'),
'add_new' => __('Add New', 'file-manager-advanced'),
'add_new_item' => __('Add New Block', 'file-manager-advanced'),
'new_item' => __('New Block', 'file-manager-advanced'),
'edit_item' => __('Edit Block', 'file-manager-advanced'),
'view_item' => __('View Block', 'file-manager-advanced'),
'all_items' => __('All Blocks', 'file-manager-advanced'),
'search_items' => __('Search Blocks', 'file-manager-advanced'),
'not_found' => __('No blocks found.', 'file-manager-advanced'),
'not_found_in_trash' => __('No blocks found in Trash.', 'file-manager-advanced'),
);
$args = array(
'labels' => $labels,
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => false, // We'll add it manually via submenu
'query_var' => true,
'rewrite' => false,
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => null,
'menu_icon' => 'dashicons-media-archive',
'supports' => array('title'),
'show_in_rest' => false, // Disable Gutenberg
);
register_post_type('fma_blocks', $args);
$this->register_blocks_dummy_data();
}
/**
* Register dummy data for blocks post type
*/
private function register_blocks_dummy_data()
{
// Run only once to prevent duplicates
if (get_option('fma_blocks_dummy_data_created'))
return;
$dummy_blocks = [
[
'title' => 'Test Block 1',
'block_type' => 'Logged In',
'shortcode_id' => 'abc123xyz',
'status' => 'Active',
],
[
'title' => 'Test Block 2',
'block_type' => 'Non Logged In',
'shortcode_id' => 'xyz456abc',
'status' => 'Inactive',
],
[
'title' => 'Sample Block 3',
'block_type' => 'Logged In',
'shortcode_id' => 'pqr789lmn',
'status' => 'Active',
],
];
foreach ($dummy_blocks as $block) {
$post_id = wp_insert_post([
'post_type' => 'fma_blocks',
'post_title' => $block['title'],
'post_status' => 'publish',
]);
if (!is_wp_error($post_id)) {
update_post_meta($post_id, 'block_type', $block['block_type']);
update_post_meta($post_id, 'shortcode_id', $block['shortcode_id']);
update_post_meta($post_id, 'status_label', $block['status']);
}
}
update_option('fma_blocks_dummy_data_created', true);
}
/**
* Add meta boxes for blocks post type
*/
public function add_blocks_meta_boxes()
{
// Only add if pro plugin is not active
if (class_exists('file_manager_advanced_shortcode')) {
return;
}
add_meta_box(
'fma_blocks_pro_overlay',
__('Block Configuration', 'file-manager-advanced'),
array($this, 'blocks_pro_overlay_meta_box_callback'),
'fma_blocks',
'normal',
'high'
);
}
/**
* Blocks Pro Overlay Meta Box Callback
*/
public function blocks_pro_overlay_meta_box_callback($post)
{
?>
$item) {
if (isset($item[2]) && $item[2] === 'file_manager_advanced_shortcodes') {
unset($submenu['file_manager_advanced_ui'][$key]);
}
}
}
// Add new submenu pointing to blocks post type
// This will add it at the end, we'll reorder it below
add_submenu_page(
'file_manager_advanced_ui',
__('Blocks', 'file-manager-advanced'),
__('Blocks', 'file-manager-advanced'),
'manage_options',
'edit.php?post_type=fma_blocks'
);
// Reorder submenu to put Blocks at the original position (after AI Code Pilot, before DB Access)
if (isset($submenu['file_manager_advanced_ui']) && is_array($submenu['file_manager_advanced_ui'])) {
$blocks_item = null;
$menu_items = array();
// Find and extract blocks item
foreach ($submenu['file_manager_advanced_ui'] as $key => $item) {
if (isset($item[2]) && $item[2] === 'edit.php?post_type=fma_blocks') {
$blocks_item = $item;
} else {
$menu_items[] = $item;
}
}
// Insert blocks at the correct position
if ($blocks_item) {
$insert_position = 2; // Default: after Settings (0) and AI Code Pilot (1), so position 2
$ai_code_pilot_found = false;
// Find AI Code Pilot position
foreach ($menu_items as $index => $item) {
if (isset($item[2]) && $item[2] === 'ai-code-pilot') {
$insert_position = $index + 1; // Insert after AI Code Pilot
$ai_code_pilot_found = true;
break;
}
}
// If AI Code Pilot not found, insert after Settings (position 1)
if (!$ai_code_pilot_found) {
$insert_position = 1;
}
// Insert blocks at the calculated position
array_splice($menu_items, $insert_position, 0, array($blocks_item));
// Update submenu
$submenu['file_manager_advanced_ui'] = $menu_items;
}
}
}
/**
* Add blur overlay to blocks list page (same style as OneDrive/Dropbox)
*/
public function add_blocks_list_blur_overlay()
{
// Only add if pro plugin is not active
if (class_exists('file_manager_advanced_shortcode')) {
return;
}
// Only on blocks post type pages
$screen = get_current_screen();
if (!$screen || $screen->post_type !== 'fma_blocks') {
return;
}
// Only on list page (edit.php), not on edit page
if ($screen->base === 'edit' && $screen->post_type === 'fma_blocks') {
?>