qtranslate / qtranslate-xt

qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
546 stars 103 forks source link

Running any WP_CLI command breaks with qtranslate-xt #1344

Open hirasso opened 1 year ago

hirasso commented 1 year ago

Describe the bug When running any WP_CLI command, qtranslate breaks with this message:

Fatal error: Uncaught TypeError: qtranxf_match_page(): Argument #2 ($url_path) must be of type string, null given, called in /wp-content/plugins/qtranslate-xt/src/utils.php on line 334 and defined in /wp-content/plugins/qtranslate-xt/src/utils.php:262
Stack trace:
#0 /wp-content/plugins/qtranslate-xt/src/utils.php(334): qtranxf_match_page(Array, NULL, '', '!')
#1 /wp-content/plugins/qtranslate-xt/src/frontend.php(25): qtranxf_parse_page_config(Array, NULL, '')
#2 /wp-content/plugins/qtranslate-xt/src/frontend.php(898): qtranxf_get_front_page_config()
#3 /wp-content/plugins/qtranslate-xt/src/init.php(128): qtranxf_add_front_filters()
#4 /wp-core/wp-includes/class-wp-hook.php(308): qtranxf_init_language('')
#5 /wp-core/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#6 /wp-core/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#7 /wp-core/wp-settings.php(486): do_action('plugins_loaded')
  thrown in /wp-content/plugins/qtranslate-xt/src/utils.php on line 262

To Reproduce Steps to reproduce the behavior:

  1. Activate qtranslate
  2. Run any WP_CLI command, for example wp core update

Expected behavior The WordPress core should be updated

Debug info Go to <YOUR_SITE>/wp-admin/options-general.php?page=qtranslate-xt#troubleshooting. Press Collect information button and copy/paste the output below.

{
  "PHP_VERSION": "8.0.8",
  "WP_VERSION": "6.2.2",
  "QTX_VERSION": "3.15.1",
  "Plugins": [
    "ACF Autosize 2.0.15",
    "Advanced Custom Fields: Unique ID Field 1.0.0",
    "Admin Collapse Subpages 2.4",
    "Admin Post Navigation 2.1",
    "Advanced Custom Fields PRO 6.1.6",
    "Category Checklist Tree 1.3.2",
    "Check &amp; Log Email 1.0.7",
    "Classic Editor 1.6.3",
    "Debug Bar 1.1.4",
    "Yoast Duplicate Post 4.5",
    "Email Address Encoder 1.0.22",
    "Enable Media Replace 4.1.2",
    "Filenames to latin 2.7",
    "Git Updater 12.2.1",
    "iOS Images Fixer 1.2.4",
    "Limit Login Attempts 1.7.2",
    "Loop Post Navigation Links 3.0.2",
    "Post Type Switcher 3.2.1",
    "qTranslate-XT 3.15.1",
    "Regenerate Thumbnails 3.1.5",
    "Relevanssi 4.20.0",
    "Rewrite Rules Inspector 1.3.1",
    "RH Admin Utilities 1.9.0",
    "RH Privacy Consent 1.1.2",
    "RH Shortcodes 1.1.3",
    "RH Updater 1.2.0",
    "Safe SVG 2.1.1",
    "External Links 6.8.1",
    "Simple Page Ordering 2.5.0",
    "YIKES Simple Taxonomy Ordering 2.3.4",
    "Term Management Tools 2.0.1",
    "User Switching 1.7.0",
    "WordPress Importer 0.8.1",
    "Yoast SEO 20.7",
    "Media Library Categories Premium 2.1.1",
    "WP Super Cache 1.9.4",
    "WP-Sweep 1.1.8",
    "WP Sync DB 1.6"
  ]
}

Proposed Solution I was able to mute the error by bailing early if WP_CLI is defined:

function qtranxf_init_language(): void {
    global $q_config, $pagenow;

    if (defined('WP_CLI')) return;

    qtranxf_load_config();
    // ...
}

I don't know if this has any downsides, but it worked for me.

hirasso commented 9 months ago

@herrvigg did you ever come around to having a look at this?

For the time being, I can use --skip-plugins to exclude qTranslate-XT.

Instead of this:

wp transient delete --all

I have to do this:

wp --skip-plugins="qtranslate-xt" transient delete --all

But it would be very nice to have it just fixed in qtranslate-xt, as stated above.

herrvigg commented 6 months ago

I don't see how #1387 would solve this.

In qtranxf_get_front_page_config line 24 can you add this?

var_dump($q_config['url_info']);

It seems $q_config['url_info']['wp-path'] is not set (null). The other fields may give some indications. Could be some special WP installation that is not supported in some script.

hirasso commented 6 months ago

I'll post the var dump tomorrow. I'm indeed using a custom directory structure as described in https://github.com/qtranslate/qtranslate-xt/pull/1387#issuecomment-1890916854 (Test 3)

hirasso commented 6 months ago

@herrvigg This is the requested dump:

array(10) {
  ["cookie_front_or_admin_found"]=>
  bool(false)
  ["pagenow"]=>
  string(9) "index.php"
  ["REQUEST_METHOD"]=>
  string(3) "GET"
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(0) ""
  ["path"]=>
  bool(false)
  ["path-base"]=>
  string(5) "/core"
  ["doing_front_end"]=>
  bool(true)
  ["language"]=>
  string(2) "de"
  ["set_cookie"]=>
  bool(true)
}

This is the directory structure I'm using:

.
├── content # wp content folder
│  ├── ... 
├── core # wp core folder
│  ├── ... 
├── index.php
└── wp-config.php