Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.20 #1995

Merged
merged 59 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4224ce2
Bump fast-xml-parser and is-svg
dependabot[bot] Sep 1, 2023
79ec7d8
Add support for Adavnaced Post Creation
doekenorg Feb 5, 2024
b27e6a8
Add notice when advanced post creation is active
doekenorg Feb 5, 2024
9b09bf6
Add link to APC + update readme
doekenorg Feb 5, 2024
122729a
fix unit tests
doekenorg Feb 6, 2024
16a1aae
Sanitize URL
zackkatz Feb 14, 2024
e367ba0
Add new window screen reader text
zackkatz Feb 14, 2024
d82efea
Add message for translators
zackkatz Feb 14, 2024
4985637
Update docblocks
zackkatz Feb 14, 2024
9c9355c
Merge branch 'develop' into issue/1268-support-advanced-post-creation…
zackkatz Feb 14, 2024
de8d87b
Sanitize output
zackkatz Feb 14, 2024
474362c
Remove TODO
zackkatz Feb 14, 2024
f61403a
Restore readme item [ci skip]
zackkatz Feb 14, 2024
f7f44bc
Support advanced post creation add on (#1982)
zackkatz Feb 14, 2024
de5468d
Register custom post type before checking for requiremements
mrcasual Feb 15, 2024
b78011f
Display notices on All Views/New View pages when GF is not installed
mrcasual Feb 15, 2024
713917a
Make defalt alt text a string
mrcasual Feb 15, 2024
df91c1d
Update changelog [ci skip]
mrcasual Feb 15, 2024
95468eb
Merge branch 'develop' into issue/1979-invalid-post-type-when-gf-not-…
mrcasual Feb 15, 2024
c9d9ed8
Update changelog [ci skip]
mrcasual Feb 15, 2024
47bb2ef
Use Yoda conditions [ci skip]
mrcasual Feb 15, 2024
abe2c45
Update conditional check to include post edit page
mrcasual Feb 15, 2024
3b32fa2
Do not render screen options instead of hiding them via CSS [ci skip]
mrcasual Feb 15, 2024
57ec13a
Simplify and optimize code that displays notices when GF is inactive
mrcasual Feb 15, 2024
516643e
Fix "Deprecated: strpos(): Passing null to parameter" deprecation not…
mrcasual Feb 15, 2024
ba1893b
Add Foundation setting to control GravityView caching
mrcasual Feb 19, 2024
9daac96
Add warning when caching is overridden by filters
mrcasual Feb 19, 2024
9282617
Check variable type and abort early to prevent a fatal error
mrcasual Feb 19, 2024
0e02cdb
Add per-View caching support
mrcasual Feb 19, 2024
cdf28d2
Implement long-lived caching for View entries
mrcasual Feb 19, 2024
6eefc23
Remove DataTables cache settings
mrcasual Feb 19, 2024
28af802
Update changelog [ci skip]
mrcasual Feb 20, 2024
bff78ca
Update caching-related warning message
mrcasual Feb 20, 2024
6e2b32e
Open link in new tab/window
mrcasual Feb 20, 2024
ace7329
Fix caching KB URL
mrcasual Feb 20, 2024
f3ff5f8
Escape URL 'coz @zackkatz
mrcasual Feb 20, 2024
a50b8ed
Use Foundation's set/get_transient helpers
mrcasual Feb 20, 2024
ff2ef2a
Bump ip from 2.0.0 to 2.0.1
dependabot[bot] Feb 20, 2024
a62db5d
Update Foundation
mrcasual Feb 20, 2024
b5cb249
Switch back to using set/get_transient rather set/get_site_transient
mrcasual Feb 20, 2024
b733287
Use the helper delete_transient method to remove transients
mrcasual Feb 20, 2024
9794037
Bump axios and @wordpress/scripts in /future/includes/gutenberg
dependabot[bot] Feb 21, 2024
40d4203
Tweak language
zackkatz Feb 21, 2024
ea800aa
Implement global and per-View caching of entries (#1991)
zackkatz Feb 21, 2024
b6879c3
Only show notice when a form is set
doekenorg Feb 22, 2024
a4684fe
Only show notice when a form is set (#1994)
doekenorg Feb 22, 2024
3d78d0e
Add more comments [ci skip]
zackkatz Feb 22, 2024
8c2ec68
Ensure we're dealing with WP_Post
zackkatz Feb 22, 2024
e515677
Move method to Compatibility class.
zackkatz Feb 22, 2024
94de19e
Merge branch 'develop' into issue/1979-invalid-post-type-when-gf-not-…
zackkatz Feb 22, 2024
16fa659
Update Foundation to v1.2.9
mrcasual Feb 22, 2024
4197079
Update Strauss PHAR
zackkatz Feb 22, 2024
5ef6db9
Display notice on All Views/New View pages when GF is not activated (…
zackkatz Feb 22, 2024
7b4fd71
Update Foundation to v1.2.9
mrcasual Feb 22, 2024
3735f04
Bump version to 2.20 & update changelog
mrcasual Feb 22, 2024
c5af673
Bump axios and @wordpress/scripts in /future/includes/gutenberg (#1993)
mrcasual Feb 22, 2024
e5b7842
Bump ip from 2.0.0 to 2.0.1 (#1992)
mrcasual Feb 22, 2024
08a1ea0
Bump fast-xml-parser and is-svg (#1897)
mrcasual Feb 22, 2024
64ec085
Add link to caching doc [ci skip]
zackkatz Feb 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/js/admin-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@

var show_warning = ! dismissed_warning && value.configured === 0;

$( '#' + index + '-fields' ).find( '.notice-warning' ).toggle( show_warning );
$( '#' + index + '-fields' ).find( '.notice-no-link' ).toggle( show_warning );
$( 'li[aria-controls="' + index + '-view"]' )
.toggleClass( 'tab-not-configured', show_warning )
.find( '.tab-icon' )
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin-views.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions future/includes/class-gv-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ private function init() {
/** More legacy core. @todo Deprecate */
$this->plugin->include_legacy_core();

/** Register the gravityview post type upon WordPress core init. */
require_once $this->plugin->dir( 'future/includes/class-gv-view.php' );
add_action( 'init', array( '\GV\View', 'register_post_type' ) );
add_action( 'init', array( '\GV\View', 'add_rewrite_endpoint' ) );
add_filter( 'map_meta_cap', array( '\GV\View', 'restrict' ), 11, 4 );
add_action( 'template_redirect', array( '\GV\View', 'template_redirect' ) );
add_action( 'the_content', array( '\GV\View', 'content' ) );
/**
* Stop all further functionality from loading if the WordPress
* plugin is incompatible with the current environment.
Expand All @@ -141,16 +148,10 @@ private function init() {
*/
if ( ! $this->plugin->is_compatible() ) {
$this->log->error( 'GravityView 2.0 is not compatible with this environment. Stopped loading.' );

return;
}

/** Register the gravityview post type upon WordPress core init. */
require_once $this->plugin->dir( 'future/includes/class-gv-view.php' );
add_action( 'init', array( '\GV\View', 'register_post_type' ) );
add_action( 'init', array( '\GV\View', 'add_rewrite_endpoint' ) );
add_filter( 'map_meta_cap', array( '\GV\View', 'restrict' ), 11, 4 );
add_action( 'template_redirect', array( '\GV\View', 'template_redirect' ) );
add_action( 'the_content', array( '\GV\View', 'content' ) );

/** Add rewrite endpoint for single-entry URLs. */
require_once $this->plugin->dir( 'future/includes/class-gv-entry.php' );
Expand Down
95 changes: 93 additions & 2 deletions future/includes/class-gv-settings-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ public function get_gravitykit_setting( $setting, $default = null ) {
*/
public function defaults() {
$defaults = array(
'rest_api' => 0,
'public_entry_moderation' => 0,
'rest_api' => 0,
'public_entry_moderation' => 0,
'caching' => 1,
'caching_entries' => DAY_IN_SECONDS,
);

/**
Expand Down Expand Up @@ -228,6 +230,91 @@ public function add_settings( $plugins_data ) {

$default_settings = $this->defaults();

$cache_filters_in_use = [];

if ( has_filter( 'gravityview_use_cache' ) ) {
$cache_filters_in_use[] = 'gravityview_use_cache';
}

if ( has_filter( 'gravityview_cache_time_entries' ) ) {
$cache_filters_in_use[] = 'gravityview_cache_time_entries';
}

$cache_settings = [];

if ( ! empty( $cache_filters_in_use ) ) {
$notice = 1 === count( $cache_filters_in_use )
? esc_html_x( 'The [filter] active filter could be overriding cache settings.', 'Placeholders inside [] are not to be translated.', 'gk-gravityview' )
: esc_html_x( 'The following active filters could be overriding cache settings: [filters].', 'Placeholders inside [] are not to be translated.', 'gk-gravityview' );

$notice = strtr(
$notice,
[
'[filter]' => '<code>' . implode( '</code>, <code>', $cache_filters_in_use ) . '</code>',
'[filters]' => '<code>' . implode( '</code>, <code>', $cache_filters_in_use ) . '</code>',
]
);

$notice = <<<HTML
<div class="bg-yellow-50 p-4 rounded-md">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<p class="text-sm">
{$notice}
</p>
</div>
</div>
</div>
HTML;

$cache_settings[] = [
'id' => 'caching_filters_notice',
'html' => $notice,
'markdown' => false,
'excludeFromSave' => true,
];
}

$cache_settings = array_merge( $cache_settings, [
array(
'id' => 'caching',
'type' => 'checkbox',
'title' => esc_html__( 'Enable Caching', 'gk-gravityview' ),
'description' => strtr(
esc_html_x( '[url]Enabling caching[/url] improves performance by reducing the number of queries during page loads. When enabled, you can also specify cache duration for entries.', 'Placeholders inside [] are not to be translated.', 'gk-gravityview' ),
[
'[url]' => '<a class="underline" href="https://docs.gravitykit.com/article/58-about-gravityview-caching" rel="noopener noreferrer" target="_blank">',
'[/url]' => '</a>',
]
),
'value' => $this->get( 'caching', $default_settings['caching'] ),
),
array(
'id' => 'caching_entries',
'type' => 'number',
'requires' => array(
'id' => 'caching',
'operator' => '==',
'value' => 1,
),
'validation' => array(
array(
'rule' => 'min:1',
'message' => esc_html__( 'The cache duration must be at least 1 second.', 'gk-gravityview' ),
),
),
'title' => esc_html__( 'Entry Cache Duration', 'gk-gravityview' ),
'description' => esc_html__( 'Specify the duration in seconds that entry data should remain cached before being refreshed. A shorter duration ensures more up-to-date data, while a longer duration improves performance.', 'gk-gravityview' ),
'value' => $this->get( 'caching_entries', $default_settings['caching_entries'] ),
),
]
);

$settings = array(
'id' => self::SETTINGS_PLUGIN_ID,
'title' => 'GravityView',
Expand All @@ -246,6 +333,10 @@ public function add_settings( $plugins_data ) {
),
),
),
array(
'title' => esc_html__( 'Caching', 'gk-gravityview' ),
'settings' => $cache_settings,
),
array(
'title' => esc_html__( 'Permissions', 'gk-gravityview' ),
'settings' => array(
Expand Down
31 changes: 30 additions & 1 deletion future/includes/class-gv-settings-view.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace GV;

use GravityKit\GravityView\Foundation\Settings\Framework as SettingsFramework;

/** If this file is called directly, abort. */
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
die();
Expand Down Expand Up @@ -46,7 +48,6 @@ public static function with_defaults( $detailed = false ) {
* @param boolean $full_width True: Display the input and label together when rendering. False: Display label and input in separate columns when rendering.
*/
public static function defaults( $detailed = false, $group = null ) {

$default_settings = array_merge(
array(
'id' => array(
Expand Down Expand Up @@ -100,6 +101,34 @@ public static function defaults( $detailed = false, $group = null ) {
'url' => 'https://docs.gravitykit.com/article/490-entry-approval-gravity-forms',
),
),
'caching' => array(
'label' => __( 'Enable Caching', 'gk-gravityview' ),
'type' => 'checkbox',
'group' => 'default',
'value' => gravityview()->plugin->settings->get( 'caching' ),
'desc' => strtr(
esc_html_x( 'Turn caching on or off to improve performance. Default settings are configured in [url]GravityView Caching Settings[/url].', 'Placeholders inside [] are not to be translated.', 'gk-gravityview' ),
[
'[url]' => '<a href="' . esc_url( SettingsFramework::get_instance()->get_plugin_settings_url( Plugin_Settings::SETTINGS_PLUGIN_ID ) . '&s=1' ) . '">',
'[/url]' => '</a>',
]
),
'show_in_shortcode' => false,
'article' => array(
'id' => '54c67bb6e4b051242988550a',
'url' => 'https://docs.gravitykit.com/article/58-about-gravityview-caching',
),
),
'caching_entries' => array(
'label' => __( 'Entry Cache Duration', 'gk-gravityview' ),
'tooltip' => esc_html__( 'Specify the duration, in seconds, that entry data should remain cached before being refreshed. A shorter duration ensures more up-to-date data, while a longer duration improves performance.', 'gk-gravityview' ),
'type' => 'number',
'group' => 'default',
'value' => gravityview()->plugin->settings->get( 'caching_entries' ),
'show_in_shortcode' => false,
'requires' => 'caching=1',
'min' => 1,
),
'no_entries_options' => array(
'label' => __( 'No Entries Behavior', 'gk-gravityview' ),
'type' => 'select',
Expand Down
51 changes: 42 additions & 9 deletions future/includes/class-gv-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use GravityKit\GravityView\Foundation\Helpers\Arr;
use GF_Query;
use GravityView_Compatibility;
use GravityView_Cache;

/** If this file is called directly, abort. */
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
Expand Down Expand Up @@ -121,12 +123,15 @@ public function __construct() {
* @return void
*/
public static function register_post_type() {

/** Register only once */
if ( post_type_exists( 'gravityview' ) ) {
return;
}

if ( ! gravityview()->plugin->is_compatible() ) {
GravityView_Compatibility::override_post_pages_when_compatibility_fails();
}

/**
* Make GravityView Views hierarchical by returning TRUE.
* This will allow for Views to be nested with Parents and also allows for menu order to be set in the Page Attributes metabox
Expand Down Expand Up @@ -192,7 +197,7 @@ public static function register_post_type() {
* @param int $view_id The ID of the View currently being requested. `0` for general setting
*/
'public' => apply_filters( 'gravityview_direct_access', gravityview()->plugin->is_compatible(), 0 ),
'show_ui' => gravityview()->plugin->is_compatible(),
'show_ui' => true,
'show_in_menu' => false, // Menu items are added in \GV\Plugin::add_to_gravitykit_admin_menu()
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
Expand Down Expand Up @@ -1434,6 +1439,7 @@ function () use ( $query ) {

/**
* Queries database and conditionally caches results.
* First, checks if the long-lived cache is enabled and if the query is cached. If not, it checks if the short-lived cache is enabled and if the query is cached.
*
* @since 2.18.2
*
Expand All @@ -1442,8 +1448,38 @@ function () use ( $query ) {
* @return array{0: array, 1: GF_Query} Array of entries and the query object. The latter may be needed as it is modified during the query.
*/
private function run_db_query( GF_Query $query ) {
$db_entries = null;

$query_hash = md5( serialize( $query->_introspect() ) );

$atts = $this->settings->all();

$atts['query_hash'] = $query_hash;

$long_lived_cache = new GravityView_Cache( $this->form->ID, $atts );

if ( $long_lived_cache->use_cache() ) {
$cached_entries = $long_lived_cache->get();

if ( $cached_entries ) {
return [
$cached_entries,
$query,
];
}

$db_entries = $query->get();

if ( $long_lived_cache->set( $db_entries, 'entries' ) ) {
return [
$db_entries,
$query,
];
}
}

/**
* Controls whether the query is cached.
* Controls whether the query is cached per request. This is a short-lived cache.
*
* @filter gk/gravityview/view/entries/cache
*
Expand All @@ -1454,16 +1490,14 @@ private function run_db_query( GF_Query $query ) {
if ( ! apply_filters( 'gk/gravityview/view/entries/cache', true ) ) {
$db_entries = $query->get();

return array(
return [
$db_entries,
$query,
);
];
}

$query_hash = md5( serialize( $query->_introspect() ) );

if ( ! Arr::get( self::$cache, $query_hash ) ) {
$db_entries = $query->get();
$db_entries = $db_entries ?? $query->get();

self::$cache[ $query_hash ] = array(
$db_entries,
Expand All @@ -1482,7 +1516,6 @@ private function run_db_query( GF_Query $query ) {
* @return void
*/
public static function template_redirect() {

$is_csv = get_query_var( 'csv' );
$is_tsv = get_query_var( 'tsv' );

Expand Down
Loading