diff --git a/src/DisplayStrategy/DisplayDecision.php b/src/DisplayStrategy/DisplayDecision.php index c12d45fc0add0f572d7d570d67df4c0e04a15a79..2198eec0c396589ae7eb685fb3d4f804dce7b907 100644 --- a/src/DisplayStrategy/DisplayDecision.php +++ b/src/DisplayStrategy/DisplayDecision.php @@ -12,6 +12,6 @@ interface DisplayDecision { * * @return bool */ - public function should_display(); + public function should_display(): bool; } \ No newline at end of file diff --git a/src/DisplayStrategy/ShippingMethodDisplayDecision.php b/src/DisplayStrategy/ShippingMethodDisplayDecision.php new file mode 100644 index 0000000000000000000000000000000000000000..2a12fe6759569388ae9c53bec31138589061c233 --- /dev/null +++ b/src/DisplayStrategy/ShippingMethodDisplayDecision.php @@ -0,0 +1,60 @@ +<?php + +namespace WPDesk\RepositoryRating\DisplayStrategy; + +class ShippingMethodDisplayDecision implements DisplayDecision { + + /** + * @var \WC_Shipping_Zones + */ + private $shipping_zones; + + /** + * @var string + */ + private $shipping_method_id; + + /** + * @param \WC_Shipping_Zones $shipping_zones + * @param string $shipping_method_id + */ + public function __construct( \WC_Shipping_Zones $shipping_zones, string $shipping_method_id ) { + $this->shipping_zones = $shipping_zones; + $this->shipping_method_id = $shipping_method_id; + } + + /** + * @inheritDoc + */ + public function should_display(): bool { + if ( $this->is_in_shipping_settings() ) { + if ( $this->is_get_parameter_with_value( 'section', $this->shipping_method_id ) ) { + + return true; + } + + if ( isset( $_GET['instance_id'] ) ) { + $shipping_method = $this->shipping_zones::get_shipping_method( sanitize_key( $_GET['instance_id'] ) ); + if ( $shipping_method instanceof \WC_Shipping_Method ) { + + return $shipping_method->id === $this->shipping_method_id; + } + } + } + + return false; + } + + private function is_in_shipping_settings(): bool { + if ( $this->is_get_parameter_with_value( 'page', 'wc-settings' ) && $this->is_get_parameter_with_value( 'tab', 'shipping' ) ) { + return true; + } + + return false; + } + + private function is_get_parameter_with_value( string $parameter, string $value ): bool { + return isset( $_GET[ $parameter ] ) && $_GET[ $parameter ] === $value; + } + +} \ No newline at end of file diff --git a/src/TextPetition.php b/src/TextPetition.php index 1904729daaf168c9faff3ab17b8b13397e5ff218..fdda3fc9e076a8eccadb6c5f10442f84899d1943 100644 --- a/src/TextPetition.php +++ b/src/TextPetition.php @@ -20,6 +20,27 @@ class TextPetition implements Hookable { */ private $display_decision; + + /** + * @var string + */ + private $text_align; + + /** + * @var string + */ + private $plugin_author; + + /** + * @var string + */ + private $plugin_title; + + /** + * @var string + */ + private $rating_url; + /** * @param string $display_on_action * @param DisplayDecision $display_decision @@ -29,15 +50,14 @@ class TextPetition implements Hookable { $this->display_decision = $display_decision; } - public function hooks() { add_action( $this->display_on_action, [ $this, 'display_petition_if_should' ] ); } public function display_petition_if_should() { if ( $this->display_decision->should_display() ) { - + include __DIR__ . '/views/html-text-petition.php'; } } -} \ No newline at end of file +} diff --git a/src/views/html-text-petition.php b/src/views/html-text-petition.php index 18e89ed396ea33cf85936bfe4cbe83aa74e3603e..d4b54f774bd2884a2ec17641ddc09cbce8488439 100644 --- a/src/views/html-text-petition.php +++ b/src/views/html-text-petition.php @@ -1,15 +1,60 @@ <?php +/** + * @var string $text_align + * @var string $plugin_author + * @var string $plugin_title + * @var string $rating_url + */ +?><style> + .wpdesk-rating-petition { + font-size: 15px; + text-align: <?php echo esc_attr( $text_align ); ?>; + width: 100%; + } -?><div class="aligncenter"> - Created with - <span class="fcfSettings__footerIcon fcfSettings__footerIcon--heart"></span> - by Rangers from <a href="https://wpde.sk/fcf-settings-footer-wpdesk-link-pl" target="_blank">WP Desk</a> - - if you like FCF - <a href="https://wpde.sk/fcf-settings-footer-review-link-pl" target="_blank">rate us - <span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span> - <span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span> - <span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span> - <span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span> - <span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span> - </a> + .wpdesk-rating-petition a { + text-decoration: none; + color: inherit; + } + + .wpdesk-rating-petition span.heart:before { + speak: none; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + color: #dc3232; + font-size: 16px; + font-family: "dashicons"; + content: "\f487"; + font-style: normal; + font-variant: normal; + font-weight: 400; + text-transform: none; + } + .wpdesk-rating-petition span.star:before { + speak: none; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + color: #ffb900; + font-size: 16px; + font-family: "dashicons"; + content: "\f155"; + font-style: normal; + font-variant: normal; + font-weight: 400; + text-transform: none; + text-decoration: none; + } +</style> +<div class="wpdesk-rating-petition"> + <?php echo wp_kses_post( + sprintf( + __( 'Created with %1$s by %2$s - If you like %3$s %4$srate us %5$s%6$s', 'wp-wpdesk-rating-petition' ), + '<span class="heart"></span>', + $plugin_author, + $plugin_title, + '<a href="' . $rating_url . '" target="_blank">', + '<span class="star"></span><span class="star"></span><span class="star"></span><span class="star"></span><span class="star"></span>', + '</a>' + ) + ); ?> </div> \ No newline at end of file