n"; $mail .= '

' . $content . "

\r\n\r\n"; if ( ! empty( $from ) ) { $this->mail_from = $from; } add_filter( 'wp_mail_from', array( &$this, 'hook_wp_mail_from' ), 99 ); // to fix. $this->send_wp_mail( $email, $subject, $mail, $headers ); remove_filter( 'wp_mail_from', array( &$this, 'hook_wp_mail_from' ), 99 ); return true; } // phpcs:enable WordPress.Security.NonceVerification return false; } /** * Method hook_wp_mail_from() * * Hook hook_wp_mail. * * @param mixed $from_name From email. * * @return mixed $from_name From email. */ public function hook_wp_mail_from( $from_name ) { if ( ! empty( $from_name ) && ! empty( $this->mail_from ) ) { $from_name = $this->mail_from; } return $from_name; } /** * Method create_nonce_without_session() * * Create nonce without session. * * @param mixed $action Action to perform. * * @return string Custom nonce. */ public static function create_nonce_without_session( $action = - 1 ) { $user = wp_get_current_user(); $uid = (int) $user->ID; if ( ! $uid ) { $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); } $i = wp_nonce_tick(); return substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 ); } /** * Method verify_nonce_without_session() * * Verify nonce without session. * * @param string $nonce Nonce to verify. * @param mixed $action Action to perform. * * @return mixed If verified return 1 or 2, if not return false. */ public static function verify_nonce_without_session( $nonce, $action = - 1 ) { //phpcs:ignore -- NOSONAR - multi return. $nonce = (string) $nonce; $user = wp_get_current_user(); $uid = (int) $user->ID; if ( ! $uid ) { $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); } if ( empty( $nonce ) ) { return false; } $i = wp_nonce_tick(); $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 ); if ( hash_equals( $expected, $nonce ) ) { return 1; } $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 ); if ( hash_equals( $expected, $nonce ) ) { return 2; } return false; } /** * Method hook_get_ping_nonce() * * Get mainwp ping nonce. * * @return string nonce. */ public static function hook_get_ping_nonce() { return get_option( 'mainwp_child_pingnonce' ); } /** * Method hook_create_nonce_action() * * Create nonce without session and user id. * * @param bool $false_value Boolean value, it should always be FALSE. * @param mixed $action Action to perform. * * @return string Custom nonce. */ public static function hook_create_nonce_action( $false_value, $action = - 1 ) { unset( $false_value ); $data = array( 'action' => $action, 'nonce' => static::create_nonce_action( $action ), ); return rawurlencode( wp_json_encode( $data ) ); } /** * Method create_nonce_action() * * Create nonce without session and user id. * * @param mixed $action Action to perform. * * @return string Custom nonce. */ public static function create_nonce_action( $action = - 1 ) { $i = wp_nonce_tick(); return substr( wp_hash( $i . '|' . $action, 'nonce' ), - 12, 10 ); } /** * Method hook_verify_authed_action_nonce() * * Verify nonce without session and user id. * * @param bool $false_value Boolean value, it should always be FALSE. * @param string $act_nonce Nonce action to verify. * * @return mixed If verified return 1 or 2, if not return false. */ public static function hook_verify_authed_action_nonce( $false_value, $act_nonce = '' ) { unset( $false_value ); return static::verify_action_nonce( $act_nonce ); } /** * Method verify_action_nonce() * * Verify nonce without session and user id. * * @param string $act_nonce Nonce action to verify. * * @return mixed If verified return 1 or 2, if not return false. */ public static function verify_action_nonce( $act_nonce = '' ) { //phpcs:ignore -- NOSONAR - multi return. if ( empty( $act_nonce ) || ! is_string( $act_nonce ) ) { return false; } if ( false !== stripos( $act_nonce, '\\\\\\' ) ) { // find "\\\" if existed. $act_nonce = wp_unslash( $act_nonce ); // unslash twice. } $data = rawurldecode( wp_unslash( $act_nonce ) ); if ( empty( $data ) || ! is_string( $data ) ) { return false; } $data = json_decode( $data, true ); if ( ! is_array( $data ) || empty( $data['action'] ) || empty( $data['nonce'] ) ) { return false; } return static::verify_authed_nonce( $data['nonce'], $data['action'] ); } /** * Method verify_authed_nonce() * * Verify nonce without session and user id. * * @param string $nonce Nonce to verify. * @param mixed $action Action to perform. * * @return mixed If verified return 1 or 2, if not return false. */ public static function verify_authed_nonce( $nonce, $action = - 1 ) { //phpcs:ignore -- NOSONAR - multi return. $nonce = (string) $nonce; if ( empty( $nonce ) ) { return false; } $user = wp_get_current_user(); $uid = (int) $user->ID; if ( ! $uid ) { return false; } $i = wp_nonce_tick(); $expected = substr( wp_hash( $i . '|' . $action, 'nonce' ), - 12, 10 ); if ( hash_equals( $expected, $nonce ) ) { return 1; } $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action, 'nonce' ), - 12, 10 ); if ( hash_equals( $expected, $nonce ) ) { return 2; } return false; } /** * Method update_lasttime_backup() * * Update the last backup timestap. * * @param string $by Selected backup system. * @param string $time Time of the backup exacution. * * @return bool true|false If updated, return true, if the last backup time not updated, return false. */ public static function update_lasttime_backup( $by, $time ) { $backup_by = array( 'backupbuddy', 'backupwordpress', 'backwpup', 'updraftplus', 'wptimecapsule', 'wpvivid' ); if ( ! in_array( $by, $backup_by ) ) { return false; } $lasttime = get_option( 'mainwp_lasttime_backup_' . $by ); if ( $time > $lasttime ) { update_option( 'mainwp_lasttime_backup_' . $by, $time ); } return true; } /** * Method get_lasttime_backup() * * Get the last backup timestap. * * @param string $by Selected backup system. * * @return mixed If activated any of the supported backup systems, return the last backup timestamp. */ public static function get_lasttime_backup( $by ) { // phpcs:ignore -- NOSONAR - required to achieve desired results, pull request solutions appreciated. if ( 'backupwp' === $by ) { $by = 'backupwordpress'; } $activated = true; switch ( $by ) { case 'backupbuddy': if ( ! is_plugin_active( 'backupbuddy/backupbuddy.php' ) && ! is_plugin_active( 'Backupbuddy/backupbuddy.php' ) ) { $activated = false; } break; case 'backupwordpress': if ( ! is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) { $activated = false; } break; case 'backwpup': if ( ! is_plugin_active( 'backwpup/backwpup.php' ) && ! is_plugin_active( 'backwpup-pro/backwpup.php' ) ) { $activated = false; } break; case 'updraftplus': if ( ! is_plugin_active( 'updraftplus/updraftplus.php' ) ) { $activated = false; } break; case 'wptimecapsule': if ( ! is_plugin_active( 'wp-time-capsule/wp-time-capsule.php' ) ) { $activated = false; } break; case 'wpvivid': if ( ! is_plugin_active( 'wpvivid-backuprestore/wpvivid-backuprestore.php' ) ) { $activated = false; } break; default: $activated = false; break; } if ( ! $activated ) { return false; } return get_option( 'mainwp_lasttime_backup_' . $by, 0 ); } /** * Method remove_filters_by_hook_name() * * Remove filters with method name. * * @param string $hook_name Contains the hook name. * @param int $priority Contains the priority value. * * @return bool Return false if filtr is not set. */ public static function remove_filters_by_hook_name( $hook_name = '', $priority = 0 ) { /** * WordPress filter array. * * @global array $wp_filter WordPress filter array. */ 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 ] ) ) { return false; } // Loop on filters registered. foreach ( (array) $wp_filter[ $hook_name ][ $priority ] as $unique_id => $filter_array ) { // Test if filter is an object (suppoted object only). if ( isset( $filter_array['function'] ) && is_object( $filter_array['function'] ) ) { // 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 { unset( $wp_filter[ $hook_name ][ $priority ][ $unique_id ] ); } } } return false; } /** * Get an array of user roles * * @return array */ public function get_roles() { $wp_roles = new \WP_Roles(); $roles = array(); foreach ( $wp_roles->get_names() as $role => $label ) { if ( is_string( $label ) ) { $roles[ $role ] = translate_user_role( $label ); } } return $roles; } /** * Method maybe_base64_decode() * * Maybe base64 decode string. * * @param string $str input string. * * @return string $decoded Maybe base64 decode string. */ public function maybe_base64_decode( $str ) { $decoded = base64_decode( $str ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- Required for backwards compatibility. $Str1 = preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $decoded ); if ( $Str1 !== $decoded || '' === $Str1 ) { return $str; } return $decoded; } /** * Method esc_content() * * Escape content, * allowed content (a,href,title,br,em,strong,p,hr,ul,ol,li,h1,h2 ... ). * * @param mixed $content Content to escape. * @param string $type Type of content. Default = note. * @param mixed $more_allowed input allowed tags - options. * * @return string Filtered content containing only the allowed HTML. */ public static function esc_content( $content, $type = 'note', $more_allowed = array() ) { if ( ! is_string( $content ) ) { return $content; } if ( 'note' === $type ) { $allowed_html = array( 'a' => array( 'href' => array(), 'title' => array(), ), 'br' => array(), 'em' => array(), 'strong' => array(), 'p' => array(), 'hr' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(), 'h1' => array(), 'h2' => array(), ); if ( is_array( $more_allowed ) && ! empty( $more_allowed ) ) { $allowed_html = array_merge( $allowed_html, $more_allowed ); } $content = wp_kses( $content, $allowed_html ); } elseif ( 'mixed' === $type ) { $allowed_html = array( 'a' => array( 'href' => array(), 'title' => array(), 'class' => array(), 'onclick' => array(), ), 'img' => array( 'src' => array(), 'title' => array(), 'class' => array(), 'onclick' => array(), 'alt' => array(), 'width' => array(), 'height' => array(), 'sizes' => array(), 'srcset' => array(), 'usemap' => array(), ), 'br' => array(), 'em' => array(), 'strong' => array(), 'p' => array(), 'hr' => array(), 'ul' => array( 'style' => array(), ), 'ol' => array(), 'li' => array(), 'h1' => array(), 'h2' => array(), 'head' => array(), 'html' => array( 'lang' => array(), ), 'meta' => array( 'name' => array(), 'http-equiv' => array(), 'content' => array(), 'charset' => array(), ), 'title' => array(), 'body' => array( 'style' => array(), ), 'span' => array( 'id' => array(), 'style' => array(), 'class' => array(), ), 'form' => array( 'id' => array(), 'method' => array(), 'action' => array(), 'onsubmit' => array(), ), 'table' => array( 'class' => array(), ), 'thead' => array( 'class' => array(), ), 'tbody' => array( 'class' => array(), ), 'tr' => array( 'id' => array(), ), 'td' => array( 'class' => array(), ), 'div' => array( 'id' => array(), 'style' => array(), 'class' => array(), ), 'input' => array( 'type' => array(), 'name' => array(), 'class' => array(), 'value' => array(), 'onclick' => array(), ), 'button' => array( 'type' => array(), 'name' => array(), 'value' => array(), 'class' => array(), 'title' => array(), 'onclick' => array(), ), ); if ( is_array( $more_allowed ) && ! empty( $more_allowed ) ) { $allowed_html = array_merge( $allowed_html, $more_allowed ); } $content = wp_kses( $content, $allowed_html ); } else { $content = wp_kses_post( $content ); } return $content; } /** * Encrypt or Decrypt. * * @param string $str String input. * @param bool $encrypt True to encrypt, FAlSE to decrypt. * * @return string Encrypted string. */ public static function encrypt_decrypt( $str, $encrypt = true ) { $pass = wp_salt( 'auth' ); if ( $encrypt ) { $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) ); $stra = str_split( $str ); foreach ( $stra as $k => $v ) { $tmp = ord( $v ) + ord( $pass[ $k ] ); $stra[ $k ] = chr( 255 < $tmp ? ( $tmp - 256 ) : $tmp ); } return base64_encode( join( '', $stra ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. } else { $str = base64_decode( $str ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) ); $stra = str_split( $str ); foreach ( $stra as $k => $v ) { $tmp = ord( $v ) - ord( $pass[ $k ] ); $stra[ $k ] = chr( 0 > $tmp ? ( $tmp + 256 ) : $tmp ); } return join( '', $stra ); } } /** * Merge values from right array to left array. * * @param array $left_array left array. * @param array $right_array right array. * * @return array $result result array. */ public static function right_array_merge( $left_array, $right_array ) { if ( ! is_array( $left_array ) || ! is_array( $right_array ) ) { return array(); } $result = array_intersect_key( $right_array, $left_array ); return array_merge( $left_array, $result ); } }