pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.06k stars 265 forks source link

Pods Item List block cannot display {@permalink} magic tag for table-storage custom taxonomy #7059

Open mwf1 opened 1 year ago

mwf1 commented 1 year ago

Description

Summary When I try to display the permalink to the terms of a table-storage custom taxonomy using the Pods Item List block, the block errors and the page cannot be displayed.

Detail I have a custom taxonomy that is configured with table storage. The taxonomy has an image associated with it but no additional fields, hence the dedicated table only contains the ID.

I want to create a page where I display a list of the terms in this taxonomy and each term is a link to the archive page for that term. To do so, I use the Pods Item List block and use the following custom template: <a href="{@permalink}">{@name}</a><br>

This works fine for the name but once the permalink magic tag is entered, the block goes into error.

Adding some debug, I found that the call to get_term_link() in Pods.php:field() returns a WP_Error object.

object(WP_Error)#6781 (3) {
  ["errors"]=>
  array(1) {
    ["invalid_term"]=>
    array(1) {
      [0]=>
      string(11) "Empty Term."
    }
  }
  ["error_data"]=>
  array(0) {
  }
  ["additional_data":protected]=>
  array(0) {
  }
}

get_term_link() is called in Pods.php:field() as get_term_link( $this->id(), $this->pod_data['name'] ). This error gets created in get_term_link() because the term ID is passed in to $term as a string rather than an integer.

The fundamental difference appears to be that for a table-storage custom taxonomy, $this->data->row['id'] is populated with the ID as a string. In the meta-storage custom taxonomy, this field is not present.

Once I change the storage type from table to meta, the term ID is passed in to get_term_link() as an integer and the error no longer occurs. A little more digging shows that in Pods.php:field(), $this->data->row['id'] is populated with a string for a table-storage taxonomy while it is not present for a meta-storage taxonomy.

Version

2.9.13

Testing Instructions

1.1 Create a new custom taxonomy tableflag using table storage. 1.2 Add term tflag1 to the tableflag taxonomy. 1.3 Add term tflag1.1 to the tableflag taxonomy as a child of tflag1.

2.1 Create a new custom taxonomy metaflag using meta storage. 2.2 Add term mflag1 to the metaflag taxonomy. 2.3 Add term mflag1.1 to the metaflag taxonomy as a child of mflag1.

3.1 Enable the PHP debug log. 3.2 Create a new page and add the Pods Item List block. 3.3 Set POD NAME to metaflag. 3.4 Set TEMPLATE to "-Use Custom Template-". 3.5 Set CUSTOM TEMPLATE to: {@name} -- {@permalink}<br> 3.6 Observe that the block preview shows:

mflag1 -- https://mysite/metaflag/mflag1/
mflag1.1 -- https://mysite/metaflag/mflag1/mflag1-1/

4.1 Change the POD NAME to tableflag. 4.2 Observe that the block preview updates to: Error loading block: The response is not a valid JSON response.

5.1 View the PHP error log and find:

PHP Fatal error:  Uncaught Error: Object of class WP_Error could not be converted to string in /home/myuser/mysite/wp-content/plugins/pods/classes/Pods.php:4279
Stack trace:
#0 [internal function]: Pods->process_magic_tags(Array)
#1 /home/myuser/mysite/wp-content/plugins/pods/classes/Pods.php(4195): preg_replace_callback('/({@(.*?)})/m', Array, '{@name} -- {@pe...')
#2 /home/myuser/mysite/wp-content/plugins/pods/components/Templates/Templates.php(677): Pods->do_magic_tags('{@name} -- {@pe...')
#3 /home/myuser/mysite/wp-content/plugins/pods/components/Templates/Templates.php(612): Pods_Templates::do_template('{@name} -- {@pe...', Object(Pods))
#4 /home/myuser/mysite/wp-content/plugins/pods/classes/Pods.php(3750): Pods_Templates::template('', '{@name} -- {@pe...', Object(Pods), false)
#5 /home/myuser/mysite/wp-content/plugins/pods/includes/general.php(1820): Pods->template('', '{@name} -- {@pe...')
#6 /ho in /home/myuser/mysite/wp-content/plugins/pods/classes/Pods.php on line 4279

Screenshots / Screencast

No response

Possible Workaround

This problem no longer occurs once I change the taxonomy to use meta-storage.

Site Health Information

### wp-core ###

version: 6.2
site_language: en_US
user_language: en_US
timezone: +00:00
permalink: /%postname%/
https_status: true
multisite: false
user_registration: 0
blog_public: 0
default_comment_status: undefined
environment_type: production
user_count: 10
dotorg_communication: true

### wp-paths-sizes ###

wordpress_path: /home/myuser/mysite
wordpress_size: 263.86 MB (276679375 bytes)
uploads_path: /home/myuser/mysite/wp-content/uploads
uploads_size: 1.55 GB (1669631785 bytes)
themes_path: /home/myuser/mysite/wp-content/themes
themes_size: 36.79 MB (38571971 bytes)
plugins_path: /home/myuser/mysite/wp-content/plugins
plugins_size: 89.42 MB (93758472 bytes)
database_size: 37.58 MB (39403520 bytes)
total_size: 1.97 GB (2118045123 bytes)

### wp-dropins (1) ###

object-cache.php: true

### wp-active-theme ###

name: Customify Child (customify-child)
version: 0.10.4
author: *redacted*
author_website: *redacted*
parent_theme: Customify (customify)
theme_features: core-block-patterns, widgets-block-editor, automatic-feed-links, title-tag, post-thumbnails, menus, html5, customize-selective-refresh-widgets, custom-logo, woocommerce, wc-product-gallery-zoom, wc-product-gallery-lightbox, wc-product-gallery-slider, align-wide, editor-styles, widgets
theme_path: /home/myuser/mysite/wp-content/themes/customify-child
auto_update: Disabled

### wp-parent-theme ###

name: Customify (customify)
version: 0.4.1
author: WPCustomify
author_website: https://pressmaximum.com
theme_path: /home/myuser/mysite/wp-content/themes/customify
auto_update: Disabled

### wp-themes-inactive (1) ###

Twenty Twenty-Three: version: 1.1, author: the WordPress team, Auto-updates disabled

### wp-mu-plugins (2) ###

BPS Pro MU Tools: version: 17.0, author: AITpro
burst_rest_api_optimizer.php: author: (undefined), version: (undefined)

### wp-plugins-active (16) ###

ARMember - Complete Membership Plugin: version: 5.9.1, author: Repute InfoSystems, Auto-updates disabled
BulletProof Security Pro: version: 17.1, author: AITpro, Auto-updates disabled
Burst Statistics - Privacy-Friendly Analytics for WordPress: version: 1.3.5, author: Really Simple Plugins, Auto-updates disabled
Complianz | GDPR/CCPA Cookie Consent: version: 6.4.3, author: Really Simple Plugins, Auto-updates disabled
Disable Comments: version: 2.4.3, author: WPDeveloper, Auto-updates disabled
Disable REST API: version: 1.7, author: Dave McHale, Auto-updates disabled
Enable Media Replace: version: 4.1.0, author: ShortPixel, Auto-updates disabled
Error Log Monitor: version: 1.7.5, author: Janis Elsts, Auto-updates disabled
Floating Contact Button: version: 2.6, author: Christoph Nagel, Auto-updates disabled
LiteSpeed Cache: version: 5.3.3, author: LiteSpeed Technologies, Auto-updates disabled
Meta Generator and Version Info Remover: version: 15.1, author: Pankaj Kumar Mondal, Auto-updates disabled
Pods - Custom Content Types and Fields: version: 2.9.13, author: Pods Framework Team, Auto-updates disabled
Secure Copy Content Protection: version: 3.5.4, author: Copy Content Protection Team, Auto-updates disabled
WP Armour - Honeypot Anti Spam: version: 2.1.3, author: Dnesscarkey, Auto-updates disabled
WP Debugging: version: 2.11.20, author: Andy Fragen, Auto-updates disabled
WPForms Lite: version: 1.8.1.1, author: WPForms, Auto-updates disabled

### wp-plugins-inactive (1) ###

WP Bulk Delete: version: 1.2.4, author: Xylus Themes, Auto-updates disabled

### wp-media ###

image_editor: WP_Image_Editor_GD
imagick_module_version: Not available
imagemagick_version: Not available
imagick_version: Not available
file_uploads: File uploads is turned off
post_max_size: 1024M
upload_max_filesize: 1024M
max_effective_size: 1 GB
max_file_uploads: 20
gd_version: 2.3.3
gd_formats: GIF, JPEG, PNG, WebP, BMP, XPM
ghostscript_version: 8.70

### wp-server ###

server_architecture: Linux 2.6.32-954.3.5.lve1.4.89.el6.x86_64 x86_64
httpd_software: LiteSpeed
php_version: 7.4.33 64bit
php_sapi: litespeed
max_input_variables: 5000
time_limit: 120
memory_limit: 256M
max_input_time: 5000
upload_max_filesize: 1024M
php_post_max_size: 1024M
curl_version: 7.84.0 OpenSSL/1.1.1p
suhosin: false
imagick_availability: false
pretty_permalinks: true
htaccess_extra_rules: true

### wp-database ###

extension: mysqli
server_version: 10.3.38-MariaDB-cll-lve
client_version: mysqlnd 7.4.33
max_allowed_packet: 268435456
max_connections: 151

### wp-constants ###

WP_HOME: undefined
WP_SITEURL: undefined
WP_CONTENT_DIR: /home/myuser/mysite/wp-content
WP_PLUGIN_DIR: /home/myuser/mysite/wp-content/plugins
WP_MEMORY_LIMIT: 128M
WP_MAX_MEMORY_LIMIT: 256M
WP_DEBUG: false
WP_DEBUG_DISPLAY: true
WP_DEBUG_LOG: true
SCRIPT_DEBUG: true
WP_CACHE: true
CONCATENATE_SCRIPTS: undefined
COMPRESS_SCRIPTS: undefined
COMPRESS_CSS: undefined
WP_ENVIRONMENT_TYPE: Undefined
DB_CHARSET: utf8mb4
DB_COLLATE: undefined

### wp-filesystem ###

wordpress: writable
wp-content: writable
uploads: writable
plugins: writable
themes: writable
mu-plugins: writable

### pods ###

pods-server-software: LiteSpeed
pods-user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
pods-session-save-path: /opt/alt/php74/var/lib/php/session
pods-session-save-path-exists: Yes
pods-session-save-path-writable: Yes
pods-session-max-lifetime: 1440
pods-opcode-cache-apc: No
pods-opcode-cache-memcached: No
pods-opcode-cache-opcache: Yes
pods-opcode-cache-redis: No
pods-object-cache-apc: No
pods-object-cache-apcu: Yes
pods-object-cache-memcache: No
pods-object-cache-memcached: No
pods-object-cache-redis: No
pods-memory-current-usage: 16.395M
pods-memory-current-usage-real: 10.000M
pods-network-wide: No
pods-install-location: /wp-content/plugins/pods/
pods-developer: No
pods-tableless-mode: No
pods-relationship-table-enabled: Yes
pods-light-mode: No
pods-strict: No
pods-allow-deprecated: Yes
pods-api-cache: Yes
pods-shortcode-allow-evaluate-tags: No
pods-sessions: Disable sessions
pods-can-use-sessions: Yes
pods-relationship-table-status: 12,496

### wpforms ###

version: 1.8.1.1
lite: Jul 19, 2022 @ 10:15pm
upload_dir: Writable
total_forms: 2
total_submissions: 2610

### Pods Package

json
{
    "@meta": {
        "version": "2.9.13",
        "build": 1681123470
    },
    "settings": {
        "types_only": "0",
        "watch_changed_fields": "0",
        "metadata_integration": "1",
        "metadata_override_get": "0",
        "session_auto_start": "0",
        "wisdom_opt_out": "1"
    },
    "pods": [
        {
            "name": "metaflag",
            "id": 19321,
            "label": "metaflags",
            "description": "metaflag test",
            "type": "taxonomy",
            "storage": "meta",
            "label_singular": "metaflag",
            "public": "1",
            "show_ui": "1",
            "hierarchical": "1",
            "rest_enable": "0",
            "_migrated_28": "1",
            "show_in_menu": "1",
            "menu_location": "default",
            "show_in_nav_menus": "1",
            "show_tagcloud": "1",
            "show_in_quick_edit": "1",
            "built_in_post_types_hiragana_word": "1",
            "built_in_post_types_katakana_word": "1",
            "rewrite": "1",
            "rewrite_with_front": "1",
            "rewrite_hierarchical": "1",
            "capability_type": "default",
            "menu_name": "metaflag menu",
            "groups": [
                {
                    "name": "more_fields",
                    "id": 19322,
                    "label": "More Fields",
                    "description": "",
                    "weight": 0,
                    "fields": []
                }
            ]
        },
        {
            "name": "tableflag",
            "id": 19326,
            "label": "tableflags",
            "description": "tableflag test",
            "type": "taxonomy",
            "storage": "table",
            "label_singular": "tableflag",
            "public": "1",
            "show_ui": "1",
            "hierarchical": "1",
            "rest_enable": "0",
            "_migrated_28": "1",
            "show_in_menu": "1",
            "menu_name": "tableflag menu",
            "menu_location": "default",
            "show_in_nav_menus": "1",
            "show_tagcloud": "1",
            "show_in_quick_edit": "1",
            "built_in_post_types_hiragana_word": "1",
            "built_in_post_types_katakana_word": "1",
            "rewrite": "1",
            "rewrite_with_front": "1",
            "rewrite_hierarchical": "1",
            "capability_type": "default",
            "groups": [
                {
                    "name": "more_fields",
                    "id": 19327,
                    "label": "More Fields",
                    "description": "",
                    "weight": 0,
                    "fields": [
                        {
                            "name": "image",
                            "id": 19333,
                            "label": "image",
                            "description": "",
                            "weight": 0,
                            "type": "file",
                            "sister_id": "-- Select One --",
                            "required": "0",
                            "required_help_boolean": "0",
                            "unique": "0",
                            "file_format_type": "single",
                            "file_uploader": "attachment",
                            "file_type": "images",
                            "file_attachment_tab": "upload",
                            "file_upload_dir": "wp",
                            "file_edit_title": "1",
                            "file_show_edit_link": "0",
                            "file_linked": "0",
                            "file_limit": "0",
                            "file_field_template": "rows",
                            "file_add_button": "Add File",
                            "file_modal_title": "Attach a file",
                            "file_modal_add_button": "Add File",
                            "file_wp_gallery_link": "file",
                            "file_wp_gallery_columns": "3",
                            "file_wp_gallery_size": "thumbnail",
                            "repeatable": "0",
                            "repeatable_format": "default",
                            "roles_allowed": "administrator",
                            "rest_pick_response": "array",
                            "rest_pick_depth": "1"
                        }
                    ]
                }
            ]
        }
    ]
}
mwf1 commented 9 months ago

This looks similar to Error when {@permalink} is used in a template in combination with a tablebased custom taxonomy #7073