How to extend WordPress REST API to include custom meta fields for a custom post type?

I’m working on a custom WordPress project where I’ve registered a custom post type called parcel. It has several custom meta fields like pickup_pincode, drop_pincode, and delivery_type.

I want to expose these custom fields via the WordPress REST API when fetching the parcel posts (e.g., /wp-json/wp/v2/parcel).

I’ve registered the custom post type using register_post_type, and the meta fields using register_post_meta.

Here’s what I’ve tried in functions.php:

function register_parcel_meta_fields() {
    register_post_meta('parcel', 'pickup_pincode', [
        'show_in_rest' => true,
        'type'         => 'string',
        'single'       => true,
    ]);
}
add_action('init', 'register_parcel_meta_fields');

I registered the meta fields using register_post_meta() with 'show_in_rest' => true, expecting them to appear automatically in the REST API response for my custom post type parcel. However, when I fetch the data via /wp-json/wp/v2/parcel, the custom fields like pickup_pincode are missing. I expected them to be visible in the JSON response but they’re not showing up. I’m unsure if I need to do more or hook into a different filter.

Retrieve values using array_udiff in PHP

I am using array_udiff function on Multi-dimensional Arrays:

$old_list = Array ( [0] => Array ( [name] => John [src] => S ) [1] => Array ( [name] => Mary [src] => S ) )

$new_list = Array ( [0] => Array ( [name] =>John [src] => S ) [1] => Array ( [name] => Mary [src] => S ) [2] => Array ( [name] => Peter [src] => S ))

$differences = array_udiff($new_list, $old_list, function($a, $b) {

return strcmp($a["name"], $b["name"]);

});

print_r($differences);

The result is

Array ( [2] => Array ( [name] => Peter [src] => S ) )

How can I get the values Peter & S (name and src) from the variable $differences?

How to visually hide or mask /wp-admin URL in WordPress (for editors users)?

I’m working on a WordPress site and I want to hide the /wp-admin URL from users, especially when they try to access something like:
https://example.com/wp-admin/edit.php or https://example.com/wp-admin/edit.php?post_type=page

My Goal:
When someone types or clicks a link to /wp-admin/…, they should be redirected or see a custom-looking URL, like:
https://example.com/custom-admin/edit.php or https://example.com/custom-admin/edit.php?post_type=page

I know that WordPress core uses /wp-admin as the fixed admin area, Is it possible or not.

Bonus if it can be done only for specific roles like Editors.

Question:
Is there any safe and WordPress-compatible method to visually change or redirect /wp-admin URLs?

Can I set up a role-specific dashboard without completely removing access to core admin?

Finally, In WordPress, I want the /wp-admin URL to function normally, but in the browser address bar, I want to show a different custom path (like /custom-admin) instead of showing /wp-admin.

Thanks in advance!

Updating bitnami stack, WordPress, deprecated errors [duplicate]

Thanks in advance, at one time I was on top of all things PHP related. I’m attempting to update a website on the bitnami stack. The theme is out of support and I’m tasked with fixing everything.

I’m getting many deprecated errors as show below. Can someone point me in the right direction? Google isn’t much help.

   function init() {
        $this->dir = dirname( __FILE__ );


[06-Jul-2025 17:48:42 UTC] PHP Deprecated:  Creation of dynamic property Carell_Custom_Fields::$dir is deprecated in /bitnami/wordpress/wp-content/plugins/carell-custom-fields/ccf.php on line 39
[06-Jul-2025 17:48:42 UTC] PHP Deprecated:  Creation of dynamic property Carell_Custom_Fields::$url is deprecated in /bitnami/wordpress/wp-content/plugins/carell-custom-fields/ccf.php on line 40
[06-Jul-2025 17:48:42 UTC] PHP Deprecated:  Creation of dynamic property Carell_Custom_Fields::$api is deprecated in /bitnami/wordpress/wp-content/plugins/carell-custom-fields/ccf.php on line 60
[06-Jul-2025 17:48:42 UTC] PHP Deprecated:  Creation of dynamic property Carell_Custom_Fields::$form is deprecated in /bitnami/wordpress/wp-content/plugins/carell-custom-fields/ccf.php on line 61
[06-Jul-2025 17:48:42 UTC] PHP Deprecated:  Creation of dynamic property Carell_Custom_Fields::$field_group is deprecated in /bitnami/wordpress/wp-content/plugins/carell-custom-fields/ccf.php on line 62
[06-Jul-2025 17:48:42 UTC] PHP Deprecated:  Creation of dynamic property Carell_Custom_Fields::$fields is deprecated in /bitnami/wordpress/wp-content/plugins/carell-custom-fields/ccf.php on line 63

retrieve data using where condition and sort in descending order

I am trying to retrieve category (id, category_name, status) table data using where condition and sort in descending order for id. I am writing query like::

public function category()
    {
        $category = Category::where('status', 'true');
        return view('admin.services.category', compact('category'));
    }

this is showing error
Attempt to read property "category_name" on array. How to fetch data using where condition as status == true and order id in descending order?

Telegram Bot Not Responding to /start Command

I’m developing a Telegram bot using PHP, and it responds to Telegram updates, but when I send the /start command, it does not react. I’m trying to understand why the bot is not responding to /start.

Key points:
Webhook is enabled and correctly set up with the bot URL (I verified that the URL is correct).
In bot.php, I’m using json_decode(file_get_contents(“php://input”), true) to read the updates from Telegram.
In start.php, I’m handling the /start command, but the bot doesn’t send any message.
I’m using PHP to connect to a MySQL database and store user data in the users table.
I checked the log.txt file, and it correctly receives the updates, but the /start command is not being handled.

Problems I am facing:
The bot does not respond to the /start command.
I’m using send_reply(“sendMessage”, …) to send messages, but nothing happens when /start is sent.
I’m not seeing any errors in the logs when I send /start to the bot.

Anybody would help me?

Index.php can’t find the route/path of the desired files [closed]

Explanation:

I’m making a website (new to this) and wanted to make a system to handle all requests to make maintainece easier.

Idea

When a file needs to go to another path, it would go through index.php and index will reveal the path and direct it there. (A router)
And when the webserver files need to access the database(which is private) they will ask index.php to ask hub.php and hub.php will give the desired information from database.

Issues

Index.php isn’t able to find the path or connect them even though i gave the correct code.

My Files:

Folder/
    ├── database/
    │   ├── accounts/
    │   │   ├── orders/
    │   │   ├── reviews/
    │   │   └── users.json
    │   ├── designs/
    │   └── system/
    │       └── logo.png
    ├── root/
    │   ├── 0/
    │   │   ├── admin.php
    │   ├── 1/
    │   │   └── main.php
    │   ├── 2/
    │   │   ├── catalog.php
    │   │   ├── checkout_system/
    │   │   ├── design.php
    │   │   ├── functions.php
    │   │   └── list-catalog/
    │   ├── 3/
    │   │   └── contact.php
    │   ├── 4/
    │   │   ├── reviews.php
    │   │   └── submit_review.php
    │   ├── 5/
    │   │   ├── bulk-purchase/
    │   │   └── list.php
    │   ├── 6/
    │   │   └── login.php
    │   ├── 7/
    │   │   ├── footer.php
    │   │   └── header.php
    │   └── index.php
    └── hub.php

My index.php code:

<?php
error_reporting(0);
ini_set('display_errors', 0);
define('LOG_FILE', __DIR__.'/security.log');
register_shutdown_function(function() {
    if ($error = error_get_last()) {
        error_log(date('[Y-m-d H:i:s] ').print_r($error,1)."n", 3, LOG_FILE);
    }
});

session_start([
    'cookie_httponly' => 1,
    'cookie_samesite' => 'Strict',
    'sid_length' => 128,
    'sid_bits_per_character' => 6
]);

// Route mapping
$routes = [
    '/' => '/1/main.php',
    '/main' => '/1/main.php',
    '/catalog' => '/2/catalog.php',
    '/design' => '/2/design.php',
    '/contact' => '/3/contact.php',
    '/reviews' => '/4/reviews.php',
    '/submit-review' => '/4/submit_review.php',
    '/login' => '/6/login.php',
    '/logout' => '/6/logout.php',
    '/admin' => '/0/admin.php'
];

// Get requested path
$requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);

// Find matching route
foreach ($routes as $route => $file) {
    if ($requestPath === $route) {
        $absolutePath = __DIR__.$file;
        
        // 100% file existence guarantee
        if (!file_exists($absolutePath)) {
            error_log("Missing route file: $absolutePath", 3, LOG_FILE);
            http_response_code(500);
            exit('System configuration error. Admin notified.');
        }
        
        // Generate CSRF token (once per session)
        if (empty($_SESSION['csrf_token'])) {
            $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
        }
        
        // Authentication check
        $protectedRoutes = ['/admin', '/submit-review'];
        if (in_array($route, $protectedRoutes) && empty($_SESSION['user'])) {
            header('Location: /login');
            exit;
        }
        
        include $absolutePath;
        exit;
    }
}

// 404 Handling
http_response_code(404);
$contactPath = __DIR__.'/root/3/contact.php';
if (file_exists($contactPath)) {
    include $contactPath;
} else {
    echo '<h1>404 - Page Not Found</h1>';
}

My hub.php code:

<?php
// Armored session
session_start([
    'cookie_httponly' => 1,
    'cookie_samesite' => 'Strict'
]);

// JSON responses
header('Content-Type: application/json');

// Request validation fortress
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    exit(json_encode(['error' => 'POST requests only']));
}

$refererHost = parse_url($_SERVER['HTTP_REFERER'] ?? '', PHP_URL_HOST);
$serverHost = $_SERVER['HTTP_HOST'] ?? '';
if ($refererHost !== $serverHost) {
    http_response_code(403);
    exit(json_encode(['error' => 'Cross-origin requests forbidden']));
}

// CSRF vault
$token = $_POST['csrf_token'] ?? '';
if (!isset($_SESSION['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $token)) {
    http_response_code(403);
    exit(json_encode(['error' => 'Security token mismatch']));
}

function verifyAuth() {
    if (empty($_SESSION['user'])) {
        http_response_code(401);
        exit(json_encode(['error' => 'Authentication required']));
    }
}

try {
    $action = $_POST['action'] ?? '';
    
    switch ($action) {
        case 'login':
            $username = $_POST['username'] ?? '';
            $password = $_POST['password'] ?? '';
            
            // Load users
            $users = json_decode(file_get_contents(__DIR__.'/database/accounts/users.json'), true) ?: [];
            foreach ($users as $id => $user) {
                if ($user['username'] === $username && password_verify($password, $user['password'])) {
                    $_SESSION['user'] = [
                        'id' => $id,
                        'name' => $user['name'],
                        'level' => $user['level'] ?? 1
                    ];
                    session_regenerate_id(true);
                    exit(json_encode(['success' => true]));
                }
            }
            exit(json_encode(['success' => false, 'error' => 'Invalid credentials']));
            
        case 'get_designs':
            $designs = [];
            $path = __DIR__.'/database/designs/';
            
            // Glob with absolute security
            foreach (glob($path.'*.{jpg,png,webp}', GLOB_BRACE) as $file) {
                $designs[] = [
                    'name' => basename($file),
                    'url' => '/database/designs/'.rawurlencode(basename($file))
                ];
            }
            exit(json_encode(['designs' => $designs]));
            
        case 'submit_review':
            verifyAuth();
            $data = [
                'id' => 'rev_'.bin2hex(random_bytes(8)),
                'user_id' => $_SESSION['user']['id'],
                'name' => $_POST['name'] ?? '',
                'rating' => max(1, min(5, (int)($_POST['rating'] ?? 5))),
                'comment' => substr($_POST['comment'] ?? '', 0, 500),
                'date' => date('Y-m-d H:i:s')
            ];
            
            // Write with atomic safety
            $tmpFile = tempnam(sys_get_temp_dir(), 'rev');
            file_put_contents($tmpFile, json_encode($data));
            rename($tmpFile, __DIR__."/database/accounts/reviews/pending/{$data['id']}.json");
            
            exit(json_encode(['success' => true]));
            
        default:
            http_response_code(400);
            exit(json_encode(['error' => 'Invalid action']));
    }
} catch (Throwable $e) {
    http_response_code(500);
    exit(json_encode(['error' => 'System processing error']));
}

Attempted Troubleshooting:

  • I made sure they are the exact path
  • i asked ai if there is error in the code and it said no

How to write a SQL query to produce a result which has more than 2 levels of depth

tell me, is it possible to get all the data from 4 tables with one SQL query?

Here is the DB diagram with connections:
enter image description here

Thus, a product can have 1 category, many configurations in which many options.

I would like to get something like this result after the request:

{
  "product_1": {
    "name": "product1",
    "category": "cat1",
    "equipments": {
      "0": {
        "name": "equip1",
        "options": {
          "options1": "options 1",
          "options2": "options 2",
          "options3": "options 3"
        }
      },
      "1": {
        "name": "equip2",
        "options": {
          "options1": "options 3",
          "options2": "options 2"
        }
      }
    }
  },
  "product_2": {
    "name": "product2",
    "category": "cat2",
    "equipments": {
      "0": {
        "name": "equip1",
        "options": {
          "options1": "options 1",
          "options2": "options 3"
        }
      },
      "1": {
        "name": "equip2",
        "options": {
          "options1": "options 3"
        }
      }
    }
  }
}

Is it possible to get this with one query? I’m already tired of these Join and JSON_ARRAYAGG functions, it doesn’t work, I tried to combine them, nothing… Maybe I’m wasting my time and should I use several queries? Or is it possible to get all the data for all the connections in one query? I’m writing in PHP using PDO. Please help me with my problem.

UPD:

Here is an example of what I tried, this is one of the options. Here I was able to get a value only from two tables “Equipments” and “Options”, then I tried to combine another JOIN and it doesn’t work at all.

$stmt = $link->prepare("select equipment.*, JSON_ARRAYAGG(JSON_OBJECT(
            'name', options.name,
            'descript', options.descript
            )) AS Options FROM equipment
            LEFT JOIN options ON equipment.id=options.equipment_id GROUP BY equipment.id
          ");

Why does bybit api return an empty list after requesting trade history?

I am trying to get my trade history from the Bybit api V5, but it keeps returning an empty list although getting my wallet balance works.

I wrote this code below and although the “getBybitWalletBalance” function works perfectly, the “getBybitTradeHistory” function keeps returning an empty list. My last trade on BTCUSDT perpetuals was a month ago. I also tried the other categories, but they all give the same output.

bybit.php

<?php

    $apiKey = '...';
    $apiSecret = '...';
    $window = "5000";

    // Global
    function bybitSignature($method, $path, $query, $body) {
        global $apiKey, $apiSecret, $window;
        $timestamp = round(microtime(true) * 1000);
        if($method === "GET") {
            return hash_hmac("sha256", $timestamp . $apiKey . $window . $query, $apiSecret);
        } else {
            return hash_hmac("sha256", $timestamp . $apiKey . $window . $body, $apiSecret);
        }
    }

    function bybitCurl($url, $signature) {
        global $apiKey, $window;
        $timestamp = round(microtime(true) * 1000);
        $ch = curl_init();
        
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Accept: application/json",
            "X-BAPI-API-KEY: " . $apiKey,
            "X-BAPI-TIMESTAMP: " . $timestamp,
            "X-BAPI-SIGN: " . $signature,
            "X-BAPI-RECV-WINDOW: " . $window
        ));
        
        if(curl_errno($ch)) {
            return curl_error($ch);
        } else {
            return curl_exec($ch);
        }
        
        curl_close($ch);
    }

    // Trade
    function getBybitTradeHistory($category) {
        return bybitCurl("https://api.bybit.com/v5/execution/list?category=" . $category, bybitSignature("GET", "/v5/execution/list", "category=" . $category, ""));
    }

    // Account
    function getBybitWalletBalance($accountType) {
        return bybitCurl("https://api.bybit.com/v5/account/wallet-balance?accountType=" . $accountType, bybitSignature("GET", "/v5/account/wallet-balance", "accountType=" . $accountType, ""));
    }

    var_dump(json_decode(getBybitTradeHistory("linear"), true));

?>

output
array(5) { ["retCode"]=> int(0) ["retMsg"]=> string(2) "OK" ["result"]=> array(3) { ["nextPageCursor"]=> string(0) "" ["category"]=> string(6) "linear" ["list"]=> array(0) { } } ["retExtInfo"]=> array(0) { } ["time"]=> int(1751725711326) }

Do I still need an Eloquent decimal cast for DECIMAL(10,6) columns in Laravel 12 / PHP 8.2?

I’m building a Laravel 12 e‑commerce site (PHP 8.2).
Product prices are stored in MySQL as DECIMAL(10,6):

base_price DECIMAL(10,6),
profit     DECIMAL(10,6)

Many articles recommend adding a cast in the model to avoid floating‑point errors:

AppModelsProduct
protected function casts(): array
{
    return [
        'base_price' => 'decimal:6',
        'profit'     => 'decimal:6',
    ];
}

What I tried

  • With no cast and with the decimal:6 cast I get exactly the same results in my calculations.
  • Simple test:
$a = "1097.500000";
$b = "835.700000";
$c = $a - $b;
dd($c);   // 261.8  (as expected)

No visible precision problems.

  • I also have more complex code that deals with profit, base_price, offer_price, and user discount calculations — and so far, I haven’t encountered any floating-point issues or inaccuracies in the results.
$priceSource = (is_numeric($product->offer_price) && $product->offer_price != 0)
    ? $product->offer_price
    : $product->base_price;

$grossPrice = $priceSource + $product->profit; 
$price = $grossPrice - ($grossPrice * $userVipDiscount / 100);

My confusion

  • If the column is already DECIMAL(10,6), does Eloquent still need the cast?

  • Have PHP 8.2 and Laravel 12 improved this enough that the extra cast is redundant?

  • In what practical situations would the decimal:6 cast still make a difference?
    I’d like to understand whether the cast is just defensive habit or still necessary for real‑world money calculations.

Magento 2.4.7-p6: zymion/module-seo-friendly-images 1.5.5 – Class ProductSelectBuilder does not exist on compile

After updating the module zymion/module-seo-friendly-images from version 1.5.4 to 1.5.5 on Magento 2.4.7-p6, I started getting the following error during dependency injection compilation (php bin/magento setup:di:compile):
Impossible to process constructor argument Parameter #16 [ ?MagentoSitemapModelResourceModelCatalogProductSelectBuilder $productSelectBuilder = NULL ] of ZymionSeoFriendlyImagesModelResourceModelCatalogProduct class

Class “MagentoSitemapModelResourceModelCatalogProductSelectBuilder” does not exist

pgsql
Kopiuj
Edytuj

  • This issue did not occur with version 1.5.4 of the module.
  • I have checked the Magento 2.4.7-p6 core code and there is no class called ProductSelectBuilder in MagentoSitemapModelResourceModelCatalog.
  • It seems the new version of the module expects this class to exist, but it doesn’t in my Magento version.

Questions:

  • Has anyone else encountered this issue?
  • Is this a bug in the module or a compatibility problem with my Magento version?
  • Is there a recommended workaround or patch for this problem?

Additional info:

  • Magento version: 2.4.7-p6
  • Module: zymion/module-seo-friendly-images
  • Problem started after upgrading from 1.5.4 to 1.5.5
  • Reverting to 1.5.4 solves the problem, but I would prefer to use the latest version if possible.

Any help or suggestions would be greatly appreciated!

Get Mollie payment API status woocommerce [closed]

I am using Woocommerce with Mollie payments.
If the payment is cancelled or failed Mollie redirect the user to the payment page on my website. For handling errors I want to know which status Mollie returns to my website so I can do something like

if(paymentStatus == 'faild'){ //do something } 

Somebody who knows to do this?

How to use sendChecklist for telegram bot?

I send

Request::send('sendChecklist', [
'chat_id' => 'my int id',
'checklist' => json_encode([
    'title' => 'qwerty',
    'tasks' => [
        [
            'id' => 1,
            'text' => 'a',
        ],
        [
            'id' => 2,
            'text' => 'b',
        ]
    ],
]);

via https://github.com/php-telegram-bot/core longman/telegram-bot
comment line in Request::send() before (because this is new feature)

//        self::ensureValidAction($action);

And get response:

LongmanTelegramBotEntitiesServerResponse {#56
  +bot_username: "my bot username"
  +raw_data: array:3 [
    "ok" => false
    "error_code" => 400
    "description" => "Bad Request: PREMIUM_ACCOUNT_REQUIRED"
  ]

Why?
I am premium user.