mirror of
https://ghproxy.net/https://github.com/elementor/activity-log.git
synced 2025-10-04 01:30:46 +08:00
Internal: Add SM & IO PLG [ED-15944] (#216)
Co-authored-by: ariel Klikstein <ariel@elementor.com>
This commit is contained in:
parent
1756c28078
commit
e1feb4f7f3
2 changed files with 261 additions and 6 deletions
|
@ -13,6 +13,8 @@ class AAL_Activity_Log_List_Table extends WP_List_Table {
|
|||
|
||||
protected $_allow_caps = array();
|
||||
|
||||
protected $data_types = array();
|
||||
|
||||
protected function _get_allow_caps() {
|
||||
if ( empty( $this->_allow_caps ) ) {
|
||||
$user = get_user_by( 'id', get_current_user_id() );
|
||||
|
@ -193,6 +195,133 @@ class AAL_Activity_Log_List_Table extends WP_List_Table {
|
|||
);
|
||||
}
|
||||
|
||||
public function display_rows() {
|
||||
foreach ( $this->items as $item ) {
|
||||
$this->single_row( $item );
|
||||
|
||||
$this->maybe_promotion_row( $item->object_type );
|
||||
}
|
||||
}
|
||||
|
||||
private function maybe_promotion_row( $object_type ) {
|
||||
static $promotion_printed = [
|
||||
'emails' => false,
|
||||
'attachments' => false,
|
||||
];
|
||||
|
||||
$object_type = strtolower( $object_type );
|
||||
|
||||
if ( ! isset( $promotion_printed[ $object_type ] ) || $promotion_printed[ $object_type ] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$promotion_printed[ $object_type ] = true;
|
||||
|
||||
$promotion_html = $this->get_promotion_html_by_object_type( $object_type );
|
||||
|
||||
if ( empty( $promotion_html ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dismiss_button = sprintf(
|
||||
'<button class="aal-promotion-dismiss">%s</button>',
|
||||
esc_html__( 'Dismiss', 'aryo-activity-log' )
|
||||
);
|
||||
|
||||
printf(
|
||||
'<tr class="aal-table-promotion-row" data-promotion-id="%s" data-nonce="%s"><td colspan="' . count( $this->get_columns() ) . '"><div class="aal-table-promotion-inner">%s%s</div></td></tr>',
|
||||
esc_attr( $object_type ),
|
||||
wp_create_nonce( 'aal_promotion' ),
|
||||
$promotion_html,
|
||||
$dismiss_button
|
||||
);
|
||||
}
|
||||
|
||||
private function get_promotion_html_by_object_type( $object_type ) {
|
||||
if ( ! current_user_can( 'install_plugins' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->is_user_promotion_viewed( $object_type ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'emails' === $object_type ) {
|
||||
$plugin_file_path = 'site-mailer/site-mailer.php';
|
||||
$plugin_slug = 'site-mailer';
|
||||
|
||||
$cta_data = $this->get_plugin_cta_data( $plugin_slug, $plugin_file_path );
|
||||
if ( empty( $cta_data ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$title = sprintf( '<strong>%s</strong>', esc_html__( 'Ensure your emails avoid the spam folder!', 'aryo-activity-log' ) );
|
||||
$body = esc_html__( 'Use Site Mailer for improved email deliverability, detailed email logs, and an easy setup.', 'aryo-activity-log' );
|
||||
|
||||
return sprintf(
|
||||
'<div class="aal-promotion">%s %s<a class="aal-promotion-cta" href="%s">%s</a></div>',
|
||||
$title,
|
||||
$body,
|
||||
$cta_data['url'],
|
||||
$cta_data['text']
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'attachments' === $object_type ) {
|
||||
$plugin_file_path = 'image-optimization/image-optimization.php';
|
||||
$plugin_slug = 'image-optimization';
|
||||
|
||||
$cta_data = $this->get_plugin_cta_data( $plugin_slug, $plugin_file_path );
|
||||
if ( empty( $cta_data ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$title = sprintf( '<strong>%s</strong>', esc_html__( 'Optimize Your Images for a Faster Website!', 'aryo-activity-log' ) );
|
||||
$body = esc_html__( 'Reduce image sizes without losing quality and improve your site speed.', 'aryo-activity-log' );
|
||||
|
||||
return sprintf(
|
||||
'<div class="aal-promotion">%s %s<a class="aal-promotion-cta" href="%s">%s</a></div>',
|
||||
$title,
|
||||
$body,
|
||||
$cta_data['url'],
|
||||
$cta_data['text']
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function is_user_promotion_viewed( $promotion_id ) {
|
||||
$is_viewed = get_user_meta( get_current_user_id(), "_aal_promotion_{$promotion_id}_notice_viewed", true );
|
||||
|
||||
return ! empty( $is_viewed );
|
||||
}
|
||||
|
||||
private function get_plugin_cta_data( $plugin_slug, $plugin_file_path ) {
|
||||
if ( is_plugin_active( $plugin_file_path ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->is_plugin_installed( $plugin_file_path ) ) {
|
||||
$url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $plugin_file_path . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $plugin_file_path );
|
||||
$cta_text = esc_html__( 'Activate Plugin', 'elementor' );
|
||||
} else {
|
||||
$url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $plugin_slug ), 'install-plugin_' . $plugin_slug );
|
||||
$cta_text = esc_html__( 'Install Plugin', 'elementor' );
|
||||
}
|
||||
|
||||
return [
|
||||
'url' => $url,
|
||||
'text' => $cta_text,
|
||||
];
|
||||
}
|
||||
|
||||
private function is_plugin_installed( $plugin_slug ) {
|
||||
$plugins = get_plugins();
|
||||
|
||||
return isset( $plugins[ $plugin_slug ] );
|
||||
}
|
||||
|
||||
public function column_default( $item, $column_name ) {
|
||||
$return = '';
|
||||
|
||||
|
@ -432,7 +561,7 @@ class AAL_Activity_Log_List_Table extends WP_List_Table {
|
|||
;'
|
||||
);
|
||||
|
||||
$types = $wpdb->get_results(
|
||||
$this->data_types = $wpdb->get_col(
|
||||
'SELECT DISTINCT `object_type` FROM `' . $wpdb->activity_log . '`
|
||||
WHERE 1 = 1
|
||||
' . $this->_get_where_by_role() . '
|
||||
|
@ -442,7 +571,7 @@ class AAL_Activity_Log_List_Table extends WP_List_Table {
|
|||
);
|
||||
|
||||
// Make sure we get items for filter.
|
||||
if ( $users || $types ) {
|
||||
if ( $users || $this->data_types ) {
|
||||
if ( ! isset( $_REQUEST['dateshow'] ) )
|
||||
$_REQUEST['dateshow'] = '';
|
||||
|
||||
|
@ -504,13 +633,20 @@ class AAL_Activity_Log_List_Table extends WP_List_Table {
|
|||
}
|
||||
}
|
||||
|
||||
if ( $types ) {
|
||||
if ( ! isset( $_REQUEST['typeshow'] ) )
|
||||
if ( $this->data_types ) {
|
||||
if ( ! isset( $_REQUEST['typeshow'] ) ) {
|
||||
$_REQUEST['typeshow'] = '';
|
||||
}
|
||||
|
||||
$output = array();
|
||||
foreach ( $types as $type )
|
||||
$output[] = sprintf( '<option value="%s"%s>%s</option>', $type->object_type, selected( $_REQUEST['typeshow'], $type->object_type, false ), __( $type->object_type, 'aryo-activity-log' ) );
|
||||
foreach ( $this->data_types as $object_type ) {
|
||||
$output[] = sprintf(
|
||||
'<option value="%s"%s>%s</option>',
|
||||
$object_type,
|
||||
selected( $_REQUEST['typeshow'], $object_type, false ),
|
||||
__( $object_type, 'aryo-activity-log' )
|
||||
);
|
||||
}
|
||||
|
||||
echo '<select name="typeshow" id="hs-filter-typeshow">';
|
||||
printf( '<option value="">%s</option>', __( 'All Topics', 'aryo-activity-log' ) );
|
||||
|
|
|
@ -74,6 +74,46 @@ class AAL_Admin_Ui {
|
|||
line-height: 30px;
|
||||
text-decoration: none;
|
||||
}
|
||||
.aal-table-promotion-row td {
|
||||
padding: 0;
|
||||
}
|
||||
.aal-table-promotion-inner {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 20px;
|
||||
background: white;
|
||||
border: 1px solid #4C43E5;
|
||||
border-inline-start-width: 3px;
|
||||
}
|
||||
.aal-promotion-cta {
|
||||
margin-inline-start: 5px;
|
||||
font-weight: bold;
|
||||
color: #4C43E5;
|
||||
}
|
||||
.aal-promotion-dismiss {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
transition: all .1s ease-in-out;
|
||||
border: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
color: #7c7c7c;
|
||||
}
|
||||
.aal-promotion-dismiss::before {
|
||||
content: '\f335';
|
||||
display: block;
|
||||
font: normal 20px/20px dashicons;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.aal-promotion-dismiss:hover {
|
||||
color: #4C43E5;
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
.toplevel_page_activity-log-page .manage-column {
|
||||
width: auto;
|
||||
|
@ -93,6 +133,34 @@ class AAL_Admin_Ui {
|
|||
}
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
jQuery( document ).ready( ( $ ) => {
|
||||
const aalPromotionWrapSelector = 'tr.aal-table-promotion-row';
|
||||
$( '.aal-promotion-dismiss', aalPromotionWrapSelector ).on( 'click', function( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
const $promotionWrap = $( this ).closest( aalPromotionWrapSelector );
|
||||
|
||||
$promotionWrap.hide();
|
||||
|
||||
$.post( ajaxurl, {
|
||||
action: 'aal_promotion_dismiss',
|
||||
promotion_id: $promotionWrap.data( 'promotion-id' ),
|
||||
nonce: $promotionWrap.data( 'nonce' ),
|
||||
} );
|
||||
} );
|
||||
|
||||
$( '.aal-promotion-cta', aalPromotionWrapSelector ).on( 'click', function( event ) {
|
||||
const $promotionWrap = $( this ).closest( aalPromotionWrapSelector );
|
||||
|
||||
$.post( ajaxurl, {
|
||||
action: 'aal_promotion_campaign',
|
||||
promotion_id: $promotionWrap.data( 'promotion-id' ),
|
||||
nonce: $promotionWrap.data( 'nonce' ),
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
@ -109,6 +177,9 @@ class AAL_Admin_Ui {
|
|||
public function __construct() {
|
||||
add_action( 'admin_menu', array( &$this, 'create_admin_menu' ), 20 );
|
||||
add_action( 'admin_head', array( &$this, 'admin_header' ) );
|
||||
|
||||
add_action( 'wp_ajax_aal_promotion_dismiss', [ $this, 'ajax_aal_promotion_dismiss' ] );
|
||||
add_action( 'wp_ajax_aal_promotion_campaign', [ $this, 'ajax_aal_promotion_campaign' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,4 +193,52 @@ class AAL_Admin_Ui {
|
|||
|
||||
return $this->_list_table;
|
||||
}
|
||||
|
||||
public function ajax_aal_promotion_dismiss() {
|
||||
if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'aal_promotion' ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
if ( empty( $_POST['promotion_id'] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$promotion_id = sanitize_key( $_POST['promotion_id'] );
|
||||
|
||||
update_user_meta( get_current_user_id(), "_aal_promotion_{$promotion_id}_notice_viewed", 'true' );
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
public function ajax_aal_promotion_campaign() {
|
||||
if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'aal_promotion' ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
if ( empty( $_POST['promotion_id'] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
if ( 'emails' === $_POST['promotion_id'] ) {
|
||||
$campaign_data = [
|
||||
'source' => 'sm-aal-install',
|
||||
'campaign' => 'sm-plg',
|
||||
'medium' => 'wp-dash',
|
||||
];
|
||||
|
||||
set_transient( 'elementor_site_mailer_campaign', $campaign_data, 30 * DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
if ( 'media' === $_POST['promotion_id'] ) {
|
||||
$campaign_data = [
|
||||
'source' => 'io-aal-install',
|
||||
'campaign' => 'io-plg',
|
||||
'medium' => 'wp-dash',
|
||||
];
|
||||
|
||||
set_transient( 'elementor_image_optimization_campaign', $campaign_data, 30 * DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue