ap_menu_obejct()

Description #

Create array of object containing AnsPress pages. To be used in admin menu metabox.

Changelog #

VersionDescription
unknownunknown
4.1.0Introduced.

Source #

File: includes/theme.php

function ap_menu_obejct() {
	$menu_items = array();

	foreach ( (array) anspress()->pages as $k => $args ) {
		if ( $args['show_in_menu'] ) {
			$object_id = 1;
			$object    = $k;
			$title     = $args['title'];
			$url       = home_url( '/' );
			$type      = 'anspress-links';

			$main_pages = array_keys( ap_main_pages() );

			if ( in_array( $k . '_page', $main_pages, true ) ) {
				$post = get_post( ap_opt( $k . '_page' ) );

				// Proceed only if post is available.
				if ( $post ) {
					$object_id = ap_opt( $k . '_page' );
					$object    = 'page';
					$url       = get_permalink( $post );
					$title     = $post->post_title;
					$type      = 'post_type';
				}
			}

			$menu_items[] = (object) array(
				'ID'               => 1,
				'db_id'            => 0,
				'menu_item_parent' => 0,
				'object_id'        => $object_id,
				'post_parent'      => 0,
				'type'             => $type,
				'object'           => $object,
				'type_label'       => __( 'AnsPress links', 'anspress-question-answer' ),
				'title'            => $title,
				'url'              => $url,
				'target'           => '',
				'attr_title'       => '',
				'description'      => '',
				'classes'          => array( 'anspress-menu-' . $k ),
				'xfn'              => '',
			);
		}
	}

	/**
	 * Hook for filtering default AnsPress menu objects.
	 *
	 * @param array $menu_items Array of menu objects.
	 * @since 4.1.2
	 */
	return apply_filters( 'ap_menu_object', $menu_items );
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment