Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a44c543
Merge branch 'release/1.14.12' into develop
sumaisa-mou Mar 5, 2025
a96a7a0
Alert WP Admins When Transactional Email Is Disabled After Failure
sumaisa-mou Apr 11, 2025
e6c3813
Fix phpcs
sumaisa-mou Apr 11, 2025
a99dc46
Merge pull request #363 from weMail/feature/alert-wp-admins-on-email-…
sumaisa-mou Apr 11, 2025
063cd8b
Handle permission for new endpoint
sumaisa-mou Apr 15, 2025
861911d
Added functionality to send transaction disable notification emails t…
sumaisa-mou Apr 15, 2025
a9fde0d
Merge branch 'release/1.14.13'
sumaisa-mou Apr 15, 2025
044cef0
Merge branch 'release/1.14.13' into develop
sumaisa-mou Apr 15, 2025
9ab6eb3
Fix vulnerability issue.
sumaisa-mou Apr 24, 2025
18625b1
Fix phpcs.
sumaisa-mou Apr 25, 2025
85862f1
Merge pull request #364 from weMail/hotfix/fix-vulnerability-issue
sumaisa-mou Apr 25, 2025
4b0976e
Merge branch 'master' into develop
sumaisa-mou Apr 25, 2025
b74b730
Fix vulnerability issue.
sumaisa-mou Apr 25, 2025
0bae9c8
Merge branch 'release/1.14.14'
sumaisa-mou Apr 25, 2025
ff36489
Merge branch 'release/1.14.14' into develop
sumaisa-mou Apr 25, 2025
264020c
chore: update league/csv to version 9.8
sumaisa-mou Jun 24, 2025
d88c2e3
Refactor
sumaisa-mou Jun 24, 2025
7a59d02
Fix phpcs
sumaisa-mou Jun 24, 2025
2b03acb
Fix phpcs
sumaisa-mou Jun 24, 2025
b3da424
Refactor
sumaisa-mou Jun 24, 2025
cb0292d
Fix phpcs
sumaisa-mou Jun 24, 2025
bce2a3c
Merge pull request #365 from weMail/hotfix/fix-csv-import-issue
sumaisa-mou Jun 24, 2025
c18d081
fix: Resolved CSV import issues on PHP 8.1 and 8.2
sumaisa-mou Jun 24, 2025
3bfa4a5
Merge branch 'release/1.14.15'
sumaisa-mou Jun 24, 2025
e111fcd
Merge branch 'release/1.14.15' into develop
sumaisa-mou Jun 24, 2025
c8875ad
Merge branch 'develop' into feature/saas-new-onboarding
bdmehedi Jun 26, 2025
8251659
Merge branch 'master' into develop
bdmehedi Jun 26, 2025
07dfd84
Merge branch 'develop' into feature/saas-new-onboarding
bdmehedi Jun 26, 2025
79ff7b2
Old plugin version compatibility
bdmehedi Jul 21, 2025
1d0e65a
phpcs fixed
bdmehedi Jul 21, 2025
6988f91
Fixed phpcs
bdmehedi Jul 21, 2025
aeeacce
Fixed phpcs
bdmehedi Jul 21, 2025
2882038
Fixed phpcs
bdmehedi Jul 21, 2025
cd2218d
Fixed sanitization, pull and patch request in proxy
bdmehedi Jul 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.3"
php-version: "7.4"
coverage: none
tools: composer, cs2pr

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"require": {
"php": ">=5.5",
"league/csv": "^7.2",
"league/csv": "9.8",
"appsero/client": "v2.0.4"
},
"require-dev": {
Expand Down
179 changes: 110 additions & 69 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion includes/Admin/Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function connect_notice() {
update_option( 'wemail_site_connection_notice', 1 );
}
}
if ( ! get_user_meta( get_current_user_id(), 'wemail_api_key', true ) && (int) get_option( 'wemail_site_connection_notice' ) !== 1 && ! ( isset( $_GET['page'] ) && $_GET['page'] === 'wemail' ) ) {
if ( ! get_option( 'wemail_api_key' ) && (int) get_option( 'wemail_site_connection_notice' ) !== 1 && ! ( isset( $_GET['page'] ) && $_GET['page'] === 'wemail' ) ) {
add_action( 'admin_notices', array( $this, 'connect_notice_html' ) );
}
}
Expand Down
3 changes: 2 additions & 1 deletion includes/Admin/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
public function enqueue_scripts() {
wp_enqueue_media();

wp_register_script( 'wemail-tiny-mce', site_url( '/wp-includes/js/tinymce/tinymce.min.js' ), array(), true );

Check warning on line 67 in includes/Admin/Scripts.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

In footer ($in_footer) is not set explicitly wp_register_script; It is recommended to load scripts in the footer. Please set this value to `true` to load it in the footer, or explicitly `false` if it should be loaded in the header.
wp_register_script( 'wemail-tiny-mce-code', wemail()->wemail_cdn . '/vendor/tinymce/plugins/code/plugin.min.js', array( 'wemail-tiny-mce' ), $this->version, true );
wp_register_script( 'wemail-tiny-mce-hr', wemail()->wemail_cdn . '/vendor/tinymce/plugins/hr/plugin.min.js', array( 'wemail-tiny-mce-code' ), $this->version, true );

Expand Down Expand Up @@ -139,7 +139,8 @@
'user' => array(
'hash' => $user->hash,
'role' => $user->role,
'permissions' => $user->permissions,
'allowed' => $user->allowed,
// 'permissions' => $user->permissions,
),
'currentUser' => $current_user ? array(
'name' => $current_user->display_name,
Expand Down
41 changes: 32 additions & 9 deletions includes/Core/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ public function has_api_key() {
return (bool) $this->api_key;
}

/**
* Added url
*
* @param [string] $url
* @return void
*/
public function url( $url ) {
$this->url = $url;
return $this;
}

/**
* Magic method to set resource and endpoints
*
Expand Down Expand Up @@ -367,7 +378,25 @@ public function send_json( $json = true ) {
* @return mixed
*/
public function put( $data, $args = array() ) {
$data['_method'] = 'put';
$args = $this->args( $args );
$args['method'] = 'PUT';

return $this->post( $data, $args );
}

/**
* API - PATCH request caller
*
* @since 2.0.0
*
* @param array $data PUT data
* @param array $args wp_remote_request argument overrides
*
* @return mixed
*/
public function patch( $data, $args = array() ) {
$args = $this->args( $args );
$args['method'] = 'PATCH';

return $this->post( $data, $args );
}
Expand All @@ -385,15 +414,9 @@ public function put( $data, $args = array() ) {
public function delete( $data = array(), $args = array() ) {
$args = $this->args( $args );

$args['method'] = 'delete';
$args['method'] = 'DELETE';

$args['body'] = ! empty( $data ) ? $data : null;

$url = $this->build_url();

$response = wp_remote_request( $url, $args );

return $this->response( $response );
return $this->post( $data, $args );
}

/**
Expand Down
27 changes: 13 additions & 14 deletions includes/Core/User/Integrations/WpUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function wemail_user_profile_updated( $user_id, $old_user_data ) {
return;
}

$access_token = get_user_meta( $user_id, 'wemail_api_key', true );
$access_token = get_option( 'wemail_api_key' );

if ( empty( $access_token ) ) {
return;
Expand All @@ -56,7 +56,6 @@ public function wemail_user_profile_updated( $user_id, $old_user_data ) {
$data = array(
'name' => $user->data->display_name,
'email' => $user->data->user_email,
'token' => $access_token,
);

$response = wemail()->api->set_api_key( $access_token )->auth()->users()->profile()->update()->post( $data );
Expand All @@ -65,7 +64,7 @@ public function wemail_user_profile_updated( $user_id, $old_user_data ) {
return;
}

$this->update_user_permission( $access_token, $user_id );
// $this->update_user_permission( $access_token, $user_id );
}

/**
Expand Down Expand Up @@ -174,9 +173,9 @@ protected function create_wemail_user( $user, $role ) {
return;
}

update_user_meta( $user->ID, 'wemail_api_key', $response['access_token'] );
// update_user_meta( $user->ID, 'wemail_api_key', $response['access_token'] );

$this->update_user_permission( $response['access_token'], $user->ID );
// $this->update_user_permission( $response['access_token'], $user->ID );
}

/**
Expand All @@ -186,17 +185,17 @@ protected function create_wemail_user( $user, $role ) {
* @param $user_id
*/
protected function update_user_permission( $access_token, $user_id ) {
$api_key = apply_filters( 'wemail_api_key', $access_token );
$user_data = wemail()->api->set_api_key( $api_key )->auth()->users()->me()->query( array( 'include' => 'role,permissions' ) )->get();
// $api_key = apply_filters( 'wemail_api_key', $access_token );
// $user_data = wemail()->api->set_api_key( $api_key )->auth()->users()->me()->query( array( 'include' => 'role,permissions' ) )->get();

if ( is_wp_error( $user_data ) ) {
return;
}
// if ( is_wp_error( $user_data ) ) {
// return;
// }

if ( ! empty( $user_data['data'] ) ) {
$user_data = $user_data['data'];
// if ( ! empty( $user_data['data'] ) ) {
// $user_data = $user_data['data'];

update_user_meta( $user_id, 'wemail_user_data', $user_data );
}
// update_user_meta( $user_id, 'wemail_user_data', $user_data );
// }
}
}
64 changes: 28 additions & 36 deletions includes/Core/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
public $role = null;

/**
* User permissions
* Is user allowed to access weMail
*
* @since 1.0.0
* @since 1.14.16
*
* @var array
* @var boolean
*/
public $permissions = array();
public $allowed = false;

/**
* API resource query for URL to build
Expand All @@ -69,30 +69,14 @@
return;
}

// $api_key = get_user_meta( $user_id, 'wemail_api_key', true );

Check warning on line 72 in includes/Core/User/User.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 59% valid code; is this commented out code?
$api_key = get_option( 'wemail_api_key' );
$api_key = apply_filters( 'wemail_api_key', $api_key, $user_id );

if ( $api_key ) {
$user_data = get_user_meta( $user_id, 'wemail_user_data', true );
$this->check_user_role($user_id);
if ( ! $user_data ) {
$user_data = wemail()->api->wp()->users()->rolePermissions()->query( array( 'email' => $user_email ) )->get();

if ( is_wp_error( $user_data ) ) {
return;
}

if ( ! empty( $user_data['data'] ) ) {
$user_data = $user_data['data'];

update_user_meta( $user_id, 'wemail_user_data', $user_data );
}
}

$this->hash = $user_data['hash'];
$this->role = $user_data['role'];
$this->permissions = $user_data['permissions'];
$this->hash = $api_key ? true : false;
$this->role = wp_get_current_user()->roles;
$this->allowed = $this->check_user_role( $user_id );
}

$this->user_id = $user_id;
Expand All @@ -108,24 +92,32 @@
*
* @return bool
*/
public function can( $permission ) {

Check warning on line 95 in includes/Core/User/User.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $permission is never used
if ( $this->permissions && array_key_exists( $permission, $this->permissions ) ) {
return true;
}
// if ( $this->permissions && array_key_exists( $permission, $this->permissions ) ) {

Check warning on line 96 in includes/Core/User/User.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 50% valid code; is this commented out code?
// return true;
// }

return $this->check_user_role( $this->user_id );

return false;
// return false;

Check warning on line 102 in includes/Core/User/User.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 75% valid code; is this commented out code?
}

public function check_user_role($user_id)
{
$accessible_roles = get_option( 'wemail_accessible_roles' );
if (!empty(array_intersect(wp_get_current_user()->roles, $accessible_roles)) && empty($this->permissions)) {
delete_user_meta($user_id, 'wemail_user_data');
}
if (empty(array_intersect(wp_get_current_user()->roles, $accessible_roles))) {
if (get_user_meta( $user_id, 'wemail_user_data', true )) {
delete_user_meta($user_id, 'wemail_user_data');
public function check_user_role( $user_id ) {
$accessible_roles = get_option( 'wemail_accessible_roles', array() );
$current_roles = wp_get_current_user()->roles;

// Check if user has any accessible role
$has_accessible_role = ! empty( array_intersect( $current_roles, $accessible_roles ) );

if ( $has_accessible_role ) {
// User has accessible role - keep their data
return true;
} else {
// User doesn't have accessible role - delete their data
if ( get_user_meta( $user_id, 'wemail_user_data', true ) ) {
delete_user_meta( $user_id, 'wemail_user_data' );
}
return false;
}
}
}
2 changes: 1 addition & 1 deletion includes/Core/Users/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct() {
* @return array
*/
public function register_submenu( $menu_items, $capability ) {
if (wemail()->user->can('manage_settings') && in_array('administrator', wp_get_current_user()->roles, true) ) {
if ( wemail()->user->can( 'manage_settings' ) && in_array( 'administrator', wp_get_current_user()->roles, true ) ) {
$menu_items[] = array(
__( 'Teams', 'wemail' ),
$capability,
Expand Down
2 changes: 1 addition & 1 deletion includes/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
new FormIntegrations();
new SyncSubscriberWp();
new SyncSubscriberErp();
// new SyncWpUser();
// new SyncWpUser();

Check warning on line 19 in includes/Hooks.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

This comment is 67% valid code; is this commented out code?
new MailHooks();
Ecommerce::instance();
new SyncAffiliateWp();
Expand Down
20 changes: 11 additions & 9 deletions includes/Rest/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
$query = new WP_User_Query(
array(
'fields' => 'ID',
'meta_key' => 'wemail_api_key',

Check warning on line 94 in includes/Rest/Csv.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of meta_key, possible slow query.
'meta_value' => $api_key,

Check warning on line 95 in includes/Rest/Csv.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of meta_value, possible slow query.
)
);

Expand Down Expand Up @@ -120,10 +120,10 @@

$reader = $this->reader( $file_id );

$query = $reader->query();
$count = iterator_count( $reader );

$data = array(
'total' => iterator_count( $query ) - 1,
'total' => $count - 1, // Subtract 1 for header row
);

return new WP_REST_Response( $data, 200 );
Expand Down Expand Up @@ -155,14 +155,16 @@

$reader = $this->reader( $file_id );

$meta_fields = $reader->fetchOne();
$meta_fields = array_filter( $meta_fields );
$meta_fields = array_unique( $meta_fields );
// Set the header offset so records are returned as associative arrays
$reader->setHeaderOffset( 0 );

// Use Statement for offset/limit
$stmt = \League\Csv\Statement::create()
->offset( $offset )
->limit( $limit );

$subscribers = $reader
->setOffset( $offset + 1 ) // +1 to ignore the header
->setLimit( $limit )
->fetchAssoc( $meta_fields );
$records = $stmt->process( $reader ); // Iterator of associative arrays
$subscribers = iterator_to_array( $records );

$data = array(
'subscribers' => $subscribers,
Expand Down
45 changes: 45 additions & 0 deletions includes/Rest/Help/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use WeDevs\WeMail\RestController;
use WeDevs\WeMail\Core\Help\SystemInfo;
use WP_REST_Server;
use WP_User_Query;

class Help extends RestController {

Expand Down Expand Up @@ -60,6 +61,17 @@
),
)
);
register_rest_route(
$this->namespace,
$this->rest_base . '/admin/users',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'users' ),
'permission_callback' => array( $this, 'permission' ),
),
)
);
}

/**
Expand Down Expand Up @@ -112,4 +124,37 @@
)
);
}

public function users() {
$args = array(
'role' => 'administrator',
);

$users = get_users( $args );

$emails = array_map(
function ( $user ) {
return $user->user_email;
},
$users
);

return rest_ensure_response( $emails );
}

public function permission( $request ) {
$api_key = $request->get_header( 'X-WeMail-Key' );

if ( ! empty( $api_key ) ) {
$query = new WP_User_Query(
array(
'fields' => 'ID',
'meta_key' => 'wemail_api_key',

Check warning on line 152 in includes/Rest/Help/Help.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of meta_key, possible slow query.
'meta_value' => $api_key,

Check warning on line 153 in includes/Rest/Help/Help.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Detected usage of meta_value, possible slow query.
)
);
return (bool) $query->get_total();
}
return false;
}
}
Loading
Loading