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,201 @@
<?php
/*
Copyright 2022-2023 Marcin Pietrzak (marcin@iworks.pl)
this program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'iworks_omnibus' ) ) {
return;
}
class iworks_omnibus {
private $objects = array();
private $root;
public function __construct() {
/**
* set plugin root
*
* @since 2.3.4
*/
$this->root = dirname( dirname( dirname( __FILE__ ) ) );
/**
* plugins screen
*/
add_action( 'plugins_loaded', array( $this, 'action_plugins_loaded' ) );
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 );
/**
* iWorks Rate Class
*
* Allow to change iWorks Rate logo for admin notice.
*
* @since 1.0.2
*
* @param string $logo Logo, can be empty.
* @param object $plugin Plugin basic data.
*/
add_filter( 'iworks_rate_notice_logo_style', array( $this, 'filter_plugin_logo' ), 10, 2 );
}
public function action_plugins_loaded() {
$dir = dirname( __FILE__ ) . '/omnibus';
/**
* WooCommerce
*
* @since 1.0.0
*/
if (
defined( 'WC_PLUGIN_FILE' )
&& defined( 'WC_VERSION' )
) {
/**
* Check minimal WooCommerce version to run.
*
* @since 2.3.4
*
*/
if ( version_compare( WC_VERSION, '5.5', '<' ) ) {
add_action( 'admin_notices', array( $this, 'action_admin_notices_show_woocommerce_version' ) );
} else {
/**
* Add Settings link on the Plugins list
*
* @since 1.0.2
*/
add_filter( 'plugin_action_links_' . basename( $this->root ) . '/omnibus.php', array( $this, 'add_settings_link' ), 90, 4 );
include_once $dir . '/integration/class-iworks-omnibus-integration-woocommerce.php';
$this->objects['woocommerce'] = new iworks_omnibus_integration_woocommerce();
}
}
/**
* LearnPress
*
* @since 1.0.1
*/
if ( defined( 'LP_PLUGIN_FILE' ) ) {
include_once $dir . '/integration/class-iworks-omnibus-learnpress.php';
$this->objects['learnpress'] = new iworks_omnibus_integration_learnpress();
}
/**
* Easy Digital Downloads
*
* @since 1.1.1
*/
if ( class_exists( 'Easy_Digital_Downloads' ) ) {
include_once $dir . '/integration/class-iworks-omnibus-easydigitaldownloads.php';
$this->objects['easydigitaldownloads'] = new iworks_omnibus_integration_easydigitaldownloads();
}
/**
* Debug Bar
*
* @since 2.4.0
*/
if ( isset( $GLOBALS['debug_bar'] ) ) {
include_once $dir . '/integration/class-iworks-omnibus-integration-debug-bar.php';
$this->objects['debug-bar'] = new iworks_omnibus_integration_debug_bar();
}
/**
* Omnibus loaded action
*
* @since 2.1.4
*/
do_action( 'omnibus/loaded' );
}
/**
* Ask for rating.
*
* @since 1.0.2
*/
public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
if ( isset( $plugin_data['slug'] ) && 'omnibus' == $plugin_data['slug'] ) {
$plugin_meta['rating'] = sprintf( __( 'If you like <strong>Omnibus</strong> please leave us a %1$s&#9733;&#9733;&#9733;&#9733;&#9733;%2$s rating. A huge thanks in advance!', 'omnibus' ), '<a href="https://wordpress.org/support/plugin/omnibus/reviews/?rate=5#new-post" target="_blank">', '</a>' );
}
return $plugin_meta;
}
/**
* Plugin logo for rate messages
*
* @since 1.0.2
*
* @param string $logo Logo, can be empty.
* @param object $plugin Plugin basic data.
*/
public function filter_plugin_logo( $logo, $plugin ) {
if ( is_object( $plugin ) ) {
$plugin = (array) $plugin;
}
if ( 'omnibus' === $plugin['slug'] ) {
return plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'assets/images/logo.svg';
}
return $logo;
}
/**
* Add settings link to plugin_row_meta.
*
* @since 1.0.2
*
* @param array $actions An array of the plugin's metadata, including the version, author, author URI, and plugin URI.
*/
public function add_settings_link( $actions, $plugin_file, $plugin_data, $context ) {
$actions['settings'] = sprintf(
'<a href="%s">%s</a>',
add_query_arg(
array(
'page' => 'wc-settings',
'tab' => 'omnibus',
),
admin_url( 'admin.php' )
),
__( 'Settings', 'omnibus' )
);
return $actions;
}
/**
* get template
*
* @since 2.3.4
*/
private function get_file( $file, $group = '' ) {
return sprintf(
'%s/assets/templates/%s%s.php',
$this->root,
'' === $group ? '' : $group . '/',
sanitize_title( $file )
);
}
/**
* Show minimal WooCommerce version to run.
*
* @since 2.3.4
*
*/
public function action_admin_notices_show_woocommerce_version() {
$file = $this->get_file( 'woocommerce-version' );
$args = array(
'version-current' => WC_VERSION,
'version-minimal' => '5.5.0',
);
load_template( $file, true, $args );
}
}

View File

@@ -0,0 +1,518 @@
<?php
/*
Copyright 2022-2023 Marcin Pietrzak (marcin@iworks.pl)
this program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'iworks_omnibus_integration' ) ) {
return;
}
abstract class iworks_omnibus_integration {
/**
* meta field name
*
* @since 1.0.0
*/
protected $meta_name = '_iwo_price_lowest';
/**
* meta field name last change
*
* @since 1.0.0
*/
protected $meta_name_last_change = '_iwo_price_last_change';
/**
* last price drop timestamp
*
* @since 2.0.0
*/
protected $last_price_drop_timestamp = '_iwo_last_price_drop_timestamp';
/**
* just a price log
*
* @since 2.3.5
*/
protected $meta_price_log_name = '_iwo_price_log';
/**
* Add price log
*
* @since 1.0.0
*/
private function add_price_log( $post_id, $price, $update_last_drop ) {
/**
* allow to skip price log
*
* @since 2.3.0
*/
if ( apply_filters( 'iworks_omnibus_add_price_log_skip', false, $post_id, $price, $update_last_drop ) ) {
return;
}
/**
* save only for published posts
*
* @since 2.0.0
*/
if ( 'publish' !== get_post_status( $post_id ) ) {
return;
}
/**
* do not save empty price
*
* @since 2.0.2
*/
if ( empty( $price ) ) {
return;
}
$now = time();
$data = array(
'price' => $price,
'timestamp' => $now,
'user_id' => get_current_user_id(),
);
/**
* filter data
*
* @since 2.3.2
*/
$data = apply_filters( 'iworks_omnibus_add_price_log_data', $data, $post_id );
/**
* add
*/
add_post_meta( $post_id, $this->meta_name, $data );
/**
* update last price drop timestamp
*
* @since 2.0.0
*/
if ( $update_last_drop ) {
if ( ! update_post_meta( $post_id, $this->last_price_drop_timestamp, $now ) ) {
add_post_meta( $post_id, $this->last_price_drop_timestamp, $now, true );
}
}
}
/**
* Save price history
*
* @since 1.0.0
*/
protected function save_price_history( $post_id, $price ) {
$price_last = $this->get_last_price( $post_id );
if ( 'unknown' === $price_last ) {
$this->add_price_log( $post_id, $price, true );
}
/**
* try to get previous price
*
* @since 2.3.9
*/
$price_previous = null;
/**
* filter prices names
*
* @since 2.3.9
*/
if ( is_array( $price_last ) ) {
$prices_names = apply_filters(
'iworks_omnibus/save_price_history/prices_names',
array(
'price',
'price_sale',
'price_regular',
)
);
foreach ( $prices_names as $key ) {
/**
* already set, go away!
*/
if ( ! empty( $price_previous ) ) {
continue;
}
/**
* check it
*/
if ( isset( $price_last[ $key ] ) ) {
$price_previous = $price_last[ $key ];
}
}
}
/**
* check to log
*/
if (
! empty( $price_previous )
&& floatval( $price ) !== floatval( $price_previous )
) {
$this->add_price_log( $post_id, $price, floatval( $price ) !== floatval( $price_previous ) );
}
}
/**
* get last recorded price
*
* @since 1.0.0
*/
private function get_last_price( $post_id ) {
$meta = get_post_meta( $post_id, $this->meta_name );
if ( empty( $meta ) ) {
return 'unknown';
}
$old = strtotime( sprintf( '-%d days', $this->get_days() ) );
$timestamp = 0;
$last = array();
foreach ( $meta as $data ) {
if ( $old >= $data['timestamp'] ) {
continue;
}
if ( $timestamp < $data['timestamp'] ) {
$timestamp = $data['timestamp'];
$last = $data;
}
}
return $last;
}
/**
* Get lowest price in history
*
* @since 1.0.0
*/
protected function _get_lowest_price_in_history( $lowest, $post_id ) {
$meta = get_post_meta( $post_id, $this->meta_name );
if ( empty( $meta ) ) {
return array();
}
uasort( $meta, array( $this, 'sort_meta_by_price' ) );
$price_lowest = array();
$now = time();
$price = array(
'init' => true,
'price' => PHP_INT_MAX,
'timestamp' => $now,
'from' => $now,
);
$old = strtotime( sprintf( '-%d days', $this->get_days() ) );
$last_price_drop_timestamp = intval( get_post_meta( $post_id, $this->last_price_drop_timestamp, true ) );
if ( ! empty( $last_price_drop_timestamp ) ) {
$old = strtotime( sprintf( '-%d days', $this->get_days() ), $last_price_drop_timestamp );
}
foreach ( $meta as $data ) {
if ( floatval( $data['price'] ) > $price['price'] ) {
continue;
}
if ( intval( $old ) >= intval( $data['timestamp'] ) ) {
continue;
}
if ( intval( $last_price_drop_timestamp ) === intval( $data['timestamp'] ) ) {
continue;
}
$price = $data;
$price['from'] = $old;
}
if ( isset( $price['init'] ) ) {
return array();
}
/**
* Diff in days between promotion and now.
*
* @since 2.3.9
*/
if ( isset( $price['timestamp'] ) ) {
$price['diff-in-days'] = round( ( time() - $price['timestamp'] ) / DAY_IN_SECONDS );
}
return $price;
}
/**
* Add Omnibus message to price.
*
* @since 1.0.0
* @since 2.3.2 param $message has been added.
*
* @param $price
* @param $price_lowest
* @param callback $format_price_callback Price format callback function.
* @param string $message Message template.
*/
protected function add_message( $price, $price_lowest, $format_price_callback = null, $message = null ) {
if ( ! is_array( $price_lowest ) ) {
return $price;
}
if ( ! isset( $price_lowest['price'] ) ) {
return $price;
}
if ( empty( $price_lowest['price'] ) ) {
return $price;
}
/**
* Set message template if ir is needed
*/
if ( empty( $message ) ) {
$message = __( 'Previous lowest price was %2$s.', 'omnibus' );
if (
'custom' === get_option( $this->get_name( 'message_settings' ), 'no' )
|| 'yes' === get_option( $this->get_name( 'message_settings' ), 'no' )
) {
$message = get_option(
$this->get_name( 'message' ),
__( 'Previous lowest price was %2$s.', 'omnibus' )
);
}
}
/**
* mesage template filter
*
* @since 2.3.0
*/
$message = apply_filters( 'iworks_omnibus_message_template', $message, $price, $price_lowest );
if ( empty( $message ) ) {
return $price;
}
/**
* price to show
*/
$price_to_show = $price_lowest['price'];
/**
* WooCommerce: include tax
*/
if ( 'no' === get_option( 'woocommerce_prices_include_tax' ) ) {
if ( 'yes' === get_option( $this->get_name( 'include_tax' ), 'yes' ) ) {
if (
isset( $price_lowest['price_including_tax'] )
&& $price_lowest['price_including_tax'] > $price_to_show
) {
$price_to_show = $price_lowest['price_including_tax'];
}
}
}
if ( is_callable( $format_price_callback ) ) {
$price_to_show = $format_price_callback( $price_to_show );
}
/**
* add attributes
*/
$attributes = array();
foreach ( $price_lowest as $key => $value ) {
$attributes[] = sprintf( 'data-iwo-%s="%s"', esc_html( $key ), esc_attr( $value ) );
}
$price .= apply_filters(
'iworks_omnibus_message',
sprintf(
'<p class="iworks-omnibus" %s>%s</p>',
implode( ' ', $attributes ),
sprintf(
$message,
$this->get_days(),
$price_to_show
)
)
);
/**
* replace
*
* @since 2.1.7
*/
$price = preg_replace( '/{days}/', $this->get_days(), $price );
$price = preg_replace( '/{price}/', $price_to_show, $price );
$price = preg_replace( '/{timestamp}/', $price_lowest['timestamp'], $price );
$price = preg_replace( '/{when}/', date_i18n( get_option( 'date_format' ), $price_lowest['timestamp'] ), $price );
/**
* use filter `iworks_omnibus_message_html`
*/
$message = apply_filters( 'iworks_omnibus_message_html', $price, $price_lowest );
/**
* use filter `orphan_replace`
*
* @since 2.2.2
*/
$message = apply_filters( 'orphan_replace', $message );
/**
* return
*/
return $message;
}
public function get_name( $name = '' ) {
if ( empty( $name ) ) {
return $this->meta_name;
}
return sanitize_title(
sprintf(
'%s_%s',
$this->meta_name,
$name
)
);
}
/**
* get numbers of days
*
* @since 1.1.0
*/
protected function get_days() {
return apply_filters(
'iworks_omnibus_days',
max( 30, intval( get_option( $this->get_name( 'days' ), 30 ) ) )
);
}
/**
* Header helper
*
* @since 1.1.0
*/
protected function print_header( $class = '' ) {
printf(
'<h3%s>%s</h3>',
empty( $class ) ? '' : sprintf( ' class="%s"', esc_attr( $class ) ),
esc_html__( 'Omnibus Directive', 'omnibus' )
);
}
protected function settings_title() {
return array(
'title' => __( 'Omnibus Directive Settings', 'omnibus' ),
'type' => 'title',
'id' => $this->meta_name,
);
}
protected function settings_days() {
return array(
'title' => __( 'Number of days', 'omnibus' ),
'desc' => __( 'This controls the number of days to show. According to the Omnibus Directive, minimum days is 30 after curent sale was started.', 'omnibus' ),
'id' => $this->get_name( 'days' ),
'default' => '30',
'type' => 'number',
'custom_attributes' => array(
'min' => 30,
),
);
}
protected function settings_messages() {
return array(
array(
'type' => 'title',
'title' => __( 'Messages', 'omnibus' ),
),
$this->settings_message_settings(),
$this->settings_message(),
array(
'type' => 'sectionend',
'id' => $this->get_name( 'sectionend' ),
),
);
}
protected function settings_message_settings() {
return array(
'title' => __( 'Price Message', 'omnibus' ),
'checkboxgroup' => 'start',
'type' => 'radio',
'default' => 'default',
'id' => $this->get_name( 'message_settings' ),
'options' => array(
'default' => __( 'Default messages (recommended).', 'omnibus' ),
'custom' => __( 'Custom messages.', 'omnibus' ),
),
'desc' => __( 'Custom messages will be used only when you choose "Custom messages." option.', 'omnibus' ),
);
}
protected function settings_message() {
$description = array();
/* translators: Do not translate {price}, it is the replacement placeholder ! */
$description[] = esc_html__( 'Use the {price} placeholder to display price.', 'omnibus' );
/* translators: Do not translate {timestamp}, it is the replacement placeholder ! */
$description[] = esc_html__( 'Use the {timestamp} placeholder to display timestamp.', 'omnibus' );
/* translators: Do not translate {days}, it is the replacement placeholder ! */
$description[] = esc_html__( 'Use the {days} placeholder to display days.', 'omnibus' );
/* translators: Do not translate {when}, it is the replacement placeholder ! */
$description[] = esc_html__( 'Use the {when} placeholder to display date.', 'omnibus' );
return array(
'type' => 'text',
'id' => $this->get_name( 'message' ),
'default' => __( 'Previous lowest price: {price}.', 'omnibus' ),
'checkboxgroup' => 'end',
'desc' => str_replace(
array( '{', '}' ),
array( '<code>{', '}</code>' ),
implode( '<br />', $description )
),
);
}
/**
* sort log by price
*/
private function sort_meta_by_price( $a, $b ) {
if ( floatval( $a['price'] ) === floatval( $b['price'] ) ) {
return 0;
}
return floatval( $a['price'] ) > floatval( $b['price'] ) ? 1 : -1;
}
/**
* check is turn on for different cases
*
* @since 2.3.2
*/
protected function is_on( $value ) {
if ( empty( $value ) ) {
return false;
}
if ( is_bool( $value ) ) {
return $value;
}
if ( is_numeric( $value ) ) {
return 0 < $value;
}
if ( is_string( $value ) ) {
switch ( $value ) {
case 'yes':
case '1':
case 'on':
return true;
}
}
return false;
}
protected function price_log( $post_id, $data ) {
if ( ! is_array( $data ) ) {
return;
}
if ( 'publish' !== get_post_status( $post_id ) ) {
return;
}
$data['timestamp'] = time();
add_post_meta(
$post_id,
$this->meta_price_log_name,
$data
);
}
}

View File

@@ -0,0 +1,241 @@
<?php
/*
Copyright 2022-2023 Marcin Pietrzak (marcin@iworks.pl)
this program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'iworks_omnibus_integration_easydigitaldownloads' ) ) {
return;
}
include_once dirname( dirname( __FILE__ ) ) . '/class-iworks-omnibus-integration.php';
class iworks_omnibus_integration_easydigitaldownloads extends iworks_omnibus_integration {
public function __construct() {
add_action( 'edd_after_price_field', array( $this, 'action_edd_after_price_field' ) );
add_action( 'edd_purchase_link_end', array( $this, 'action_edd_purchase_link_end' ), 10, 2 );
add_action( 'updated_postmeta', array( $this, 'action_updated_postmeta' ), 10, 4 );
add_filter( 'edd_download_price_after_html', array( $this, 'filter_edd_download_price_after_html' ), 10, 4 );
add_filter( 'edd_settings_gateways', array( $this, 'filter_edd_settings_gateways' ) );
add_filter( 'edd_settings_sections_gateways', array( $this, 'filter_edd_settings_sections_gateways' ), 99 );
add_filter( 'option__iwo_price_lowest_edd_days', array( $this, 'get_edd_days' ), 10, 2 );
add_filter( 'option_edd_settings', array( $this, 'set_defaults' ), 10, 2 );
add_filter( 'pre_option__iwo_price_lowest_edd_days', array( $this, 'get_edd_days' ), 10, 2 );
}
public function get_edd_days( $value, $option ) {
return $this->get_setting( 'days' );
}
public function set_defaults( $value, $option ) {
if ( isset( $value[ $this->get_name( 'days' ) ] ) ) {
return $value;
}
$value[ $this->get_name['days'] ] = 30;
$value[ $this->get_name['download'] ] = 1;
$value[ $this->get_name['admin_list'] ] = 1;
$value[ $this->get_name['admin_edit'] ] = 1;
return $value;
}
private function get_setting( $setting_name ) {
$settings = get_option( 'edd_settings' );
$name = $this->get_name( $setting_name );
if ( isset( $settings[ $name ] ) ) {
if ( 'days' === $setting_name ) {
return max( 30, intval( $settings[ $name ] ) );
}
return 'yes';
}
if ( 'days' === $setting_name ) {
return 30;
}
return 'no';
}
public function filter_edd_download_price_after_html( $formatted_price, $download_id, $price, $price_id ) {
if ( ! $this->should_it_show_up() ) {
return $formatted_price;
}
$price_lowest = $this->get_lowest_price( $download_id );
if ( empty( $price_lowest ) ) {
return $formatted_price;
}
return $formatted_price . $this->add_message( '', $price_lowest, 'wc_price' );
}
private function get_lowest_price( $post_id ) {
$product = new EDD_Download( $post_id );
return $this->_get_lowest_price_in_history( $product->get_price(), $post_id );
}
public function action_edd_after_price_field( $post_id ) {
if ( ! $this->should_it_show_up() ) {
return;
}
$price_lowest = $this->get_lowest_price( $post_id );
$this->print_header();
?>
<div class="edd-form-group">
<div class="edd-form-group__control">
<table>
<tr>
<td><?php esc_html_e( 'Price', 'omnibus' ); ?></td>
<td>
<input type="text" class="edd-form-group__input" value="<?php echo empty( $price_lowest ) ? '' : esc_attr( $price_lowest['price'] ); ?>" readonly="readonly" />
<span alt="f223" class="edd-help-tip dashicons dashicons-editor-help" title="<?php printf( __( 'The lowest price in %d days.', 'omnibus' ), $this->get_days() ); ?>"></span>
</td>
</tr>
<tr>
<td><?php esc_html_e( 'Date', 'omnibus' ); ?></td>
<td>
<input type="text" class="edd-form-group__input" value="<?php echo empty( $price_lowest ) ? '' : date_i18n( get_option( 'date_format' ), $price_lowest['timestamp'] ); ?>" readonly="readonly" />
<span alt="f223" class="edd-help-tip dashicons dashicons-editor-help" title="<?php printf( __( 'The date when lowest price in %d days occurred.', 'omnibus' ), $this->get_days() ); ?>"></span>
</td>
</tr>
</table>
</div>
</div>
<?php
}
public function filter_edd_settings_sections_gateways( $sections ) {
$sections['iworks-omnibus'] = __( 'Omnibus', 'omnibus' );
return $sections;
}
public function filter_edd_settings_gateways( $settings ) {
$settings['iworks-omnibus'] = array(
$this->get_name( 'download' ) => array(
'id' => $this->get_name( 'download' ),
'name' => __( 'Show on', 'omnibus' ),
'desc' => __( 'Single Download', 'easy-digital-downloads' ),
'type' => 'checkbox',
),
$this->get_name( 'admin_list' ) => array(
'id' => $this->get_name( 'admin_list' ),
'desc' => __( 'Admin Download List', 'easy-digital-downloads' ),
'type' => 'checkbox',
),
$this->get_name( 'admin_edit' ) => array(
'id' => $this->get_name( 'admin_edit' ),
'desc' => __( 'Admin Edit Download', 'easy-digital-downloads' ),
'type' => 'checkbox',
),
$this->get_name( 'days' ) => array(
'id' => $this->get_name( 'days' ),
'name' => __( 'Number of days', 'omnibus' ),
'desc' => __( 'This controls the number of days to show. According to the Omnibus Directive, minimum days is 30.', 'omnibus' ),
'std' => 30,
'type' => 'number',
'size' => 'small',
'min' => 30,
),
);
return $settings;
}
public function action_updated_postmeta( $meta_id, $object_id, $meta_key, $meta_value ) {
if ( 'edd_price' !== $meta_key ) {
return;
}
$post = get_post( $object_id );
if ( empty( $post ) ) {
return;
}
if ( 'download' !== get_post_type( $post ) ) {
return;
}
if ( 'publish' !== get_post_status( $post ) ) {
return;
}
$this->save_price_history( $object_id, $meta_value );
}
public function action_edd_purchase_link_end( $post_id, $args ) {
if ( ! $this->should_it_show_up() ) {
return;
}
$this->run();
}
/**
* run helper
*
* @since 1.2.0
*/
private function run( $context = 'view' ) {
if ( ! is_singular( 'download' ) ) {
return;
}
$post_id = get_the_ID();
$price_lowest = $this->get_lowest_price( $post_id );
if ( empty( $price_lowest ) ) {
return;
}
$message = $this->add_message( '', $price_lowest, 'wc_price' );
if ( 'return' === $context ) {
return $message;
}
echo $message;
}
public function get_name( $name = '' ) {
if ( empty( $name ) ) {
return parent::get_name( 'edd' );
}
return parent::get_name( 'edd_' . $name );
}
/**
* helper to decide show it or no
*/
private function should_it_show_up() {
/**
* for admin
*/
if ( is_admin() ) {
$screen = get_current_screen();
if ( 'download' === $screen->id ) {
if ( 'no' === $this->get_setting( 'admin_edit' ) ) {
return false;
}
}
if ( 'edit-download' === $screen->id ) {
if ( 'no' === $this->get_setting( 'admin_list' ) ) {
return false;
}
}
return true;
}
/**
* front-end
*/
if ( is_single() ) {
if ( 'no' === $this->get_setting( 'download' ) ) {
return false;
}
return true;
}
return true;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*
Copyright 2023-2023 Marcin Pietrzak (marcin@iworks.pl)
this program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined( 'ABSPATH' ) || exit;
class iworks_omnibus_integration_debug_bar_panel extends Debug_Bar_Panel {
function init() {
$this->title( __( 'Omnibus', 'omnibus' ) );
}
function prerender() {
$this->set_visible( ! is_admin() );
}
function render() {
echo '<div id="debug-bar-omnibus">';
if ( is_singular( 'product' ) ) {
}
echo '</div>';
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*
Copyright 2023-2023 Marcin Pietrzak (marcin@iworks.pl)
this program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'iworks_omnibus_integration_debug_bar' ) ) {
return;
}
include_once dirname( dirname( __FILE__ ) ) . '/class-iworks-omnibus-integration.php';
class iworks_omnibus_integration_debug_bar extends iworks_omnibus_integration {
public function __construct() {
add_filter( 'debug_bar_panels', array( $this, 'filter_debug_bar_panels' ) );
}
public function filter_debug_bar_panels( $panels ) {
include_once __DIR__ . '/class-iworks-omnibus-integration-debug-bar-panel.php';
$panels[] = new iworks_omnibus_integration_debug_bar_panel();
return $panels;
}
}

View File

@@ -0,0 +1,557 @@
<?php
/**
* WooCommerce advanced settings
*/
defined( 'ABSPATH' ) || exit;
/**
* Settings for API.
*/
if ( class_exists( 'iworks_omnibus_integration_woocommerce_settings', false ) ) {
return new iworks_omnibus_integration_woocommerce_settings();
}
/**
* WC_Settings_Advanced.
*/
class iworks_omnibus_integration_woocommerce_settings extends WC_Settings_Page {
private $meta_name;
/**
* Constructor.
*/
public function __construct() {
$this->id = 'omnibus';
$this->label = __( 'Omnibus', 'omnibus' );
parent::__construct();
add_action( 'woocommerce_admin_field_omnibus_info', array( $this, 'omnibus_info' ) );
}
public function omnibus_info( $value ) {
$text = str_replace(
array( '{', '}' ),
array( '<code>{', '}</code>' ),
implode( PHP_EOL, $value['info'] )
);
echo '<tr><td colspan="2" class="' . esc_attr( $value['class'] ) . '">';
echo wp_kses_post( wpautop( wptexturize( $text ) ) );
echo '</td></tr>';
}
/**
* Get own sections.
*
* @return array
*/
protected function get_own_sections() {
return array(
'' => __( 'Display Price', 'omnibus' ),
'where' => __( 'Where on site', 'omnibus' ),
'messages' => __( 'Messages', 'omnibus' ),
'admin' => __( 'Admin Dashboard', 'omnibus' ),
// 'debug' => __( 'Debug', 'omnibus' ),
);
}
/**
* Get settings for the default section.
*
* @return array
*/
protected function get_settings_for_default_section() {
$settings = array(
array(
'title' => __( 'Display Price', 'omnibus' ),
'type' => 'title',
'id' => $this->get_name(),
'desc' => esc_html__( 'European Union guidance requires displaying the minimal price if a product is on sale. But if you use publicly available discounts, e.g., "discount code" you should consider showing omnibus prices all the time.', 'omnibus' ),
),
array(
'title' => __( 'Display minimal price', 'omnibus' ),
'id' => $this->get_name( 'on_sale' ),
'default' => 'yes',
'type' => 'radio',
'options' => array(
'yes' => esc_html__( 'Only when the product is on sale', 'omnibus' ),
'no' => esc_html__( 'Always (use if you have publicly available discounts)', 'omnibus' ),
),
),
array(
'title' => __( 'Where on Single Product', 'omnibus' ),
'desc' => __( 'Allows you to choose where the message is displayed. According to the directive, we recommend displaying it right after the price. Some places may not work depending on the theme you are using and how your site is built.', 'omnibus' ),
'id' => $this->get_name( 'where' ),
'default' => 'woocommerce_get_price_html',
'type' => 'select',
'options' => array(
'woocommerce_get_price_html' => esc_html__( 'After the price (recommended)', 'omnibus' ),
'do_not_show' => esc_html__( 'Do not show. I will handle it myself.', 'omnibus' ),
/** meta */
'woocommerce_product_meta_start' => esc_html__( 'Before the product meta data', 'omnibus' ),
'woocommerce_product_meta_end' => esc_html__( 'After the product meta data', 'omnibus' ),
/** product summary */
'woocommerce_before_single_product_summary' => esc_html__( 'Before the single product summary', 'omnibus' ),
'woocommerce_after_single_product_summary' => esc_html__( 'After the single product summary', 'omnibus' ),
/** cart form */
'woocommerce_before_add_to_cart_form' => esc_html__( 'Before the add to cart form', 'omnibus' ),
/** cart button */
'woocommerce_before_add_to_cart_button' => esc_html__( 'Before the add to cart button', 'omnibus' ),
'woocommerce_after_add_to_cart_button' => esc_html__( 'After the add to cart button', 'omnibus' ),
/** cart quantity */
'woocommerce_before_add_to_cart_quantity' => esc_html__( 'Before the add to cart quantity', 'omnibus' ),
'woocommerce_after_add_to_cart_quantity' => esc_html__( 'After the add to cart quantity', 'omnibus' ),
// 'woocommerce_single_product_summary' => esc_html__( 'Single product summary', 'omnibus' ),
/** content */
'the_content_start' => esc_html__( 'At the begining of the content', 'omnibus' ),
'the_content_end' => esc_html__( 'At the end of the content', 'omnibus' ),
),
),
array(
'type' => 'sectionend',
'id' => $this->get_name( 'sectionend' ),
),
);
/**
* WooCommerce Tax
*/
if (
'yes' === get_option( 'woocommerce_calc_taxes', 'no' )
&& 'no' === get_option( 'woocommerce_prices_include_tax', 'no' )
) {
$settings[] = array(
'title' => __( 'Tax', 'omnibus' ),
'type' => 'title',
'id' => $this->get_name( 'tax' ),
);
$settings[] = array(
'title' => __( 'Include tax', 'omnibus' ),
'id' => $this->get_name( 'include_tax' ),
'default' => 'yes',
'type' => 'checkbox',
'desc' => __( 'Display price with tax', 'omnibus' ),
);
$settings[] = array(
'type' => 'sectionend',
'id' => $this->get_name( 'tax-sectionend' ),
);
}
/**
* Products
*/
$settings[] = array(
'title' => __( 'Type of Product', 'omnibus' ),
'type' => 'title',
'id' => $this->get_name( 'types' ),
);
$products = array(
array(
'desc' => __( 'Simple product', 'omnibus' ),
'id' => $this->get_name( 'simple' ),
),
array(
'desc' => __( 'Variable product: global', 'omnibus' ),
'id' => $this->get_name( 'variable' ),
),
array(
'desc' => __( 'Variable product: variation', 'omnibus' ),
'id' => $this->get_name( 'variation' ),
),
);
/**
* Tutor LMS (as relatedo to WooCommerce)
*
* @since 1.0.1
*/
if ( defined( 'TUTOR_VERSION' ) ) {
$tutor_option = get_option( 'tutor_option' );
if (
is_array( $tutor_option )
&& isset( $tutor_option['monetize_by'] )
&& 'wc' === $tutor_option['monetize_by']
) {
$products[] = array(
'desc' => __( 'Tutor course', 'omnibus' ),
'id' => $this->get_name( 'tutor' ),
);
}
}
/**
* YITH WooCommerce Product Bundles
*
* @since 1.1.0
*/
if ( defined( 'YITH_WCPB_VERSION' ) ) {
$products[] = array(
'desc' => __( 'YITH Bundle', 'omnibus' ),
'id' => $this->get_name( 'yith_bundle' ),
);
}
/**
* filter avaialble products list
*
* @since 1.1.0
*/
$products = apply_filters( 'iworks_omnibus_integration_woocommerce_settings', $products );
/**
* add to Settings
*/
foreach ( $products as $index => $one ) {
if ( 0 === $index ) {
$one['title'] = __( 'Show for type', 'omnibus' );
$one['checkboxgroup'] = 'start';
}
$one = wp_parse_args(
$one,
array(
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
)
);
if ( ( 1 + $index ) === count( $products ) ) {
$one['checkboxgroup'] = 'end';
}
$settings[] = $one;
}
$settings[] = array(
'type' => 'sectionend',
'id' => $this->get_name( 'types-sectionend' ),
);
return apply_filters( 'iworks_omnibus_settings', $settings );
}
/**
* Get settings for the messages section.
*
* @return array
*/
protected function get_settings_for_where_section() {
$settings = array(
/**
* Show on
*/
array(
'title' => __( 'Where to display on site', 'omnibus' ),
'type' => 'title',
'id' => $this->get_name( 'show-on' ),
'desc' => __( 'Select the places where you want to display information about prices. Some options may not work properly depending on the theme you\'re using or how your site is built.', 'omnibus' ),
),
array(
'title' => __( 'Single Product', 'omnibus' ),
'id' => $this->get_name( 'product' ),
'default' => 'yes',
'type' => 'checkbox',
'desc' => __( 'Show a single product page.', 'omnibus' ),
),
array(
'title' => __( 'Shop', 'omnibus' ),
'id' => $this->get_name( 'shop' ),
'default' => 'no',
'type' => 'checkbox',
'desc' => sprintf(
__( 'Show on the <a href="%s#woocommerce_shop_page_id" target="_blank">Shop Page</a>.', 'omnibus' ),
add_query_arg(
array(
'page' => 'wc-settings',
'tab' => 'products',
),
admin_url( 'admin.php' )
)
),
'desc_tip' => __( 'This setting is only for WooCommerce Shop Page. It will not work if you use something else, such as a page builder products page.', 'omnibus' ),
),
array(
'title' => __( 'Cart', 'omnibus' ),
'id' => $this->get_name( 'cart' ),
'default' => 'no',
'type' => 'checkbox',
'desc' => sprintf(
__( 'Show on the <a href="%s#woocommerce_cart_page_id" target="_blank">Cart Page</a>.', 'omnibus' ),
add_query_arg(
array(
'page' => 'wc-settings',
'tab' => 'advanced',
),
admin_url( 'admin.php' )
)
),
'desc_tip' => __( 'This setting is only for WooCommerce Cart Page. It will not work if you use something else, such as a page builder cart page.', 'omnibus' ),
),
array(
'title' => __( 'Any loop', 'omnibus' ),
'id' => $this->get_name( 'loop' ),
'default' => 'no',
'type' => 'checkbox',
'desc' => __( 'Show on any product list.', 'omnibus' ),
),
array(
'title' => __( 'Taxonomy Page', 'omnibus' ),
'id' => $this->get_name( 'tax' ),
'default' => 'no',
'type' => 'checkbox',
'desc' => __( 'Show on any taxonomy (tags, categories, custom taxonomies).', 'omnibus' ),
),
array(
'title' => __( 'Related Products List', 'omnibus' ),
'id' => $this->get_name( 'related' ),
'default' => 'no',
'type' => 'checkbox',
'desc' => __( 'Show on the related products box.', 'omnibus' ),
'desc_tip' => __( 'This setting is only for WooCommerce related products box. It will not work if you use something else, such as a page builder related products.', 'omnibus' ),
),
array(
'title' => __( 'Everywhere Else', 'omnibus' ),
'id' => $this->get_name( 'default' ),
'default' => 'no',
'type' => 'checkbox',
'desc' => __( 'Display anywhere else', 'omnibus' ),
'desc_tip' => __( 'Display anywhere else that doesn\'t fit any of the above.', 'omnibus' ),
),
array(
'type' => 'sectionend',
'id' => $this->get_name( 'show-on-end' ),
),
);
return apply_filters( 'iworks_omnibus_where_settings', $settings );
}
/**
* Get settings for the messages section.
*
* @return array
*/
protected function get_settings_for_messages_section() {
$description = array();
/* translators: Do not translate {price}, it is the replacement placeholder ! */
$description[] = esc_html__( 'Use the {price} placeholder to display price.', 'omnibus' );
/* translators: Do not translate {timestamp}, it is the replacement placeholder ! */
$description[] = esc_html__( 'Use the {timestamp} placeholder to display timestamp.', 'omnibus' );
/* translators: Do not translate {days}, it is the replacement placeholder ! */
$description[] = esc_html__( 'Use the {days} placeholder to display days.', 'omnibus' );
/* translators: Do not translate {when}, it is the replacement placeholder ! */
$description[] = esc_html__( 'Use the {when} placeholder to display date.', 'omnibus' );
$settings =
array(
array(
'title' => esc_html__( 'Messages Settings', 'omnibus' ),
'type' => 'title',
'id' => $this->get_name( 'messages' ),
),
array(
'title' => __( 'No Previous Price', 'omnibus' ),
'id' => $this->get_name( 'missing' ),
'default' => 'current',
'type' => 'radio',
'options' => array(
'current' => esc_html__( 'Display current price', 'omnibus' ),
'inform' => esc_html__( 'Inform about it', 'omnibus' ),
'no' => esc_html__( 'Do not display anything', 'omnibus' ),
),
'desc_tip' => esc_html__( 'What do you want to show when no data is available?', 'omnibus' ),
),
array(
'title' => __( 'Short Term Product', 'omnibus' ),
'id' => $this->get_name( 'short_message' ),
'default' => 'no',
'type' => 'radio',
'options' => array(
'inform' => esc_html__( 'Inform about it', 'omnibus' ),
'no' => esc_html__( 'Do not display anything', 'omnibus' ),
),
'desc_tip' => esc_html__( 'What should I do for a product with a short term life?', 'omnibus' ),
),
array(
'type' => 'sectionend',
'id' => $this->get_name( 'messages-end' ),
),
array(
'title' => esc_html__( 'Messages', 'omnibus' ),
'type' => 'title',
'id' => $this->get_name( 'messages-custom' ),
),
array(
'title' => __( 'Custom', 'omnibus' ),
'type' => 'checkbox',
'default' => 'no',
'id' => $this->get_name( 'message_settings' ),
'desc' => __( 'Allow to use custom messages', 'omnibus' ),
'class' => 'iworks_omnibus_messages_settings',
),
array(
'type' => 'omnibus_info',
'info' => $description,
'class' => 'iworks_omnibus_messages_settings_field',
),
array(
'title' => __( 'Omnibus Message', 'omnibus' ),
'type' => 'text',
'id' => $this->get_name( 'message' ),
'default' => __( 'Previous lowest price: {price}.', 'omnibus' ),
'class' => 'iworks_omnibus_messages_settings_field',
'desc' => __( 'A message displaying the last lowest price before the promotion was introduced.', 'omnibus' ),
),
array(
'title' => __( 'No Data Message', 'omnibus' ),
'type' => 'text',
'id' => $this->get_name( 'message_no_data' ),
'default' => __( 'The previous price is not available.', 'omnibus' ),
'class' => 'iworks_omnibus_messages_settings_field',
'desc' => __( 'A message informing about the lack of price data for the selected product.', 'omnibus' ),
),
array(
'title' => __( 'Short Term Product Message', 'omnibus' ),
'type' => 'text',
'id' => $this->get_name( 'message_short' ),
'default' => __( 'This is short term product.', 'omnibus' ),
'class' => 'iworks_omnibus_messages_settings_field',
'desc' => __( 'A message informing that there is no need to inform about the price due to the short expiry date.', 'omnibus' ),
),
array(
'type' => 'sectionend',
'id' => $this->get_name( 'where-custom-end' ),
),
);
return apply_filters( 'iworks_omnibus_where_settings', $settings );
}
/**
* Get settings for the admin section.
*
* @return array
*/
protected function get_settings_for_admin_section() {
$settings =
array(
array(
'title' => esc_html__( 'Product List', 'omnibus' ),
'type' => 'title',
'id' => $this->get_name( 'admin-list' ),
),
array(
'title' => __( 'Admin Dashboard List', 'omnibus' ),
'id' => $this->get_name( 'admin_list' ),
'default' => 'no',
'type' => 'checkbox',
'desc' => __( 'Show on products list screen', 'omnibus' ),
'show_if_checked' => 'option',
'checkboxgroup' => 'start',
),
array(
'id' => $this->get_name( 'admin_list_short' ),
'default' => 'no',
'type' => 'checkbox',
'desc' => sprintf(
__( 'Show short message: %2$sOD: $1$s%3$s', 'omnibus' ),
wc_price( 11.70 ),
'<code>',
'</code>'
),
'show_if_checked' => 'yes',
'checkboxgroup' => 'end',
),
array(
'type' => 'sectionend',
'id' => $this->get_name( 'admin-list-end' ),
),
array(
'title' => esc_html__( 'Product Edit', 'omnibus' ),
'type' => 'title',
'id' => $this->get_name( 'admin-edit' ),
),
array(
'title' => __( 'Admin Edit Screen', 'omnibus' ),
'id' => $this->get_name( 'admin_edit' ),
'default' => 'yes',
'type' => 'checkbox',
'desc' => __( 'Show on product edit screen', 'omnibus' ),
),
array(
'desc' => __( 'Show checkbox to allow turn off Omnibus message', 'omnibus' ),
'desc_tip' => __( 'You can not display the message for Goods which are liable to deteriorate or expire rapidly.', 'omnibus' ),
'id' => $this->get_name( 'admin_short' ),
'default' => 'yes',
'type' => 'checkbox',
'title' => __( 'Short Term Goods', 'omnibus' ),
),
array(
'type' => 'sectionend',
'id' => $this->get_name( 'admin-edit-end' ),
),
array(
'title' => esc_html__( 'Other', 'omnibus' ),
'type' => 'title',
'id' => $this->get_name( 'admin-other' ),
),
array(
'title' => __( 'Number Of Days', 'omnibus' ),
'desc' => __( 'This controls the number of days to show. According to the Omnibus Directive, minimum days is 30 after curent sale was started.', 'omnibus' ),
'id' => $this->get_name( 'days' ),
'default' => '30',
'type' => 'number',
'css' => 'width: 80px;',
'custom_attributes' => array(
'min' => 30,
),
),
array(
'type' => 'sectionend',
'id' => $this->get_name( 'admin-other-end' ),
),
);
return apply_filters( 'iworks_omnibus_admin_settings', $settings );
}
/**
* get name
*
* @since 2.3.0
*/
private function get_name( $name = '' ) {
$this->meta_name = apply_filters( 'iworks_omnibus_get_name', '' );
if ( empty( $name ) ) {
return $this->meta_name;
}
return sanitize_title(
sprintf(
'%s_%s',
$this->meta_name,
$name
)
);
}
/**
* Get settings for the debug section.
*
* @since 2.4.0
*
* @return array
*/
protected function get_settings_for_debug_section() {
$settings = array(
array(
'title' => esc_html__( 'Debug', 'omnibus' ),
'type' => 'title',
),
array(
'title' => __( 'Settings', 'omnibus' ),
'type' => 'textarea',
'desc' => __( 'Please copy this field to support question', 'omnibus' ),
),
array(
'title' => __( 'Product', 'omnibus' ),
'id' => $this->get_name( 'product_debug' ),
'type' => 'checkbox',
'desc' => __( 'Display debug information in product content', 'omnibus' ),
),
array(
'type' => 'sectionend',
),
);
return apply_filters( 'iworks_omnibus_debug_settings', $settings );
}
}
return new iworks_omnibus_integration_woocommerce_settings();
// phpcs:enable

View File

@@ -0,0 +1,342 @@
<?php
/*
Copyright 2022-2023 Marcin Pietrzak (marcin@iworks.pl)
this program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'iworks_omnibus_integration_learnpress' ) ) {
return;
}
include_once dirname( dirname( __FILE__ ) ) . '/class-iworks-omnibus-integration.php';
class iworks_omnibus_integration_learnpress extends iworks_omnibus_integration {
public function __construct() {
add_filter( 'learn_press_course_price_html', array( $this, 'filter_learn_press_course_price_html' ), 10, 3 );
add_filter( 'pre_option', array( $this, 'filter_pre_option' ), 10, 3 );
/**
* admin init
*
* @since 2.1.0
*/
add_action( 'admin_init', array( $this, 'action_admin_init' ) );
/**
* maybe save initial data
*
* @since 2.3.0
*/
add_action( 'shutdown', array( $this, 'action_shutdown_maybe_save_price' ) );
}
/**
* admin init
*
* @since 2.1.0
*/
public function action_admin_init() {
add_action( 'save_post_lp_course', array( $this, 'action_learnpress_save_post_lp_course' ), 10, 2 );
add_filter( 'learn-press/courses-settings-fields', array( $this, 'filter_learnpress_courses_settings_fields' ) );
add_filter( 'lp/course/meta-box/fields/price', array( $this, 'filter_learnpress_admin_show_omnibus' ) );
add_filter( 'plugin_action_links', array( $this, 'filter_add_link_omnibus_configuration' ), PHP_INT_MAX, 4 );
}
/**
* Add configuration link to plugin_row_meta.
*
* @since 2.1.0
*
*/
public function filter_add_link_omnibus_configuration( $actions, $plugin_file, $plugin_data, $context ) {
if ( 'learnpress/learnpress.php' !== $plugin_file ) {
return $actions;
}
$settings_page_url = add_query_arg(
array(
'page' => 'learn-press-settings',
'tab' => 'courses',
),
admin_url( 'admin.php' )
);
$actions['omnibus'] = sprintf(
'<a href="%s#learn_press_%s">%s</a>',
$settings_page_url,
$this->get_name( 'on_sale' ),
__( 'Omnibus', 'omnibus' )
);
return $actions;
}
/**
* translate options to LearnPress options
*
* @since 2.1.0
*/
public function filter_pre_option( $pre, $option, $default ) {
if ( ! preg_match( '/^_iwo_price_lowest_lp_/', $option ) ) {
return $pre;
}
$value = get_option( 'learn_press_' . $option, $default );
if ( false === $value ) {
return 'no';
}
if ( true === $value ) {
return 'yes';
}
return $value;
}
/**
* LearnPress: add confirmation fields
*
* @since 2.1.0
*/
public function filter_learnpress_courses_settings_fields( $settings ) {
return array_merge(
$settings,
array(
$this->settings_title(),
array(
'title' => __( 'Only on sale', 'omnibus' ),
'id' => $this->get_name( 'on_sale' ),
'default' => 'yes',
'type' => 'checkbox',
'desc' => __( 'Display only for the course on sale.', 'omnibus' ),
),
/**
* Show on
*/
array(
'title' => __( 'Show on', 'omnibus' ),
'desc' => __( 'Course single', 'omnibus' ),
'id' => $this->get_name( 'product' ),
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'desc_tip' => __( 'Show or hide on a single course page.', 'omnibus' ),
),
array(
'id' => $this->get_name( 'default' ),
'default' => 'no',
'type' => 'checkbox',
'desc' => __( 'Display anywhere else', 'omnibus' ),
'desc_tip' => __( 'Display anywhere else that doesn\'t fit any of the above.', 'omnibus' ),
'checkboxgroup' => 'end',
),
/**
* admin
*/
array(
'title' => __( 'Show on admin on', 'omnibus' ),
'desc' => __( 'Courses list', 'omnibus' ),
'id' => $this->get_name( 'admin_list' ),
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Course edit', 'omnibus' ),
'id' => $this->get_name( 'admin_edit' ),
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
$this->settings_days(),
/**
* messages
*/
$this->settings_message_settings(),
$this->settings_message(),
array(
'type' => 'sectionend',
),
)
);
}
/**
* Save LearnPress Course
*
* @since 1.0.1
*/
public function action_learnpress_save_post_lp_course( $post_id, $post ) {
if ( 'publish' !== get_post_status( $post ) ) {
return;
}
$course = learn_press_get_course( $post_id );
if ( ! is_a( $course, 'LP_Course' ) ) {
return;
}
$price = $course->get_price();
$this->save_price_history( $post_id, $price );
}
/**
* LearnPress: show prices in admin
*
* @since 1.0.1
*/
public function filter_learnpress_admin_show_omnibus( $configuration ) {
if ( ! $this->should_it_show_up( $post_id ) ) {
return $configuration;
}
if ( 'no' === get_option( $this->get_name( 'admin_edit' ) ) ) {
return $configuration;
}
global $post_id;
$price_lowest = $this->learnpress_get_lowest_price_in_history( $post_id );
$configuration[ $this->meta_name . 'price' ] = new LP_Meta_Box_Text_Field(
esc_html__( 'Omnibus Price', 'omnibus' ),
sprintf(
esc_html__( 'The lowest price in %d days.', 'omnibus' ),
$this->get_days()
),
is_array( $price_lowest ) && isset( $price_lowest['price'] ) ? $price_lowest['price'] : esc_html__( 'no data available', 'omnibus' ),
array(
'type_input' => 'text',
'custom_attributes' => array(
'readonly' => 'readonly',
),
)
);
$configuration[ $this->meta_name . 'date' ] = new LP_Meta_Box_Text_Field(
esc_html__( 'Omnibus Date', 'omnibus' ),
sprintf(
esc_html__( 'The date when lowest price in %d days occurred.', 'omnibus' ),
$this->get_days()
),
is_array( $price_lowest ) && isset( $price_lowest['timestamp'] ) ? date_i18n( get_option( 'date_format' ), $price_lowest['timestamp'] ) : esc_html__( 'no data available', 'omnibus' ),
array(
'type_input' => 'text',
'custom_attributes' => array(
'readonly' => 'readonly',
),
)
);
return $configuration;
}
/**
* LearnPress: add Omnibus price information
*
* @since 1.0.1
*/
public function filter_learn_press_course_price_html( $price_html, $has_sale_price, $post_id ) {
if ( ! $this->should_it_show_up( $post_id ) ) {
return $price_html;
}
$price_lowest = $this->learnpress_get_lowest_price_in_history( $post_id );
return $this->add_message( $price_html, $price_lowest, 'learn_press_format_price' );
}
/**
* LearnPress: get lowest price in days
*
* @since 1.0.1
*/
private function learnpress_get_lowest_price_in_history( $post_id ) {
if ( ! function_exists( 'learn_press_get_course' ) ) {
return;
}
$course = learn_press_get_course( $post_id );
if ( ! is_a( $course, 'LP_Course' ) ) {
return array();
}
return $this->_get_lowest_price_in_history( $course->get_price(), $post_id );
}
public function get_name( $name = '', $add_prefix = '' ) {
if ( empty( $name ) ) {
return parent::get_name( 'lp' );
}
return parent::get_name( 'lp_' . $name );
}
/**
* helper to decide show it or no
*/
private function should_it_show_up( $post_id ) {
if ( 'yes' === get_option( $this->get_name( 'on_sale' ), 'yes' ) ) {
$course = learn_press_get_course( $post_id );
if ( ! $course->has_sale_price() ) {
return apply_filters( 'iworks_omnibus_show', false );
}
}
/**
* for admin
*/
if ( is_admin() ) {
$screen = get_current_screen();
if ( 'lp_course' === $screen->id ) {
if ( 'no' === get_option( $this->get_name( 'admin_edit' ), 'yes' ) ) {
return apply_filters( 'iworks_omnibus_show', false );
}
}
if ( 'edit-lp_course' === $screen->id ) {
if ( 'no' === get_option( $this->get_name( 'admin_list' ), 'yes' ) ) {
return apply_filters( 'iworks_omnibus_show', false );
}
}
return apply_filters( 'iworks_omnibus_show', true );
}
/**
* front-end
*/
if (
is_single()
&& is_main_query()
&& ( learn_press_is_course() )
) {
if ( 'no' === get_option( $this->get_name( 'single' ), 'yes' ) ) {
return apply_filters( 'iworks_omnibus_show', false );
}
return apply_filters( 'iworks_omnibus_show', true );
}
/**
* at least add filter
*/
$show = 'yes' === get_option( $this->get_name( 'default' ), 'no' );
return apply_filters( 'iworks_omnibus_show', $show );
}
/**
* maybe save product price
*/
public function action_shutdown_maybe_save_price() {
if ( ! is_singular( 'lp_course' ) ) {
return;
}
if ( ! empty( get_post_meta( get_the_ID(), $this->get_name() ) ) ) {
return;
}
$course = learn_press_get_course( get_the_ID() );
if ( ! is_a( $course, 'LP_Course' ) ) {
return;
}
$data = array(
'price' => $course->get_price(),
'timestamp' => get_the_modified_date( 'U' ),
'type' => 'autosaved',
);
if ( empty( $data['price'] ) ) {
return;
}
add_post_meta( $course->get_ID(), $this->meta_name, $data );
}
}

View File

@@ -0,0 +1,107 @@
.iworks-rate {
font-family: "Exo 2", sans-serif;
padding: 20px 30px; }
.iworks-rate h4 {
margin: 10px 0 0;
padding: 4px 38px 4px 0;
font-size: 16px;
font-weight: 500;
line-height: 1.618;
--logo: attr(data-logo); }
.iworks-rate h4 strong {
font-weight: 900; }
.iworks-rate p {
font-size: 14px;
max-width: 800px;
line-height: 1.618;
margin: 0 0 10px;
padding: 4px 0; }
.iworks-rate.has-logo h4 {
display: flex;
align-items: center; }
.iworks-rate-logo {
display: block;
width: 3em;
height: 3em;
margin-right: .3em;
content: "";
background-color: transparent;
background-repeat: no-repeat;
background-position: 50%;
background-size: contain; }
.iworks-rate-buttons {
margin-top: -10px;
padding: 10px 2px;
overflow: hidden; }
.iworks-rate-buttons .iworks-rate-button {
float: left;
margin: 20px 20px 0 0; }
.iworks-rate-button {
margin: 20px auto;
position: relative;
display: inline-block;
min-width: 180px;
padding: 9px 30px;
font-weight: 500;
font-size: 14px;
line-height: 1.618;
text-align: center;
text-decoration: none;
background-color: #fff;
opacity: 1;
box-sizing: border-box;
box-shadow: none;
outline: none;
border: 1px solid transparent;
transition: color 0.3s !important;
z-index: 10;
cursor: pointer; }
.iworks-rate-button--green {
border-color: #46b450;
color: #46b450; }
.iworks-rate-button--green:after {
background-color: #46b450; }
.iworks-rate-button--green:focus {
color: #46b450;
box-shadow: 0 0 0 1px #46b450, 0 0 2px 1px rgba(79, 148, 212, 0.8);
outline: 1px solid transparent; }
.iworks-rate-button--green:hover {
color: #fff;
background-color: #46b450; }
.iworks-rate-button--blue {
border-color: #0073aa;
color: #0073aa; }
.iworks-rate-button--blue:after {
background-color: #0073aa; }
.iworks-rate-button--blue:focus {
box-shadow: 0 0 0 1px #0073aa, 0 0 2px 1px rgba(79, 148, 212, 0.8);
color: #0073aa;
outline: 1px solid transparent; }
.iworks-rate-button--blue:hover {
color: #fff;
background-color: #0073aa; }
.iworks-rate-button:before {
float: left;
margin-right: 10px;
font-family: dashicons;
font-size: 20px;
line-height: 1.1; }
.iworks-rate-button:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 0;
bottom: 0;
transition: all ease .3s;
z-index: -1; }
.iworks-rate-button:hover:after {
width: 100%; }
.iworks-rate-center {
text-align: center; }
/*# sourceMappingURL=admin.css.map */

View File

@@ -0,0 +1,23 @@
jQuery(
function() {
var $parent = jQuery('.notice-iworks-rate');
jQuery('.iworks-rate-button, .notice-dismiss', $parent).on('click', function(e) {
var data = {
action: 'iworks_rate_button',
plugin_id: $parent.data('id'),
button: jQuery(this).data('action')
};
if ('get-help' === jQuery(this).data('action')) {
return true;
}
jQuery.post(
$parent.data('ajax-url'),
data,
function(response) {
$parent.detach();
}
);
return true;
});
}
);

View File

@@ -0,0 +1,146 @@
$au: 1.618;
$color_blue: #0073aa;
$color_green: #46b450;
$color_white: #fff;
.iworks-rate {
font-family: "Exo 2", sans-serif;
padding: 20px 30px;
h4 {
margin: 10px 0 0;
padding: 4px 38px 4px 0;
font: {
size: 16px;
weight: 500;
}
strong {
font-weight: 900;
}
line-height: $au;
--logo: attr(data-logo);
}
p {
font-size: 14px;
max-width: 800px;
line-height: $au;
margin: 0 0 10px;
padding: 4px 0;
}
&.has-logo {
h4 {
display: flex;
align-items: center;
}
}
}
.iworks-rate-logo {
display: block;
width: 3em;
height: 3em;
margin-right: .3em;
content: "";
background: {
color: transparent;
repeat: no-repeat;
position: 50%;
size: contain;
}
}
.iworks-rate-buttons {
margin-top: -10px;
padding: 10px 2px;
overflow: hidden;
.iworks-rate-button {
float: left;
margin: 20px 20px 0 0;
}
}
.iworks-rate-button {
margin: 20px auto;
position: relative;
display: inline-block;
min-width: 180px;
padding: 9px 30px;
font: {
weight: 500;
size: 14px;
}
line-height: $au;
text: {
align: center;
decoration: none;
}
background-color: $color_white;
opacity: 1;
box-sizing: border-box;
box-shadow: none;
outline: none;
border: 1px solid transparent;
transition: color .3s!important;
z-index: 10;
cursor: pointer;
&--green {
border-color: $color_green;
color: $color_green;
&:after {
background-color: $color_green;
}
&:focus {
color: $color_green;
box-shadow: 0 0 0 1px $color_green,0 0 2px 1px rgba(79,148,212,.8);
outline: 1px solid transparent
}
&:hover {
color: $color_white;
background-color: $color_green;
}
}
&--blue {
border-color: $color_blue;
color: $color_blue;
&:after {
background-color: $color_blue;
}
&:focus {
box-shadow: 0 0 0 1px $color_blue,0 0 2px 1px rgba(79,148,212,.8);
color: $color_blue;
outline: 1px solid transparent
}
&:hover {
color: $color_white;
background-color: $color_blue;
}
}
&:before{
float: left;
margin-right: 10px;
font-family: dashicons;
font-size: 20px;
line-height: 1.1;
}
&:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 0;
bottom: 0;
transition: all ease .3s;
z-index: -1;
}
&:hover {
&:after {
width: 100%;
}
}
}
.iworks-rate-center {
text-align: center;
}

View File

@@ -0,0 +1 @@
<svg width="500" height="500" xmlns="http://www.w3.org/2000/svg"><path fill="#231f20" d="m 216.7,383.1 c -91.8,0 -166.4,-74.5 -166.4,-166.4 0,-32.4 9.5,-62.4 25.5,-88.0 -2.6,7.9 -4.0,16.4 -4.0,25.3 0,45.5 36.8,82.4 82.3,82.4 45.4,0 82.3,-36.9 82.3,-82.4 0,-45.4 -36.9,-82.3 -82.3,-82.3 -8.8,0 -17.3,1.4 -25.2,4.0 25.5,-16 55.5,-25.3 87.7,-25 91.8,0 166.4,74.5 166.4,166.4 0,91.9 -74.6,166.4 -166.4,166.4 M 75.5,357.9 28.5,404.9 c 48.2,48.1 114.7,78 188.2,78 147,0 266.2,-119.2 266.2,-266.2 0,-73.5 -29.8,-140.1 -78,-188.2 l -47.1,47.0 0.1,0.1 c -36.2,-36.2 -86.1,-58.5 -141.2,-58.5 -110.2,0 -199.6,89.4 -199.6,199.6 0,55.0 22.3,104.9 58.4,141 v 0.2 z" /></svg>

After

Width:  |  Height:  |  Size: 661 B

View File

@@ -0,0 +1,510 @@
<?php
/**
* iWorks_Rate - Dashboard Notification module.
*
* @version 2.1.2
* @author iworks (Marcin Pietrzak)
*
*/
if ( ! class_exists( 'iworks_rate' ) ) {
class iworks_rate {
/**
* This class version.
*
* @since 1.0.1
* @var string
*/
private $version = '2.1.2';
/**
* $wpdb->options field name.
*
* @since 1.0.0
* @var string
*/
protected $option_name = 'iworks_rates';
/**
* List of all registered plugins.
*
* @since 1.0.0
* @var array
*/
protected $plugins = array();
/**
* Module options that are stored in database.
* Timestamps are stored here.
*
* Note that this option is stored in site-meta for multisite installs.
*
* @since 1.0.0
* @var array
*/
protected $stored = array();
/**
* Initializes and returns the singleton instance.
*
* @since 1.0.0
*/
static public function instance() {
static $Inst = null;
if ( null === $Inst ) {
$Inst = new iworks_rate();
}
return $Inst;
}
/**
* Set up the iworks_rate module. Private singleton constructor.
*
* @since 1.0.0
*/
private function __construct() {
/**
* settings
*/
$this->stored = wp_parse_args(
get_site_option( $this->option_name, false, false ),
array()
);
/**
* actions
*/
add_action( 'load-index.php', array( $this, 'load' ) );
add_action( 'iworks-register-plugin', array( $this, 'register' ), 5, 3 );
add_action( 'wp_ajax_iworks_rate_button', array( $this, 'ajax_button' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );
/**
* own hooks
*/
add_filter( 'iworks_rate_assistance', array( $this, 'filter_get_assistance_widget' ), 10, 2 );
add_filter( 'iworks_rate_love', array( $this, 'filter_get_love_widget' ), 10, 2 );
/**
* advertising
*
* @since 2.1.0
*/
add_filter( 'iworks_rate_advertising_og', array( $this, 'filter_get_advertising_og' ) );
}
/**
* Inicialize admin area
*
* @since 2.0.2
*/
public function admin_init() {
foreach ( $this->plugins as $plugin_file => $plugin ) {
add_filter( 'plugin_action_links_' . $plugin_file, array( $this, 'add_donate_link' ), 10, 4 );
}
}
/**
* Add donate link to plugin_row_meta.
*
* @since 2.0.2
*
* @param array $actions An array of the plugin's metadata, including the version, author, author URI, and plugin URI.
*/
public function add_donate_link( $actions, $plugin_file, $plugin_data, $context ) {
$slug = 'iworks';
if (
isset( $this->plugins[ $plugin_file ] )
&& isset( $this->plugins[ $plugin_file ]['slug'] )
) {
$slug = $this->plugins[ $plugin_file ]['slug'];
}
$settings_page_url = apply_filters( 'iworks_rate_settings_page_url_' . $slug, null );
if ( ! empty( $settings_page_url ) ) {
$actions['settings'] = sprintf(
'<a href="%s">%s</a>',
esc_url( $settings_page_url ),
__( 'Settings', 'omnibus' )
);
}
$actions['donate'] = sprintf(
'<a href="https://ko-fi.com/iworks?utm_source=%s&utm_medium=plugin-links" target="_blank">%s</a>',
$slug,
__( 'Provide us a coffee', 'omnibus' )
);
return $actions;
}
public function load() {
$plugin_id = $this->choose_plugin();
if ( empty( $plugin_id ) ) {
return;
}
$this->plugin_id = $plugin_id;
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
add_action( 'admin_notices', array( $this, 'show' ) );
}
/**
* Save persistent module-data to the WP database.
*
* @since 1.0.0
*/
protected function store_data() {
update_site_option( $this->option_name, $this->stored );
}
/**
* Action handler for 'iworks-register-plugin'
* Register an active plugin.
*
* @since 1.0.0
* @param string $plugin_id WordPress plugin-ID (see: plugin_basename).
* @param string $title Plugin name for display.
* @param string $slug the plugin slug on wp.org
*/
public function register( $plugin_id, $title, $slug ) {
// Ignore incorrectly registered plugins to avoid errors later.
if ( empty( $plugin_id ) || empty( $title ) || empty( $slug ) ) {
return;
}
$data = array(
'title' => $title,
'slug' => $slug,
);
$this->plugins[ $plugin_id ] = $data;
/**
* check for option update
*
* @since 2.0.6
*
*/
$update = false;
/*
* When the plugin is registered the first time we store some infos
* in the persistent module-data that help us later to find out
* if/which message should be displayed.
*/
if ( empty( $this->stored[ $plugin_id ] ) ) {
$this->stored[ $plugin_id ] = wp_parse_args(
array(
'registered' => time(),
'show_at' => time() + rand( 7, 14 ) * DAY_IN_SECONDS,
'rated' => 0,
'hide' => 0,
),
$data
);
$update = true;
}
/**
* check slug & mark for update if needed
*
* @since 2.0.6
*/
if ( $this->stored[ $plugin_id ]['slug'] !== $slug ) {
$this->stored[ $plugin_id ]['slug'] = $slug;
$update = true;
}
/**
* check title - can be diferent due language
*
* @since 2.0.6
*/
$this->stored[ $plugin_id ]['title'] = $title;
/**
* Finally save the details if it is needed
*/
if ( $update ) {
$this->store_data();
}
}
/**
* Ajax handler called when the user chooses the CTA button.
*
* @since 1.0.0
*/
public function ajax_button() {
$plugin_id = filter_input( INPUT_POST, 'plugin_id', FILTER_DEFAULT );
if ( empty( $plugin_id ) ) {
wp_send_json_error();
}
if ( ! isset( $this->plugins[ $plugin_id ] ) ) {
wp_send_json_error();
}
switch ( filter_input( INPUT_POST, 'button', FILTER_DEFAULT ) ) {
case '':
case 'add-review':
$this->add_weeks( $plugin_id );
wp_send_json_success();
case 'hide':
$this->add_weeks( $plugin_id );
$this->hide( $plugin_id );
wp_send_json_success();
case 'donate':
$this->add_months( $plugin_id );
wp_send_json_success();
}
wp_send_json_success();
}
public function hide( $plugin_id ) {
if ( ! isset( $this->stored[ $plugin_id ] ) ) {
return;
}
$this->stored[ $plugin_id ]['rated'] = time();
$this->store_data();
}
private function add_weeks( $plugin_id ) {
if ( ! isset( $this->stored[ $plugin_id ] ) ) {
return;
}
$this->stored[ $plugin_id ]['show_at'] = time() + rand( 4, 6 ) * WEEK_IN_SECONDS + rand( 0, 7 ) * DAY_IN_SECONDS;
$this->store_data();
}
private function add_months( $plugin_id ) {
if ( ! isset( $this->stored[ $plugin_id ] ) ) {
return;
}
$this->stored[ $plugin_id ]['show_at'] = time() + rand( 15, 30 ) * WEEK_IN_SECONDS + rand( 0, 14 ) * DAY_IN_SECONDS;
$this->store_data();
}
/**
* Ajax handler called when the user chooses the dismiss button.
*
* @since 1.0.0
*/
public function dismiss() {
$plugin = $this->get_plugin_from_post();
if ( is_wp_error( $plugin ) ) {
wp_send_json_error();
}
wp_send_json_success();
}
/**
* Action handler for 'load-index.php'
* Set-up the Dashboard notification.
*
* @since 1.0.0
*/
public function enqueue() {
wp_enqueue_style(
__CLASS__,
plugin_dir_url( __FILE__ ) . 'admin.css',
array(),
$this->version
);
wp_enqueue_script(
__CLASS__,
plugin_dir_url( __FILE__ ) . 'admin.js',
array(),
$this->version,
true
);
}
/**
* Action handler for 'admin_notices'
* Display the Dashboard notification.
*
* @since 1.0.0
*/
public function show() {
$this->render_message( $this->plugin_id );
}
/**
* Check to see if there is a pending message to display and returns
* the message details if there is.
*
* Note that this function is only called on the main Dashboard screen
* and only when logged in as super-admin.
*
* @since 1.0.0
* @return object|false
* string $plugin WordPress plugin ID?
*/
protected function choose_plugin() {
if ( wp_is_mobile() ) {
return false;
}
/**
* list
*/
$choosen = array();
/**
* change time by filter
*/
$now = apply_filters( 'iworks_rate_set_custom_time', time() );
foreach ( $this->stored as $plugin_id => $item ) {
if ( ! isset( $this->plugins[ $plugin_id ] ) ) {
if ( isset( $this->stored[ $plugin_id ] ) ) {
unset( $this->stored[ $plugin_id ] );
$this->store_data();
}
continue;
}
if ( intval( $item['show_at'] ) > $now ) {
continue;
}
$choosen[] = $plugin_id;
}
if ( empty( $choosen ) ) {
return false;
}
return $choosen[ array_rand( $choosen ) ];
}
/**
* Renders the actual Notification message.
*
* @since 1.0.0
*/
protected function render_message( $plugin_id ) {
$file = $this->get_file( 'thanks' );
$plugin = $this->get_plugin_data_by_plugin_id( $plugin_id );
load_template( $file, true, $plugin );
}
/**
* @since 2.0.1
*/
private function get_file( $file, $group = '' ) {
return sprintf(
'%s/templates/%s%s%s.php',
dirname( __FILE__ ),
$group,
'' === $group ? '' : '/',
sanitize_title( $file )
);
}
/**
* @since 2.0.1
*/
private function get_plugin_data_by_plugin_id( $plugin_id ) {
$plugin = wp_parse_args(
$this->plugins[ $plugin_id ],
$this->stored[ $plugin_id ]
);
$plugin['plugin_id'] = $plugin_id;
$plugin['logo'] = apply_filters( 'iworks_rate_notice_logo_style', '', $plugin );
$plugin['ajax_url'] = admin_url( 'admin-ajax.php' );
$plugin['classes'] = array(
'iworks-rate',
'iworks-rate-' . $plugin['slug'],
'iworks-rate-notice',
);
if ( ! empty( $plugin['logo'] ) ) {
$plugin['classes'][] = 'has-logo';
}
$plugin['url'] = esc_url(
sprintf(
_x( 'https://wordpress.org/plugins/%s', 'plugins home', 'omnibus' ),
$plugin['slug']
)
);
$plugin['support_url'] = esc_url(
sprintf(
_x( 'https://wordpress.org/support/plugin/%s', 'plugins support home', 'omnibus' ),
$plugin['slug']
)
);
return $plugin;
}
/**
* @since 2.0.1
*/
private function get_plugin_id_by_slug( $slug ) {
foreach ( $this->stored as $plugin_id => $plugin ) {
if ( $slug === $plugin['slug'] ) {
return $plugin_id;
}
}
return new WP_Error();
}
/**
* @since 2.0.1
*/
public function filter_get_assistance_widget( $content, $slug ) {
$plugin_id = $this->get_plugin_id_by_slug( $slug );
if ( is_wp_error( $plugin_id ) ) {
return $content;
}
$this->enqueue();
$plugin = $this->get_plugin_data_by_plugin_id( $plugin_id );
$file = $this->get_file( 'support', 'widgets' );
ob_start();
load_template( $file, true, $plugin );
$content = ob_get_contents();
ob_end_clean();
return $content;
}
/**
* @since 2.0.1
*/
public function filter_get_love_widget( $content, $slug ) {
$plugin_id = $this->get_plugin_id_by_slug( $slug );
if ( is_wp_error( $plugin_id ) ) {
return $content;
}
$this->enqueue();
$plugin = $this->get_plugin_data_by_plugin_id( $plugin_id );
$file = $this->get_file( 'donate', 'widgets' );
ob_start();
load_template( $file, true, $plugin );
$content = ob_get_contents();
ob_end_clean();
return $content;
}
/**
* Get advertising for "OG — Better Share on Social Media" plugin.
*
* @since 2.1.0
*/
public function filter_get_advertising_og( $data ) {
return array(
'iworks-adverting-og' => array(
'title' => __( 'OpenGraph', 'omnibus' ),
'callback' => array( $this, 'get_advertising_og_content' ),
'context' => 'side',
'priority' => 'low',
),
);
}
/**
* Advertising content for "OG — Better Share on Social Media" plugin.
*
* @since 2.1.0
*/
public function get_advertising_og_content() {
$args = array(
'install_plugin_url' => $this->get_install_plugin_url( 'og' ),
'plugin_name' => __( 'OG — Better Share on Social Media', 'omnibus' ),
'plugin_wp_home' => __( 'https://wordpress.org/plugins/og/', 'omnibus' ),
);
$file = $this->get_file( 'og', 'plugins' );
load_template( $file, true, $args );
}
/**
* get admin plugin install url
*
* @since 2.1.0
*/
private function get_install_plugin_url( $slug ) {
return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
}
}
// Initialize the module.
iworks_rate::instance();
}

View File

@@ -0,0 +1,18 @@
<p><?php
esc_html_e( 'Would you like to boost your website sharing abilities?', 'omnibus ' );
?></p>
<p>
<?php
printf(
esc_html__( 'Don\'t wait, install plugin %s!', 'omnibus' ),
sprintf(
'<a href="%s" target="_blank"><strong>%s</strong></a>',
$args['plugin_wp_home'],
$args['plugin_name']
)
);
?>
</p>
<p class="iworks-rate-center"><a href="<?php echo esc_url( $args['install_plugin_url'] ); ?>" class="iworks-rate-button iworks-rate-button--green dashicons-admin-plugins
"><?php echo esc_html( __( 'Install', 'omnibus' ) ); ?></a></p>

View File

@@ -0,0 +1,34 @@
<?php
/**
* Notice displayed in admin panel.
*/
?>
<div class="notice notice-success is-dismissible notice-iworks-rate"
data-slug="<?php echo esc_attr( $args['slug'] ); ?>"
data-id="<?php echo esc_attr( $args['plugin_id'] ); ?>"
data-ajax-url="<?php echo esc_url( $args['ajax_url'] ); ?>"
>
<div class="<?php echo esc_attr( implode( ' ', $args['classes'] ) ); ?>">
<h4>
<?php
if ( ! empty( $args['logo'] ) ) {
printf( '<span class="iworks-rate-logo" style="background-image:url(%s)"></span>', esc_url( $args['logo'] ) ); }
?>
<span><?php printf( esc_html( __( 'Thank you for using our plugin %s!', 'omnibus' ) ), sprintf( '<strong>%s</strong>', $args['title'] ) ); ?></span></h4>
<?php
/* translators: %1$s: open anchor tag, %2$s: close anchor tag */
$content = __( 'Please let us know what you think about our plugin. It is important that we can develop this tool. Thank you for all the ratings, reviews and donates. If you have a technical problem, please before you add a review %1$scheck our FAQ%2$s or contact us if you did not find help there. We will try to help you!', 'omnibus' );
echo wpautop( wp_kses_post( sprintf( $content, sprintf( '<a href="%s#faq" target="_blank">', $args['url'] ), '</a>' ) ) );
?>
<div class="iworks-rate-buttons">
<a data-action="get-help" href="<?php echo $args['support_url']; ?>/#new-post" target="_blank" class="iworks-rate-button iworks-rate-button--green" ><?php echo esc_html( __( 'Get help', 'omnibus' ) ); ?></a>
<?php if ( intval( $args['rated'] ) === 0 ) { ?>
<a data-action="add-review" href="<?php echo $args['support_url']; ?>/reviews/?rate=5#new-post" target="_blank" class="iworks-rate-button iworks-rate-button--green" ><?php echo esc_html( __( 'Add review', 'omnibus' ) ); ?></a>
<?php } ?>
<a data-action="donate" href="https://ko-fi.com/iworks/?utm_source=<?php echo $args['slug']; ?>&utm_medium=notice-thanks" target="_blank" class="iworks-rate-button iworks-rate-button--green dashicons-heart" ><?php echo esc_html( __( 'Provide us a coffee', 'omnibus' ) ); ?></a>
<?php if ( intval( $args['rated'] ) === 0 ) { ?>
<button type="button" data-action="hide" class="iworks-rate-button iworks-rate-button--blue" ><?php echo esc_html( __( 'I added review, do not show again', 'omnibus' ) ); ?></button>
<?php } ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,4 @@
<p><?php echo wp_kses_post( __( 'However, working on plugins and technical support requires many hours of work. If you want to appreciate it, you can provide me a coffee.', 'omnibus' ) ); ?></p>
<p><?php echo wp_kses_post( __( 'If every plugin user did it, I could devote myself fully to working on this plugin. Thanks everyone!', 'omnibus' ) ); ?></p>
<p class="iworks-rate-center"><a href="https://ko-fi.com/iworks/?utm_source=<?php echo $args['slug']; ?>&utm_medium=widget-donate" target="_blank" class="iworks-rate-button iworks-rate-button--blue dashicons-heart"><?php echo esc_html( __( 'Provide me a coffee', 'omnibus' ) ); ?></a></p>

View File

@@ -0,0 +1,34 @@
<p>
<?php
echo wp_kses_post(
__( 'Do you have a technical problem? Please contact us. We will be happy to help you. Or maybe you have an idea for a new feature? Please let us know about it by filling the support form. We will try to add it!', 'omnibus' )
);
?>
</p>
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %1$s: open anchor tag, %2$s: close anchor tag, %3$s: open anchor tag, %4$s: close anchor tag */
__( 'Please %1$scheck our FAQ%2$s before adding a thread with technical problem. If you do not find help there, %3$scheck support forum%4$s for similar problems.', 'omnibus' ),
'<a href="' . $args['url'] . '#faq" target="_blank">',
'</a>',
'<a href="' . $args['support_url'] . '" target="_blank">',
'</a>'
)
);
?>
</p>
<p class="iworks-rate-center">
<a href="<?php echo $args['support_url']; ?>" target="_blank" class="iworks-rate-button iworks-rate-button--blue" ><?php echo esc_html( __( 'Get help', 'omnibus' ) ); ?></a>
</p>
<p>
<?php
echo wp_kses_post(
__( 'Do you like our plugin? Could you rate him? Please let us know what you think about our plugin. It is important that we can develop this tool. Thank you for all the ratings, reviews and donates.', 'omnibus' )
);
?>
</p>
<p class="iworks-rate-center">
<a href="<?php echo add_query_arg( 'rate', '5', $args['support_url'] . '/reviews/' ); ?>#new-post" target="_blank" class="iworks-rate-button iworks-rate-button--blue" ><?php echo esc_html( __( 'Add review', 'omnibus' ) ); ?></a>
</p>