Skip to content

Commit

Permalink
Merge pull request #1 from ajaxloadmore/hotfix/php-warnings
Browse files Browse the repository at this point in the history
Fix for php warnings
  • Loading branch information
dcooney authored Feb 16, 2023
2 parents 7831569 + 0e7f640 commit 75e9b70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Donate link: https://connekthq.com/donate/
Tags: ajax load more, rest api, api, rest, ajax, infinite scroll, javascript, query, endpoints, endpoint, lazy load
Requires at least: 4.0
Tested up to: 6.1
Stable tag: 1.2.2
Stable tag: 1.2.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -74,6 +74,9 @@ Yes! As long as you are using the default /wp-json/ajaxloadmore/posts endpoint a

== Changelog ==

= 1.2.3 - February 23, 2023 =
* FIX: Fixed up PHP warnign messages found in debug log for default endpoint.

= 1.2.2 - December 30, 2022 =
* FIX: Added fix for saving posts in editor when REST API shortcode in place.
* UPDATE: Updated custo endpoint to rely on core ALM query params.
Expand Down
6 changes: 3 additions & 3 deletions ajax-load-more-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author: Darren Cooney
* Twitter: @KaptonKaos
* Author URI: https://connekthq.com
* Version: 1.2.2
* Version: 1.2.3
* License: GPL
* Copyright: Darren Cooney & Connekt Media
*
Expand All @@ -23,8 +23,8 @@
*/
define( 'ALM_RESTAPI_PATH', plugin_dir_path( __FILE__ ) );
define( 'ALM_RESTAPI_URL', plugins_url( '', __FILE__ ) );
define( 'ALM_RESTAPI_VERSION', '1.2.2' );
define( 'ALM_RESTAPI_RELEASE', 'December 30, 2022' );
define( 'ALM_RESTAPI_VERSION', '1.2.3' );
define( 'ALM_RESTAPI_RELEASE', 'February 16, 2023' );

/**
* Activation hook
Expand Down
9 changes: 5 additions & 4 deletions endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ function alm_get_posts( $data ) {
$response = [];

// Set Defaults.
$args = [];
$page = $data['page'];
$args = [];
$page = isset( $data['page'] ) ? $data['page'] : 0;
$posts_per_page = isset( $data['posts_per_page'] ) ? $data['posts_per_page'] : 5;

if ( method_exists( 'ALM_QUERY_ARGS', 'alm_build_queryargs' ) ) {
/**
Expand All @@ -67,7 +68,7 @@ function alm_get_posts( $data ) {
*
* @see https://connekthq.com/plugins/ajax-load-more/docs/variables/
*/
$alm_item = $args['page'] * $posts_per_page;
$alm_item = $page * $posts_per_page;
$alm_found_posts = $posts->found_posts;
$alm_post_count = $posts->post_count;
$alm_current = 0;
Expand All @@ -90,7 +91,7 @@ function alm_get_posts( $data ) {

// Build $data JSON object.
$data[] = [
'alm_page' => $args['page'] + 1,
'alm_page' => $page + 1,
'alm_item' => ( $alm_item++ ) + 1,
'alm_current' => $alm_current,
'alm_found_posts' => $alm_found_posts,
Expand Down

0 comments on commit 75e9b70

Please sign in to comment.