Skip to content

Commit

Permalink
Merge pull request #27 from mainwp/thang
Browse files Browse the repository at this point in the history
Thang
  • Loading branch information
thanghv authored Feb 25, 2020
2 parents fbc6ad0 + 14e9fd3 commit 501137f
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 25 deletions.
6 changes: 4 additions & 2 deletions class/class-mainwp-child-skeleton-key.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ function mainwp_skeleton_key_handle_fatal_error() {
$error = error_get_last();
if ( isset( $error['type'] ) && in_array($error['type'], array(1, 4, 16, 64, 256) ) && isset( $error['message'] ) ) {
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
} else {
MainWP_Helper::write( MainWP_Child_Skeleton_Key::$information );
}
// to fix issue double <mainwp></mainwp> header in response
// else {
// MainWP_Helper::write( MainWP_Child_Skeleton_Key::$information );
// }
}

register_shutdown_function( 'mainwp_skeleton_key_handle_fatal_error' );
Expand Down
98 changes: 82 additions & 16 deletions class/class-mainwp-child-wordfence.php
Original file line number Diff line number Diff line change
Expand Up @@ -1282,53 +1282,119 @@ function save_settings_new()

// if saving then validate data
if (in_array('apiKey', $saving_opts)) {

$apiKey = trim( $_POST['apiKey'] );
if ( ! $apiKey ) { //Empty API key (after trim above), then try to get one.
$apiKey = strtolower(trim($apiKey));
$existingAPIKey = wfConfig::get('apiKey', '');



$ping = false;
if ( empty( $apiKey ) && empty($existingAPIKey) ) { // then try to get one.

$api = new wfAPI( '', wfUtils::getWPVersion() );
try {
$keyData = $api->call( 'get_anon_api_key' );
if ( $keyData['ok'] && $keyData['apiKey'] ) {
wfConfig::set( 'apiKey', $keyData['apiKey'] );
wfConfig::set( 'isPaid', 0 );
$result['apiKey'] = $keyData['apiKey'];
wfConfig::set('keyType', wfAPI::KEY_TYPE_FREE);
wordfence::licenseStatusChanged();
$result['apiKey'] = $apiKey = $keyData['apiKey'];
$result['isPaid'] = 0;
$reload = 'reload';
} else {
throw new Exception( "We could not understand the Wordfence server's response because it did not contain an 'ok' and 'apiKey' element." );
throw new Exception("The Wordfence server's response did not contain the expected elements.");
}
} catch ( Exception $e ) {
$result['error'] = 'Your options have been saved, but we encountered a problem. You left your API key blank, so we tried to get you a free API key from the Wordfence servers. However we encountered a problem fetching the free key: ' . htmlentities( $e->getMessage() );

$result['error'] = 'Your options have been saved, but you left your license key blank, so we tried to get you a free license key from the Wordfence servers. There was a problem fetching the free key: ' . wp_kses( $e->getMessage(), array() );
return $result;
}
} else if ( wfConfig::get( 'apiKey' ) !== $apiKey ) {

} else if ( !empty( $apiKey ) && $existingAPIKey != $apiKey ) {
$api = new wfAPI( $apiKey, wfUtils::getWPVersion() );
try {
$res = $api->call( 'check_api_key', array(), array() );
$res = $api->call('check_api_key', array(), array('previousLicense' => $existingAPIKey));
if ( $res['ok'] && isset( $res['isPaid'] ) ) {
wfConfig::set( 'apiKey', $apiKey );
wfConfig::set( 'isPaid', $res['isPaid'] ); //res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools.

// wfConfig::set( 'apiKey', $apiKey );
// wfConfig::set( 'isPaid', $res['isPaid'] ); //res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools.
// $result['apiKey'] = $apiKey;
// $result['isPaid'] = $res['isPaid'];
// if ( $res['isPaid'] ) {
// $result['paidKeyMsg'] = true;
// }

$isPaid = wfUtils::truthyToBoolean($res['isPaid']);
wfConfig::set('apiKey', $apiKey);
wfConfig::set('isPaid', $isPaid); //res['isPaid'] is boolean coming back as JSON and turned back into PHP struct. Assuming JSON to PHP handles bools.
wordfence::licenseStatusChanged();
if (!$isPaid) {
wfConfig::set('keyType', wfAPI::KEY_TYPE_FREE);
}


$result['apiKey'] = $apiKey;
$result['isPaid'] = $res['isPaid'];
if ( $res['isPaid'] ) {
$result['isPaid'] = $isPaid;
if ( $isPaid ) {
$result['paidKeyMsg'] = true;
}

$ping = true;
$reload = 'reload';
} else {
throw new Exception( 'We could not understand the Wordfence API server reply when updating your API key.' );
}
} catch ( Exception $e ) {
$result['error'] = 'Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );

return $result;
}
} else {
$ping = true;
$apiKey = $existingAPIKey;
}

if ( $ping ) {

$api = new wfAPI($apiKey, wfUtils::getWPVersion());
try {
$api = new wfAPI( $apiKey, wfUtils::getWPVersion() );
$res = $api->call( 'ping_api_key', array(), array() );
} catch ( Exception $e ) {
$result['error'] = 'Your options have been saved. However we noticed you do not change your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );
$keyType = wfAPI::KEY_TYPE_FREE;
$keyData = $api->call('ping_api_key', array(), array('supportHash' => wfConfig::get('supportHash', ''), 'whitelistHash' => wfConfig::get('whitelistHash', '')));
if (isset($keyData['_isPaidKey'])) {
$keyType = wfConfig::get('keyType');
}
if (isset($keyData['dashboard'])) {
wfConfig::set('lastDashboardCheck', time());
wfDashboard::processDashboardResponse($keyData['dashboard']);
}
if (isset($keyData['support']) && isset($keyData['supportHash'])) {
wfConfig::set('supportContent', $keyData['support']);
wfConfig::set('supportHash', $keyData['supportHash']);
}
if (isset($keyData['_whitelist']) && isset($keyData['_whitelistHash'])) {
wfConfig::setJSON('whitelistPresets', $keyData['_whitelist']);
wfConfig::set('whitelistHash', $keyData['_whitelistHash']);
}
if (isset($keyData['scanSchedule']) && is_array($keyData['scanSchedule'])) {
wfConfig::set_ser('noc1ScanSchedule', $keyData['scanSchedule']);
if (wfScanner::shared()->schedulingMode() == wfScanner::SCAN_SCHEDULING_MODE_AUTOMATIC) {
wfScanner::shared()->scheduleScans();
}
}

wfConfig::set('keyType', $keyType);

if (!isset($result['apiKey'])) {
$isPaid = ( $keyType == wfAPI::KEY_TYPE_FREE ) ? false : true;
$result['apiKey'] = $apiKey;
$result['isPaid'] = $isPaid;
if ( $isPaid ) {
$result['paidKeyMsg'] = true;
}
}

} catch ( Exception $e ) {
$result['error'] = 'Your options have been saved. However we tried to verify your license key with the Wordfence servers and received an error: ' . wp_kses($e->getMessage(), array()) ;
return $result;
}
}
Expand Down
23 changes: 19 additions & 4 deletions class/class-mainwp-child.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
@error_reporting( E_ALL );
@ini_set( 'display_errors', TRUE );
@ini_set( 'display_startup_errors', TRUE );
} else {
if (isset($_REQUEST['mainwpsignature'])) {
@ini_set( 'display_errors', FALSE );
@error_reporting( 0 );
}
}

define( 'MAINWP_CHILD_NR_OF_COMMENTS', 50 );
Expand Down Expand Up @@ -112,7 +117,7 @@ function wp_verify_nonce( $nonce, $action = - 1 ) {
}

class MainWP_Child {
public static $version = '4.0.6.2';
public static $version = '4.0.7';
private $update_version = '1.5';

private $callableFunctions = array(
Expand Down Expand Up @@ -750,7 +755,7 @@ function admin_menu() {
}
self::$subPages = $sub_pages;
self::$subPagesLoaded = true;
MainWP_Helper::update_option( 'mainwp_child_subpages', self::$subPages );
//MainWP_Helper::update_option( 'mainwp_child_subpages', self::$subPages ); // to fix error for some case
}
add_action( 'mainwp-child-pageheader', array( __CLASS__, 'render_header' ) );
add_action( 'mainwp-child-pagefooter', array( __CLASS__, 'render_footer' ) );
Expand Down Expand Up @@ -2481,7 +2486,7 @@ function newPost() {
$information['link'] = $res['link'];

do_action('mainwp_child_after_newpost', $res);

MainWP_Helper::write( $information );
}

Expand Down Expand Up @@ -3783,10 +3788,20 @@ function getSiteStats( $information = array(), $exit = true ) {
$information['plugin_updates'] = array();
}
foreach( $cached_plugins_update as $slug => $plugin_update ) {

// to fix incorrect info
if ( !property_exists( $plugin_update, 'new_version' ) || empty( $plugin_update->new_version ) ) {
if ( !property_exists( $plugin_update, 'new_version' ) || empty( $plugin_update->new_version ) ) { // may do not need to check this?
// to fix for some premiums update info
if ( property_exists( $plugin_update, 'update' ) ) {
if ( !property_exists( $plugin_update->update, 'new_version' ) || empty( $plugin_update->update->new_version ) ) {
continue;
}
} else {
continue;
}

}

if ( !isset( $information['plugin_updates'][ $slug ] ) ) {
$information['plugin_updates'][ $slug ] = $plugin_update;
}
Expand Down
4 changes: 3 additions & 1 deletion class/class-mainwp-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ static function createPost( $new_post, $post_custom, $post_category, $post_featu
//Save the post to the wp
remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); // to fix brake scripts or html
$post_status = $new_post['post_status'];
$new_post['post_status'] = 'auto-draft';
$new_post['post_status'] = 'auto-draft'; // child reports: to logging as created post

// update post
if ( $edit_post_id ) {
Expand All @@ -572,6 +572,7 @@ static function createPost( $new_post, $post_custom, $post_category, $post_featu
if ( $current_post && ( ( !isset( $new_post['post_type'] ) && $current_post->post_type == 'post' ) || ( isset( $new_post['post_type'] ) && $new_post['post_type'] == $current_post->post_type ) ) ) {
$new_post['ID'] = $edit_post_id;
}
$new_post['post_status'] = $post_status; // child reports: to logging as update post
}

$new_post_id = wp_insert_post( $new_post, $wp_error );
Expand All @@ -584,6 +585,7 @@ static function createPost( $new_post, $post_custom, $post_category, $post_featu
return array( 'error' => 'Empty post id');
}

if ( !$edit_post_id )
wp_update_post( array( 'ID' => $new_post_id, 'post_status' => $post_status ) );

if ( ! empty( $terms ) ) {
Expand Down
2 changes: 1 addition & 1 deletion mainwp-child.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Author: MainWP
Author URI: https://mainwp.com
Text Domain: mainwp-child
Version: 4.0.6.2
Version: 4.0.7
*/
include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress

Expand Down
13 changes: 12 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Plugin URI: https://mainwp.com
Requires at least: 3.6
Tested up to: 5.3.2
Requires PHP: 5.6
Stable tag: 4.0.6.2
Stable tag: 4.0.7
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -71,6 +71,17 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m

== Changelog ==

= 4.0.7 - 2-25-20 =
* Fixed: an issue with saving Bulk Setting Manager keys
* Fixed: an issue with saving Wordfence extension settings
* Fixed: an issue with overwriting PHP error reporting configuration
* Added: pull request #9 to add an action to allow additional post customization when a new post is created - Thanks [joshlabau](https://github.com/joshlabau)
* Added: pull request #13 to replace __autoload() with spl_autoload_register - Thanks [Christian Foellmann](https://github.com/cfoellmann)
* Added: pull request #23 to fix a typo - Thanks [Marco Frodl](https://github.com/marcofrodl)
* Added: pull request #24 to prevent overwriting PHP error reporting configuration - Thanks [Stanislav Khromov](https://github.com/khromov)
* Updated: improved premium plugins and themes updates detection system
* Removed: unused database options

= 4.0.6.2 - 2-3-20 =
* Fixed: connection problems caused by issues with json_encode function

Expand Down

0 comments on commit 501137f

Please sign in to comment.