Searching for phpmailer alternatives

I have created an online assessment tools for hiring candidates.
The website is built on php.
I want to explore EMAIL INTEGRATIONS for our website, for sending exam links to the candidates except for phpmailer since I need to send more than 150 mails/per hour
(150 mails/hour is the threshold of phpmailer)
I am searching for some good alternatives.
It’s not an issue if I have to make a payment for them.

Fonts generated in HTML & PDF are different in wkhtmltopdf

Seems this question has been posted a few times, but posting here again because I couldn’t find anything useful for my issue 🙁

I am using wkhtmltopdf to generate pdf files from HTML views. I have added custom fonts in the site. The rendered HTML view looks great. But the CSS styles aren’t applied in the PDF properly.

My CSS

@font-face {
    font-family: 'MyFont';
    src: url('fonts/MyFont-Light.otf') format('opentype'),
    url('fonts/MyFont-Light.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
}

@font-face {
    font-family: 'MyFont';
    src: url('fonts/MyFont-Regular.otf') format('opentype'),
    url('fonts/MyFont-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

body {
    font-family: 'MyFont', Helvetica, Arial, sans-serif;
    font-weight: 300;
}

h1 {
    font-weight: 400;
}

HTML View
enter image description here

PDF View
enter image description here

Can someone please help me resolve this issue? Thanks in advance.

How to modify wp_query in wordpress

i am working with wordpress,And i want to pass one parameter name “post_title” in wp_query,So i can change query and can get correct data,But my query is not changed(not displaying as i expected),I tried with following code

$args = array(
    'post_type' => 'user',
    'posts_per_page' => -1,
     'post_title' => $_GET['post_title'],
    'post_status' => [ 'publish']
);
$query = new WP_Query($args);

when i print my $query->request then i getting following query

[request] = "SELECT   MZAGsQVeposts.* FROM MZAGsQVeposts  WHERE 1=1  AND MZAGsQVeposts.post_type = 'user' AND ((MZAGsQVeposts.post_status = 'publish')) ORDER BY MZAGsQVeposts.post_date DESC";

But expected query is

"SELECT   MZAGsQVeposts.* FROM MZAGsQVeposts  WHERE 1=1  AND MZAGsQVeposts.post_type = 'user' AND ((MZAGsQVeposts.post_status = 'publish')) AND MZAGsQVeposts.post_title='Lisa I' ORDER BY MZAGsQVeposts.post_date DESC";

Where i am wrong ? Thanks in advance.

Strange behaviour with file_get_contents/file_put_contents

Wanted to write a quick one liner to count page loads, not worrying about users, sessions or refreshes, and tried this:

file_put_contents(“page.test”, ((file_get_contents(“page.test”))+1));

echo “Test:”.file_get_contents(“page.test”);

On every load or refresh, the page.test file increases by 3, not 1 which I expected. If I write each step as a separate line of code and use a counter variable as an intermediate step, then it all works as expected, but the one liner goes up 3 at a time.

Appreciate some wisdom from the experts! Thank you. Ray

PHPMailer, can’t send svg img with and without attachement

My Mail is defined like that

        $this->mail = new PHPMailer();
        $this->mail->IsSMTP();
        $this->mail->CharSet    = 'UTF-8';
        $this->mail->Host       = '';
        $this->mail->SMTPAuth   = true;
        $this->mail->Port       = 465;
        $this->mail->SMTPSecure = 'ssl';
        $this->mail->Username   = '';
        $this->mail->Password   = '';
        $this->mail->From       = '';
        $this->mail->FromName   = '';
        $this->mail->WordWrap   = 78;
        switch( is_array( $address ) )
        {
            case false: $this->mail->addAddress( $address ); break;
            case true : foreach( $address as $addr ) { $this->mail->addAddress( $addr ); } break;
        }
        $this->mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT']."/image/icon/logo-f39200.svg", "logo-f39200", 'logo-f39200.svg' );
        $this->mail->IsHTML(true);
        $this->mail->Body    = $msg;
        $this->mail->Subject = $subject;

And I want to put an svg image inside it but It don’t work, here’s my body :

$message  = '
    <html>
        <head>
            <title>
                Lorem lorem
            </title>
        </head>
        <body>
            <div style="height:300px;border:1px solid red;display:flex; flex-direction:column; justify-content:flex-start; align-items:center"> //The style tag was here for test
                <h2>Lorem</h2>
                <div>
                    <p>
                       Lorem lorem lorem lorem
                    </p>
                </div>
                <img src="cid:logo-f39200" alt="logo"/>
            </div>    
        </body>
    </html>';

I try with :

  • src=”cid:logo” + addEmbeddedImage //I got the attachment but no image in the body of the mail
  • src=”absolute path” + addEmbeddedImage //I got the attachment but no image
  • src=”aboslute path” //I got nothing
  • addEmbeddedImage //I got the attachement only

Don’t know what I miss, thanks in advance

Persisting Log entity using another EntityManager

I have second connection and entity manager configured for logging only. It works fine in my logging service, but there is a problem with:

$user = $this->security->getUser();
$log->setUser($user);

When trying this I’ve got “A new entity was found through the relationship” exception. And it’s ok, because second entity manager doesn’t know about User and is trying to cascade persist object (which is not configured). In previous version of Symfony (3.x I guess) I used this workaround (from my previous version of code):

$user = $token->getUser();
$userManaged = $em->getRepository('AppBundle:User')->find($user->getId());
$log->setUser($userManaged);

It worked, but now (Symfony 6.0.7) it no longer works. I’m trying now:

    $user = $this->security->getUser();
    if($user){
        $userManaged = $em->getRepository('App:User')->find($user->getId());
        $log->setUser($userManaged);            
    }

And still having “A new entity was found through the relationship”.

How should I do this in proper way? Here is my doctrine.yml ORM section:

orm:
    auto_generate_proxy_classes: true
    default_entity_manager: default
    entity_managers:
        default:
            connection: default                
            naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            auto_mapping: true
            mappings:
                App: ~
                    is_bundle: false
                    dir: '%kernel.project_dir%/src/Entity'
                    prefix: 'AppEntity'
                    alias: App
        log:
            connection: log
            naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            mappings:
                App:
                    is_bundle: false
                    dir: '%kernel.project_dir%/src/Entity'
                    prefix: 'AppEntity'
                    alias: App

Laravel – Grabbing multiple CarbonPeriod and then continue a while loop with it

So I have this code:

$companyHolidays = Holiday::all();
$newholiday = [];
foreach($companyHolidays as $holiday){
    $newholiday[] = [
        'id' => $holiday->id,
        'title' => $holiday->title,
        'start' => $holiday->start,
        'end' => $holiday->end,
        'parsed_company_holidays' => CarbonPeriod::create($holiday->start, $holiday->end)
    ];
}


$customHoliday = [];
foreach ($newholiday as $holiday) {
   $customHoliday[] = $holiday['parsed_company_holidays']->toArray();
}


   while ($i < $eventRepeats) {

        // add one week
        $eventStart->addDays(7);


        if (in_array($eventStart->translatedFormat('Y-m-d'), $holidaysArray)) {
            continue;
        }

        // todo: this here is the issue
        if (in_array($eventStart->translatedFormat('Y-m-d'), $newholiday)) {
            continue;
        }


        echo '<div class="text-primary font-normal mt-6 mb-2">'.$count++.'. Termin</div>';
        echo '<div class="bg-dark-gray rounded-lg border-l-4">';
        echo '<div class="p-3">';
        echo $eventStart->translatedFormat('l, d. F Y, H:i');
        echo ' - ';
        echo $eventEnd->translatedFormat('H:i');
        echo '</div></div>';

        // increase iteration
        $i++;

    }

if I do dd($customHoliday); I get the following:

enter image description here

Inside it are these:

enter image description here

So for comparing the dates inside the if (in_array($eventStart->translatedFormat('Y-m-d'), $newholiday)) {

it would probably look like the $holidaysArray:

enter image description here

But I cannot figur out how to merge all the arrays and then make the dates inside the $customHoliday comparable like the $holidaysArray (based on YASUMI API)

because I already implemented the holiday API and it continue the loop, if in the array:

if (in_array($eventStart->translatedFormat('Y-m-d'), $holidaysArray)) {
    continue;
}

but with the current way it does not work with this:

if (in_array($eventStart->translatedFormat('Y-m-d'), $newholiday)) {
    continue;
}

Finding differences in json in Laravel

I am beginner in Laravel.
I make my application in Laravel 8,

I have this value in DB:

$json = {
    "old": {
        "id": 1, 
        "hash": "19f149b6-f7e2-4d61-b3c5-d46ebc92f681", 
        "car_id": 2, 
        "comments": "uwagi", 
        "driver_id": 1, 
        "address_to": "adres dostawy", 
        "carrier_id": 22, 
        "company_id": 1, 
        "created_at": "2022-04-14T09:07:41.000000Z", 
        "data_start": "2022-04-01", 
        "deleted_at": null, 
        "updated_at": "2022-04-14T09:07:41.000000Z", 
        "carrier_nip": "728-597-9477", 
        "data_finish": "2022-04-04", 
        "address_from": "adres wyjazdu", 
        "carrier_city": "Lake Emersonville", 
        "carrier_name": "Satterfield, Lebsack and O'Conner", 
        "order_number": "Numer zlecenia", 
        "speed_number": "Numer zlecenia speed - spedycja", 
        "carrier_email": "[email protected]", 
        "carrier_phone": "347.731.2768 x1508", 
        "dispatcher_id": 3, 
        "carrier_street": "6342 Pollich Crossroad", 
        "selected_files": "[7,8,9]", 
        "transport_type": 2, 
        "deliver_comments": null, 
        "transport_status": 3, 
        "is_neutral_option": 2,
        "selected_products": "[1,3]", 
        "transport_content": "kontakt", 
        "delivery_signature": null, 
        "selected_documents": "[5]", 
        "carrier_postal_code": "36804-7962", 
        "hidden_carrier_data": 0, 
        "delivery_name_surname": null, 
        "delivery_signature_binary": null, 
        "disable_change_status_driver": 0
    }, 
    "attributes": {
        "id": 1, 
        "hash": "19f149b6-f7e2-4d61-b3c5-d46ebc92f681", 
        "car_id": 2, 
        "comments": "uwagi", 
        "driver_id": 1, 
        "address_to": 
        "adres dostawy", 
        "carrier_id": 22, 
        "company_id": 1, 
        "created_at": "2022-04-14T09:07:41.000000Z", 
        "data_start": "2022-04-01", 
        "deleted_at": null, 
        "updated_at": "2022-04-14T09:09:08.000000Z", 
        "carrier_nip": "728-597-9477", 
        "data_finish": "2022-04-04", 
        "address_from": "adres wyjazdu", 
        "carrier_city": "Lake Emersonville", 
        "carrier_name": "Satterfield, Lebsack and O'Conner", 
        "order_number": "Numer zlecenia", 
        "speed_number": "Numer zlecenia speed - spedycja", 
        "carrier_email": "[email protected]", 
        "carrier_phone": "347.731.2768 x1508", 
        "dispatcher_id": 4, 
        "carrier_street": "6342 Pollich Crossroad", 
        "selected_files": "[7,8,9]", 
        "transport_type": 2, 
        "deliver_comments": null, 
        "transport_status": 3, 
        "is_neutral_option": 2, 
        "selected_products": "[1,3,2]", 
        "transport_content": "kontakt", 
        "delivery_signature": null, 
        "selected_documents": "[5,6,4]", 
        "carrier_postal_code": "36804-7962", 
        "hidden_carrier_data": 0, 
        "delivery_name_surname": null, 
        "delivery_signature_binary": null, 
        "disable_change_status_driver": 0
        }
    }

I need show differences from OLD and Attributes.
How can I make it?

Please help me.

multidimensional array remove item from child array

i have a problem with my multidimensional array. I want to remove some items from child array by $id value.

here is my multidimensional example array and selectedIds:

$myArray = [
    ['id' => '2', 
    'name' => 'Punk'
    ],[
    'id' => '5', 
    'name' => 'Rock', 
    'children' => [
        '30' => ['id' => '30', 
                'name' => 'Hard Rock', 
                'parentId' => '5'
                ], 
        '40' => ['id' => '40', 
                'name' => 'Soft Rock', 
                'parentId' => '5'
                ],  
        '50' => ['id' => '50', 
                'name' => 'Glam Rock', 
                'parentId' => '5'
                ]
        ]
    ]
];

$selectedIds = [2,5,30];

and i want to remove from array those items which are not in selectedIds array.

so i want to have output:

$outputArray = [
    [
    'id' => '2', 
    'name' => 'Punk'
    ],[
    'id' => '5', 
    'name' => 'Rock', 
    'children' => [
            '30' => ['id' => '30', 
                    'name' => 'Hard Rock', 
                    'parentId' => '5']
                ]
    ]
];

i try to make it with foreach and array_key_exist but its not correct:

foreach ($myArray as $key=>$value) {
    if (array_key_exists('children', $value)) {
        foreach ($selectedIds as $id) {
            if (isset($value['children'][$id])) {
                $outputArray[] = $value['children'][$id];
            }
        }
    }
}
print_r($outputArray);

this outpus is only item with id 30

How to fix Fatal error in Ratchet Websocket?

When I run my server.php file, it gives me the following error on cmd:
PHP Fatal error: Uncaught RuntimeException: Failed to listen on "tcp://0.0.0.0:8080": An attempt was made to access a socket in a way forbidden by its access permissions. (EACCES) in C:xampphtdocsvchatvendorreactsocketsrcTcpServer.php:184

is there any way to fix it?

Translate c# Http request into php CURL, what is “request.AddParameter” of c# in php?

I’ve a c# sample script as following:

/* Step One: Call /auth/token for client Authentication and to obtain an Access Token */
/* Replace siteDomainName with the corresponding domain URL*/
var client = new RestClient("{siteDomainName}/auth/token");
client.Timeout = -1;

string svcCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes({applicationId} + ":" + {sharedSecret}));
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Basic " + svcCredentials);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{ "RefreshToken": {refeshToken} }",ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
var tokenResponse = JsonConvert.DeserializeObject( response.Content);

/* Step Two: Call Product API /v1/product/{productCode} using the Access Token obtained for API Authorization */
client = new RestClient("{siteDomainName}/v1/product/{productCode}");
client.Timeout = -1;

var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer {tokenResponse.Token}");
request.AddParameter("text/plain", "",  ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

I don’t understand how to translate this line request.AddParameter("application/json", "{ "RefreshToken": {refeshToken} }",ParameterType.RequestBody);

here is the php so far i tried

<?php
$app_id = "20dd14a2d3cfsdf4eb1234756b26b";
$shared_secret = "d561e8sdf8ca0b914f452201ad523";
$refresh_token = "39fe926b233dfb130ca0f69e8356c";
$svcCredentials = base64_encode($app_id .":". $shared_secret);

$url = "https://example.com.au";

$ch = curl_init($url . "/auth/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, "application/json");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{ RefreshToken: {39fe926b96sdfb130ca0f69e8356c} }');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    "Authorization: Basic $svcCredentials",
                    "Content-Type: application/json"
                ));
//curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));

$token = curl_exec($ch);
var_dump($token);

PHP – An unidentified value inside array suddenly appear after unset()?

What Im trying to do is I want to delete specific array index value inside this array that Im comparing it with another array. I heard unset is the way to go so I give it a try. Below is the json encode before the unset().

[
 {
  "crs_id": "1269",
  "crs_code": "UI3/212",
  "crs_title_bm": "LOL",
  "crs_title_bi": "OLO",
  "crs_description_bm": "ye ah tu",
  "crs_description_bi": "righttt",
  "crs_edit_by": "991018222222",
  "crs_edit_date": "2022-04-11 05:43:30",
  "crs_aprv_type1": "0",
  "crs_aprv_val1": null,
  "crs_aprv_type2": "0",
  "crs_aprv_val2": null,
  "crs_aprv_type3": "0",
  "crs_aprv_val3": null,
  "crs_aprv_type4": "0",
  "crs_aprv_val4": null,
  "crs_aprv_type5": "0",
  "crs_aprv_val5": null,
  "crs_indakua": "1",
  "crs_indpengembangan": "0",
  "crs_status": "1",
  "cat_id": "27",
  "typ_id": "7",
  "clssfctn_id": "8",
  "crs_grp_id": "8",
  "crs_org_id": "16",
  "cdept_id": "40408000017"
 },
 {
  "crs_id": "1270",
  "crs_code": "ABC18",
  "crs_title_bm": "LOL2",
  "crs_title_bi": "OLO2",
  "crs_description_bm": "yow",
  "crs_description_bi": "right",
  "crs_edit_by": "991018222222",
  "crs_edit_date": "2022-04-11 05:42:52",
  "crs_aprv_type1": "0",
  "crs_aprv_val1": null,
  "crs_aprv_type2": "0",
  "crs_aprv_val2": null,
  "crs_aprv_type3": "0",
  "crs_aprv_val3": null,
  "crs_aprv_type4": "0",
  "crs_aprv_val4": null,
  "crs_aprv_type5": "0",
  "crs_aprv_val5": null,
  "crs_indakua": "1",
  "crs_indpengembangan": "0",
  "crs_status": "1",
  "cat_id": "27",
  "typ_id": "7",
  "clssfctn_id": "4",
  "crs_grp_id": "9",
  "crs_org_id": "11",
  "cdept_id": "40405000000"
 },
 {
  "crs_id": "1271",
  "crs_code": "TIME12",
  "crs_title_bm": "CHECK",
  "crs_title_bi": "CHECK",
  "crs_description_bm": "nk check it is mase",
  "crs_description_bi": "nk check it is mase",
  "crs_edit_by": "991018222222",
  "crs_edit_date": "2022-04-11 05:41:54",
  "crs_aprv_type1": "0",
  "crs_aprv_val1": null,
  "crs_aprv_type2": "0",
  "crs_aprv_val2": null,
  "crs_aprv_type3": "0",
  "crs_aprv_val3": null,
  "crs_aprv_type4": "0",
  "crs_aprv_val4": null,
  "crs_aprv_type5": "0",
  "crs_aprv_val5": null,
  "crs_indakua": "1",
  "crs_indpengembangan": "0",
  "crs_status": "1",
  "cat_id": "27",
  "typ_id": "4",
  "clssfctn_id": "4",
  "crs_grp_id": "3",
  "crs_org_id": "18",
  "cdept_id": "40408000034"
 }
]

It is exactly what I hope to see so nothing wrong here. Below is the json encode after the unset().

{
 "1": {
       "crs_id": "1270",
       "crs_code": "ABC18",
       "crs_title_bm": "LOL2",
       "crs_title_bi": "OLO2",
       "crs_description_bm": "yow",
       "crs_description_bi": "right",
       "crs_edit_by": "991018222222",
       "crs_edit_date": "2022-04-11 05:42:52",
       "crs_aprv_type1": "0",
       "crs_aprv_val1": null,
       "crs_aprv_type2": "0",
       "crs_aprv_val2": null,
       "crs_aprv_type3": "0",
       "crs_aprv_val3": null,
       "crs_aprv_type4": "0",
       "crs_aprv_val4": null,
       "crs_aprv_type5": "0",
       "crs_aprv_val5": null,
       "crs_indakua": "1",
       "crs_indpengembangan": "0",
       "crs_status": "1",
       "cat_id": "27",
       "typ_id": "7",
       "clssfctn_id": "4",
       "crs_grp_id": "9",
       "crs_org_id": "11",
       "cdept_id": "40405000000"
      }
 }

The above json encode is still what I hope to see, it show the correct array key index to be shown but what make it a problem for me is the value "1" suddenly appear and I noticed it no longer in an array form(?) since before unset it shown [.....] but after unset it shown {....}

What I want to see is the "1" is gone and instead of {....} I want it to be [.....]

How to compare key’s value and get value in PHP array

I have an array like this

Array
(
    [10] => 0
    [30] => 2
    [90] => 5
    [365] => 10

)

Array Key have #days and value have #percentage.

Now if pass day value between 0 to 10 days then percentage will be 0, if between 11 to 30 days then percentage will be 2 if between 31 to 90 days then percentage will be 5
if 500 days then 10

My code is

    $closest = null;
    foreach ($stake as $k=>$v) {
        echo "abs($search - $closest)";
        echo "abs($k - $search)";
        if ($closest === null || abs($search - $closest) > abs($k - $search)) {
          $closest = $k;
       }
    }

but when i pass 11 it’s return 10 instead of 30

WordPress – Load more posts with AJAX & exclude posts

I made a “load more” button to my website, following this awesome tutorial.
Everything works fine, but in the homepage i have 3 different loops (1 sticky post, 3 evidence) and the load more starts from post #5.

In the main loops, I have excluded the already-showed posts with the IDs and “post__not_in” and everything works fine.

The problem is when I call the load more, the loop starts from post 1. If I set to start from page 2 I have a duplicate post (that’s because I have to load post in multiple of 3).

I’have tried to get the IDs list in my loadmore file with GLOBALS, but it seems not working 🙁

How can I pass my main loop variable to the load more query?

This is my main loop:

<?php
$myquery = new WP_Query([
    'post_type'      => 'post',
  'posts_per_page' => 3,
  'post_status'    => 'publish',
'orderby' => 'date',
'order'   => 'DESC',
    'post__not_in' => $ids
]); if($myquery->have_posts()): ?>

<div class="articles-container append-posts">
    <?php
    while($myquery->have_posts()) : $myquery->the_post();
$ids[] = get_the_ID(); ?>

<?php get_template_part( 'template-parts/loop', 'posts' ); ?>

<?php endwhile; ?>
</div>

This is the load-more file:

function misha_loadmore_ajax_handler(){

// prepare our arguments for the query
$args = json_decode( stripslashes( $_POST['query'] ), true );
$args['paged'] = $_POST['page'] + 1; // we need next page to be loaded
$args['post_status'] = 'publish';
$args['post_type'] = 'post';
$args['post_per_page'] = 3;
$args['orderby'] = 'date';
$args['order'] = 'DESC';

// it is always better to use WP_Query but not here
query_posts( $args );

if( have_posts() ) :

    // run the loop
    while( have_posts() ): the_post();

        // look into your theme code how the posts are inserted, but you can use your own HTML of course
        // do you remember? - my example is adapted for Twenty Seventeen theme
        get_template_part( 'template-parts/loop', 'posts' );
        // for the test purposes comment the line above and uncomment the below one
        // the_title();


    endwhile;

endif;
die; // here we exit the script and even no wp_reset_query() required! }

WordPress update theme after install in PHP loop (Theme_Upgrader)

I’m working on a plugin that will automatically download a theme from a list, then update, and activate it.

Considering there are a number of potential errors (i.e. improper PHP version, etc), I’m trying to make it re-try after encountering an error.

The problem is that if the first theme fails (in this case, because of a PHP error – requires 7.2, I am testing with 7.0), WordPress will not perform the update on the second theme (retrogeek.0.4.zip).

However, if I make retrogeek.0.4.zip the first theme in the list, WordPress will automatically update the theme. This appears to be some sort of caching issue, but I’ve been trying for 3+ hours now and cannot get it to work.

I’ve tried a ton of variations of wp_clean_themes_cache(false) and anything else I can find. There really isn’t much documentation on this sort of thing.

I’ve also tried:

  • Nulling $test_theme_installer at the end of the loop
  • Making $test_theme_install->upgrade a variable and nulling it
  • Using “bulk_upgrade” outside of the loop

Here is the code I have now:

require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
require_once(ABSPATH . 'wp-admin/includes/class-theme-upgrader.php');

$grab_theme_url = array(
        'https://downloads.wordpress.org/theme/sirat.0.8.8.zip',
        'https://downloads.wordpress.org/theme/retrogeek.0.4.zip',
);

for($i=0; $i < 3; $i++) {

 $grab_theme_url = $grab_theme_url[$i];
 $theme_folder_path = ABSPATH . "wp-content/themes/";
 $theme_zip_file = basename(parse_url($grab_theme_url, PHP_URL_PATH));

 copy($grab_theme_url, $theme_folder_path . $theme_zip_file);

 $theme_file_unzipped = preg_replace('/.(.*)/','',$theme_zip_file);

 // ----------------------------------------------------------------------------------------
 //  Install and update the theme
 // ----------------------------------------------------------------------------------------
 $args = array('clear_update_cache' => false);

 $test_theme_install = new Theme_Upgrader();
 $test_theme_installer = $test_theme_install->install($theme_folder_path . $theme_zip_file, $args);

 if($test_theme_installer !== null) {
     $test_theme_install->upgrade($theme_file_unzipped, $args);
     break;
 }
     echo "Theme incompatible... trying again.";
     unlink($theme_folder_path . $theme_zip_file);

}