Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
emily sparkle

when i update to v7 on rockvoices…

i can’t figure out how to get this back on the left navigation. once upon a time you sweetly gave me this code and now our content managers rely on it! how do i get it back for them. thanks so much.

:) emily sparkle

View post on imgur.com

6 days, 19 hours ago
Tobias Schutter
Developer

Hi Emily, to know what exactly this code does we need to see it in its entirety. Can you send u the AdminColumnsMenu class to support@admincolumns.com?

6 days, 4 hours ago
emily sparkle

oh, sorry….

class AdminColumnsMenu {

	private $list_id;
	private $label;
	private $list_screen;
	private $menu_slug;

	public function __construct( $list_id, $label = null ) {
		$this->list_id = (string) $list_id;
		$this->label   = $label;
		$this->menu_slug = 'rv-ac-layout-' . sanitize_key( $this->list_id );

		$this->list_screen = $this->find_list_screen( $this->list_id );
		if ( ! $this->list_screen ) {
			return;
		}

		if ( null === $this->label && method_exists( $this->list_screen, 'get_title' ) ) {
			$this->label = (string) $this->list_screen->get_title();
		}
		if ( empty( $this->label ) ) {
			$this->label = 'Columns';
		}

		add_action( 'admin_menu', array( $this, 'register_menu' ) );
	}

	private function find_list_screen( $list_id ) {
		if ( ! function_exists( 'AC' ) ) {
			return null;
		}

		$ac = AC();
		if ( ! is_object( $ac ) || ! method_exists( $ac, 'get_storage' ) ) {
			return null;
		}

		$storage = $ac->get_storage();
		if ( ! is_object( $storage ) || ! method_exists( $storage, 'find' ) ) {
			return null;
		}

		try {
			// ACP 6/7 compatible: prefer typed ID object when available.
			if ( class_exists( 'AC\\Type\\ListScreenId' ) ) {
				$id_obj = new AC\Type\ListScreenId( $list_id );
				return $storage->find( $id_obj );
			}

			// Fallback for older/newer APIs that may accept a scalar id.
			return $storage->find( $list_id );
		} catch ( Throwable $e ) {
			return null;
		}
	}

	private function get_parent_url() {
		if ( ! $this->list_screen || ! method_exists( $this->list_screen, 'get_post_type' ) ) {
			return 'edit.php?post_type=choir_location';
		}

		$post_type = (string) $this->list_screen->get_post_type();
		if ( '' === $post_type ) {
			return 'edit.php?post_type=choir_location';
		}

		if ( 'post' === $post_type ) {
			return 'edit.php';
		}

		return 'edit.php?post_type=' . $post_type;
	}

	private function get_menu_slug() {
		return $this->menu_slug;
	}

	private function get_menu_url() {
		if ( ! $this->list_screen ) {
			return '';
		}

		if ( method_exists( $this->list_screen, 'get_table_url' ) ) {
			return (string) $this->list_screen->get_table_url();
		}
		if ( method_exists( $this->list_screen, 'get_edit_link' ) ) {
			return (string) $this->list_screen->get_edit_link();
		}
		if ( method_exists( $this->list_screen, 'get_url' ) ) {
			return (string) $this->list_screen->get_url();
		}

		return '';
	}

	public function register_menu() {
		$parent_url = $this->get_parent_url();
		$menu_slug  = $this->get_menu_slug();
		$menu_url   = $this->get_menu_url();
		if ( '' === $parent_url || '' === $menu_slug || '' === $menu_url ) {
			return;
		}

		add_submenu_page(
			$parent_url,
			$this->label,
			$this->label,
			'manage_options',
			$menu_slug,
			array( $this, 'render_menu_page' )
		);
	}

	public function render_menu_page() {
		$menu_url = $this->get_menu_url();
		if ( '' === $menu_url ) {
			wp_die( esc_html__( 'Admin Columns layout URL is unavailable.', 'fonty-rv' ) );
		}

		wp_safe_redirect( $menu_url );
		exit;
	}
}

add_action( 'ac/ready', function () {
	add_action( 'init', function () {
		// Provide a valid ListID and the rest is done automatically.
		new AdminColumnsMenu( '650c803ad4a96', '- Locations' );
		new AdminColumnsMenu( '6582dd74d48e3', '- Enrollment' );
		new AdminColumnsMenu( '6582fb33e7608', '- Concerts' );
		new AdminColumnsMenu( '66c73d6a26cc7', '- Dates Maintenance' );
	} );
} );
1 hour, 15 minutes ago

You must be logged in to reply to this topic.