Call to undefined function readline()

When i try to write
$choice = readline();
it shows me

Fatal error: Uncaught Error: Call to undefined function readline()

But for other readlines, like $title = readline("Enter title: ") it doesn’t show me errors. What is the cause? I’m using php version 8.4.0

How can i fix it without needing to write longer codes (if possible) ?

I tried to make a do..while loop where there are multiple choices – cases, but it doesn’t seem to like it

do {
    echo "nn";
    echo "1 - show all booksn";
    echo "2 - show a bookn";
    echo "3 - add a bookn";
    echo "4 - delete a bookn";
    echo "5 - quitnn";
    $choice = readline();

    switch ($choice) {
        case 1:
            foreach ($books as $id => $book) {
                displayBook($id, $book);
            }

            break;
        case 2:
            $id = readline("Enter book id: ");
            displayBook($id, $books[$id]);

            break;
        case 3:
            addBook($books);
            break;
        case 4:
            deleteBook($books);
            break;
        case 5:
            echo "Goodbye!n";
            $continue = false;
            break;
        case 13:
            print_r($books); // hidden option to see full $books content
            break;
        default:
            echo "Invalid choicen";
    };

} while ($continue == true);

Getting “page over page” problem in laravel 11+ using inertia react for frontend

I have been struggling with this error for 2 weeks. Project setup is basically simple:

  • docker-compose for building app, redis and mariadb containers
  • nginx on production server for serving app and build assets from react

After a while, especially while submitting login or any POST request handling from react jsx template (using inertia router.post method), it opens up a new window inside current one with redirect.

Here is my login controller method

public function login(Request $request)
{
    $credentials = $request->validate([
        'email' => 'required|email',
        'password' => 'required',
    ]);

    if (Auth::guard('client')->attempt($credentials, $request->boolean('remember'))) {
        $client = Auth::guard('client')->user();

        if ($client->status) {
            $request->session()->regenerate();

            return Inertia::location(route('client.admin'));
        }

        Auth::guard('client')->logout();

        throw ValidationException::withMessages([
            'email' => 'Your account is inactive.',
        ]);
    }

    throw ValidationException::withMessages([
        'email' => 'The provided credentials do not match our records.',
    ]);
}

Attaching screenshots:

plaintext JSON output of login form followed by "Redirecting to" login form with "Email" and "Password" fields, "Remember me" checkbox, and "LOG IN" button

I would appreciate any help in resolving this. Thanks.

using polylang , how to move all the translation po files directly (using a plugin) instead of migrating them manually

HI I am working on a creating of a plugin where site is built using child of a classic theme In my site i am already using polylang (free) version now i tried to build a plugin

where I need to Ensure all French translations from the theme .po files are imported into the Polylang database automatically

Current status:I Manual conversion of _()/e() to pll()/pll_e() in the theme is done and working.

So Now i my requirement is to Create a one-time plugin to import existing .po translations into Polylang GUI/database.

The Purpose of it is to Avoid manual entry errors, reduce deployment downtime, and ensure translations work correctly in live/production.

Scope: Use existing .pot, .po, .mo files from the theme. No additional files are required. in my wp-contents/Language contain the theme and plugin folders where the all .po, .mo files are present

so on enabling this plugin all French translations must be verified and confirmed functional before task completion.

Also English strings may appear on French pages if the import is not done properly. The plugin is single-use, not continuous.

Requirement:
Create a one-time plugin that imports all French translations from theme .po files into Polylang’s database.

Site: child of a classic theme
Polylang (free) active
Manual conversion of _() / e() → pll() / pll_e() is already done
Goal: avoid manual errors, ensure translations work correctly in production
Plugin draft (current code):

<?php
/**
 * Plugin Name: Polylang French Translation Importer - DEBUG
 * Description: Debug version to import French translations from .po files into Polylang database
 * Version: 1.3
 * Author: Your Name
 */

if (!defined('ABSPATH')) exit;

class PolylangFrenchImporter {
    private $import_path;

    public function __construct() {
        $this->import_path = WP_CONTENT_DIR . '/languages/themes/';
        add_action('admin_menu', [$this, 'add_admin_page']);
    }

    public function add_admin_page() {
        add_management_page(
            'Polylang Import',
            'Polylang Import',
            'manage_options',
            'polylang-import',
            [$this, 'render_import_page']
        );
    }

    public function render_import_page() {
        if (isset($_POST['run_import'])) {
            $this->run_import();
        }

        echo '<div class="wrap"><h1>Polylang PO Import Debug</h1>';
        echo '<form method="post">';
        submit_button('Run Import', 'primary', 'run_import');
        echo '</form></div>';
    }

    private function run_import() {
        if (!function_exists('pll_get_the_language')) {
            echo '<p style="color:red;">Polylang not active!</p>';
            return;
        }

        require_once ABSPATH . 'wp-admin/includes/translation-install.php';

        $files = glob($this->import_path . '*.po');
        if (!$files) {
            echo '<p style="color:red;">No .po files found in: ' . esc_html($this->import_path) . '</p>';
            return;
        }

        foreach ($files as $file) {
            $locale = basename($file, '.po');
            echo '<h3>Processing: ' . esc_html($locale) . '</h3>';

            $translations = $this->parse_po_file($file);
            if (!$translations) {
                echo '<p style="color:red;">Failed to load PO file or no translations found.</p>';
                continue;
            }

            global $wpdb;
            $table = $wpdb->prefix . 'polylang_strings';

            $count = 0;
            foreach ($translations as $msgid => $msgstr) {
                if (!$msgid || !$msgstr) continue;

                $wpdb->insert($table, [
                    'string'  => $msgid,
                    'context' => 'theme',
                    'name'    => md5($msgid),
                    'value'   => $msgstr,
                    'group'   => 'po-import',
                    'multiline' => 0,
                ]);
                $count++;
            }

            echo '<p style="color:green;">Imported ' . intval($count) . ' strings from ' . esc_html($file) . '</p>';
        }
    }

    private function parse_po_file($file) {
        if (!class_exists('PO')) {
            require_once ABSPATH . 'wp-includes/pomo/po.php';
        }

        $po = new PO();
        $loaded = $po->import_from_file($file);
        if (!$loaded) {
            error_log('Failed to load PO file: ' . $file);
            return false;
        }

        $translations = [];
        foreach ($po->entries as $entry) {
            if (!empty($entry->translations[0])) {
                $translations[$entry->singular] = $entry->translations[0];
            }
        }

        error_log('Parsed ' . count($translations) . ' strings from ' . $file);
        return $translations;
    }
}

new PolylangFrenchImporter();
Error while testing:

PO files are detected (fr_CA.po, en_CA.po) ✅
But import_from_file fails → Failed to load PO file ❌
Results: Strings Found = 0, Strings Imported = 0
Debug log shows PO files exist but cannot be parsed

Laravel installer error – Could not scan for classes vendor/sebastian/code-unit-reverse-lookup/src/ which does not appear to be a file [duplicate]

When trying to create a new Laravel project, the Laravel installer throws the following error:

Could not scan for classes inside "/home/aes256/test/vendor/sebastian/code-unit-reverse-lookup/src/" which does not appear to be a file nor a folder
> pre-package-uninstall: IlluminateFoundationComposerScripts::prePackageUninstall
Script IlluminateFoundationComposerScripts::prePackageUninstall handling the pre-package-uninstall event terminated with an exception

In ComposerScripts.php line 66:

  [ErrorException]
  Constant LARAVEL_START already defined

Re-running the Laravel installer with verbose mode shows the following additional info:

Executing async command (CWD): 'rm' '-rf' '/home/aes256/test/vendor/sebastian/code-unit-reverse-lookup'
Could not scan for classes inside "/home/aes256/test/vendor/sebastian/code-unit-reverse-lookup/src/" which does not appear to be a file nor a folder
> pre-package-uninstall: IlluminateFoundationComposerScripts::prePackageUninstall
Script IlluminateFoundationComposerScripts::prePackageUninstall handling the pre-package-uninstall event terminated with an exception

In ComposerScripts.php line 66:

  [ErrorException]
  Constant LARAVEL_START already defined


Exception trace:
  at /home/aes256/test/vendor/laravel/framework/src/Illuminate/Foundation/ComposerScripts.php:66
 IlluminateFoundationBootstrapHandleExceptions->handleError() at /home/aes256/test/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:258
 IlluminateFoundationBootstrapHandleExceptions->{closure:IlluminateFoundationBootstrapHandleExceptions::forwardsTo():257}() at n/a:n/a
 define() at /home/aes256/test/vendor/laravel/framework/src/Illuminate/Foundation/ComposerScripts.php:66
 IlluminateFoundationComposerScripts::prePackageUninstall() at phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:508
 ComposerEventDispatcherEventDispatcher->executeEventPhpScript() at phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:284
 ComposerEventDispatcherEventDispatcher->doDispatch() at phar:///usr/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:158
 ComposerEventDispatcherEventDispatcher->dispatchPackageEvent() at phar:///usr/bin/composer/src/Composer/Installer/InstallationManager.php:369
 ComposerInstallerInstallationManager->executeBatch() at phar:///usr/bin/composer/src/Composer/Installer/InstallationManager.php:322
 ComposerInstallerInstallationManager->downloadAndExecuteBatch() at phar:///usr/bin/composer/src/Composer/Installer/InstallationManager.php:221
 ComposerInstallerInstallationManager->execute() at phar:///usr/bin/composer/src/Composer/Installer.php:839
 ComposerInstaller->doInstall() at phar:///usr/bin/composer/src/Composer/Installer.php:649
 ComposerInstaller->doUpdate() at phar:///usr/bin/composer/src/Composer/Installer.php:298
 ComposerInstaller->run() at phar:///usr/bin/composer/src/Composer/Command/UpdateCommand.php:281
 ComposerCommandUpdateCommand->execute() at phar:///usr/bin/composer/vendor/symfony/console/Command/Command.php:298
 SymfonyComponentConsoleCommandCommand->run() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:1040
 SymfonyComponentConsoleApplication->doRunCommand() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:301
 SymfonyComponentConsoleApplication->doRun() at phar:///usr/bin/composer/src/Composer/Console/Application.php:400
 ComposerConsoleApplication->doRun() at phar:///usr/bin/composer/vendor/symfony/console/Application.php:171
 SymfonyComponentConsoleApplication->run() at phar:///usr/bin/composer/src/Composer/Console/Application.php:137
 ComposerConsoleApplication->run() at phar:///usr/bin/composer/bin/composer:98
 require() at /usr/bin/composer:29

Is it something to be concerned about?

Tried a different Linux machine with fresh PHP + Composer install, same error.

edit: trying to create new project using PHPUnit instead of Pest works fine.

Doctrine ORM: Transaction commit fails after rollback in batch loop (Symfony 5.4, PHP 7.4)

I’m running a batch process in Symfony 5.4.48 (PHP 7.4.30, Doctrine ORM 2.20.3) where I need to handle database transactions per iteration. If a business condition fails, I want to rollback the transaction and continue to the next item. However, after a rollback, the next iteration fails with:

Transaction commit failed because the transaction has been marked for rollback only.

Here’s a simplified version of my code:

<?php
foreach ($items as $item) {
    $em = $doctrine->getManager();
    $connection = $em->getConnection();
    $connection->beginTransaction();
    try {
        // ... business logic ...
        if ($shouldRollback) {
            $connection->rollBack();
            $doctrine->resetManager();
            continue;
        }
        $connection->commit();
    } catch (Throwable $e) {
        if ($connection->isTransactionActive()) {
            $connection->rollBack();
        }
        $doctrine->resetManager();
        continue;
    }
}

Even after calling $doctrine->resetManager(), the next $em and $connection seem to be in a “rollback only” state, and commit() fails.

Environment:

  • Symfony: 5.4.48
  • Doctrine ORM: 2.20.3
  • PHP: 7.4.30
  • OS: Windows

What I’ve tried:

  • Resetting the EntityManager with $doctrine->resetManager()
  • Reacquiring the EntityManager and Connection after rollback
  • Checking transaction state with $connection->isRollbackOnly()

Questions:

  • Is this the expected behavior for Doctrine ORM?
  • How can I fully reset the EntityManager/Connection so that the next transaction works?
  • Is there a recommended pattern for batch processing with per-iteration transactions in Doctrine?

Magento error on static-content:deploy -f

I’m getting this error Unexpected input in styles-l-temp.less

frontend/Pearl/weltpixel/en_US          2964/3067           ===========================> 96% %   3 secs
Compilation from source: /opt/bitnami/apps/magento/htdocs/app/design/frontend/Pearl/weltpixel/web/css/styles-l-temp.less
ParseError: Unexpected input in styles-l-temp.less on line 1, column 1
1| #@import '../WeltPixel_FrontendOptions/css/source/module/_store_completehome_extend.less';
2|
3|


  [MagentoFrameworkExceptionFileSystemException]
  Cannot read contents from file "/opt/bitnami/apps/magento/htdocs/pub/static/frontend/Pearl/weltpixel/en_US/c
  ss/styles-l-temp.css" Warning!file_get_contents(/opt/bitnami/apps/magento/htdocs/pub/static/frontend/Pearl/w
  eltpixel/en_US/css/styles-l-temp.css): failed to open stream: No such file or directory

So, i remove the #@import to @import and execute these commands:

sudo rm -rf /opt/bitnami/apps/magento/htdocs/var/cache/*
sudo rm -rf /opt/bitnami/apps/magento/htdocs/var/page_cache/*
sudo rm -rf /opt/bitnami/apps/magento/htdocs/var/view_preprocessed/*
sudo rm -rf /opt/bitnami/apps/magento/htdocs/pub/static/frontend/*

Now, when execute static-content:deploy -f command is shows this error:

bitnami@ip-172-26-13-233:/opt/bitnami/apps/magento/htdocs$ sudo /opt/bitnami/apps/magento/htdocs/bin/magento-cli setup:static-content:deploy -f

Deploy using quick strategy
frontend/Magento/blank/en_US            3037/3037           ============================ 100% %  3 secs          frontend/Magento/blank/en_US            3037/3037           ============================ 100% %  3 secs          frontend/Magento/blank/en_US            3037/3037           ============================ 100% %  3 secs          
frontend/Magento/blank/en_US            3037/3037           ============================ 100% %  3 secs          
frontend/Magento/blank/en_US            3037/3037           ============================ 100% %  3 secs          
frontend/Magento/blank/en_US            3037/3037           ============================ 100% %  3 secs          
frontend/Magento/blank/en_US            3037/3037           ============================ 100% %  3 secs          
adminhtml/Magento/backend/en_US         2383/2383           ============================ 100% %  2 secs          frontend/Magento/blank/en_US            3037/3037           ============================ 100% %  3 secs          
adminhtml/Magento/backend/en_US         2383/2383           ============================ 100% %  2 secs          frontend/Magento/blank/en_US            3037/3037           ============================ 100% %  3 secs          
adminhtml/Magento/backend/en_US         2383/2383           ============================ 100% %  2 secs          
frontend/Magento/luma/en_US             3053/3053           ============================ 100% %  4 secs          
frontend/Pearl/weltpixel/en_US          2951/3067           ==========================>- 96% %   3 secs
#0 /opt/bitnami/apps/magento/htdocs/vendor/magento/framework/App/View/Asset/Publisher.php(73): MagentoFrameworkViewAssetFile->getSourceFile()
#1 /opt/bitnami/apps/magento/htdocs/vendor/magento/framework/App/View/Asset/Publisher.php(61): MagentoFrameworkAppViewAssetPublisher->publishAsset(Object(MagentoFrameworkViewAssetFile))
#2 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Service/DeployStaticFile.php(89): MagentoFrameworkAppViewAssetPublisher->publish(Object(MagentoFrameworkViewAssetFile))
#3 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Service/DeployPackage.php(189): MagentoDeployServiceDeployStaticFile->deployFile('css/styles-l-te...', Array)
#4 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Service/DeployPackage.php(136): MagentoDeployServiceDeployPackage->processFile(Object(MagentoDeployPackagePackageFile), Object(MagentoDeployPackagePackage))
#5 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Service/DeployPackage.php(107): MagentoDeployServiceDeployPackage->deployEmulated(Object(MagentoDeployPackagePackage), Array, false)
#6 [internal function]: MagentoDeployServiceDeployPackage->MagentoDeployService{closure}()
#7 /opt/bitnami/apps/magento/htdocs/vendor/magento/framework/App/State.php(186): call_user_func_array(Object(Closure), Array)
#8 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Service/DeployPackage.php(108): MagentoFrameworkAppState->emulateAreaCode('frontend', Object(Closure))
#9 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Process/Queue.php(300): MagentoDeployServiceDeployPackage->deploy(Object(MagentoDeployPackagePackage), Array)
#10 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Process/Queue.php(219): MagentoDeployProcessQueue->execute(Object(MagentoDeployPackagePackage))
#11 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Process/Queue.php(162): MagentoDeployProcessQueue->assertAndExecute('frontend/Pearl/...', Array, Array)
#12 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Strategy/QuickDeploy.php(76): MagentoDeployProcessQueue->process()
#13 /opt/bitnami/apps/magento/htdocs/vendor/magento/module-deploy/Service/DeployStaticContent.php(109): MagentoDeployStrategyQuickDeploy->deploy(Array)
#14 /opt/bitnami/apps/magento/htdocs/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php(140): MagentoDeployServiceDeployStaticContent->deploy(Array)
#15 /opt/bitnami/apps/magento/htdocs/vendor/symfony/console/Command/Command.php(241): MagentoSetupConsoleCommandDeployStaticContentCommand->execute(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#16 /opt/bitnami/apps/magento/htdocs/vendor/symfony/console/Application.php(844): SymfonyComponentConsoleCommandCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#17 /opt/bitnami/apps/magento/htdocs/vendor/symfony/console/Application.php(193): SymfonyComponentConsoleApplication->doRunCommand(Object(MagentoSetupConsoleCommandDeployStaticContentCommand), Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#18 /opt/bitnami/apps/magento/htdocs/vendor/magento/framework/Console/Cli.php(104): SymfonyComponentConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#19 /opt/bitnami/apps/magento/htdocs/vendor/symfony/console/Application.php(117): MagentoFrameworkConsoleCli->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#20 /opt/bitnami/apps/magento/htdocs/bin/magento(30): SymfonyComponentConsoleApplication->run()
#21 {main}


  [MagentoFrameworkExceptionFileSystemException]
  Cannot read contents from file "/opt/bitnami/apps/magento/htdocs/pub/static/frontend/Pearl/weltpixel/en_US/c
  ss/styles-l-temp.css" Warning!file_get_contents(/opt/bitnami/apps/magento/htdocs/pub/static/frontend/Pearl/w
  eltpixel/en_US/css/styles-l-temp.css): failed to open stream: No such file or directory


setup:static-content:deploy [-f|--force] [-s|--strategy [STRATEGY]] [-a|--area [AREA]] [--exclude-area [EXCLUDE-AREA]] [-t|--theme [THEME]] [--exclude-theme [EXCLUDE-THEME]] [-l|--language [LANGUAGE]] [--exclude-language [EXCLUDE-LANGUAGE]] [-j|--jobs [JOBS]] [--symlink-locale] [--content-version CONTENT-VERSION] [--refresh-content-version-only] [--no-javascript] [--no-css] [--no-less] [--no-images] [--no-fonts] [--no-html] [--no-misc] [--no-html-minify] [--] [<languages>]...

I was trying to add another store with a subdomain. The domain completehome.completeattire.com was created, and the issue occurred when I started the service.

How to create a plugin to “Ensure all French translations from the theme .po files are imported into the Polylang database automatically” [closed]

HI I am working on a creating of a plugin where site is built using child of a classic theme

where I need to Ensure all French translations from the theme .po files are imported into the Polylang database automatically

Current status:I Manual conversion of _()/e() to pll()/pll_e() in the theme is done and working.

So Now i my requirement is to Create a one-time plugin to import existing .po translations into Polylang GUI/database.

The Purpose of it is to Avoid manual entry errors, reduce deployment downtime, and ensure translations work correctly in live/production.

Scope: Use existing .pot, .po, .mo files from the theme. No additional files are required. in my wp-contents/Language contain the theme and plugin folders where the all .po, .mo files are present

so on enabling this plugin all French translations must be verified and confirmed functional before task completion.

Also English strings may appear on French pages if the import is not done properly. The plugin is single-use, not continuous.

Why is there no newline being presented here?

I wrote the following bit of code to read through a passed in email stream (or .eml file while I’m testing).

During the test, it’s supposed to read through each line of a stream but it seems it’s just outputting as one line, even thouhg there is a newline in the stream.

My code is as follows:

function sendMailForward($email) {
    // Load recipients from ENV (comma-separated list)
    $newRecipients = preg_split("/,s*/", $_ENV['ADMIN_EMAIL'] ?? '', -1, PREG_SPLIT_NO_EMPTY);

    // For StackOverflow: This passes in a comma-separated list of emails, this line is not part of the problem.

    $raw_email = "";
    while (!feof($email)) {
        $raw_email .= fread($email, 1024);
    }
    fclose($email);

    // Extract headers for a clean subject and sender
    $headers = [];
    $lines = explode("n", $raw_email); // This line, somehow, doesn't see newlines in the stream.
    foreach ($lines as $line) {
        echo "New line!n"; // This was me trying to test and what should show up multiple times, only shows up once.
        if (strpos($line, ":") !== false) {
            $parts = explode(":", $line, 2);
            $key = trim($parts[0]);
            $value = trim($parts[1]);
            $headers[$key] = $value;
        }
        // Stop at the first blank line, which marks the end of headers
        if (trim($line) == "") {
            break;
        }
    }

    $original_subject = isset($headers['Subject']) ? "FWD: " . $headers['Subject'] : "FWD: No Subject";
    $original_from = isset($headers['From']) ? $headers['From'] : "unknown sender";

    $subject = $original_subject;
    $message = "--- Original message from $original_from ---nn" . $raw_email;
    $extra_headers = "From: [email protected]"; // Customize 'From' address


    foreach ($newRecipients as $recipient) {
        $to = $recipient;
        // Send the email
        mail($to, $subject, $message, $extra_headers);
    }
}

What should I change in the above code? Should I force a newline to be appended? Or is there something else happening that I should be aware of.

(If it also helps, the rest of the email is non-existent too.)

Per request below. This is the email I’m using to test.


From: "Megan at TCGplayer" <[email protected]>
To: "TCGPlayer Account" <[email protected]>
Subject: Test Email for Forwarding
Date: Sat, 28 Sep 2025 08:00:00 -0400
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

Hello,

This is a test email to verify the mail forwarding module.

Best regards,
Test System

EDIT 2: Someone asked for how is the code being used.

// Read original message from stdin
$rawEmail = file_get_contents('php://stdin');

sendMailForward($rawEmail);

Simply put just invoking it.

my wordpress site gets a 500 error that keeps coming back [closed]

I am hosting a website and every now and then I get the 500 error on the website.
I went through all of it:

  • checking permissions and chmoding
  • removing the .htaccess and rewriting it
  • disabling plugins (i only have the acf plugin )

when i fix the error, it comes back the next day without me even touching the files :/

How to avoid duplicating unchanged endpoints when versioning a REST API? [closed]

I need to introduce a breaking change to one endpoint in a REST API. The backend currently versions by duplicating the entire app per version. Example layout:

/rest
    /v1
        /controllers
        /models
    /v2
        /controllers
        /models
    /v3
        /controllers
        /models

Not all endpoints change with each version. When a bug is fixed in v2, the same fix must be applied manually in v3. This duplication is error-prone.

What project structure or pattern allows:

  1. Shared implementation for unchanged endpoints across versions.

  2. Isolation for versioned endpoints when breaking changes are required.

Constraints:

  • Language/framework agnostic.

  • Folder layout or structural examples are acceptable.

  • I want to know how to implement this technically, not whether one approach is “better.”

Custom WordPress login modal with AJAX – logging in works but then any attempt to access /wp-admin causes a redirect to ‘SITE_URL/home’

I have created a custom login modal for my wordpress site. In seems to be working on the surface, as in it logs in correctly, the admin bar appears at the top on page refresh and I’m able to access front-end content that is only available to admin accounts when I log in as an admin.

However, when I try to access any page in the dashboard (/wp-admin), the page hangs for a
while and then redirects me to the homepage with ‘/home’ added to the URL.

I built the functions.php action that receives the login data from the front-end and calls wp_signon() as I saw in the documentation. So I’m a bit confused why it is behaving as it is. Am I missing something from the login process?

Here is the action:

function ajax_custom_login() {
    $remember = isset($_POST['remember']) && $_POST['remember'] === 'on';

    $info = array();
    $info['user_login']    = sanitize_text_field($_POST['username']);
    $info['user_password'] = sanitize_text_field($_POST['password']);
    $info['remember']      = $remember;

    $user = wp_signon($info, false);

    if (is_wp_error($user)) {
        wp_send_json_error(array('message' => $user->get_error_message()));
    } else {
        wp_send_json_success(array('message' => 'Login successful, redirecting...'));
    }
}

I am using Wordfence and require administrators to use 2FA (not normal users) so I’m assuming this might be part of the problem. However, I’ve tried logging into the administrator account using the /wp-login.php page and told WordFence to “Remember for 30 days”.

Edit: Potentially ignore the Wordfence part below this – I have just tried the login process with my custom login form, after deactivating Wordfence, and the redirect is still happening. So it doesn’t seem like that is the problem.

If I do this, then log out and then log in with the custom login form, I thought it would let me log in because Wordfence is remembering the login for 30 days. It seems like it might be partially doing this because I’m able to get a success response back from wp_signon() and the admin bar appears on refresh, but I’m wondering if Wordfence is causing the ‘SITE_URL/home’ redirect? Is this a known problem? Am I missing something else in the login process?

Any advice would be greatly appreciated.

WordPress Unsafe SQL calls

I create one custom plugin and submit for review to wordpress.org. But the give me test log they says Unsafe SQL calls

`includes/databases/class-stepup-user-crud.php:313 $sql_orders = $wpdb->prepare(
"
SELECT p.*
FROM {$db->tb_posts} p
INNER JOIN {$db->tb_postmeta} pm ON p.ID = pm.post_id AND meta_key = %s AND (meta_value = %d OR meta_value like '%s')
",
'_user_id',
$user_id,
$user_id_str
);
includes/databases/class-stepup-user-crud.php:338 $sql = $sql_orders /* . ' UNION ' . $sql_guest_orders */ . $sql_rest;
includes/databases/class-stepup-user-crud.php:341 $order_posts = $db->wpdb->get_results($sql);
# There is a call to a wpdb::prepare() function, that's correct.
# You cannot add variables like "$db->tb_posts" directly to the SQL query.
# Using wpdb::prepare($query, $args) you will need to include placeholders for each variable within the query and include the variables in the second parameter.
# The SQL query needs to be included in a wpdb::prepare($query, $args) function.`

I added $db->tb_posts in global class.

they says do not use variable like these

You cannot add variables like "$db->tb_posts" directly to the SQL query

Please help me.

I read these content
https://www.wordfence.com/blog/2025/08/how-to-find-sql-injection-vulnerabilities-in-wordpress-plugins-and-themes/

some document says use $wpdb::prapare() and I already used it but not found correct solution.

These is my query

    $sql_orders = $wpdb->prepare( "SELECT p.* FROM {$db->tb_posts} p INNER JOIN {$db->tb_postmeta} pm ON p.ID = pm.post_id AND meta_key = %s AND (meta_value = %d OR meta_value like '%s')", '_user_id',$user_id,$user_id_str); 
$sql = $sql_orders . $sql_rest; 
$order_posts = $db->wpdb->get_results($sql); 

Is there a way to make my tabs appear 4 in a row for large screens, 3 in a row for medium screens, and stack atop each other for small screens?

I am using Tailwind CSS in my PHP/HTML project, so the only solution I’m looking for is tailwind. I got the tabs to sit side by side, but unfortunately, when I test on small screens, they still sit side by side, and appear horribly squished and out of screen. Which is why I want them to be stacked atop each other on small screens. Also, I haven’t been able to get the tabs to display in rows of 4s for large screens but rows of 3s for medium screens. my code:

<div class="flex flex-wrap justify-center gap-4 mt-8 px-4">
    <?php
    if (isLoggedIn()) {
        $links = [
            ['name' => 'Home', 'href' => '/', 'icon' => 'home'],
            ['name' => 'Inspections', 'href' => '/inspections', 'icon' => 'clipboard'],
            ['name' => 'Questions', 'href' => '/questions', 'icon' => 'question-mark'],
            ['name' => 'Inspectors', 'href' => '/inspectors', 'icon' => 'user-plus'],
            ['name' => 'Cover Pages', 'href' => '/covers', 'icon' => 'document-text'],
            ['name' => 'Profile', 'href' => '/profile', 'icon' => 'user'],
            ['name' => 'Contact', 'href' => '/contact', 'icon' => 'users'],
        ];
    }

    foreach ($links as $link): ?>
        <a href="<?= BASE_PATH . $link['href'] ?>" class="flex flex-col items-center justify-center bg-gray-100 dark:bg-gray-800 rounded-lg shadow hover:bg-gray-200 dark:hover:bg-gray-700 transition cursor-pointer" style="width:140px; height:140px;">
            <?php switch ($link['icon']) {
                case 'home':
                    echo '<svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-blue-600 dark:text-white mb-2" fill="currentColor" viewBox="0 0 24 24">
                        <path d="M3 9.75L12 3l9 6.75V21a.75.75 0 01-.75.75H3.75A.75.75 0 013 21V9.75z" />
                    </svg>';
                    break;
                case 'clipboard':
                    echo '<svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-blue-600 dark:text-white mb-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M15.666 3.888A2.25 2.25 0 0 0 13.5 2.25h-3c-1.03 0-1.9.693-2.166 1.638m7.332 0c.055.194.084.4.084.612v0a.75.75 0 0 1-.75.75H9a.75.75 0 0 1-.75-.75v0c0-.212.03-.418.084-.612m7.332 0c.646.049 1.288.11 1.927.184 1.1.128 1.907 1.077 1.907 2.185V19.5a2.25 2.25 0 0 1-2.25 2.25H6.75A2.25 2.25 0 0 1 4.5 19.5V6.257c0-1.108.806-2.057 1.907-2.185a48.208 48.208 0 0 1 1.927-.184" />
                    </svg>';
                    break;
                case 'question-mark':
                    echo '<svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-blue-600 dark:text-white mb-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 5.25h.008v.008H12v-.008Z" />
                    </svg>';
                    break;
                case 'user-plus':
                    echo '<svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-blue-600 dark:text-white mb-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M18 7.5v3m0 0v3m0-3h3m-3 0h-3m-2.25-4.125a3.375 3.375 0 1 1-6.75 0 3.375 3.375 0 0 1 6.75 0ZM3 19.235v-.11a6.375 6.375 0 0 1 12.75 0v.109A12.318 12.318 0 0 1 9.374 21c-2.331 0-4.512-.645-6.374-1.766Z" />
                    </svg>';
                    break;
                case 'document-text':
                    echo '<svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-blue-600 dark:text-white mb-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />
                    </svg>';
                    break;
                case 'user':
                    echo '<svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-blue-600 dark:text-white mb-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0ZM4.501 20.118a7.5 7.5 0 0 1 14.998 0A17.933 17.933 0 0 1 12 21.75c-2.676 0-5.216-.584-7.499-1.632Z" />
                    </svg>';
                    break;
                case 'users':
                    echo '<svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-blue-600 dark:text-white mb-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M17.25 6.75a3 3 0 11-6 0 3 3 0 016 0zM6.75 6.75a3 3 0 116 0 3 3 0 01-6 0zM3 21a6 6 0 0112 0M9 21a6 6 0 0112 0" />
                    </svg>';
                    break;
            } ?>
            <span class="text-sm font-medium text-gray-700 dark:text-gray-200 mb-2"><?= $link['name'] ?></span>
        </a>
    <?php endforeach; ?>
</div>

I tried updating the grid container to this:

<div class="grid gap-4 mt-8 px-4 max-w-screen-lg mx-auto grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 auto-cols-max justify-items-center">

and the tab anchors to this:

<a href="<?= BASE_PATH . $link['href'] ?>" class="h-[140px] flex flex-col items-center justify-center bg-gray-100 dark:bg-gray-800 rounded-lg shadow hover:bg-gray-200 dark:hover:bg-gray-700 transition cursor-pointer">

which made the tabs stack on small screens exactly as I wanted; however, the same also is happening on large screens and medium screens, which is not the effect I intended.

In PHP, should a child class redeclare constructor dependencies if the parent constructor already defines them, or can it omit them entirely?

So I’m kinda stuck wrapping my head around this whole parent-child dependency thing. My assumption was, once you declare all the dependencies in the parent (BaseController), the child (like IndexController) wouldn’t need to declare them again in its own constructor; it could just rely on parent::__construct(). Tried removing the four dependencies from IndexController, but got hit with an error. Basically, you still gotta re-declare those four deps in the child’s constructor so they can be passed up to parent::__construct(). At least that’s what the AI told me. Lastly, are those use statements really necessary to be in every file?

BaseController.php

   <?php

use AppModelsSiteSettings;
use AppServices{
    AuthService,
    LoggerService,
    MessageService
};

class BaseController
{
    public function __construct(
        protected SiteSettings $siteSettings,
        protected AuthService $authService,
        protected LoggerService $loggerService,
        protected MessageService $messageService
    ) {}
} 

IndexController.php

<?php

use AppModelsSiteSettings;
use AppServices{
    AuthService,
    LoggerService,
    MessageService
};

class IndexController extends BaseController
{
    public function __construct(
        SiteSettings $site_settings,
        AuthService $auth_service,
        LoggerService $logger_service,
        MessageService $message_service,
        private ServersRepository $serversRepository,
        private ServerFilter $serverFilter,
        private CategoriesRepository $categoriesRepository,
        private LanguagesRepository $languagesRepository
    ) {
        parent::__construct(
            $site_settings,
            $auth_service,
            $logger_service,
            $message_service
        );
    }
$this->messageService->get('MSG_LOGIN_SUCCESS');
} 

Container.php

<?php

use AppModelsSiteSettings;
use AppServices{
AuthService,
LoggerService,
MessageService
};

class Container
{
public function __construct()
{

        $this->factories[IndexController::class] = function (Container $c) {
            return new IndexController(
                $c->get(SiteSettings::class),
                $c->get(AuthService::class),
                $c->get(LoggerService::class),
                $c->get(MessageService::class),
                $c->get(ServersRepository::class),
                $c->get(ServerFilter::class),
                $c->get(CategoriesRepository::class),
                $c->get(LanguagesRepository::class)
            );
        };
}