Skip to content

Commit

Permalink
Merge pull request #33 from kprajapatii/master
Browse files Browse the repository at this point in the history
1.3.5
  • Loading branch information
kprajapatii authored Sep 3, 2024
2 parents 84f78b2 + bdc697c commit 91409fa
Show file tree
Hide file tree
Showing 16 changed files with 287 additions and 206 deletions.
5 changes: 2 additions & 3 deletions ayecode-connect.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

/**
* Plugin Name: AyeCode Connect
* Plugin URI: https://ayecode.io/
* Description: A service plugin letting users connect AyeCode Services to their site.
* Version: 1.3.4
* Version: 1.3.5
* Author: AyeCode
* Author URI: https://ayecode.io
* Requires at least: 4.7
Expand All @@ -20,7 +19,7 @@
}

if ( !defined( 'AYECODE_CONNECT_VERSION' ) ) {
define( 'AYECODE_CONNECT_VERSION', '1.3.4' );
define( 'AYECODE_CONNECT_VERSION', '1.3.5' );
}

if ( !defined( 'AYECODE_CONNECT_SSL_VERIFY' ) ) {
Expand Down
10 changes: 5 additions & 5 deletions includes/class-ayecode-connect-remote-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public function parse_elementor_data( $post_id ) {
* @param $cpt
*/
public function delete_demo_posts( $cpt ) {
$this->debug_log( 'start', __METHOD__, __FILE__, __LINE__ );
$this->debug_log( 'start', __METHOD__ . ':' . $cpt, __FILE__, __LINE__ );

// Elementor allow delete kit (without this it throws a confirmation page and blocks import)
$_GET['force_delete_kit'] = 1;
Expand All @@ -625,7 +625,7 @@ public function delete_demo_posts( $cpt ) {
}
}

$this->debug_log( 'end', __METHOD__, __FILE__, __LINE__ );
$this->debug_log( 'end', __METHOD__ . ':' . $cpt, __FILE__, __LINE__ );
}

/**
Expand Down Expand Up @@ -1841,14 +1841,14 @@ public function install_theme( $result ) {
)
);

$this->debug_log( $api, __METHOD__ . ':' . $slug . ':themes_api', __FILE__, __LINE__ );

if ( is_wp_error( $api ) ) {
$this->debug_log( $api->get_error_message(), __METHOD__ . ':themes_api error', __FILE__, __LINE__ );
$this->debug_log( $api->get_error_message(), __METHOD__ . ':' . $slug . ':themes_api error', __FILE__, __LINE__ );

$result = array( "success" => false );
} else if ( ! empty( $api->download_link ) ) {
$download_link = $api->download_link;
} else {
$this->debug_log( $api, __METHOD__ . ':' . $slug . ':themes_api', __FILE__, __LINE__ );
}
}

Expand Down
65 changes: 50 additions & 15 deletions includes/class-ayecode-demo-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public function prevent_redirects(){
// prevent some transient redirects
delete_transient( '_gd_activation_redirect' );
delete_transient( 'gd_social_importer_redirect' );
delete_option( 'uwp_activation_redirect' );
delete_option( 'uwp_setup_wizard_notice' );
}
}

Expand Down Expand Up @@ -231,7 +233,7 @@ public function settings_page( $wizard = false ) {
<div class="bsui" style="<?php if(!$wizard){ ?>margin-left: -20px; display: flex<?php } ?>">
<div class="<?php if(!$wizard){ ?>containerx bg-white w-100 p-4 m-4 border rounded<?php } ?>">
<?php
$sites = $this->get_sites();
$sites = $this->get_sites( true );

echo aui()->alert(array(
'type'=> 'danger',
Expand Down Expand Up @@ -669,10 +671,10 @@ public function get_demo_tabs_head( $sites ) {
*
* @return mixed
*/
public function get_sites(){

public function get_sites( $refresh = false ) {
$sites = get_transient( 'ayecode_connect_demos' );
if ( empty( $demos ) ) {

if ( empty( $sites ) || $refresh ) {
$args = array(
'timeout' => 30,
'redirection' => 0,
Expand All @@ -683,12 +685,13 @@ public function get_sites(){

if ( ! is_wp_error( $data ) && $data['response']['code'] == 200 ) {
$responseBody = wp_remote_retrieve_body( $data );
$sites = json_decode( $responseBody );

$sites = json_decode( $responseBody );

set_transient( 'ayecode_connect_demos', $sites, HOUR_IN_SECONDS );
}
}


return $sites;
}

Expand Down Expand Up @@ -808,6 +811,8 @@ public function import_content() {
$error = array();

if ( $step === 0 ) {
$this->debug_log( $site->theme, __METHOD__ . ':demo site' , __FILE__, __LINE__ );

$result = $this->download_content( $demo );
//$result = '49015-kadence-jobs-directory-v5XCrTvqLMGp.html';// Test from remote site. // @todo

Expand All @@ -831,7 +836,7 @@ public function import_content() {
// Theme
$result = $this->set_demo_theme( $data_file );

$this->debug_log( $result, __METHOD__ . ':step:' . $step . ' response - set_demo_theme' , __FILE__, __LINE__ );
$this->debug_log( ( is_wp_error( $result ) ? $result->get_error_message() : $result ), __METHOD__ . ':step:' . $step . ' response - set_demo_theme' , __FILE__, __LINE__ );

if ( is_wp_error( $result ) ) {
$error = $result;
Expand All @@ -846,7 +851,7 @@ public function import_content() {
// Plugins
$result = $this->set_demo_plugins( $data_file );

$this->debug_log( $result, __METHOD__ . ':step:' . $step . ' response - set_demo_plugins' , __FILE__, __LINE__ );
$this->debug_log( ( is_wp_error( $result ) ? $result->get_error_message() : $result ), __METHOD__ . ':step:' . $step . ' response - set_demo_plugins' , __FILE__, __LINE__ );

if ( is_wp_error( $result ) ) {
$error = $result;
Expand Down Expand Up @@ -876,11 +881,15 @@ public function import_content() {
'log_data' => ! empty( $result['errors'] ) ? __( 'Could not install plugins:', 'ayecode-connect' ) . '<div class="d-inline-block my-1">- ' . implode( '</div><div class="d-inline-block my-1">- ', array_values( $result['errors'] ) ) . '<div>' : ''
);
}

// Delete plugin redirect.
delete_option( 'uwp_activation_redirect' );
delete_option( 'uwp_setup_wizard_notice' );
} else if ( $step === 3 ) {
// Settings
$result = $this->set_demo_settings( $data_file );

$this->debug_log( $result, __METHOD__ . ':step:' . $step . ' response - set_demo_settings' , __FILE__, __LINE__ );
$this->debug_log( ( is_wp_error( $result ) ? $result->get_error_message() : $result ), __METHOD__ . ':step:' . $step . ' response - set_demo_settings' , __FILE__, __LINE__ );

if ( is_wp_error( $result ) ) {
$error = $result;
Expand All @@ -897,7 +906,7 @@ public function import_content() {
// Categories
$result = $this->set_demo_categories( $data_file );

$this->debug_log( $result, __METHOD__ . ':step:' . $step . ' response - set_demo_categories' , __FILE__, __LINE__ );
$this->debug_log( ( is_wp_error( $result ) ? $result->get_error_message() : $result ), __METHOD__ . ':step:' . $step . ' response - set_demo_categories' , __FILE__, __LINE__ );

if ( is_wp_error( $result ) ) {
$error = $result;
Expand All @@ -913,7 +922,7 @@ public function import_content() {
// Page templates
$result = $this->set_page_templates( $data_file );

$this->debug_log( $result, __METHOD__ . ':step:' . $step . ' response - set_page_templates' , __FILE__, __LINE__ );
$this->debug_log( ( is_wp_error( $result ) ? $result->get_error_message() : $result ), __METHOD__ . ':step:' . $step . ' response - set_page_templates' , __FILE__, __LINE__ );

if ( is_wp_error( $result ) ) {
$error = $result;
Expand All @@ -930,7 +939,7 @@ public function import_content() {
// Dummy posts
$result = $this->set_dummy_posts( $data_file, $site );

$this->debug_log( $result, __METHOD__ . ':step:' . $step . ' response - set_dummy_posts:' . $page , __FILE__, __LINE__ );
$this->debug_log( ( is_wp_error( $result ) ? $result->get_error_message() : $result ), __METHOD__ . ':step:' . $step . ' response - set_dummy_posts:' . $page , __FILE__, __LINE__ );

if ( is_wp_error( $result ) ) {
$error = $result;
Expand Down Expand Up @@ -961,7 +970,7 @@ public function import_content() {
// Widgets
$result = $this->set_widgets( $data_file, $site );

$this->debug_log( $result, __METHOD__ . ':step:' . $step . ' response - set_widgets' , __FILE__, __LINE__ );
$this->debug_log( ( is_wp_error( $result ) ? $result->get_error_message() : $result ), __METHOD__ . ':step:' . $step . ' response - set_widgets' , __FILE__, __LINE__ );

if ( is_wp_error( $result ) ) {
$error = $result;
Expand All @@ -978,7 +987,7 @@ public function import_content() {
// Menus
$result = $this->set_menus( $data_file, $site );;

$this->debug_log( $result, __METHOD__ . ':step:' . $step . ' response - set_menus' , __FILE__, __LINE__ );
$this->debug_log( ( is_wp_error( $result ) ? $result->get_error_message() : $result ), __METHOD__ . ':step:' . $step . ' response - set_menus' , __FILE__, __LINE__ );

if ( is_wp_error( $result ) ) {
$error = $result;
Expand Down Expand Up @@ -1153,8 +1162,12 @@ public function set_demo_theme( $demo_file ) {
return $data;
}

if ( $_errors = $this->parse_error_messages( $data ) ) {
return new WP_Error( 'install_theme_error', wp_sprintf( __( 'Theme Install Error: %s', 'ayecode-connect' ), implode( " ", $_errors ) ) );
}

if ( ! ( is_array( $data ) && ! empty( $data['slug'] ) ) ) {
return new WP_Error( 'invalid_demo_data', __( 'Invalid demo data found for theme.', 'ayecode-connect' ) );
return new WP_Error( 'install_theme_error', wp_sprintf( __( 'Theme Install Error: %s', 'ayecode-connect' ), __( 'Invalid demo data found for theme.', 'ayecode-connect' ) ) );
}

$slug = $data['slug'];
Expand Down Expand Up @@ -1738,6 +1751,28 @@ public function check_ayecode_demo_folder_protection() {
return new WP_Error( 'demo_download_folder_error', __( 'Unable to create demo data download folder.' ) );
}
}

public function parse_error_messages( $res, $code = '' ) {
if ( ! ( is_array( $res ) && ! empty( $res['errors'] ) ) ) {
return array();
}

if ( empty( $code ) ) {
$all_messages = array();

foreach ( $res['errors'] as $code => $messages ) {
$all_messages = array_merge( $all_messages, $messages );
}

return $all_messages;
}

if ( isset( $res['errors'][ $code ] ) ) {
return $res['errors'][ $code ];
} else {
return array();
}
}
}

/**
Expand Down
Binary file modified languages/ayecode-connect-en_US.mo
Binary file not shown.
Loading

0 comments on commit 91409fa

Please sign in to comment.