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

Problem with script in PHP CLI #766

Closed
mayaliny opened this issue Dec 5, 2019 · 6 comments
Closed

Problem with script in PHP CLI #766

mayaliny opened this issue Dec 5, 2019 · 6 comments
Labels
bug Something isn't working, reproducible core Core functionalities, including the admin section need info The submitter must provide more info severity: critical Critical functionality

Comments

@mayaliny
Copy link

mayaliny commented Dec 5, 2019

Hello,
i'm writing a parser to be called from the command line, and i noticed that when qtranslate XT (ver. 3.7.1) is enabled the script simply exits (no errors shown or logged).

When the plugin is disabled the script is able to import data into WP correctly.

Are you doing something do disable the CLI?

FWIW I'm loading wordpress with this code at the very beginning of my script:

`// Let's load WordPress

if( php_sapi_name() !== 'cli' ) {
    die("Meant to be run from command line");
}

function find_wordpress_base_path() {
    $dir = dirname(__FILE__);
    do {
        //it is possible to check for other files here
        if( file_exists($dir."/wp-config.php") ) {
            return $dir;
        }
    } while( $dir = realpath("$dir/..") );
    return null;
}

define( 'BASE_PATH', find_wordpress_base_path()."/" );
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require(BASE_PATH . 'wp-load.php');

`

any clue?

@herrvigg
Copy link
Collaborator

herrvigg commented Dec 7, 2019

I don't use this, but it is supposed to work. The only places where WP_CLI is handled is here to disabled the redirections:

return ! is_admin() && ! wp_doing_ajax() && ! ( defined( 'WP_CLI' ) && WP_CLI ) && ! wp_doing_cron() && empty( $_POST )

and here for the language detection:

if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {

Apart from this, nothing special. So if the scripts exits you should add more logging info to understand where it happens.

@herrvigg herrvigg added the need info The submitter must provide more info label Feb 18, 2020
@herrvigg herrvigg added the core Core functionalities, including the admin section label Oct 7, 2020
@hirasso
Copy link

hirasso commented Nov 13, 2022

Hi there! Today I also ran into a problem wit WP_CLI and qtranslate (I'm trying to implement a custom command). This is the error output I am getting:

Notice: Undefined index: wp-path in /.../content/plugins/qtranslate-xt/qtranslate_core.php on line 440
Warning: assert(): language needs to be shown in url - cancelled by can_redirect, url_info={
    "cookie_front_or_admin_found": false,
    "pagenow": "index.php",
    "REQUEST_METHOD": "GET",
    "scheme": "http",
    "host": "",
    "path": false,
    "path-base": "\/core",
    "doing_front_end": true,
    "lang_browser": null,
    "doredirect": "language needs to be shown in url - cancelled by can_redirect",
    "language": "de",
    "set_cookie": true
} failed in /.../plugins/qtranslate-xt/qtranslate_core.php on line 100

QTX_VERSION: 3.12.1
WP Version: 6.0.3

@herrvigg
Copy link
Collaborator

So WP_CLI is not set and the request looks really weird with host="", path=false, path-base="\/core".
Can you explain what you are trying to do from the CLI?

@hirasso
Copy link

hirasso commented Nov 16, 2022

Maybe the issue is somehow related to my website using a custom folder structure? It looks like this:

.
├── content
├── core
├── index.php
└── wp-config.php

...where /content is my wp-content folder and /core contains all WP files.

By the way, I am also getting this error when trying to run any of the built-in WP CLI commands, like e.g. wp core update.

@herrvigg
Copy link
Collaborator

Related to #1326.

@herrvigg
Copy link
Collaborator

Fix released in 3.14.2.

@herrvigg herrvigg added bug Something isn't working, reproducible severity: critical Critical functionality labels Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working, reproducible core Core functionalities, including the admin section need info The submitter must provide more info severity: critical Critical functionality
Projects
None yet
Development

No branches or pull requests

3 participants