diff --git a/friends-admin.css b/friends-admin.css index 5016ed05..e5383ec8 100644 --- a/friends-admin.css +++ b/friends-admin.css @@ -278,3 +278,7 @@ span#friends_enable_retention_number_line { width: .8rem; z-index: 1; } + +#friends-dashboard-widget .author-avatar { + vertical-align: middle; +} diff --git a/friends-admin.js b/friends-admin.js index b08afde3..f6412e3b 100644 --- a/friends-admin.js +++ b/friends-admin.js @@ -344,6 +344,29 @@ jQuery( function ( $ ) { } } ); + setTimeout( function () { + if ( $( '#friends-dashboard-widget' ).length ) { + $( '#friends-dashboard-widget' ).append( ' ' ); + $.post( + friends.ajax_url, + { + _ajax_nonce: $( '#friends-dashboard-widget' ).data( 'nonce' ), + action: 'friends_dashboard', + }, + function ( response ) { + if ( response.success ) { + $( '#friends-dashboard-widget' ).html( response.data ); + } else { + $( '#friends-dashboard-widget i' ) + .removeClass( 'friends-loading' ) + .addClass( 'dashicons dashicons-warning' ) + .prop( 'title', response.data ); + } + } + ); + } + }, 500 ); + setTimeout( function () { if ( $( '#fetch-feeds' ).length ) { $( '#fetch-feeds' ).append( ' ' ); diff --git a/friends.php b/friends.php index c4d0f4bc..0fed8cc4 100644 --- a/friends.php +++ b/friends.php @@ -182,7 +182,7 @@ function validate_feed_rules( $rules ) { * @return false|string URL or false on failure. */ function check_url( $url ) { - return check_url( $url ); + return Friends::check_url( $url ); } // Integrations. diff --git a/includes/class-admin.php b/includes/class-admin.php index ad704fa5..d285ab6d 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -64,6 +64,8 @@ private function register_hooks() { add_action( 'remove_user_from_blog', array( $this, 'delete_user' ) ); add_action( 'tool_box', array( $this, 'toolbox_bookmarklets' ) ); add_action( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ) ); + add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widget' ) ); + add_action( 'wp_ajax_friends_dashboard', array( $this, 'ajax_friends_dashboard' ) ); add_filter( 'site_status_tests', array( $this, 'site_status_tests' ) ); add_filter( 'site_status_test_php_modules', array( $this, 'site_status_test_php_modules' ) ); add_filter( 'debug_information', array( $this, 'site_health_debug' ) ); @@ -3047,6 +3049,51 @@ public function dashboard_glance_items( $items ) { return $items; } + public function add_dashboard_widget() { + wp_add_dashboard_widget( 'friends_dashboard_widget', __( 'Friends: Latest Posts', 'friends' ), array( $this, 'render_dashboard_widget' ), null, null, 'column3' ); + } + + public function render_dashboard_widget() { + ?> +
+
+ get_total() ) { + Friends::template_loader()->get_template_part( + 'admin/dashboard-widget-welcome', + null, + array() + ); + + } else { + Friends::template_loader()->get_template_part( + 'admin/dashboard-widget', + null, + array( + 'posts' => get_posts( + array( + 'post_type' => apply_filters( 'friends_frontend_post_types', array( 'post' ) ), + ) + ), + ) + ); + } + $data = ob_get_contents(); + ob_end_clean(); + + wp_send_json_success( + $data + ); + } + public function site_status_tests( $tests ) { $tests['direct']['friends-roles'] = array( 'label' => __( 'Friend roles were created', 'friends' ), diff --git a/includes/class-frontend.php b/includes/class-frontend.php index 8d64be9f..fef0b125 100644 --- a/includes/class-frontend.php +++ b/includes/class-frontend.php @@ -796,6 +796,10 @@ function ( $feed ) { 'post_format' => $this->post_format, ); + if ( isset( $_GET['welcome'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $args['show_welcome'] = true; + } + return Friends::template_loader()->get_template_part( 'frontend/index', $this->post_format, $args, false ); } @@ -1159,7 +1163,7 @@ public function friend_posts_query( $query ) { } $page_id = get_query_var( 'page' ); -// phpcs:disable WordPress.Security.NonceVerification.Recommended + // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['share'] ) ) { $share_hash = hash( 'crc32b', apply_filters( 'friends_share_salt', wp_salt( 'nonce' ), $page_id ) . $page_id ); if ( $_GET['share'] === $share_hash ) { diff --git a/templates/admin/dashboard-widget-welcome.php b/templates/admin/dashboard-widget-welcome.php new file mode 100644 index 00000000..1a8e60f9 --- /dev/null +++ b/templates/admin/dashboard-widget-welcome.php @@ -0,0 +1,13 @@ + +

+ diff --git a/templates/admin/dashboard-widget.php b/templates/admin/dashboard-widget.php new file mode 100644 index 00000000..3dce5e28 --- /dev/null +++ b/templates/admin/dashboard-widget.php @@ -0,0 +1,47 @@ + + diff --git a/templates/admin/settings-header.php b/templates/admin/settings-header.php index 1ecf6850..f09b6ea3 100644 --- a/templates/admin/settings-header.php +++ b/templates/admin/settings-header.php @@ -47,7 +47,7 @@ } if ( is_array( $_page ) ) { $query = $_page; - $_page = $args['page']; + $_page = $_page['page']; } else { $query = array( 'page' => $_page, diff --git a/templates/frontend/index.php b/templates/frontend/index.php index a06f8ecb..206a2523 100644 --- a/templates/frontend/index.php +++ b/templates/frontend/index.php @@ -12,15 +12,17 @@ $args ); +$show_welcome = isset( $args['show_welcome'] ) && $args['show_welcome']; + ?>
frontend->post_format ) { + if ( ! $show_welcome && $args['friends']->frontend->post_format ) { $post_formats = get_post_format_strings(); if ( $args['friend_user'] ) { @@ -49,7 +51,7 @@ } } else { $any_friends = Friends\User_Query::all_associated_users(); - if ( $any_friends->get_total() > 0 ) { + if ( ! $show_welcome && $any_friends->get_total() > 0 ) { Friends\Friends::template_loader()->get_template_part( 'frontend/no-posts', $args['post_format'], $args ); } else { Friends\Friends::template_loader()->get_template_part( 'frontend/no-friends', $args['post_format'], $args ); diff --git a/templates/frontend/parts/header.php b/templates/frontend/parts/header.php index 364cb489..54ed87ea 100644 --- a/templates/frontend/parts/header.php +++ b/templates/frontend/parts/header.php @@ -43,12 +43,12 @@ * }, 10, 3 ); * ``` */ -$avatar = apply_filters( 'friends_author_avatar_url', $avatar, $friend_user, get_the_id() ); ++ 45 ?>