Asking for wordpress elementor css to be fetched in react app

kindly help me solve this problem, my react app is not fetching the wordpress built in css not custom one, but made with elementor. it is only fetching the data through axios

i am making a react + wordpress website. I am fetching my data from wordpress through axios like this
import React, { useEffect, useState } from ‘react’;
import axios from ‘axios’;

const Posts = () => {
const [pages, setPages] = useState([]);

useEffect(() => {
    let url = 'http://localhost/frontva/wp-json/wp/v2/pages';
    axios.get(url).then((res) => {
        setPages(res.data);
    });
}, []);

console.log('pages', pages);

return (
    <div >
        {pages.map((page, index) => (
            <div key={page.id}>
                {index === 2 && (
                    <>
                        {/* <h1 className='text-5xl animate-bounce'>{page.title.rendered}</h1> */}
                        <p dangerouslySetInnerHTML={{ __html: page.content.rendered}}></p>
                    
                    </>
                )}
            </div>
        ))}
    </div>
);

};

export default Posts;

in this way my pages are rendering i have 3 pages and i am showing only at index 2 which is the homepage but my react app is only fetching the data it is not fetching the the elementor css like i have build the whole homepage through elementor and didnt use any custom css but when i am fetching the data it is not showing any css only the data is being fetched with no css no responsivness how do i make this issue resolve?

How to Remove slug from Custom Post type created from Custom Post Type UI WordPress plugin?

I have created a custom post type called “product” using ‘Custom Post Type UI’ WordPress plugin and have created few pages using “product CPT” with assigning a parent.

Existing url structure is:
https://example.com/product/parent_url/child_url

I need to remove “product/” slug from the URL. Once I remove the “product/” slug from URL, it works fine when there is no parent added.

function remove_cpt_slug( $post_link, $post, $leavename ) {
    if ( ! in_array( $post->post_type, array( 'product' ) ) || 'publish' != $post->post_status )
        return $post_link;
    $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
    return $post_link;
}
add_filter( 'post_type_link', 'remove_cpt_slug', 10, 3 );

When parent is there, it returns 404 (without /product slug).

Settings:
Hierarchical = True, Rewrite = True, Custom Rewrite Slug = ‘ ‘, With Front = False, Capability Type = page


Also I tried with changing ‘rewrite slug’ => ‘/’ and it makes it working fine for product CPT pages. But looks like it conflict with other permalinks and most of normal pages returns 404.

function custom_post_type_rewrite_rule($args, $post_type) {
    if ($post_type === 'product') {
        $args['rewrite'] = array(
            'slug' => '/',
            'with_front' => true,
        );
    }
    return $args;
}
add_filter('register_post_type_args', 'custom_post_type_rewrite_rule', 999, 2);

Current permalink structure: https://example.com/%postname%

How can I keep “https://example.com/parent_url/child_url” for product pages without braking other permalinks..?

Microsoft Azure Build and deploy PHP app to Azure Web App: Laravel App – Unable to create lockable file

We have a Laravel PHP application and we have deployed with the Build and deploy PHP app to Azure Web App workflow.

we have used nginx.

Sometimes we are facing issues related to permissions please find the below detailed error:

Unable to create lockable file: /home/site/wwwroot/storage/framework/cache/data/5a/0f/5a0fce553c194ec423d77dd06617ff2720c4c5c6. Please ensure you have permission to create files in this location.

Thanks

so the solution is we need to give the permission and ownership using the below command:
chmod -R 775 /home/site/wwwroot/storage
chown -R www-data:www-data /home/site/wwwroot/storage

but after execution, nothing happened, and I was facing the same problem randomly.

Can anyone help with it?

Setting Cache-Control TTL from PHP on a Google Cloud Storage object changes the wrong metadata

As recommended by Lighthouse, I am trying to set my images in Google Cloud Storage to a long TTL (the default is 1 hour, I’m trying to set one year). I can set it correctly from the command line, using something like this:

gsutil setmeta -h "Cache-Control:public,max-age=31536000" gs://mybucket/myfolder/myfname.jpg

But what I need to do is to set it using PHP, which I’m doing using Google’s recommended code looking like this:

$client = new GoogleCloudStorageStorageClient([
   'projectId' => "xxx",
   'keyFilePath' => "yyy.json",
        ]);
$bucket = $client->bucket($bucketname);
$object = $bucket->upload($data, ['name' => "$folder/$objectname"]);
$object->update(['metadata' => ['Cache-Control' => 'public,max-age=' . (3600 * 24 * 365)]]);

The trouble is that the data I provide goes not into the main Cache-Control metadata item, but into a separate “Custom metadata” item, which is not actually used by GCS when serving my file and is therefore useless.

The attached screenshot shows the effect on the metadata. Btw when done using the command line, it’s the higher Cache-Control box (in grey on the screenshot) that gets filled in, which is the one that GCS uses when serving the file.

Any ideas on how to make the PHP work?

A couple of notes:

  1. I think this may be the same issue as this one:
    https://issuetracker.google.com/issues/721233
  2. This question is
    similar to an old one here, but it’s not identical and the answers
    there didn’t work for me:
    Set Cache-Control on Google Cloud Storage bucket

Metadata shown on console after update.

Redis queued jobs are failing randomly due to IlluminateDatabaseEloquentModelNotFoundException · No query results for model

Recently after moving our queue driver to ‘redis’ we are facing more issue with some jobs/event listeners in the ‘default’ queue getting failed. At this time of failing, its also not getting inserted into the failed_jobs table. We are using a MariaDB database.

The reason for failure of these jobs are

IlluminateDatabaseEloquentModelNotFoundException
No query results for model [AppModel].

Strange thing is that, its happening randomly and when it starts to happen many jobs in the same queue worker ( default ) are also failing. I can also see that during the course of failure of jobs, there are also some jobs which are success in the same queue.

We can rule out the possibility of non existence of the model in the DB. I am sure that model exists in the database when the event happens.

After logging in Bugsnag we could see that issue happens when the payload is being unserialized and tries to resolve the model. At that time some how model is not getting back, which ends in throwing the exception.

Any help on this topic would be very much appreciated.

Microsoft Teams – Microsoft Graph API to return JSON with meetingURL – PHP

At our company, we are trying to implement this script so we can call a page and get in return a JSON file with a teams meeting url generated everytime we call it.

We allways get this error:

Fatal error: Uncaught MicrosoftGraphGeneratedModelsODataErrorsODataError in C:xampphtdocsteamsapivendormicrosoftmicrosoft-graphsrcGeneratedModelsODataErrorsODataError.php:36 Stack trace: #0 C:xampphtdocsteamsapivendormicrosoftkiota-serialization-jsonsrcJsonParseNode.php(108): MicrosoftGraphGeneratedModelsODataErrorsODataError::createFromDiscriminatorValue(Object(MicrosoftKiotaSerializationJsonJsonParseNode)) #1 C:xampphtdocsteamsapivendormicrosoftkiota-http-guzzlesrcGuzzleRequestAdapter.php(666): MicrosoftKiotaSerializationJsonJsonParseNode->getObjectValue(Array) #2 C:xampphtdocsteamsapivendormicrosoftkiota-http-guzzlesrcGuzzleRequestAdapter.php(160): MicrosoftKiotaHttpGuzzleRequestAdapter->throwFailedResponse(Object(GuzzleHttpPsr7Response), Array, Object(OpenTelemetryAPITraceNonRecordingSpan)) #3 C:xampphtdocsteamsapivendorphp-httppromisesrcFulfilledPromise.php(39): MicrosoftKiotaHttpGuzzleRequestAdapter->MicrosoftKiotaHttp{closure}(Object(GuzzleH in C:xampphtdocsteamsapivendormicrosoftmicrosoft-graphsrcGeneratedModelsODataErrorsODataError.php on line 36

  1. We created the App on Azure, as a “Entreprise App” (Tested just App Registrations also, didn’t work also) — Created with Admin account;
  2. Added this permissions: Calendars.ReadWrite, Mail.ReadWrite, OnlineMeetings.ReadWrite.All, User.Read, User.ReadWrite.All, VirtualEvent.Read.All (Granted Admin Consent);
  3. Added Single-page applications redirect url: http://localhost/teamspai/index.php
  4. Tested as Multitenant and Singletenant – not working both options;
  5. Added Access using Powershell: New-CsApplicationAccessPolicy.. to the AppId and then Grant-CsApplicationAccessPolicy .. -Global;

We just need to return a JSON with the URL for the meeting.

Our code:

<?php 
include_once('vendor/autoload.php');
use MicrosoftGraphGraphServiceClient;
use MicrosoftKiotaAbstractionsApiException;
use MicrosoftKiotaAuthenticationOauthClientCredentialContext;
use MicrosoftGraphGeneratedModelsOnlineMeeting;


$scopes = ['https://graph.microsoft.com/.default'];
$tenantId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$clientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 
$tokenRequestContext = new ClientCredentialContext(
    $tenantId,
    $clientId,
    $clientSecret
);

$graphServiceClient = new GraphServiceClient($tokenRequestContext);
$requestBody = new OnlineMeeting(); 
$result = $graphServiceClient->me()->onlineMeetings()->post($requestBody)->wait();
echo json_encode($result);
?>

Hope someone can help us!

I tried:

  • Add Permissions
  • Single Tenant
  • Multi Tenant
  • Access Policy
  • Downgrade MSGraph
  • Created new App

Why do my bootstrap tooltips get stuck when I reload html content with ajax?

On my site I use Bootstrap v5.3
I have a main page (index.php) and a PHP file which I use to request information from the database (load.php).

I use a jquery function to load content via load.php to my main page every 30 seconds and display it there.

I also have a navbar with a reload button on my main page. This reload button has a tooltip.

When I click the reload button, load.php is called again.

The content that is reloaded via load.php also contains tooltips.

When I click the reload button, the content is loaded and displayed correctly (the tooltips also work). But the tooltip of the reload button gets stuck.

What could be the reason for this?

I tried to add the Enable Tooltips JavaScript from the Bootstrap documentation to load.php as well.

const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))

Laravel Nova sortable fields

In Laravel Nova, I am able to sort fields of a resource from descending and ascending order, however, after that I can’t click on the field’s name in the table heading to sort it back from descending to ascending. Is there a way to resolve this?

I’d also like to ask if there is a way to add a clear state for sorting, if ascending and descending are representing by arrows in the table heading, in the middle, I want to add a “-” which will help the user clear the order which will default the ordering to desc by id, is this possible?

It seems like this only works for BelongsTo() field in my case where the user can switch back and forward, but for other fields, the user can only switch from asc to desc, and then they’re stuck and can’t click to switch back from desc to asc. I’ve searched for solutions and it seems that people are suggesting to override the indexQuery(), however, that did not work.

possible for a php snippet to work on desktop and then break mobile?

I needed to report the sku code in an e-commerce wishlist. I have YITH Wishlist premium installed on the site and use bricks builder.
I used the following code:

<?php 

function add_sku_after_product_name( $item, $wishlist ) {
    $product = $item->get_product();
    $SKU = $product->get_sku();
    echo wp_kses_post('<p> [SKU: '.$SKU.']</p>');
}

// Mi aggancio all'action hook 'yith_wcwl_table_after_product_name' 
add_action( 'yith_wcwl_table_after_product_name', 'add_sku_after_product_name', 10, 2 );

On desktop it works fine, but on mobile it gives me a critical error. What could it be?

(when I disable the snippet the wishlist goes back to working perfectly)

I tried changing where the snippet was being loaded, but to no avail.

I need help identifying why my bootstrap/php site code is not recognizing custom js and jquery files but the bootstrap js cdns work fine

I am working on a bootstrap, jquery/js, php, mysql site, and for some reason my custom JS files are not working properly. Right now I’m trying to add a class active with jquery script to my menu, the bootstrap cdns are working well both css and js, but my own js files aren’t. The add class does not work, nor does other things I’ve tried with custom js files. It seems as if they were just not linked at all. I’m relatively new to php and building a site in this manner, in which certain php files are componentes, while other are pages. I’m not sure if I am just making beginners mistakes. This is my footer.php file:

 <footer class="site-footer text-center fixed-bottom">
            <p>&copy; 2024 PHP Site | All rights reserved.</p>
        </footer>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.js" integrity="sha512-+k1pnlgt4F1H8L7t3z95o3/KO+o78INEcXTbnoJQ/F2VqDVhWoaiVml/OEHv9HsVgxUaVW+IbiZPUJQfF/YxZw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
    <script src="js/class-active.js"></script>
</body>

</html>

This is what my header.php file looks like:

<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $pageTitle; ?> | <?php echo $siteTitle; ?></title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="css/index.css">
</head>

<body>
    <header class="site-header">
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
            <div class="container-fluid">
                <a class="navbar-brand" aria-current="page" href="index.php"><img class="house-img" src="img/house.png"></a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav mx-auto mb-2 mb-lg-0 d-flex justify-content-between">
                        <li class="nav-item" id="navigation-about">
                            <a class="nav-link" href="about.php">About Us</a>
                        </li>
                        <li class="nav-item" id="navigation-menu">
                            <a class="nav-link" href="#">Menu Item</a>
                        </li>
                        <li class="nav-item" id="navigation-faq">
                            <a class="nav-link" href="faq.php">FAQ</a>
                        </li>
                        <?php
                        if (isset($_SESSION['user_id'])) {
                            // If logged in, show the Logout option
                            echo '<li class="nav-item" id="navigation-logout">
                                    <a class="nav-link" href="logout.php">Log Out</a>
                                  </li>';
                        } else {
                            // If not logged in, show Login and Register options
                            echo '<li class="nav-item dropdown">
                                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                        Login
                                    </a>
                                    <ul class="dropdown-menu">
                                        <li><a class="dropdown-item" id="nav-login" href="login.php">Log In</a></li>
                                        <li><a class="dropdown-item" id="nav-register" href="sign-up.php">Register</a></li>
                                    </ul>
                                  </li>';
                        }
                        ?>

                    </ul>
                    <form class="d-flex" role="search">
                        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
                        <button class="btn btn-outline-success" type="submit">Search</button>
                    </form>
                </div>
            </div>
        </nav>
    </header>

And what a single page looks like, about.php:

<?php
include 'config.php';
$pageTitle = "About Us";
include 'header.php';
?>



    <h1 class="text-center mt-5"><?php echo $pageTitle; ?></h1>


    <?php include 'footer.php'; ?>

Finally the jQuery for the add class, that is not working…

// Use jQuery's document ready function to ensure the DOM is fully loaded
$(document).ready(function() {
    // Attach a click event handler to the <a> tags within .nav-item
    $('.nav-item a').on('click', function() {
        // Remove 'active' class from all <a> tags within .nav-item
        $('.nav-item a').removeClass('active');
        
        // Add 'active' class to the clicked <a> tag
        $(this).addClass('active');
    });
});

I linked all the scripts in the footer.php. What am I doing wrong?
Thanks for any help you provide. The site is live at php.jacobowitzdevs.com

SQL Order by highest count first [closed]

I am using the following query to fetch data from my sql tables

SELECT tips.* ,stocks.*
FROM tips 
LEFT JOIN stocks ON stocks.nse = tips.sym 
WHERE tips.dat = '$day' 
GROUP BY tips.sym 
ORDER BY stocks.indu  DESC;

I need to order the result in the order of largest occurrence first ie if there is 10 abc , 12 xyz ,8 qwe as indu , i need to display 12 xyz first 10 abc as next . then 8 qwe s.

Any help is really appreciated

Internal server error happened after setting headers for response [duplicate]

Dear all

I set headers of responses and I got an internal server error , when some headers are disable there is no error

I defined a function to set response header in php on XAMPP as below

public static function setHeaders($status_code)
    {
        header("Access-Control-Allow-Origin : *");
        header("Content-Type:application/json; charset:UTF-8");
        header("Access-Control-Allow-Methods :PUT, GET, POST,DELETE");
        header("Access-Control-Max-Age :3600");
        header ("Access-Control-Allow-Headers : Content-Type, X-requested-with,Authorization");
        header("HTTP/1.1 $status_code) " . self::statusTexts[$status_code]);
    }

when I want to get responses an error occurs. like this

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/8.1.6 Server at localhost Port 80

but when these following header functions are disable (they are commented below);

       // header("Access-Control-Allow-Origin : *");
        header("Content-Type:application/json; charset:UTF-8");
       // header("Access-Control-Allow-Methods :PUT, GET, POST,DELETE");
       // header("Access-Control-Max-Age :3600");
       // header ("Access-Control-Allow-Headers : Content-Type, x-requested
        header("HTTP/1.1 $status_code) " . self::statusTexts[$status_code]);

,there is not any error and response is OK.

why ?Is there any suggestion?

I will be very grateful for your help, friends.

Carbon add method

Certainly something trivial, but I’m stuck!

I have a start date initialized like this:

$startDate = Carbon::createFromFormat('Y-m-d H:i', '2024-02-01 08:00');

I add days to this date to get an end date:

$qtyDays = 25;
$endDate = $startDate->addDays($qtyDays);

What I don’t understand is that the end date is calculated correctly. But the start date contains the end date.

How not to touch the start date ? Even though I read the Carbon doc, I don’t understand what’s going on.

Lost leading newline characters when getting value from a textarea [duplicate]

I want to pass a string variable from PHP to javascript, I tried the third method in this answer, but I when I got the value (textarea.value) from the textarea, I lost the leading newline characters.

I tried to add a character like “=” at the beginning and the end of my string, it seems that I solved this problem. Are there any ways better to deal with this problem? Are there any other problems which can cause I getting different value that I may encounter?

PHP code:

<textarea id="data"><?php echo htmlspecialchars("nna"); ?></textarea>

javascript code:

let a=document.getElementById("data").value;
// expect: "nna"
// actual: "na"