Skip to content

Commit

Permalink
Feature/query loop integration (#220)
Browse files Browse the repository at this point in the history
* Adding Previous Posts functionality for Elementor

* Updated template saving, code cleanup.

* Updated query loop functionality

* Initial release prep
  • Loading branch information
dcooney authored Dec 4, 2024
1 parent dfb7a66 commit d39969b
Show file tree
Hide file tree
Showing 53 changed files with 9,992 additions and 17,808 deletions.
18 changes: 16 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Donate link: https://connekthq.com/donate/
Tags: infinite scroll, load more, lazy load, endless scroll, ajax load more
Requires at least: 5.0
Requires PHP: 5.6
Tested up to: 6.6
Stable tag: 7.1.3
Tested up to: 6.7
Stable tag: 7.1.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -260,6 +260,20 @@ How to install Ajax Load More.

== Changelog ==

= 7.1.4 - December 4, 2024 =
* UPDATE: Updated Axios HTTP library to latest version.
* UPDATE: Added feature to re-save default Repeater Template if template was deleted from the filesystem.
* UDPATE: Modified the `alm` db columns to match upcoming Templates add-on requirements.
* UPDATE: Added functionality required for Elementor Add-on update to support loading previous posts on paged results.
* UPDATE: Started integration with Query Loop block and Ajax Load More.
* FIX: Fixed z-index issue with ALM navigation in WP admin.
* FIX: Added fix for `load_plugin_textdomain` php notice.
* FIX: Fixed issue with Preloaded amount being 0 and no post remaining.
* FIX: Fixed issue with Comments add-on and allowing for a default post ID.
* UPDATE: Code cleanup and other minor bug fixes.
* UPDATE: Various admin UI/UX updates.


= 7.1.3 - October 1, 2024 =
* UPDATE: Various security fixes.

Expand Down
3 changes: 1 addition & 2 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
function alm_admin_hooks() {
require_once plugin_dir_path( __FILE__ ) . '/classes/class-nag.php';
}
// phpcs:ignore
// add_action( 'admin_init', 'alm_admin_hooks' );
add_action( 'admin_init', 'alm_admin_hooks' );

/**
* Render a notification in the dashboard.
Expand Down
16 changes: 10 additions & 6 deletions admin/classes/class-nag.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?php

// phpcs:ignorefile
/**
* Admin Notice Nag.
*
* @package AjaxLoadMore
*/

if ( ! class_exists( 'ALM_NAG' ) ) :

/**
* ALM_NAG Class.
*/
class ALM_NAG {

const OPTION_INSTALL_DATE = 'alm-install-date';
const OPTION_ADMIN_NOTICE_KEY = 'alm-hide-notice';
const OPTION_NAG_DELAY = '-7 days';
Expand Down Expand Up @@ -51,7 +56,6 @@ private function catch_hide_notice() {
* Bind nag message
*/
private function bind() {

// Is admin notice hidden?
$current_user = wp_get_current_user();
$hide_notice = get_user_meta( $current_user->ID, ALM_Nag::OPTION_ADMIN_NOTICE_KEY, true );
Expand Down Expand Up @@ -115,8 +119,8 @@ public function display_admin_notice() {
$query_params = $this->get_admin_querystring_array();
$query_string = '?' . http_build_query( array_merge( $query_params, array( ALM_Nag::OPTION_ADMIN_NOTICE_KEY => '1' ) ) );

echo '<div class="updated" style="padding: 15px;">';
printf( __( "<p style='padding: 0; margin: 0 0 15px;'>You've been using <b style='color: #222;'><a href='%1\$s'>Ajax Load More</a></b> for some time now, could you please give it a review at wordpress.org?<br/>All reviews, both good and bad are important as they help the plugin grow and improve over time.</p><p style='padding: 0; margin: 0 0 15px;'><a href='%2\$s' target='_blank' class='button button-primary'>Yes, I'll leave a review</a> &nbsp; <a href='%3\$s' class='button'>No thanks</a> &nbsp; <a href='%4\$s' class='button-no'>I've already done this</a></p><p style='padding: 10px 0 0; margin: 0;'><small><a href='http://connekthq.com/plugins/' target='_blank'>Check out our other <b>Connekt</b> WordPress plugins</a></small></p>" ), get_admin_url() . 'admin.php?page=ajax-load-more', 'http://wordpress.org/support/view/plugin-reviews/ajax-load-more', $query_string, $query_string );
echo '<div class="notice-info notice" style="padding: 15px;">';
printf( __( "<p style='padding: 0; margin: 0 0 15px;'>You've been using <b style='color: #222;'><a href='%1\$s'>Ajax Load More</a></b> for some time now, could you please give it a review at wordpress.org?<br/>All reviews, both good and bad are important as they help the plugin grow and improve over time.</p><p style='padding: 0; margin: 0;'><a href='%2\$s' target='_blank' class='button button-primary'>Leave Review</a> &nbsp; <a href='%3\$s' class='button'>No thanks</a> &nbsp; <a href='%4\$s' class='button-no'>I've already done this</a></p>" ), get_admin_url() . 'admin.php?page=ajax-load-more', 'http://wordpress.org/support/view/plugin-reviews/ajax-load-more', $query_string, $query_string );
echo '</div>';
}
}
Expand Down
111 changes: 14 additions & 97 deletions admin/functions/plugin-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,104 +7,21 @@
*/

/**
* Update default repeater on plugin update.
* If plugin versions do not match or the plugin has been updated and we need to update our repeaters.
* ALM upgrade routine.
*
* @since 2.0.5
* @return void
*/
function alm_core_update() {
// Exit if Repeater Templates are disbaled.
if ( defined( 'ALM_DISABLE_REPEATER_TEMPLATES' ) && ALM_DISABLE_REPEATER_TEMPLATES ) {
return false;
}

// Add 'alm_version' to WP options table if it does not exist.
if ( ! get_option( 'alm_version' ) ) {
add_option( 'alm_version', ALM_VERSION );
}

$alm_installed_ver = get_option( 'alm_version' );
if ( $alm_installed_ver !== ALM_VERSION ) {
alm_run_update(); // Update repeaters.
}
}
add_action( 'init', 'alm_core_update' );

/**
* Run the plugin update on all blogs.
*
* @since 2.7.2
*/
function alm_run_update() {
global $wpdb;

if ( is_multisite() ) {
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );

// Loop all blogs and run update routine.
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
alm_update_template_files();
update_option( 'alm_version', ALM_VERSION );
restore_current_blog();
}
} else {
alm_update_template_files();
update_option( 'alm_version', ALM_VERSION );
}
}

/**
* Update routine for template files.
*
* @throws Exception Unable to write to template file.
* @since 2.7.2
*/
function alm_update_template_files() {
global $wpdb;
$table_name = $wpdb->prefix . 'alm';

// Get all rows where name is 'default'.
$rows = $wpdb->get_results( "SELECT * FROM $table_name WHERE name = 'default'" ); // phpcs:ignore

if ( $rows ) {

foreach ( $rows as $row ) {
$data = $wpdb->get_var( "SELECT repeaterDefault FROM $table_name WHERE name = 'default'" ); // phpcs:ignore

// If required: Create base directory (alm_templates).
$base_dir = AjaxLoadMore::alm_get_repeater_path();
AjaxLoadMore::alm_mkdir( $base_dir );

$file = $base_dir . '/default.php';

/**
* Create template only if the template does not exist.
*
* Note: This should never ever run, but this is used as a fallback incase for some reason Repeater
* have been deleted or cleaned by another plugin.
*/
if ( ! file_exists( $file ) ) {
try {
// phpcs:ignore
$o = fopen( $file, 'w+' ); // Open file.
if ( ! $o ) {
throw new Exception( '[Ajax Load More] Error opening default repeater template - Please check your file path and ensure your server is configured to allow Ajax Load More to read and write files within the `' . $base_dir . '` directory.' );
}
// phpcs:ignore
$w = fwrite( $o, $data ); // Save the file.
if ( ! $w ) {
throw new Exception( '[Ajax Load More] Error updating default repeater template - Please check your file path and ensure your server is configured to allow Ajax Load More to read and write files within the `' . $base_dir . '` directory.' );
}
// phpcs:ignore
fclose( $o ); // Close file.

} catch ( Exception $e ) { // Display error message in console.
if ( ! isset( $options['_alm_error_notices'] ) || $options['_alm_error_notices'] === '1' ) {
echo '<script>console.log("' . wp_kses_post( $e->getMessage() ) . '");</script>';
}
}
}
}
function alm_upgrade_routine() {
// Delete `pluginVersion` column from `alm` table.
if ( get_option( 'alm_drop_pluginVersion' ) !== 'true' ) {
global $wpdb;
$table_name = $wpdb->prefix . 'alm';
$wpdb->hide_errors(); // Suppress errors.
$wpdb->query( "ALTER TABLE $table_name DROP pluginVersion" );
update_option( 'alm_drop_pluginVersion', 'true' );

// Delete alm_version option.
delete_option( 'alm_version' );
}
}
add_action( 'admin_init', 'alm_upgrade_routine' );
15 changes: 5 additions & 10 deletions admin/functions/repeater-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function alm_save_repeater() {
$options = get_option( 'alm_settings' );

// Get form variables.
$c = Trim( stripslashes( $form_data['value'] ) ); // Value.
$n = Trim( stripslashes( str_replace( '/', '', $form_data['repeater'] ) ) ); // Name.
$t = Trim( stripslashes( $form_data['type'] ) ); // Type.
$a = Trim( stripslashes( $form_data['alias'] ) ); // Alias.
$c = trim( stripslashes( $form_data['value'] ) ); // Value.
$n = trim( stripslashes( str_replace( '/', '', $form_data['repeater'] ) ) ); // Name.
$t = trim( stripslashes( $form_data['type'] ) ); // Type.
$a = trim( stripslashes( $form_data['alias'] ) ); // Alias.

// Default.
if ( $t === 'default' ) {
Expand Down Expand Up @@ -81,24 +81,19 @@ function alm_save_repeater() {

// Save to database.
if ( $t === 'default' ) {
$data_update = [
'repeaterDefault' => "$c",
'pluginVersion' => ALM_VERSION,
];
$data_update = [ 'repeaterDefault' => "$c" ];
$data_where = [ 'name' => 'default' ];
} elseif ( $t === 'unlimited' ) { // Custom Repeaters v2.
$table_name = $wpdb->prefix . 'alm_unlimited';
$data_update = [
'repeaterDefault' => "$c",
'alias' => "$a",
'pluginVersion' => ALM_UNLIMITED_VERSION,
];
$data_where = [ 'name' => $n ];
} else { // Custom Repeaters.
$data_update = [
'repeaterDefault' => "$c",
'alias' => "$a",
'pluginVersion' => ALM_REPEATER_VERSION,
];
$data_where = [ 'name' => $n ];
}
Expand Down
4 changes: 2 additions & 2 deletions admin/functions/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ function alm_container_type_callback() {
?>
<input type="radio" id="_alm_container_type_one" name="alm_settings[_alm_container_type]" value="1" <?php echo checked( 1, $value, false ); ?> />
<label for="_alm_container_type_one">
&lt;ul&gt; <span style="padding-top: 2px;">&lt;!--<?php esc_attr_e( 'Ajax Posts Here', 'ajax-load-more' ); ?>--&gt;</span> &lt;/ul&gt;
&lt;ul&gt; <span style="padding-top: 2px;">&lt;!--<em><?php esc_attr_e( 'Ajax Posts Here', 'ajax-load-more' ); ?></em>--&gt;</span> &lt;/ul&gt;
</label>
<input type="radio" id="_alm_container_type_two" name="alm_settings[_alm_container_type]" value="2" <?php echo checked( 2, $value, false ); ?> />
<label for="_alm_container_type_two">
&lt;div&gt; <span style="padding-top: 2px;">&lt;!--<?php esc_attr_e( 'Ajax Posts Here', 'ajax-load-more' ); ?>--&gt;</span> &lt;/div&gt;
&lt;div&gt; <span style="padding-top: 2px;">&lt;!--<em><?php esc_attr_e( 'Ajax Posts Here', 'ajax-load-more' ); ?></em>--&gt;</span> &lt;/div&gt;
</label>
<label style="cursor: default !important">
<span style="display:block"><?php esc_attr_e( 'You can modify the container type when building a shortcode.', 'ajax-load-more' ); ?></span>
Expand Down
1 change: 1 addition & 0 deletions admin/includes/components/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
<h1>
<span class="offscreen"><?php echo wp_kses_post( $alm_admin_heading ); ?></span>
</h1>
<hr class="wp-header-end" />
</div>
39 changes: 27 additions & 12 deletions admin/views/repeater-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,17 @@
} else {
// Custom Repeaters.
if ( has_action( 'alm_custom_repeaters' ) || has_action( 'alm_unlimited_repeaters' ) ) {
// Expand/Collapse toggle.
include ALM_PATH . 'admin/includes/components/toggle-all-button.php';
include ALM_PATH . 'admin/includes/components/toggle-all-button.php'; // Expand/Collapse toggle.
}
?>

<!-- Default Template -->
<div class="row template default-repeater" id="default-template">
<?php
// Check for local repeater template.
$alm_local_template = false;
$alm_read_only = 'false';
$alm_template_dir = 'alm_templates';
// Check for local repeater template.
$alm_local_template = false;
$alm_read_only = 'false';
$alm_template_dir = 'alm_templates';
if ( is_child_theme() ) {
$alm_template_theme_file = get_stylesheet_directory() . '/' . $alm_template_dir . '/default.php';
if ( ! file_exists( $alm_template_theme_file ) ) {
Expand All @@ -174,12 +173,15 @@
}

$filename = alm_get_default_repeater(); // Get default repeater template.
$handle = fopen( $filename, 'r' ); // Open file.
$contents = '';
if ( filesize( $filename ) != 0 ) {
$contents = fread( $handle, filesize( $filename ) );
}
$content = '';
if ( file_exists( $filename ) ) {
// phpcs:ignore
$handle = fopen( $filename, 'r' );
// phpcs:ignore
$content = filesize( $filename ) !== 0 ? fread( $handle, filesize( $filename ) ) : '';
// phpcs:ignore
fclose( $handle );
}
?>
<h3 class="heading" tabindex="0"><?php esc_attr_e( 'Default Template', 'ajax-load-more' ); ?></h3>
<div class="expand-wrap">
Expand Down Expand Up @@ -209,7 +211,20 @@
?>
<div class="alm-row">
<div class="column">
<textarea rows="10" id="template-default" class="_alm_repeater"><?php echo $contents; // phpcs:ignore ?></textarea>
<?php
// Add warning if template doesn't exist in filesystem.
if ( ! $content ) {
// Get content from DB.
global $wpdb;
$table_name = $wpdb->prefix . 'alm';
$row = $wpdb->get_row( "SELECT * FROM $table_name WHERE repeaterType = 'default'" ); // Get first result only
$content = ! empty ( $row ) && $row->repeaterDefault ? $row->repeaterDefault : '';
?>
<p class="warning-callout notify missing-template" style="margin: 10px 0 20px;">
<?php esc_attr_e( 'This default ALM template is missing from the filesystem! Click the "Save Template" button to save the template.', 'ajax-load-more' ); ?>
</p>
<?php } ?>
<textarea rows="10" id="template-default" class="_alm_repeater"><?php echo $content; // phpcs:ignore ?></textarea>
<script>
var editor_default = CodeMirror.fromTextArea(document.getElementById("template-default"), {
mode: "application/x-httpd-php",
Expand Down
Loading

0 comments on commit d39969b

Please sign in to comment.