Start applying fast AJAX option to comments

Because if you only use the theme comments, the performance boost is tremendous!
This commit is contained in:
Tetrakern 2023-08-23 13:00:19 +02:00
parent 49583e2938
commit 26e0b67868
3 changed files with 33 additions and 6 deletions

View File

@ -611,16 +611,23 @@ define( 'FICTIONEER_OPTIONS', array(
'fictioneer_flush_object_cache' => array(
'name' => 'fictioneer_flush_object_cache',
'group' => 'fictioneer-settings-general-group',
'sanitize_callback' => 'fictioneer_sanitize_disable_widget_checkbox',
'sanitize_callback' => 'fictioneer_sanitize_checkbox',
'label' => __( 'Flush object cache on content updates', 'fictioneer' ),
'default' => false
),
'fictioneer_see_some_evil' => array(
'name' => 'fictioneer_see_some_evil',
'group' => 'fictioneer-settings-general-group',
'sanitize_callback' => 'fictioneer_sanitize_disable_widget_checkbox',
'sanitize_callback' => 'fictioneer_sanitize_checkbox',
'label' => __( 'Monitor posts for suspicious content', 'fictioneer' ),
'default' => false
),
'fictioneer_enable_fast_ajax_comments' => array(
'name' => 'fictioneer_enable_fast_ajax_comments',
'group' => 'fictioneer-settings-general-group',
'sanitize_callback' => 'fictioneer_sanitize_checkbox',
'label' => __( 'Enable fast AJAX for comments', 'fictioneer' ),
'default' => false
)
),
'integers' => array(

View File

@ -563,7 +563,18 @@
<input name="fictioneer_enable_ajax_comment_moderation" type="checkbox" id="fictioneer_enable_ajax_comment_moderation" <?php echo checked( 1, get_option( 'fictioneer_enable_ajax_comment_moderation' ), false ); ?> value="1">
<div>
<span><?php echo FICTIONEER_OPTIONS['booleans']['fictioneer_enable_ajax_comment_moderation']['label']; ?></span>
<p class="sub-label"><?php _e( 'Moderation actions directly in the comment section.', 'fictioneer' ) ?></p>
<p class="sub-label"><?php _e( 'Moderation actions directly in the comment section.', 'fictioneer' ); ?></p>
</div>
</label>
<label for="fictioneer_enable_fast_ajax_comments" class="label-wrapped-checkbox row">
<input name="fictioneer_enable_fast_ajax_comments" type="checkbox" id="fictioneer_enable_fast_ajax_comments" <?php echo checked( 1, get_option( 'fictioneer_enable_fast_ajax_comments' ), false ); ?> value="1">
<div>
<span><?php echo FICTIONEER_OPTIONS['booleans']['fictioneer_enable_fast_ajax_comments']['label']; ?></span>
<p class="sub-label"><?php printf(
__( 'Accelerate AJAX comment requests by skipping plugins and theme initialization. Actions and filters will be ignored unless applied by core or a <a href="%s" target="_blank">must-use plugin</a>.', 'fictioneer' ),
'https://wordpress.org/documentation/article/must-use-plugins/' );
?></p>
</div>
</label>
@ -658,7 +669,7 @@
</div>
<div class="textarea row">
<textarea name="fictioneer_comments_notice" id="fictioneer_comments_notice" rows="4" style="height: 160px;"><?php echo get_option( 'fictioneer_comments_notice' ); ?></textarea>
<textarea name="fictioneer_comments_notice" id="fictioneer_comments_notice" rows="4" style="height: 165px;"><?php echo get_option( 'fictioneer_comments_notice' ); ?></textarea>
<p class="sub-label"><?php _e( 'Notice above comments. Leave empty to hide. HTML allowed.', 'fictioneer' ) ?></p>
</div>

View File

@ -14,14 +14,23 @@
if (
( defined( 'DOING_AJAX' ) && DOING_AJAX ) &&
isset( $_REQUEST['fcn_fast_ajax'] ) &&
isset( $_REQUEST['action'] ) &&
strpos( $_REQUEST['action'], 'fictioneer_ajax' ) === 0
strpos( $_REQUEST['action'] ?? '', 'fictioneer_ajax' ) === 0
) {
add_filter( 'option_active_plugins', 'fictioneer_exclude_plugins' );
}
$request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
// Check if AJAX comment request
if (
get_option( 'fictioneer_enable_fast_ajax_comments' ) &&
( defined( 'DOING_AJAX' ) && DOING_AJAX ) &&
strpos( $_REQUEST['action'] ?? '', 'fictioneer_ajax' ) === 0 &&
strpos( $_REQUEST['action'] ?? '', 'comment' ) !== false
) {
add_filter( 'option_active_plugins', 'fictioneer_exclude_plugins' );
}
// Check REST Request
if ( strpos( $request_uri, 'wp-json/fictioneer/' ) !== false ) {
add_filter( 'option_active_plugins', 'fictioneer_exclude_plugins' );