Merge with branch01

This commit is contained in:
Thang Hoang Van 2018-11-14 21:33:36 +07:00
parent 214ac3046a
commit 6aa7538183
14 changed files with 583 additions and 509 deletions

View file

@ -176,7 +176,11 @@ class MainWP_Helper {
}
static function uploadFile( $file_url, $path, $file_name ) {
$file_name = sanitize_file_name( $file_name );
// to fix uploader extension rename htaccess file issue
if ( $file_name != '.htaccess' && $file_name != '.htpasswd' ) {
$file_name = sanitize_file_name( $file_name );
}
$full_file_name = $path . DIRECTORY_SEPARATOR . $file_name; //Local name
$response = wp_remote_get( $file_url, array(
@ -211,7 +215,7 @@ class MainWP_Helper {
static function createPost( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others = array() ) {
global $current_user;
/**
* Hook: `mainwp_before_post_update`
*
@ -222,7 +226,7 @@ class MainWP_Helper {
* @param string $post_category Post categories.
* @param string $post_tags Post tags.
*/
do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags );
// Options fields.
@ -236,7 +240,7 @@ class MainWP_Helper {
'async_css',
'defer_all_js',
);
$wprocket_activated = false;
if ( MainWP_Child_WP_Rocket::isActivated() ) {
if ( function_exists( 'get_rocket_option' ) ) {
@ -308,7 +312,7 @@ class MainWP_Helper {
}
// else {
// $new_post['post_status'] = 'publish';
// }
// }
}
$wpr_options = isset( $_POST['wpr_options'] ) ? $_POST['wpr_options'] : array();
@ -534,7 +538,7 @@ class MainWP_Helper {
$not_allowed[] = '_edit_post_status';
$post_to_only_existing_categories = false;
if (is_array($post_custom)) {
foreach ( $post_custom as $meta_key => $meta_values ) {
if ( ! in_array( $meta_key, $not_allowed ) ) {
@ -564,7 +568,7 @@ class MainWP_Helper {
}
}
}
// yoast seo extension
if ( $seo_ext_activated ) {
$_seo_opengraph_image = isset( $post_custom[ WPSEO_Meta::$meta_prefix . 'opengraph-image' ] ) ? $post_custom[ WPSEO_Meta::$meta_prefix . 'opengraph-image' ] : array();
@ -622,11 +626,11 @@ class MainWP_Helper {
if (isset($others['featured_image_data'])) {
$_image_data = $others['featured_image_data'];
update_post_meta( $upload['id'], '_wp_attachment_image_alt', $_image_data['alt'] );
wp_update_post( array( 'ID' => $upload['id'],
wp_update_post( array( 'ID' => $upload['id'],
'post_excerpt' => $_image_data['caption'],
'post_content' => $_image_data['description'],
'post_title' => $_image_data['title']
)
)
);
}
}
@ -959,11 +963,11 @@ class MainWP_Helper {
return $str;
}
public static function return_bytes( $val ) {
public static function return_bytes( $val ) {
$val = trim( $val );
$last = $val[ strlen( $val ) - 1 ];
$val = rtrim($val, $last);
$last = strtolower( $last );
$last = strtolower( $last );
switch ( $last ) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
@ -1192,7 +1196,7 @@ class MainWP_Helper {
public static function getRevisions( $max_revisions ) {
global $wpdb;
$sql = " SELECT `post_parent`, COUNT(*) cnt
FROM $wpdb->posts
FROM $wpdb->posts
WHERE `post_type` = 'revision'
GROUP BY `post_parent`
HAVING COUNT(*) > " . $max_revisions;
@ -1216,7 +1220,7 @@ class MainWP_Helper {
FROM $wpdb->posts
WHERE `post_parent`=" . $results[ $i ]->post_parent . "
AND `post_type`='revision'
ORDER BY `post_modified` ASC
ORDER BY `post_modified` ASC
";
$results_posts = $wpdb->get_results( $sql_get );
@ -1312,7 +1316,7 @@ class MainWP_Helper {
*/
static function remove_filters_with_method_name( $hook_name = '', $method_name = '', $priority = 0 ) {
global $wp_filter;
// Take only filters on right hook name and priority
if ( ! isset( $wp_filter[ $hook_name ][ $priority ] ) || ! is_array( $wp_filter[ $hook_name ][ $priority ] ) ) {
@ -1324,7 +1328,7 @@ static function remove_filters_with_method_name( $hook_name = '', $method_name =
if ( isset( $filter_array['function'] ) && is_array( $filter_array['function'] ) ) {
// Test if object is a class and method is equal to param !
if ( is_object( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) && $filter_array['function'][1] == $method_name ) {
// Test for WordPress >= 4.7 WP_Hook class
// Test for WordPress >= 4.7 WP_Hook class
if ( is_a( $wp_filter[ $hook_name ], 'WP_Hook' ) ) {
unset( $wp_filter[ $hook_name ]->callbacks[ $priority ][ $unique_id ] );
} else {
@ -1412,160 +1416,160 @@ static function remove_filters_with_method_name( $hook_name = '', $method_name =
if ( defined( 'MAINWP_NOSSL' ) ) return !MAINWP_NOSSL;
return function_exists( 'openssl_verify' );
}
public static function check_files_exists( $files = array(), $return = false ) {
public static function check_files_exists( $files = array(), $return = false ) {
$missing = array();
if (is_array($files)) {
if (is_array($files)) {
foreach($files as $name) {
if (!file_exists( $name )) {
$missing[] = $name;
}
}
$missing[] = $name;
}
}
} else {
if (!file_exists( $files )) {
$missing[] = $files;
$missing[] = $files;
}
}
if (!empty($missing)) {
$message = 'Missing file(s): ' . implode(',', $missing);
$message = 'Missing file(s): ' . implode(',', $missing);
if ($return)
return $message;
else
throw new Exception( $message );
throw new Exception( $message );
}
return true;
}
public static function check_classes_exists($classes = array(), $return = false) {
public static function check_classes_exists($classes = array(), $return = false) {
$missing = array();
if (is_array($classes)) {
if (is_array($classes)) {
foreach($classes as $name) {
if (!class_exists( $name )) {
$missing[] = $name;
$missing[] = $name;
}
}
}
} else {
if ( !class_exists($classes) )
$missing[] = $classes;
}
if ( !empty($missing) ) {
if ( !empty($missing) ) {
$message = 'Missing classes: ' . implode(',', $missing);
if ($return) {
return $message;
} else {
throw new Exception( $message );
throw new Exception( $message );
}
}
}
return true;
}
public static function check_methods($object, $methods = array(), $return = false) {
$missing = array();
if (is_array($methods)) {
$missing = array();
foreach($methods as $name) {
if ( !method_exists($object, $name) ) {
$missing[] = $name;
$missing[] = $name;
}
}
}
} else if (!empty($methods)) {
if ( !method_exists($object, $methods) )
$missing[] = $methods;
}
}
if ( !empty($missing) ) {
$message = 'Missing method: ' . implode(',', $missing);
if ($return) {
return $message;
} else {
throw new Exception( $message );
throw new Exception( $message );
}
}
return true;
}
public static function check_properties($object, $properties = array(), $return = false) {
$missing = array();
if (is_array($properties)) {
if (is_array($properties)) {
foreach($properties as $name) {
if ( !property_exists($object, $name) ) {
$missing[] = $name;
$missing[] = $name;
}
}
}
} else if (!empty($properties)) {
if ( !property_exists($object, $properties) )
$missing[] = $properties;
}
}
if ( !empty($missing) ) {
$message = 'Missing properties: ' . implode(',', $missing);
if ($return) {
return $message;
} else {
throw new Exception( $message );
throw new Exception( $message );
}
}
return true;
}
public static function check_functions($funcs = array(), $return = false) {
$missing = array();
if (is_array($funcs)) {
if (is_array($funcs)) {
foreach($funcs as $name) {
if ( !function_exists( $name) ) {
$missing[] = $name;
$missing[] = $name;
}
}
}
} else if (!empty($funcs)) {
if ( !function_exists($funcs) )
$missing[] = $funcs;
}
}
if ( !empty($missing) ) {
$message = 'Missing functions: ' . implode(',', $missing);
if ($return) {
return $message;
} else {
throw new Exception( $message );
throw new Exception( $message );
}
}
return true;
return true;
}
/**
* Handle fatal error for requests from the dashboard
* mwp_action requests
* wordpress_seo requests
* mwp_action requests
* wordpress_seo requests
* This will do not handle fatal error for sync request from the dashboard
*/
public static function handle_fatal_error() {
public static function handle_fatal_error() {
function handle_shutdown() {
// handle fatal errors and compile errors
$error = error_get_last();
if ( isset( $error['type'] ) && isset( $error['message'] ) &&
if ( isset( $error['type'] ) && isset( $error['message'] ) &&
( E_ERROR === $error['type'] || E_COMPILE_ERROR === $error['type'] )
)
)
{
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
}
}
}
if (isset($_POST['function']) && isset($_POST['mainwpsignature']) &&
(isset($_POST['mwp_action']) || 'wordpress_seo' == $_POST['function']) // wordpress_seo for Wordpress SEO
}
if (isset($_POST['function']) && isset($_POST['mainwpsignature']) &&
(isset($_POST['mwp_action']) || 'wordpress_seo' == $_POST['function']) // wordpress_seo for Wordpress SEO
) {
register_shutdown_function( 'handle_shutdown' );
}
}
}
}
}