Last active
September 25, 2015 16:21
-
-
Save annalinneajohansson/9e2d4c222d5dc6818b45 to your computer and use it in GitHub Desktop.
Register wp dashboard widgets created via ACF Flexible Fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function custom_dashboard_widgets() { | |
| if ( function_exists( 'get_field' ) ) { | |
| if ( get_field( 'custom-dashboard-widgets', 'options' ) ) { | |
| $i = 0; | |
| while( has_sub_field( 'custom-dashboard-widgets', 'options' ) ) : | |
| $i++; | |
| if ( 'video_clip_widget' === get_row_layout() ) : | |
| wp_add_dashboard_widget( 'custom_dashboard_widget_' . $i, get_sub_field( 'title' ), 'custom_dashboard_widgets_output', false, array( 'content' => get_sub_field( 'video' ), 'class' => 'custom_dashboard_widget_video', 'layout' => get_row_layout() ) ); | |
| elseif ( 'post_widget' === get_row_layout() ) : | |
| $widget_posts = new WP_Query( array( 'post__in' => array( get_sub_field( 'post' ) ), 'post_type' => 'any' ) ); | |
| if ( $widget_posts->have_posts() ) : | |
| while ( $widget_posts->have_posts() ) : $widget_posts->the_post(); | |
| wp_add_dashboard_widget( 'custom_dashboard_widget_' . $i, get_the_title( $post ), 'custom_dashboard_widgets_output', false, array( 'content' => get_the_content(), 'class' => 'custom_dashboard_widget_post', 'layout' => get_row_layout() ) ); | |
| endwhile; | |
| wp_reset_postdata(); | |
| endif; | |
| else : | |
| wp_add_dashboard_widget( 'custom_dashboard_widget_' . $i, get_sub_field( 'title' ), 'custom_dashboard_widgets_output', false, array( 'content' => get_sub_field( 'content' ), 'class' => 'custom_dashboard_widget_regular', 'layout' => get_row_layout() ) ); | |
| endif; | |
| endwhile; | |
| } | |
| } | |
| add_action( 'wp_dashboard_setup', 'custom_dashboard_widgets', 999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment