Skip to content

Commit

Permalink
Merge pull request #417 from mainwp/mainwp-child-dev
Browse files Browse the repository at this point in the history
Fixed: gallery post issue
  • Loading branch information
thanghv authored Aug 28, 2024
2 parents d67a903 + e463e0a commit 958ba1a
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 278 deletions.
4 changes: 2 additions & 2 deletions class/class-mainwp-child-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ private function get_post_edit( $id ) { //phpcs:ignore -- NOSONAR - complex.
'post_password' => $post->post_password,
);

if ( empty( $post_featured_image ) ) { // Featured image is set, retrieve URL.
if ( ! empty( $post_featured_image ) ) { // Featured image is set, retrieve URL.
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
$post_featured_image = $img[0];
}
Expand Down Expand Up @@ -693,7 +693,7 @@ private function get_page_edit( $id ) { //phpcs:ignore -- NOSONAR - complex.
'post_password' => $post->post_password,
);

if ( empty( $post_featured_image ) ) {
if ( ! empty( $post_featured_image ) ) {
$img = wp_get_attachment_image_src( $post_featured_image, 'full' );
$post_featured_image = $img[0];
}
Expand Down
38 changes: 0 additions & 38 deletions class/class-mainwp-child-server-information-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,6 @@ public static function get_class_name() {
return __CLASS__;
}

/**
* Initiate check on important System Variables and compare them to required defaults.
*
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::check()
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::check_mainwp_directory()
*
* @return int $i Number of detected issues.
*/
protected static function get_warnings() {
$i = 0;
if ( ! static::check( '>=', '3.4', 'get_wordpress_version' ) ) {
++$i;
}
if ( ! static::check( '>=', '5.2.4', 'get_php_version' ) ) {
++$i;
}
if ( ! static::check( '>=', '5.0', 'get_my_sql_version' ) ) {
++$i;
}
if ( ! static::check( '>=', '30', 'get_max_execution_time', '=', '0' ) ) {
++$i;
}
if ( ! static::check( '>=', '2M', 'get_upload_max_filesize', null, null, true ) ) {
++$i;
}
if ( ! static::check( '>=', '2M', 'get_post_max_size', null, null, true ) ) {
++$i;
}
if ( ! static::check( '>=', '10000', 'get_output_buffer_size' ) ) {
++$i;
}
if ( ! static::check_mainwp_directory() ) {
++$i;
}

return $i;
}

/**
* Check if MainWP Directory is writeable.
*
Expand Down
163 changes: 0 additions & 163 deletions class/class-mainwp-child-server-information.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,169 +31,6 @@ public static function get_class_name() {
return __CLASS__;
}

/**
* Add hooks after WordPress has finished loading but before any headers are sent.
*
* @uses MainWP_Child_Server_Information::dismiss_warnings() Dismiss warnings.
*/
public static function init() {
add_action(
'wp_ajax_mainwp-child_dismiss_warnings',
array(
static::get_class_name(),
'dismiss_warnings',
)
);
}

/**
* Dismiss warnings.
*
* @uses \MainWP\Child\MainWP_Helper::update_option() Update option by option name.
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::get_warnings() Initiate check on important System Variables and compare them to required defaults.
* @uses get_option() Retrieves an option value based on an option name.
* @see https://developer.wordpress.org/reference/functions/get_option/
*
* @used-by MainWP_Child_Server_Information::init() Add hooks after WordPress has finished loading but before any headers are sent.
*/
public static function dismiss_warnings() {
// phpcs:disable WordPress.Security.NonceVerification
if ( isset( $_POST['what'] ) ) {
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
if ( ! is_array( $dismissWarnings ) ) {
$dismissWarnings = array();
}
if ( 'warning' === $_POST['what'] ) {
if ( isset( $_POST['warnings'] ) ) {
$warnings = intval( $_POST['warnings'] );
} else {
$warnings = static::get_warnings();
}
$dismissWarnings['warnings'] = $warnings;
}
MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
}
// phpcs:enable
}

/**
* Render warnings.
*
* @uses \MainWP\Child\MainWP_Helper::update_option() Update option by option name.
* @uses \MainWP\Child\MainWP_Child_Server_Information_Base::get_warnings() Initiate check on important System Variables and compare them to required defaults.
* @uses get_option() Retrieves an option value based on an option name.
* @see https://developer.wordpress.org/reference/functions/get_option/
*
* @used-by MainWP_Child_Server_Information::init() Add hooks after WordPress has finished loading but before any headers are sent.
*/
public static function render_warnings() {
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
if ( isset( $_SERVER['REQUEST_URI'] ) && ( stristr( $request_uri, 'mainwp_child_tab' ) || stristr( $request_uri, 'mainwp-reports-page' ) || stristr( $request_uri, 'mainwp-reports-settings' ) ) ) {
return;
}

// improved query.
if ( static::is_mainwp_pages() ) {
return;
}

$warnings = static::get_warnings();

$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
if ( ! is_array( $dismissWarnings ) ) {
$dismissWarnings = array();
}

if ( isset( $dismissWarnings['warnings'] ) && $dismissWarnings['warnings'] >= $warnings ) {
$warnings = 0;
}

if ( 0 === $warnings ) {
return;
}

if ( $warnings > 0 ) {
$dismissWarnings['warnings'] = 0;
}

MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
?>
<script language="javascript">
dismiss_warnings = function ( pElement, pAction ) {
var table = jQuery( pElement.parents( 'table' )[0] );
pElement.parents( 'tr' )[0].remove();
if ( table.find( 'tr' ).length == 0 ) {
jQuery( '#mainwp-child_server_warnings' ).hide();
}

var data = {
action: 'mainwp-child_dismiss_warnings',
what: pAction,
warnings: <?php echo intval( $warnings ); ?>
};

jQuery.ajax( {
type: "POST",
url: ajaxurl,
data: data,
success: function ( resp ) {},
error: function () {},
dataType: 'json'
} );

return false;
};
jQuery( document ).on( 'click', '#mainwp-child-connect-warning-dismiss', function () {
return dismiss_warnings( jQuery( this ), 'warning' );
} );
jQuery( document ).on( 'click', '#mainwp-child-all-pages-warning-dismiss', function () {
return dismiss_warnings( jQuery( this ), 'conflict' );
} );
</script>
<style type="text/css">
.mainwp-child_info-box-red-warning {
background-color: rgba(187, 114, 57, 0.2) !important;
border-bottom: 4px solid #bb7239 !important;
border-top: 1px solid #bb7239 !important;
border-left: 1px solid #bb7239 !important;
border-right: 1px solid #bb7239 !important;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 1em 0 !important;

background-image: url( '<?php echo esc_url( plugins_url( 'images/mainwp-icon-orange.png', __DIR__ ) ); ?>' ) !important;
background-position: 1.5em 50% !important;
background-repeat: no-repeat !important;
background-size: 30px !important;
}

.mainwp-child_info-box-red-warning table {
background-color: rgba(187, 114, 57, 0) !important;
border: 0px;
padding-left: 4.5em;
background-position: 1.5em 50% !important;
background-repeat: no-repeat !important;
background-size: 30px !important;
}
</style>

<div class="updated mainwp-child_info-box-red-warning" id="mainwp-child_server_warnings">
<table id="mainwp-table" class="wp-list-table widefat" style="border-spacing:0;"> <?php // NOSONAR - table no th. ?>
<tbody id="the-sites-list" class="list:sites">
<?php
$warning = '';
if ( $warnings > 0 ) {
$warning .= '<tr><td colspan="2">This site may not connect to your dashboard or may have other issues. Check your <a href="options-general.php?page=mainwp_child_tab">MainWP server information page</a>.</td><td style="text-align: right;"><a href="#" id="mainwp-child-connect-warning-dismiss">Dismiss</a></td></tr>';
}
echo $warning; // phpcs:ignore WordPress.Security.EscapeOutput
?>
</tbody>
</table>
</div>
<?php
}

/**
* Method is_mainwp_pages()
*
Expand Down
4 changes: 1 addition & 3 deletions class/class-mainwp-child.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MainWP_Child {
*
* @var string MainWP Child plugin version.
*/
public static $version = '5.1.1'; // NOSONAR - not IP.
public static $version = '5.2'; // NOSONAR - not IP.

/**
* Private variable containing the latest MainWP Child update version.
Expand All @@ -55,7 +55,6 @@ class MainWP_Child {
*
* @uses \MainWP\Child\MainWP_Child_Branding::save_branding_options()
* @uses \MainWP\Child\MainWP_Child_Plugins_Check::instance()
* @uses \MainWP\Child\MainWP_Child_Server_Information::init()
* @uses \MainWP\Child\MainWP_Child_Themes_Check::instance()
* @uses \MainWP\Child\MainWP_Child_Updates::get_instance()
* @uses \MainWP\Child\MainWP_Client_Report::init()
Expand Down Expand Up @@ -100,7 +99,6 @@ public function __construct( $plugin_file ) {
MainWP_Connect::instance()->check_other_auth();

MainWP_Clone::instance()->init();
MainWP_Child_Server_Information::init();
MainWP_Client_Report::instance()->init();
MainWP_Child_Plugins_Check::instance();
MainWP_Child_Themes_Check::instance();
Expand Down
67 changes: 44 additions & 23 deletions class/class-mainwp-clone-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ public static function render_java_script() {
var pollingDownloading = undefined;
var backupDownloadFinished = false;

var pollingBackupInfo = {
'poll_check': 0,
'size_check': 0,
};

handleCloneError = function ( resp ) {
updateClonePopup( resp.error, true, 'red' );
};
Expand Down Expand Up @@ -627,48 +632,49 @@ public static function render_java_script() {

jQuery.post( ajaxurl, data, function ( pSiteId, pSiteName ) {
return function ( resp ) {
backupCreationFinished = true;
clearTimeout( pollingCreation );

var progressBar = jQuery( '#mainwp-child-clone-create-progress' );
progressBar.progressbar( 'value', parseFloat( progressBar.progressbar( 'option', 'max' ) ) );

if ( resp.error ) {
handleCloneError( resp );
return;
}
updateClonePopup( mwp_sprintf( translations['backup_created'], pSiteName, (resp.size / 1024).toFixed( 2 ) ) );
cloneInitiateBackupDownload( pSiteId, resp.url, resp.size );
cloneBackupFinishied(resp, pSiteId, pSiteName );
}
}( siteId, siteName ), 'json' );
pollingCreation = setTimeout( function () {
cloneBackupCreationPolling( siteId, rand );
}, 1000 );
pollingCreation = setTimeout( function (psiteName) {
cloneBackupCreationPolling( siteId, rand, psiteName );
}(siteName), 1000 );
};

cloneBackupCreationPolling = function ( siteId, rand ) {
cloneBackupCreationPolling = function ( siteId, rand, psiteName ) {
if ( backupCreationFinished ) return;

var data = mainwpchild_secure_data({
action: 'mainwp-child_clone_backupcreatepoll',
siteId: siteId,
rand: rand
rand: rand,
backupInfo: pollingBackupInfo
});

jQuery.post( ajaxurl, data, function ( pSiteId, pRand ) {
return function ( resp ) {
jQuery.post( ajaxurl, data, function ( pSiteId, pRand, psiteName ) {
return function ( resp, psiteName ) {
if(resp.backupFinishedResult){
cloneBackupFinishied(resp.backupFinishedResult, pSiteId, psiteName );
}
if ( backupCreationFinished ) return;
if ( resp.size ) {
var progressBar = jQuery( '#mainwp-child-clone-create-progress' );
if ( progressBar.progressbar( 'option', 'value' ) < progressBar.progressbar( 'option', 'max' ) ) {
progressBar.progressbar( 'value', resp.size );
}
if ( resp.size_byte ) {
if(resp.size_byte === pollingBackupInfo.size_check ){
pollingBackupInfo.poll_check++;
} else {
pollingBackupInfo.poll_check = 0;
}
pollingBackupInfo.size_check = resp.size_byte;
}
}
pollingCreation = setTimeout( function () {
cloneBackupCreationPolling( pSiteId, pRand );
}, 1000 );
}
}( siteId, rand ), 'json' );
}( siteId, rand, psiteName ), 'json' );
};

cloneInitiateBackupDownload = function ( pSiteId, pFile, pSize ) {
Expand Down Expand Up @@ -716,7 +722,7 @@ public static function render_java_script() {
file: pFile
});

jQuery.post( ajaxurl, data, function ( pSiteId ) {
jQuery.post( ajaxurl, data, function ( pSiteId, pFile ) {
return function ( resp ) {
if ( backupDownloadFinished ) return;
if ( resp.size ) {
Expand All @@ -727,10 +733,25 @@ public static function render_java_script() {
}

pollingDownloading = setTimeout( function () {
cloneBackupDownloadPolling( pSiteId );
cloneBackupDownloadPolling( pSiteId, pFile );
}, 1000 );
}
}( siteId ), 'json' );
}( siteId, pFile ), 'json' );
};

cloneBackupFinishied = function ( resp, pSiteId, pSiteName ) {
backupCreationFinished = true;
clearTimeout( pollingCreation );

var progressBar = jQuery( '#mainwp-child-clone-create-progress' );
progressBar.progressbar( 'value', parseFloat( progressBar.progressbar( 'option', 'max' ) ) );

if ( resp.error ) {
handleCloneError( resp );
return;
}
updateClonePopup( mwp_sprintf( translations['backup_created'], pSiteName, (resp.size / 1024).toFixed( 2 ) ) );
cloneInitiateBackupDownload( pSiteId, resp.url, resp.size );
};

cloneInitiateExtractBackup = function ( file ) {
Expand Down
Loading

0 comments on commit 958ba1a

Please sign in to comment.