From 2720f6828ecbbef43380bbc202f48ac21d8e0e34 Mon Sep 17 00:00:00 2001
From: Tigran Ghukasyan
+
+
+ %2$s',
+ $site_time_utc,
+ $st_html
+ );
+
+ ?>
+
+
+
+
+
+ site_time(); ?>
+
+
+
+
%2$s',
+ $cron_time_utc,
+ $nc_time
+ );
+
+?> tag
+ $value = '
' . esc_html( $value ) . '
';
+
+ // Return
+ return $value . '
' . esc_html( $type ) . '';
+ }
+
+ /**
+ * Try to guess the type of value the Transient is
+ *
+ * @since 2.0
+ * @param object $transient
+ * @return string
+ */
+ private function get_transient_value_type( $transient ) {
+
+ // Default type
+ $type = esc_html__( 'unknown', 'transients-manager' );
+
+ // Try to unserialize
+ $value = maybe_unserialize( $transient->option_value );
+
+ // Array
+ if ( is_array( $value ) ) {
+ $type = esc_html__( 'array', 'transients-manager' );
+
+ // Object
+ } elseif ( is_object( $value ) ) {
+ $type = esc_html__( 'object', 'transients-manager' );
+
+ // Serialized array
+ } elseif ( is_serialized( $value ) ) {
+ $type = esc_html__( 'serialized', 'transients-manager' );
+
+ // HTML
+ } elseif ( strip_tags( $value ) !== $value ) {
+ $type = esc_html__( 'html', 'transients-manager' );
+
+ // Scalar
+ } elseif ( is_scalar( $value ) ) {
+
+ if ( is_numeric( $value ) ) {
+
+ // Likely a timestamp
+ if ( 10 === strlen( $value ) ) {
+ $type = esc_html__( 'timestamp?', 'transients-manager' );
+
+ // Likely a boolean
+ } elseif ( in_array( $value, array( '0', '1' ), true ) ) {
+ $type = esc_html__( 'boolean?', 'transients-manager' );
+
+ // Any number
+ } else {
+ $type = esc_html__( 'numeric', 'transients-manager' );
+ }
+
+ // JSON
+ } elseif ( is_string( $value ) && is_object( json_decode( $value ) ) ) {
+ $type = esc_html__( 'json', 'transients-manager' );
+
+ // Scalar
+ } else {
+ $type = esc_html__( 'scalar', 'transients-manager' );
+ }
+
+ // Empty
+ } elseif ( empty( $value ) ) {
+ $type = esc_html__( 'empty', 'transients-manager' );
+ }
+
+ // Return type
+ return $type;
+ }
+
+ /**
+ * Retrieve the expiration timestamp
+ *
+ * @since 1.0
+ * @param object $transient
+ * @return int
+ */
+ private function get_transient_expiration_time( $transient ) {
+
+ // Get the same to use in the option key
+ $name = $this->get_transient_name( $transient );
+
+ // Get the value of the timeout
+ $time = $this->is_site_wide( $transient->option_name )
+ ? get_option( "_site_transient_timeout_{$name}" )
+ : get_option( "_transient_timeout_{$name}" );
+
+ // Return the value
+ return $time;
+ }
+
+ /**
+ * Retrieve the human-friendly expiration time
+ *
+ * @since 1.0
+ * @param object $transient
+ * @return string
+ */
+ private function get_transient_expiration( $transient ) {
+
+ $expiration = $this->get_transient_expiration_time( $transient );
+
+ // Bail if no expiration
+ if ( empty( $expiration ) ) {
+ return '—
' . esc_html__( 'Persistent', 'transients-manager' ) . '';
+ }
+
+ // UTC & local dates
+ $date_utc = gmdate( 'Y-m-d\TH:i:s+00:00', $expiration );
+ $date_local = get_date_from_gmt( date( 'Y-m-d H:i:s', $expiration ), 'Y-m-d H:i:s' );
+
+ // Create ',
- $site_time_utc,
- $st_html
- );
-
- ?>
%2$s',
- $cron_time_utc,
- $nc_time
- );
-
-?>
tag
- $value = '' . esc_html( $value ) . '
';
-
- // Return
- return $value . '
' . esc_html( $type ) . '';
- }
-
- /**
- * Try to guess the type of value the Transient is
- *
- * @since 2.0
- * @param object $transient
- * @return string
- */
- private function get_transient_value_type( $transient ) {
-
- // Default type
- $type = esc_html__( 'unknown', 'transients-manager' );
-
- // Try to unserialize
- $value = maybe_unserialize( $transient->option_value );
-
- // Array
- if ( is_array( $value ) ) {
- $type = esc_html__( 'array', 'transients-manager' );
-
- // Object
- } elseif ( is_object( $value ) ) {
- $type = esc_html__( 'object', 'transients-manager' );
-
- // Serialized array
- } elseif ( is_serialized( $value ) ) {
- $type = esc_html__( 'serialized', 'transients-manager' );
-
- // HTML
- } elseif ( strip_tags( $value ) !== $value ) {
- $type = esc_html__( 'html', 'transients-manager' );
-
- // Scalar
- } elseif ( is_scalar( $value ) ) {
-
- if ( is_numeric( $value ) ) {
-
- // Likely a timestamp
- if ( 10 === strlen( $value ) ) {
- $type = esc_html__( 'timestamp?', 'transients-manager' );
-
- // Likely a boolean
- } elseif ( in_array( $value, array( '0', '1' ), true ) ) {
- $type = esc_html__( 'boolean?', 'transients-manager' );
-
- // Any number
- } else {
- $type = esc_html__( 'numeric', 'transients-manager' );
- }
-
- // JSON
- } elseif ( is_string( $value ) && is_object( json_decode( $value ) ) ) {
- $type = esc_html__( 'json', 'transients-manager' );
-
- // Scalar
- } else {
- $type = esc_html__( 'scalar', 'transients-manager' );
- }
-
- // Empty
- } elseif ( empty( $value ) ) {
- $type = esc_html__( 'empty', 'transients-manager' );
- }
-
- // Return type
- return $type;
- }
-
- /**
- * Retrieve the expiration timestamp
- *
- * @since 1.0
- * @param object $transient
- * @return int
- */
- private function get_transient_expiration_time( $transient ) {
-
- // Get the same to use in the option key
- $name = $this->get_transient_name( $transient );
-
- // Get the value of the timeout
- $time = $this->is_site_wide( $transient->option_name )
- ? get_option( "_site_transient_timeout_{$name}" )
- : get_option( "_transient_timeout_{$name}" );
-
- // Return the value
- return $time;
- }
-
- /**
- * Retrieve the human-friendly expiration time
- *
- * @since 1.0
- * @param object $transient
- * @return string
- */
- private function get_transient_expiration( $transient ) {
-
- $expiration = $this->get_transient_expiration_time( $transient );
-
- // Bail if no expiration
- if ( empty( $expiration ) ) {
- return '—
' . esc_html__( 'Persistent', 'transients-manager' ) . '';
- }
-
- // UTC & local dates
- $date_utc = gmdate( 'Y-m-d\TH:i:s+00:00', $expiration );
- $date_local = get_date_from_gmt( date( 'Y-m-d H:i:s', $expiration ), 'Y-m-d H:i:s' );
-
- // Create tag
- $time = sprintf(
- '%2$s ',
- esc_attr( $date_utc ),
- esc_html( $date_local )
- );
-
- // Expired
- if ( $this->time_now > $expiration ) {
- return $time . '
' . esc_html__( 'Expired', 'transients-manager' ) . '';
- }
-
- // Return time since
- return $time . '
' . $this->time_since( $expiration - $this->time_now ) . '';
- }
-
- /**
- * Process delete and update actions
- *
- * @since 1.0
- */
- public function process_actions() {
-
- if ( empty( $this->action ) ) {
- return;
- }
-
- // Bail if malformed Transient request
- if ( empty( $_REQUEST['transient'] ) && ! in_array( $this->action, array( 'suspend_transients', 'unsuspend_transients' ), true ) ) {
- return;
- }
-
- // Bail if user is not capable
- if ( ! current_user_can( $this->capability ) ) {
- return;
- }
-
- // Bail if nonce fails
- if ( ! empty( $_REQUEST['_wpnonce'] ) && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'transients_manager' ) ) {
- return;
- }
-
- if ( ! in_array( $this->action, array( 'suspend_transients', 'unsuspend_transients' ), true ) ) {
-
- // Encode search string
- $search = ! empty( $_REQUEST['s'] )
- ? urlencode( $_REQUEST['s'] )
- : '';
-
- // Sanitize transient
- $transient = sanitize_key( $_REQUEST['transient'] );
-
- // Site wide
- $site_wide = ! empty( $_REQUEST['name'] ) && $this->is_site_wide( $_REQUEST['name'] );
- }
-
- switch ( $this->action ) {
-
- case 'suspend_transients' :
- update_option( 'pw_tm_suspend', 1 );
- wp_safe_redirect( remove_query_arg( array( 'updated', 'deleted', 'action', '_wpnonce' ) ) );
- exit;
-
- case 'unsuspend_transients' :
- delete_option( 'pw_tm_suspend', 1 );
- wp_safe_redirect( remove_query_arg( array( 'updated', 'deleted', 'action', '_wpnonce' ) ) );
- exit;
-
- case 'delete_transient' :
- $this->delete_transient( $transient, $site_wide );
- wp_safe_redirect(
- remove_query_arg(
- array( 'updated' ),
- add_query_arg(
- array(
- 'page' => $this->page_id,
- 's' => $search,
- 'deleted' => true
- ),
- admin_url( 'tools.php' )
- )
- )
- );
- exit;
-
- case 'update_transient' :
- $this->update_transient( $transient, $site_wide );
- wp_safe_redirect(
- remove_query_arg(
- array( 'deleted' ),
- add_query_arg(
- array(
- 'page' => $this->page_id,
- 's' => $search,
- 'updated' => true
- ),
- admin_url( 'tools.php' )
- )
- )
- );
- exit;
-
- case 'delete_selected_transients' :
- $this->delete_selected_transients();
- wp_safe_redirect(
- remove_query_arg(
- array( 'updated' ),
- add_query_arg(
- array(
- 'page' => $this->page_id,
- 'deleted' => true
- ),
- admin_url( 'tools.php' )
- )
- )
- );
- exit;
-
- case 'delete_expired_transients' :
- $this->delete_expired_transients();
- wp_safe_redirect(
- remove_query_arg(
- array( 'updated' ),
- add_query_arg(
- array(
- 'page' => $this->page_id,
- 'deleted' => true
- ),
- admin_url( 'tools.php' )
- )
- )
- );
- exit;
-
- case 'delete_transients_with_expiration' :
- $this->delete_transients_with_expirations();
- wp_safe_redirect(
- remove_query_arg(
- array( 'updated' ),
- add_query_arg(
- array(
- 'page' => $this->page_id,
- 'deleted' => true
- ),
- admin_url( 'tools.php' )
- )
- )
- );
- exit;
-
- case 'delete_transients_without_expiration' :
- $this->delete_transients_without_expirations();
- wp_safe_redirect(
- remove_query_arg(
- array( 'updated' ),
- add_query_arg(
- array(
- 'page' => $this->page_id,
- 'deleted' => true
- ),
- admin_url( 'tools.php' )
- )
- )
- );
- exit;
-
- case 'delete_all_transients' :
- $this->delete_all_transients();
- wp_safe_redirect(
- remove_query_arg(
- array( 'updated' ),
- add_query_arg(
- array(
- 'page' => $this->page_id,
- 'deleted' => true
- ),
- admin_url( 'tools.php' )
- )
- )
- );
- exit;
- }
- }
-
- /**
- * Delete a transient by name
- *
- * @since 1.0
- * @param object $transient
- * @param boolean $site_wide
- * @return boolean
- */
- private function delete_transient( $transient = '', $site_wide = false ) {
-
- // Bail if no Transient
- if ( empty( $transient ) ) {
- return false;
- }
-
- // Transient type
- $retval = ( false !== $site_wide )
- ? delete_site_transient( $transient )
- : delete_transient( $transient );
-
- // Return
- return $retval;
- }
-
- /**
- * Bulk delete function
- *
- * @since 1.5
- * @param array $transients
- * @return boolean
- */
- private function bulk_delete_transients( $transients = array() ) {
-
- // Bail if empty or error
- if ( empty( $transients ) || is_wp_error( $transients ) ) {
- return false;
- }
-
- // Loop through Transients, and delete them
- foreach ( $transients as $transient ) {
-
- // Site wide
- $site_wide = $this->is_site_wide( $transient );
-
- // Get prefix based on site-wide
- $prefix = ! empty( $site_wide )
- ? '_site_transient_timeout_'
- : '_transient_timeout_';
-
- // Strip prefix from name
- $name = str_replace( $prefix, '', $transient );
-
- // Delete
- $this->delete_transient( $name, $site_wide );
- }
-
- // No errors
- return true;
- }
-
- /**
- * Delete Selected transients.
- *
- * @since 1.8
- * @return false|int
- */
- public function delete_selected_transients() {
- global $wpdb;
-
- // Bail if no Transients
- if ( empty( $_REQUEST['transients'] ) || ! is_array( $_REQUEST['transients'] ) ) {
- return 0;
- }
-
- // Filter
- $transients_ids_filtered = wp_parse_id_list( $_REQUEST['transients'] );
-
- // Bail if no IDs
- if ( empty( $transients_ids_filtered ) ) {
- return 0;
- }
-
- // Query
- $placeholders = array_fill( 0, count( $transients_ids_filtered ), '%d' );
- $format = implode( ', ', $placeholders );
- $count = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_id IN ({$format})", $transients_ids_filtered ) );
-
- // Return count of deleted
- return $count;
- }
-
- /**
- * Delete all expired transients
- *
- * @since 1.1
- * @return boolean
- */
- public function delete_expired_transients() {
- global $wpdb;
-
- // Query
- $esc_time = '%' . $wpdb->esc_like( '_transient_timeout_' ) . '%';
- $prepared = $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} where option_name LIKE %s AND option_value+0 < %d", $esc_time, $this->time_now );
- $expired = $wpdb->get_col( $prepared );
-
- // Bulk delete
- return $this->bulk_delete_transients( $expired );
- }
-
- /**
- * Delete all transients with expiration
- *
- * @since 1.2
- * @return boolean
- */
- public function delete_transients_with_expirations() {
- global $wpdb;
-
- // Query
- $esc_time = '%' . $wpdb->esc_like( '_transient_timeout_' ) . '%';
- $prepared = $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} where option_name LIKE %s", $esc_time );
- $will_expire = $wpdb->get_col( $prepared );
-
- // Bulk delete
- return $this->bulk_delete_transients( $will_expire );
- }
-
- /**
- * Delete all transients without expiration
- *
- * @since 2.0
- * @return boolean
- */
- public function delete_transients_without_expirations() {
- global $wpdb;
-
- // Escape likes
- $esc_time = '%' . $wpdb->esc_like( '_transient_timeout_' ) . '%';
- $esc_name = '%' . $wpdb->esc_like( '_transient_' ) . '%';
-
- // Queries
- $timeouts = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} where option_name LIKE %s", $esc_time ) );
- $names = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} where option_name LIKE %s", $esc_name ) );
-
- // Diff to remove timeouts from names
- $items = array_diff( $names, $timeouts );
-
- // Remove "%_transient_timeout_" from left of timeouts
- foreach ( $timeouts as $index => $timeout ) {
- $pos = strrpos( $timeout, '_transient_timeout_' ) + strlen( '_transient_timeout_' );
- $timeouts[ $index ] = substr( $timeout, $pos );
- }
-
- // Remove "%_transient_" from left of items
- foreach ( $items as $index => $item ) {
- $pos = strrpos( $item, '_transient_' ) + strlen( '_transient_' );
- $items[ $index ] = substr( $item, $pos );
- }
-
- // Remove timeouts from items
- $bulk = array_diff( $items, $timeouts );
-
- // Bulk delete
- return $this->bulk_delete_transients( $bulk );
- }
-
- /**
- * Delete all transients
- *
- * @since 1.0
- * @return false|int
- */
- public function delete_all_transients() {
- global $wpdb;
-
- // Escape like
- $esc_name = '%' . $wpdb->esc_like( '_transient_' ) . '%';
-
- // Query
- $count = $wpdb->query(
- $wpdb->prepare(
- "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
- $esc_name
- )
- );
-
- // Return count
- return $count;
- }
-
- /**
- * Update an existing transient
- *
- * @since 1.0
- * @param object $transient
- * @param boolean $site_wide
- * @return boolean
- */
- private function update_transient( $transient = '', $site_wide = false ) {
-
- // Bail if no Transient
- if ( empty( $transient ) ) {
- return false;
- }
-
- // Values
- $value = stripslashes( $_POST['value'] );
- $expiration = absint( stripslashes( $_POST['expires'] ) );
-
- // Subtract now
- $expiration = ( $expiration - $this->time_now );
-
- // Transient type
- $retval = ( false !== $site_wide )
- ? set_site_transient( $transient, $value, $expiration )
- : set_transient( $transient, $value, $expiration );
-
- // Return
- return $retval;
- }
-
- /**
- * Prevent transient from being updated if transients are suspended
- *
- * @since 1.6
- * @param mixed $value
- * @param string $option
- * @return mixed
- */
- public function maybe_block_update_transient( $value = '', $option = '' ) {
-
- // Bail if not Suspended
- if ( ! get_option( 'pw_tm_suspend' ) ) {
- return $value;
- }
-
- // Bail if not a Transient
- if ( false === strpos( $option, '_transient' ) ) {
- return $value;
- }
-
- // Return false
- return false;
- }
-
- /**
- * Prevent transient from being updated if transients are suspended
- *
- * @since 1.6
- */
- public function maybe_block_set_transient( $option = '' ) {
-
- // Bail if not Suspended
- if ( ! get_option( 'pw_tm_suspend' ) ) {
- return;
- }
-
- // Bail if not a Transient
- if ( false === strpos( $option, '_transient' ) ) {
- return;
- }
-
- // Delete the Transient
- delete_option( $option );
- }
-
- /**
- * Converts a period of time in seconds into a human-readable format
- * representing the interval.
- *
- * @since 2.0
- * @param int $since A period of time in seconds.
- * @return string An interval represented as a string.
- */
- public function time_since( $since = 0 ) {
-
- // Array of time period chunks.
- $chunks = array(
- /* translators: 1: The number of years in an interval of time. */
- array( 60 * 60 * 24 * 365, _n_noop( '%s year', '%s years', 'transients-manager' ) ),
- /* translators: 1: The number of months in an interval of time. */
- array( 60 * 60 * 24 * 30, _n_noop( '%s month', '%s months', 'transients-manager' ) ),
- /* translators: 1: The number of weeks in an interval of time. */
- array( 60 * 60 * 24 * 7, _n_noop( '%s week', '%s weeks', 'transients-manager' ) ),
- /* translators: 1: The number of days in an interval of time. */
- array( 60 * 60 * 24, _n_noop( '%s day', '%s days', 'transients-manager' ) ),
- /* translators: 1: The number of hours in an interval of time. */
- array( 60 * 60, _n_noop( '%s hour', '%s hours', 'transients-manager' ) ),
- /* translators: 1: The number of minutes in an interval of time. */
- array( 60, _n_noop( '%s minute', '%s minutes', 'transients-manager' ) ),
- /* translators: 1: The number of seconds in an interval of time. */
- array( 1, _n_noop( '%s second', '%s seconds', 'transients-manager' ) ),
- );
-
- if ( $since <= 0 ) {
- return esc_html__( 'now', 'transients-manager' );
- }
-
- /**
- * We only want to output two chunks of time here, eg:
- * x years, xx months
- * x days, xx hours
- * so there's only two bits of calculation below:
- */
- $j = count( $chunks );
-
- // Step one: the first chunk.
- for ( $i = 0; $i < $j; $i++ ) {
- $seconds = $chunks[ $i ][ 0 ];
- $name = $chunks[ $i ][ 1 ];
-
- // Finding the biggest chunk (if the chunk fits, break).
- $count = floor( $since / $seconds );
-
- if ( ! empty( $count ) ) {
- break;
- }
- }
-
- // Set output var.
- $output = sprintf( translate_nooped_plural( $name, $count, 'transients-manager' ), $count );
-
- // Step two: the second chunk.
- if ( $i + 1 < $j ) {
- $seconds2 = $chunks[ $i + 1 ][ 0 ];
- $name2 = $chunks[ $i + 1 ][ 1 ];
- $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 );
-
- // Add to output var.
- if ( ! empty( $count2 ) ) {
- $output .= ' ' . sprintf( translate_nooped_plural( $name2, $count2, 'transients-manager' ), $count2 );
- }
- }
-
- return $output;
- }
-
- /**
- * Add
-
-init();
+\AM\TransientsManager\CrossPromotion::init();
From 59111c7d9eea3ab05d54a010efed41e65609b077 Mon Sep 17 00:00:00 2001
From: Tigran Ghukasyan
Date: Thu, 3 Oct 2024 13:51:12 +0400
Subject: [PATCH 2/7] plugin installation ok
---
assets/js/extra-plugins.js | 4 +--
src/CrossPromotion.php | 56 ++++++++++++++++++++++++++------------
2 files changed, 40 insertions(+), 20 deletions(-)
diff --git a/assets/js/extra-plugins.js b/assets/js/extra-plugins.js
index c6b1c35..1fe8d0b 100644
--- a/assets/js/extra-plugins.js
+++ b/assets/js/extra-plugins.js
@@ -67,11 +67,9 @@ var AmTmExtraPlugins = window.AmTmExtraPlugins || (function (document, window, $
}
button.fadeOut(500);
- status.fadeOut(500);
-
button.html(l10nAmTmExtraPlugins.activated);
+ button.prepend('');
button.fadeIn(300);
- status.fadeIn(300);
});
}
);
diff --git a/src/CrossPromotion.php b/src/CrossPromotion.php
index 0b51069..344e015 100644
--- a/src/CrossPromotion.php
+++ b/src/CrossPromotion.php
@@ -18,7 +18,7 @@ class CrossPromotion
public static function init()
{
add_action('admin_notices', [__CLASS__, 'notices']);
- add_action('wp_enqueue_scripts', [__CLASS__, 'enqueueScripts']);
+ add_action('admin_enqueue_scripts', [__CLASS__, 'enqueueScripts']);
add_action('wp_ajax_transients_manager_extra_plugin', [__CLASS__, 'installPluginAjax']);
}
@@ -33,23 +33,19 @@ public static function enqueueScripts()
return;
}
- // Don't load in case Lite is installed. Pro only has a link to the website.
- if (self::isPluginInstalled('duplicator/duplicator.php')) {
- return;
- }
-
wp_enqueue_script(
'am-tm-extra-plugins',
AM_TM_PLUGIN_URL . "assets/js/extra-plugins.js",
- array('jquery'),
+ ['jquery'],
AM_TM_VERSION,
true
);
+
wp_localize_script(
'am-tm-extra-plugins',
'l10nAmTmExtraPlugins',
array(
- 'loading' => esc_html__('Loading...', 'transients-manager'),
+ 'loading' => esc_html__('Installing...', 'transients-manager'),
'failure' => esc_html__('Failure', 'transients-manager'),
'active' => esc_html__('Active', 'transients-manager'),
'activated' => esc_html__('Activated', 'transients-manager'),
@@ -59,10 +55,10 @@ public static function enqueueScripts()
wp_localize_script(
'am-tm-extra-plugins',
'am_tm_extra_plugins',
- array(
+ [
'ajax_url' => admin_url('admin-ajax.php'),
'extra_plugin_install_nonce' => wp_create_nonce('transients_manager_extra_plugin'),
- )
+ ]
);
}
@@ -73,10 +69,6 @@ public static function enqueueScripts()
*/
public static function installPluginAjax()
{
- if (!self::shouldShowNotice()) {
- return;
- }
-
try {
if (check_ajax_referer('transients_manager_extra_plugin', 'nonce', false) === false) {
throw new \Exception(__('Invalid nonce', 'transients-manager'));
@@ -86,12 +78,12 @@ public static function installPluginAjax()
throw new \Exception(__('You do not have permission to install plugins', 'transients-manager'));
}
- $slug = filter_input(INPUT_POST, 'plugin', FILTER_SANITIZE_STRING);
+ $slug = filter_input(INPUT_POST, 'plugin', FILTER_SANITIZE_SPECIAL_CHARS);
if (empty($slug)) {
throw new \Exception(__('Invalid plugin slug', 'transients-manager'));
}
- if (self::installPlugin($slug)) {
+ if (self::installPlugin($slug) && self::activatePlugin($slug)) {
wp_send_json_success([
'success' => true,
'message' => __('Plugin installed successfully', 'transients-manager'),
@@ -138,6 +130,7 @@ private static function shouldShowNotice()
if (!current_user_can('install_plugins')) {
return false;
}
+
if ($tm->getInstallTime() + 2 * WEEK_IN_SECONDS < time()) {
return false;
}
@@ -215,7 +208,7 @@ private static function renderStyles()
flex-direction: column;
align-items: center;
border-left-width: 1px;
- padding: 20px;
+ padding: 20px 20px 30px 20px;
}
.cross-promotion .intro-text {
@@ -249,6 +242,15 @@ private static function renderStyles()
.cross-promotion-plugin a.button {
padding: 0px 30px;
}
+
+ .cross-promotion-plugin button.button {
+ display: flex;
+ align-items: center;
+ }
+
+ .cross-promotion-plugin button.button span.dashicons-yes {
+ color: #46b450;
+ }
Date: Thu, 3 Oct 2024 14:05:17 +0400
Subject: [PATCH 3/7] notice dismiss ok
---
assets/js/extra-plugins.js | 21 +++++++++++++++++++++
src/CrossPromotion.php | 31 ++++++++++++++++++++++++++++++-
src/TransientsManager.php | 4 ++--
3 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/assets/js/extra-plugins.js b/assets/js/extra-plugins.js
index 1fe8d0b..dfce9b3 100644
--- a/assets/js/extra-plugins.js
+++ b/assets/js/extra-plugins.js
@@ -73,6 +73,27 @@ var AmTmExtraPlugins = window.AmTmExtraPlugins || (function (document, window, $
});
}
);
+
+ $(document).on(
+ 'click',
+ '.notice.cross-promotion .notice-dismiss',
+ function (e) {
+ e.preventDefault();
+
+ $.post(
+ am_tm_extra_plugins.ajax_url,
+ {
+ action: 'transients_manager_cross_promo_dismiss',
+ nonce: am_tm_extra_plugins.cross_promo_dismiss_nonce,
+ }
+ ).done(function (response) {
+ if (response.success !== true) {
+ console.log("Error dismissing notice");
+ return;
+ }
+ });
+ }
+ );
},
diff --git a/src/CrossPromotion.php b/src/CrossPromotion.php
index 344e015..2b7efbe 100644
--- a/src/CrossPromotion.php
+++ b/src/CrossPromotion.php
@@ -20,6 +20,7 @@ public static function init()
add_action('admin_notices', [__CLASS__, 'notices']);
add_action('admin_enqueue_scripts', [__CLASS__, 'enqueueScripts']);
add_action('wp_ajax_transients_manager_extra_plugin', [__CLASS__, 'installPluginAjax']);
+ add_action('wp_ajax_transients_manager_cross_promo_dismiss', [__CLASS__, 'dismissNotice']);
}
/**
@@ -58,10 +59,38 @@ public static function enqueueScripts()
[
'ajax_url' => admin_url('admin-ajax.php'),
'extra_plugin_install_nonce' => wp_create_nonce('transients_manager_extra_plugin'),
+ 'cross_promo_dismiss_nonce' => wp_create_nonce('transients_manager_cross_promo_dismiss'),
]
);
}
+ /**
+ * Dismiss notice
+ *
+ * @return void
+ */
+ public static function dismissNotice()
+ {
+ if (check_ajax_referer('transients_manager_cross_promo_dismiss', 'nonce', false) === false) {
+ wp_send_json_error([
+ 'success' => false,
+ 'message' => __('Invalid nonce', 'transients-manager'),
+ ]);
+ }
+
+ if (update_option(self::NOTICE_DISMISS_KEY, true) === false) {
+ wp_send_json_error([
+ 'success' => false,
+ 'message' => __('Failed to dismiss notice', 'transients-manager'),
+ ]);
+ }
+
+ wp_send_json_success([
+ 'success' => true,
+ 'message' => __('Notice dismissed', 'transients-manager'),
+ ]);
+ }
+
/**
* Install plugin via ajax
*
@@ -131,7 +160,7 @@ private static function shouldShowNotice()
return false;
}
- if ($tm->getInstallTime() + 2 * WEEK_IN_SECONDS < time()) {
+ if ($tm->getInstallTime() + 2 * WEEK_IN_SECONDS > time()) {
return false;
}
diff --git a/src/TransientsManager.php b/src/TransientsManager.php
index ddf7ac9..8111d2c 100644
--- a/src/TransientsManager.php
+++ b/src/TransientsManager.php
@@ -101,10 +101,10 @@ public function __construct() {
*/
public function getInstallTime()
{
- $installTime = get_option('pw_tm_install_time', false);
+ $installTime = get_option('am_tm_install_time', false);
if (!$installTime) {
$installTime = time();
- update_option('pw_tm_install_time', $installTime);
+ update_option('am_tm_install_time', $installTime);
}
return $installTime;
}
From d814e0b3264afff9a632283b8d9fa150ce4f1caa Mon Sep 17 00:00:00 2001
From: Tigran Ghukasyan
Date: Thu, 3 Oct 2024 14:13:11 +0400
Subject: [PATCH 4/7] code improvements
---
src/CrossPromotion.php | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/CrossPromotion.php b/src/CrossPromotion.php
index 2b7efbe..68e351c 100644
--- a/src/CrossPromotion.php
+++ b/src/CrossPromotion.php
@@ -192,9 +192,7 @@ private static function render()
continue;
}
- $isPro = false;
if ($hasPro && self::isPluginInstalled($slug)) {
- $isPro = true;
$pluginInfo = self::getPluginBySlug($pluginInfo['pro']);
}
?>
@@ -209,7 +207,7 @@ private static function render()
-
+
From dbc4ea5c43ec9ba62d0460c0ca05ca9bf1fa3035 Mon Sep 17 00:00:00 2001
From: Tigran Ghukasyan
Date: Thu, 3 Oct 2024 14:31:03 +0400
Subject: [PATCH 5/7] code cleanup
---
readme.txt | 2 +-
src/CrossPromotion.php | 44 ++++++++++++++++++++++++++-------------
src/TransientsManager.php | 3 +++
3 files changed, 33 insertions(+), 16 deletions(-)
diff --git a/readme.txt b/readme.txt
index df64713..a9d5072 100644
--- a/readme.txt
+++ b/readme.txt
@@ -9,7 +9,7 @@ Tags: cron, tool, transient
Requires PHP: 5.6.20
Requires at least: 5.3
Tested up to: 6.5
-Stable Tag: 2.0.5
+Stable Tag: 2.0.6
Provides a familiar interface to view, search, edit, and delete Transients.
diff --git a/src/CrossPromotion.php b/src/CrossPromotion.php
index 68e351c..c75dc01 100644
--- a/src/CrossPromotion.php
+++ b/src/CrossPromotion.php
@@ -4,6 +4,8 @@
/**
* Cross promotion class
+ *
+ * @since 2.0.6 Introduced class
*/
class CrossPromotion
{
@@ -202,7 +204,7 @@ private static function render()
-
+
@@ -361,26 +365,36 @@ protected static function activatePlugin($slug)
}
/**
- * Get the plugin info
+ * Get all plugin infos
*
- * @return array Plugin info or false if not found
+ * @return array All plugins
*/
protected static function getAllPlugins()
{
return [
'duplicator/duplicator.php' => [
- 'name' => __('Duplicator - WordPress Migration & Backup Plugin', 'transients-manager'),
- 'url' => 'https://downloads.wordpress.org/plugin/duplicator.zip',
- 'desc' => __('Leading WordPress backup & site migration plugin. Over 1,500,000+ smart website owners use Duplicator to make easy, reliable and secure WordPress backups to protect their websites.', 'transients-manager'),
- 'pro' => 'duplicator-pro/duplicator-pro.php' ,
- 'isPro' => false,
+ 'name' => __('Duplicator - WordPress Migration & Backup Plugin', 'transients-manager'),
+ 'url' => 'https://downloads.wordpress.org/plugin/duplicator.zip',
+ 'desc' => __(
+ 'Leading WordPress backup & site migration plugin. Over 1,500,000+ smart website owners use Duplicator to make easy,
+ reliable and secure WordPress backups to protect their websites.',
+ 'transients-manager'
+ ),
+ 'iconUrl' => AM_TM_PLUGIN_URL . '/assets/img/duplicator-icon.svg',
+ 'pro' => 'duplicator-pro/duplicator-pro.php' ,
+ 'isPro' => false,
],
'duplicator-pro/duplicator-pro.php' => [
- 'name' => __('Duplicator Pro - WordPress Migration & Backup Plugin', 'transients-manager'),
- 'url' => 'http://duplicator.com/?utm_source=transientsmanager&utm_medium=link&utm_campaign=Cross%20Promotion',
- 'desc' => __('Leading WordPress backup & site migration plugin. Smart website owners use Duplicator Pro to make easy, reliable and secure WordPress backups to protect their websites.', 'transients-manager'),
- 'pro' => false,
- 'isPro' => true,
+ 'name' => __('Duplicator Pro - WordPress Migration & Backup Plugin', 'transients-manager'),
+ 'url' => 'http://duplicator.com/?utm_source=transientsmanager&utm_medium=link&utm_campaign=Cross%20Promotion',
+ 'desc' => __(
+ 'Leading WordPress backup & site migration plugin. Smart website owners use Duplicator Pro to make easy,
+ reliable and secure WordPress backups to protect their websites.',
+ 'transients-manager'
+ ),
+ 'iconUrl' => AM_TM_PLUGIN_URL . '/assets/img/duplicator-icon.svg',
+ 'pro' => false,
+ 'isPro' => true,
],
];
@@ -391,7 +405,7 @@ protected static function getAllPlugins()
*
* @param string $slug Plugin slug
*
- * @return array{name:string,slug:string,url:string,desc:string}|false Plugin info or false if not found
+ * @return array{name:string,url:string,desc:string,iconUrl:string,pro:mixed,isPro:bool}|false Plugin info or false if not found
*/
protected static function getPluginBySlug($slug)
{
diff --git a/src/TransientsManager.php b/src/TransientsManager.php
index 8111d2c..5283c6f 100644
--- a/src/TransientsManager.php
+++ b/src/TransientsManager.php
@@ -2,6 +2,9 @@
namespace AM\TransientsManager;
+/**
+ * Transients Manager class
+ */
class TransientsManager {
/** @var ?self */
From 14b3d62cbd63d7a01eef0cd5dbf27272caf69307 Mon Sep 17 00:00:00 2001
From: Tigran Ghukasyan
Date: Thu, 3 Oct 2024 14:44:49 +0400
Subject: [PATCH 6/7] style adjustments
---
src/CrossPromotion.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/CrossPromotion.php b/src/CrossPromotion.php
index c75dc01..15541c7 100644
--- a/src/CrossPromotion.php
+++ b/src/CrossPromotion.php
@@ -237,7 +237,7 @@ private static function renderStyles()
.cross-promotion {
display: flex;
flex-direction: column;
- align-items: center;
+ align-items: start;
border-left-width: 1px;
padding: 20px 20px 30px 20px;
}
@@ -245,6 +245,7 @@ private static function renderStyles()
.cross-promotion .intro-text {
font-size: 14px;
align-self: flex-start;
+ margin-bottom: 15px;
}
.cross-promotion-plugin {
@@ -252,7 +253,7 @@ private static function renderStyles()
flex-direction: row;
align-items: center;
justify-content: center;
- max-width: 800px;
+ max-width: 1000px;
}
.cross-promotion-plugin img {
From 9a93a1fa75d9e61e080945b2529ae56126c4bc9c Mon Sep 17 00:00:00 2001
From: Tigran Ghukasyan
Date: Thu, 3 Oct 2024 17:04:05 +0400
Subject: [PATCH 7/7] readme updates
---
readme.txt | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/readme.txt b/readme.txt
index a9d5072..d4095e8 100644
--- a/readme.txt
+++ b/readme.txt
@@ -42,6 +42,7 @@ It was originally created by
If you like this plugin and find it useful to manage transients, please leave a good rating and consider checking out our other projects:
+* [Duplicator](https://duplicator.com/) – Easy, fast and secure WordPress backups and website migration.
* [OptinMonster](https://optinmonster.com/) – Get more email subscribers with the most popular conversion optimization plugin for WordPress.
* [WPForms](https://wpforms.com/) – #1 drag & drop online form builder for WordPress (trusted by 5 million sites).
* [MonsterInsights](https://www.monsterinsights.com/) – See the stats that matter and grow your business with confidence. Best Google Analytics plugin for WordPress.
@@ -90,6 +91,9 @@ No. It only works when transients are stored in the database.
== Changelog ==
+= 2.0.6 - October 3, 2024 =
+* Improved: Product Education
+
= 2.0.5 - December 12, 2023 =
* Improved: Support for PHP8.2 and below