Skip to content

Commit

Permalink
Updated PHPCS and adding fix for cache and paging
Browse files Browse the repository at this point in the history
  • Loading branch information
dcooney committed Nov 2, 2023
1 parent 7552e4e commit 4f3df78
Show file tree
Hide file tree
Showing 20 changed files with 9,326 additions and 14,742 deletions.
76 changes: 26 additions & 50 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,58 @@
<ruleset name="WordPress Coding Standards">
<description>Apply WordPress Coding Standards</description>

<!-- Set the memory limit to 256M.
For most standard PHP configurations, this means the memory limit will temporarily be raised.
Ref: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#specifying-phpini-settings
-->
<ini name="memory_limit" value="256M"/>
<!-- WordPress Core currently supports PHP 8.0+. -->
<config name="testVersion" value="8.0"/>

<!-- Whenever possible, cache the scan results and re-use those for unchanged files on the next scan. -->
<arg name="cache"/>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<!-- Check up to 20 files simultaneously. -->
<arg name="parallel" value="20"/>

<!-- Show sniff codes in all reports. -->
<arg value="ps"/>
<!-- Only sniff PHP files. -->
<arg name="extensions" value="php" />
<arg name="colors" />
<arg value="s" /><!-- Show sniff codes in all reports. -->
<arg value="p" /><!-- Show progress. -->

<!-- Use WordPress "Extra" Coding Standards. -->
<rule ref="WordPress-Extra">
<rule ref="WordPress">
<exclude name="Generic.Arrays.DisallowShortArraySyntax" />
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.ShortPrefixPassed"/>
<exclude name="WordPress.PHP.YodaConditions.NotYoda"/>
<exclude name="WordPress.WP.PostsPerPage.posts_per_page_posts_per_page"/>
<exclude name="WordPress.Security.NonceVerification.Recommended" />
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" />
<exclude name="Universal.Files.SeparateFunctionsFromOO.Mixed" />
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
</rule>

<!-- Use WordPress "Docs" Coding Standards. -->
<rule ref="WordPress-Docs" />
<rule ref="PHPCompatibilityWP" />
<rule ref="Generic.Arrays.DisallowLongArraySyntax" />

<!-- The minimum supported WordPress version. This should match what's listed in style.css. -->
<rule ref="WordPress.WP.DeprecatedFunctions">
<properties>
<property name="minimum_supported_version" value="5.6"/>
</properties>
</rule>

<!-- Allow for theme specific exceptions to the file name rules based on the theme hierarchy. -->
<rule ref="WordPress.Files.FileName">
<!-- Prefix globals -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="is_theme" value="true"/>
<property name="prefixes" type="string" value="alm" />
<property name="prefixes" type="string" value="ajax_load_more" />
<property name="prefixes" type="string" value="AjaxLoadMore" />
</properties>
</rule>

<!-- Verify that everything in the global namespace is prefixed with a theme specific prefix.
Multiple valid prefixes can be provided as a comma-delimited list. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<!-- I18n rules -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="prefixes" type="array" value="alm, ajax_load_more, AjaxLoadMore" />
<property name="text_domain" type="string" value="ajax-load-more"/>
</properties>
</rule>

<!-- Verify that the text_domain is set to the desired text-domain.
Multiple valid text domains can be provided as a comma-delimited list. -->
<rule ref="WordPress.WP.I18n">
<!-- Allow . in hook names. -->
<rule ref="WordPress.NamingConventions.ValidHookName">
<properties>
<property name="text_domain" type="array" value="ajax-load-more"/>
<property name="additionalWordDelimiters" value="." />
</properties>
</rule>

<!-- Use WordPress PHP Compatibility. -->
<rule ref="PHPCompatibilityWP"/>

<!-- WordPress Core currently supports PHP 5.6+. -->
<config name="testVersion" value="5.6-"/>

<!-- Only sniff PHP files. -->
<arg name="extensions" value="php"/>

<!-- Only sniff the theme. -->
<file>./</file>

<!-- Don't sniff the following directories or file types. -->
<!-- Other files and folders -->
<exclude-pattern>/*.asset.php</exclude-pattern>
<exclude-pattern>/build/*</exclude-pattern>
<exclude-pattern>/node_modules/*</exclude-pattern>
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/lang/*</exclude-pattern>
</ruleset>
8 changes: 4 additions & 4 deletions admin/admin-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function alm_is_admin_screen() {
*/
function alm_has_addon_shortcodes() {
$installed = false;
$actions = array(
$actions = [
'alm_cache_installed',
'alm_cta_installed',
'alm_filters_installed',
Expand All @@ -41,7 +41,7 @@ function alm_has_addon_shortcodes() {
'alm_seo_installed',
'alm_single_post_installed',
'alm_users_installed',
);
];

// Loop actions to determine if add-on/extension is installed.
foreach ( $actions as $action ) {
Expand All @@ -65,11 +65,11 @@ function alm_has_addon_shortcodes() {
*/
function alm_has_extension_shortcodes() {
$installed = false;
$actions = array(
$actions = [
'alm_acf_installed',
'alm_rest_api_installed',
'alm_terms_installed',
);
];

// Loop actions to determine if add-on/extension is installed.
foreach ( $actions as $action ) {
Expand Down
8 changes: 4 additions & 4 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ function alm_enqueue_admin_scripts() {

// CodeMirror Syntax Highlighting if on Repater Template page.
$screen = get_current_screen();
if ( in_array( $screen->id, array( 'ajax-load-more_page_ajax-load-more-repeaters' ), true ) ) {
if ( in_array( $screen->id, [ 'ajax-load-more_page_ajax-load-more-repeaters' ], true ) ) {
// CodeMirror CSS.
wp_enqueue_style( 'alm-codemirror-css', ALM_ADMIN_URL . 'codemirror/lib/codemirror.css', '', ALM_VERSION );

Expand Down Expand Up @@ -599,12 +599,13 @@ function alm_get_tax_terms() {
$taxonomy = isset( $form_data['taxonomy'] ) ? esc_attr( $form_data['taxonomy'] ) : '';
$index = isset( $form_data['index'] ) ? esc_attr( $form_data['index'] ) : '1';
$tax_args = [
'taxonomy' => $taxonomy,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
];

$terms = get_terms( $taxonomy, $tax_args );
$terms = get_terms( $tax_args );
$value = '';
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$value .= '<ul>';
Expand Down Expand Up @@ -644,10 +645,9 @@ function alm_admin_menu_icon_svg( $base64 = true ) {
/**
* Filter the WP Admin footer text only on ALM pages
*
* @param string $text The existing footer text.
* @since 2.12.0
*/
function alm_filter_admin_footer_text( $text ) {
function alm_filter_admin_footer_text() {
$screen = alm_is_admin_screen();

if ( ! $screen ) {
Expand Down
2 changes: 1 addition & 1 deletion admin/includes/components/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$alm_current_page = filter_input( INPUT_GET, 'page', @FILTER_SANITIZE_STRING );
?>
<header class="alm-admin-toolbar">
<a class="alm-admin-toolbar--logo" href="<?php get_admin_url( null, 'admin.php?page=ajax-load-more' ); ?>">
<a class="alm-admin-toolbar--logo" href="<?php get_admin_url(); ?>admin.php?page=ajax-load-more">
<?php require_once ALM_PATH . 'admin/includes/components/logo.php'; ?>
<?php echo esc_attr( ALM_TITLE ); ?>
</a>
Expand Down
22 changes: 17 additions & 5 deletions ajax-load-more.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
* @package AjaxLoadMore
*/

/*
* FIX: Fixed issue with paging URLs when using Elementor add-on with WooCommerce products and WP archive templates.
* FIX: Fixed issue with Cache and Paging add-ons throwing an error on initial page load and causing posts not to load..
* NEW: Added `alm_restapi_url` hook to update the URL base REST API calls.
```
add_filter( 'alm_restapi_url', function(){
return 'https://google.com';
});
```
*/

define( 'ALM_VERSION', '6.2.0.1' );
define( 'ALM_RELEASE', 'October 20, 2023' );
define( 'ALM_STORE_URL', 'https://connekthq.com' );
Expand All @@ -32,7 +43,7 @@ function alm_install( $network_wide ) {
add_option( 'alm_version', ALM_VERSION ); // Add setting to options table.
if ( is_multisite() && $network_wide ) {
// Get all blogs in the network and activate plugin on each one.
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); // phpcs:ignore
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
alm_create_table();
Expand Down Expand Up @@ -98,7 +109,7 @@ public function alm_includes() {
require_once 'admin/vendor/connekt-plugin-installer/class-connekt-plugin-installer.php';
if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
// Only include this EDD helper if other plugins have not.
require_once dirname( __FILE__ ) . '/core/libs/EDD_SL_Plugin_Updater.php';
require_once __DIR__ . '/core/libs/EDD_SL_Plugin_Updater.php';
}
}
}
Expand Down Expand Up @@ -373,6 +384,7 @@ public function alm_enqueue_scripts() {
'version' => ALM_VERSION,
'ajaxurl' => apply_filters( 'alm_ajaxurl', admin_url( 'admin-ajax.php' ) ),
'alm_nonce' => wp_create_nonce( 'ajax_load_more_nonce' ),
'rest_api_url' => apply_filters( 'alm_restapi_url', '' ),
'rest_api' => esc_url_raw( rest_url() ),
'rest_nonce' => wp_create_nonce( 'wp_rest' ),
'trailing_slash' => substr( get_option( 'permalink_structure' ), -1 ) === '/' ? 'true' : 'false', // Trailing slash in permalink structure.
Expand Down Expand Up @@ -424,7 +436,7 @@ public function alm_query_posts() {
$id = isset( $params['id'] ) ? $params['id'] : '';
$post_id = isset( $params['post_id'] ) ? $params['post_id'] : '';
$slug = isset( $params['slug'] ) ? $params['slug'] : '';
$canonical_url = isset( $params['canonical_url'] ) ? esc_url( $params['canonical_url'] ) : esc_url( $_SERVER['HTTP_REFERER'] );
$canonical_url = isset( $params['canonical_url'] ) ? esc_url( $params['canonical_url'] ) : esc_url( $_SERVER['HTTP_REFERER'] ); // phpcs:ignore

// Ajax Query Type.
$query_type = isset( $params['query_type'] ) ? $params['query_type'] : 'standard'; // 'standard' or 'totalposts' - totalposts returns $alm_found_posts.
Expand Down Expand Up @@ -603,8 +615,8 @@ public function alm_query_posts() {
while ( $alm_query->have_posts() ) :
$alm_query->the_post();

$alm_loop_count++;
$alm_current++; // Current item in loop.
++$alm_loop_count;
++$alm_current; // Current item in loop.
$alm_page = $alm_page_count; // Get page number.
$alm_item = ( $alm_page_count * $posts_per_page ) - $posts_per_page + $alm_loop_count;

Expand Down
2 changes: 1 addition & 1 deletion build/admin/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'cf6b7cc79fb2357f6ea2');
<?php return array('dependencies' => array(), 'version' => '8b37e600b83a7774ad4a');
5,170 changes: 5,169 additions & 1 deletion build/admin/index.css

Large diffs are not rendered by default.

Loading

0 comments on commit 4f3df78

Please sign in to comment.