first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace WPDesk\FS\Rate;
abstract class RateNotice implements RateNoticeInterface {
const NOTICE_NAME = 'flexible_shipping_rate_plugin';
const CLOSE_TEMPORARY_NOTICE = 'close-temporary-notice-date';
/**
* Get message
*
* @return mixed
*/
abstract protected function get_message();
/**
* Action links
*
* @return array
*/
protected function action_links() {
$actions[] = sprintf(
__( '%1$sOk, you deserved it%2$s', 'flexible-shipping' ),
'<a target="_blank" href="' . esc_url( 'https://octol.io/fs-rate' ) . '">',
'</a>'
);
$actions[] = sprintf(
__( '%1$sNope, maybe later%2$s', 'flexible-shipping' ),
'<a data-type="date" class="fs-close-temporary-notice notice-dismiss-link" data-source="' . self::CLOSE_TEMPORARY_NOTICE . '" href="#">',
'</a>'
);
$actions[] = sprintf(
__( '%1$sI already did%2$s', 'flexible-shipping' ),
'<a class="close-rate-notice notice-dismiss-link" data-source="already-did" href="#">',
'</a>'
);
return $actions;
}
/**
* Should show message
*
* @return bool
*/
public function should_show_message() {
return true;
}
/**
* Show admin notice
*
* @return string|void
*/
public function show_message() {
new \FSVendor\WPDesk\Notice\PermanentDismissibleNotice(
$this->get_message(),
self::NOTICE_NAME,
\FSVendor\WPDesk\Notice\Notice::NOTICE_TYPE_INFO,
10,
array(
'class' => self::NOTICE_NAME,
'id' => self::NOTICE_NAME,
)
);
}
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* Admin notices.
*
* @package Flexible Shipping
*/
/**
* Can display notices in admin.
*/
class WPDesk_Flexible_Shipping_Admin_Notices {
const SETTINGS_CHECKED_OPTION_VALUE_SHOW_MESSAGE = '1';
const SETTINGS_CHECKED_OPTION_VALUE_DO_NOT_SHOW_MESSAGE = '2';
const BASED_ON_VALUE = 'value';
/**
* @var Flexible_Shipping_Plugin
*/
private $plugin;
/**
* WPDesk_Flexible_Shipping_Admin_Notices constructor.
*
* @param Flexible_Shipping_Plugin $plugin .
*/
public function __construct( Flexible_Shipping_Plugin $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}
/**
* Hooks.
*/
private function hooks() {
add_action( 'admin_notices', array( $this, 'admin_notices_plugin_activepayments' ) );
add_action( 'admin_notices', array( $this, 'admin_notices_plugin_enadawca' ) );
add_action( 'admin_notices', array( $this, 'admin_notices_plugin_pwr' ) );
}
/**
* @param WC_Shipping_Method $shipping_method .
*
* @return bool
*/
private function has_value_based_rule( $shipping_method ) {
$methods = get_option( 'flexible_shipping_methods_' . $shipping_method->instance_id, array() );
if ( is_array( $methods ) ) {
foreach ( $methods as $method_settings ) {
if ( isset( $method_settings['method_rules'] ) && is_array( $method_settings['method_rules'] ) ) {
foreach ( $method_settings['method_rules'] as $rule ) {
if ( isset( $rule['based_on'] ) && self::BASED_ON_VALUE === $rule['based_on'] ) {
return true;
}
}
}
}
}
return false;
}
/**
* @return bool
*/
public function is_in_zones() {
if ( isset( $_GET['page'] ) && 'wc-settings' === sanitize_key( $_GET['page'] )
&& isset( $_GET['tab'] ) && 'shipping' === sanitize_key( $_GET['tab'] )
&& ( ! isset( $_GET['section'] ) || '' === $_GET['section'] )
) {
return true;
}
return false;
}
/**
* Active payments notice.
*/
public function admin_notices_plugin_activepayments() {
if ( is_plugin_active( 'woocommerce-active-payments/activepayments.php' ) ) {
$plugin_activepayments = get_plugin_data( WP_PLUGIN_DIR . '/woocommerce-active-payments/activepayments.php' );
$version_compare = version_compare( $plugin_activepayments['Version'], '2.7' );
if ( $version_compare < 0 ) {
$class = 'notice notice-error';
$message = __( 'Flexible Shipping requires at least version 2.7 of Active Payments plugin.', 'flexible-shipping' );
$this->print_notice( $class, $message );
}
}
}
/**
* Enadawca notice.
*/
public function admin_notices_plugin_enadawca() {
if ( is_plugin_active( 'woocommerce-enadawca/woocommerce-enadawca.php' ) ) {
$plugin_enadawca = get_plugin_data( WP_PLUGIN_DIR . '/woocommerce-enadawca/woocommerce-enadawca.php' );
$version_compare = version_compare( $plugin_enadawca['Version'], '1.2' );
if ( $version_compare < 0 ) {
$class = 'notice notice-error';
$message = __( 'Flexible Shipping requires at least version 1.2 of eNadawca plugin.', 'flexible-shipping' );
$this->print_notice( $class, $message );
}
}
}
/**
* Paczka w Ruchu notice.
*/
public function admin_notices_plugin_pwr() {
if ( is_plugin_active( 'woocommerce-paczka-w-ruchu/woocommerce-paczka-w-ruchu.php' ) ) {
$plugin_pwr = get_plugin_data( WP_PLUGIN_DIR . '/woocommerce-paczka-w-ruchu/woocommerce-paczka-w-ruchu.php' );
$version_compare = version_compare( $plugin_pwr['Version'], '1.1' );
if ( $version_compare < 0 ) {
$class = 'notice notice-error';
$message = __( 'Flexible Shipping requires at least version 1.1 of Orlen Paczka plugin.', 'flexible-shipping' );
$this->print_notice( $class, $message );
}
}
}
/**
* @param string $class .
* @param string $message .
*/
private function print_notice( $class, $message ) {
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message ); // phpcs:ignore
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace WPDesk\FS\Rate;
interface RateNoticeInterface {
/**
* Show message
*
* @return string
*/
public function show_message();
/**
* Should show message
*
* @return bool
*/
public function should_show_message();
}

View File

@@ -0,0 +1,63 @@
<?php
namespace WPDesk\FS\Rate;
class RateNoticeImplementation extends RateNotice
{
/**
* Action links
*
* @return array
*/
protected function action_links() {
$actions[] = sprintf(
__( '%1$sOk, you deserved it%2$s', 'flexible-shipping' ),
'<a target="_blank" href="' . esc_url( 'https://octol.io/fs-rate' ) . '">',
'</a>'
);
$actions[] = sprintf(
__( '%1$sNope, maybe later%2$s', 'flexible-shipping' ),
'<a data-type="date" class="fs-close-temporary-notice notice-dismiss-link" data-source="' . self::CLOSE_TEMPORARY_NOTICE . '" href="#">',
'</a>'
);
$actions[] = sprintf(
__( '%1$sI already did%2$s', 'flexible-shipping' ),
'<a class="close-rate-notice notice-dismiss-link" data-source="already-did" href="#">',
'</a>'
);
return $actions;
}
/**
* Should show message
*
* @return bool
*/
public function should_show_message() {
$notice_date_dissmis = get_option( WPDesk_Flexible_Shipping_Rate_Notice::SETTINGS_OPTION_RATE_NOTICE_DATE_DISMISS, date( "Y-m-d H:i:s", strtotime( 'NOW + 2 weeks' ) ) );
$notice_date = strtotime( $notice_date_dissmis );
$current_date = strtotime( 'NOW' );
$difference = $current_date - $notice_date;
$days = (int) floor( $difference / ( 60 * 60 * 24 ) );
if ( $days > 0 ) {
return true;
}
return false;
}
/**
* Get rate message
*
* @return string
*/
protected function get_message() {
$message = __( 'Awesome, you\'ve been using Flexible Shipping for more than 2 weeks. Could you please do me a BIG favor and give it a 5-star rating on WordPress? ~Octolize Team', 'flexible-shipping' );
$message .= '<br/>';
$message .= implode( ' | ', $this->action_links() );
return $message;
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace WPDesk\FS\Rate;
/**
* Display rate notice.
*/
class WPDesk_Flexible_Shipping_Rate_Notice implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable {
const CLOSE_TEMPORARY_NOTICE_DATE = 'close-temporary-notice-date';
const CLOSE_ALREADY_DID = 'already-did';
const SETTINGS_OPTION_DISMISSED_COUNT = 'flexible_shipping_rate_dismissed_count';
const SETTINGS_RATE_NOTICE_VARIANT_ID = 'flexible_shipping_rate_notice_variant_id';
const SETTINGS_OPTION_RATE_NOTICE_DATE_DISMISS = 'flexible_shipping_rate_notice_date_dismiss';
/**
* Hooks.
*/
public function hooks() {
add_action( 'admin_notices', array( $this, 'add_admin_notice_action' ) );
add_action( 'wpdesk_notice_dismissed_notice', array( $this, 'reset_rate_variant_action' ), 10, 2 );
add_action( 'wp_ajax_flexible_shipping_rate_notice', array( $this, 'wp_ajax_flexible_shipping_rate_notice' ) );
add_action( 'wp_ajax_flexible_shipping_close_rate_notice', array( $this, 'wp_ajax_flexible_shipping_close_rate_notice' ) );
}
/**
* Reset rate variant
*
* @param string $notice_name Notice name.
* @param string $source Sorcue.
*/
public function reset_rate_variant_action( $notice_name, $source ) {
if ( 'flexible_shipping_rate_plugin' !== $notice_name ) {
return false;
}
$dismissed_count = (int) get_option( self::SETTINGS_OPTION_DISMISSED_COUNT, 0 );
if ( ( empty( $source ) || self::CLOSE_TEMPORARY_NOTICE_DATE === $source ) ) {
update_option( self::SETTINGS_OPTION_RATE_NOTICE_DATE_DISMISS, date( "Y-m-d H:i:s", strtotime( 'NOW + 2 weeks' ) ) );
delete_option( \FSVendor\WPDesk\Notice\PermanentDismissibleNotice::OPTION_NAME_PREFIX . $notice_name );
update_option( self::SETTINGS_OPTION_DISMISSED_COUNT, 1 );
} elseif ( self::CLOSE_ALREADY_DID === $source ) {
update_option( \FSVendor\WPDesk\Notice\PermanentDismissibleNotice::OPTION_NAME_PREFIX . $notice_name, 1 );
}
if ( $dismissed_count > 0 ) {
update_option( \FSVendor\WPDesk\Notice\PermanentDismissibleNotice::OPTION_NAME_PREFIX . $notice_name, 1 );
}
}
/**
* Should display notice.
*
* @return bool
*/
private function should_display_notice() {
$current_screen = get_current_screen();
$display_on_screens = [ 'shop_order', 'edit-shop_order', 'woocommerce_page_wc-settings' ];
if ( ! empty( $current_screen ) && in_array( $current_screen->id, $display_on_screens, true ) ) {
return true;
}
return false;
}
/**
* Generate rate notice variant ID.
*
* @return string
*/
private function generate_rate_notice_variant_id()
{
return 'notice_2';
}
/**
* Set defaults for notice.
*/
private function set_notice_defaults() {
add_option( self::SETTINGS_OPTION_RATE_NOTICE_DATE_DISMISS, date( "Y-m-d H:i:s", strtotime('NOW + 2 weeks') ) );
}
/**
* Add admin notice.
*/
public function add_admin_notice_action()
{
if ( $this->should_display_notice() ) {
$instance = new RateNoticeImplementation();
$this->set_notice_defaults();
if( $instance->should_show_message() ) {
$instance->show_message();
}
}
}
}