ACF Archive is not working, Advanced Custom Fields is not installed.
get_custom_post_types();
foreach ( $post_types as $key => $post_type ) {
$this->add_menu( $key );
}
}
/**
* @todo hack to solve the order menu issue (init hook)
*
* @param $menu_order
* @return mixed
*/
function menu_order( $menu_order ) {
global $submenu;
foreach ( $submenu as $key => $data ) {
if ( strpos( $key, '-archive-options' ) !== false ) {
$submenu[$key] = array_reverse( $submenu[$key], true );
}
}
return $menu_order;
}
/**
* Load the ACF Assets only on archive options page
*/
function admin_enqueue_scripts() {
$screen = get_current_screen();
foreach ( $this->admin_pages as $cpt => $admin_page ) {
if ( $this->get_admin_page_slug( $cpt ) == $screen->id ) {
acf_enqueue_scripts();
}
}
}
/**
* Load ACF spinner on page submit
*/
function admin_footer() {
$screen = get_current_screen();
foreach ( $this->admin_pages as $cpt => $admin_page ) {
if ( $this->get_admin_page_slug( $cpt ) == $screen->id ) {
$this->print_spinner_script();
}
}
}
private function get_admin_page_slug( $cpt ) {
return "admin_page_{$cpt}-archive-options";
}
/**
* Print ACF spinner script
*/
private function print_spinner_script() {
?>
'edit.php?post_type=' . $cpt,
'page_title' => $page_name,
'menu_title' => $page_name,
'capability' => 'edit_posts',
'menu_slug' => $cpt . '-archive-options',
);
add_submenu_page(
$options['parent_slug'],
$options['page_title'],
$options['menu_title'],
$options['capability'],
$options['menu_slug'],
[ $this, 'render_menu' ]
);
$this->admin_pages[$cpt] = $page_name;
}
/**
* Render the archive options page
*/
public function render_menu() {
$screen = get_current_screen();
$parts = explode( '-', $screen->parent_base );
$post_id = $parts[0];
if ( isset( $_POST[ $post_id ] ) ) {
if( acf_verify_nonce( $post_id ) ) {
if( acf_validate_save_post(true ) ) {
acf_save_post( $post_id );
}
}
}
$field_groups = acf_get_field_groups( array( 'post_id' => $post_id ) );
if ( empty( $field_groups ) ) {
echo '