client = new CTXFeed\AppServices\Client( '4e68acba-cbdc-476b-b4bf-eab176ac6a16', 'CTX Feed', WOO_FEED_FREE_FILE );
// Load
$this->insights = $this->client->insights(); // Plugin Insights
$this->promotion = $this->client->promotions(); // Promo offers
// Setup
$this->promotion->set_source( 'https://api.bitbucket.org/2.0/snippets/woofeed/RLbyop/files/woo-feed-notice.json' );
// Initialize
$this->insightInit();
$this->promotion->init();
// Housekeeping.
add_action( 'admin_menu', array( $this, 'premium_features' ), 999 );
//show admin notices when woocommerce is activated
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
add_action( 'admin_notices', array( $this, 'woo_feed_review_notice' ) );
add_action( 'wp_ajax_woo_feed_save_review_notice', array( $this, 'woo_feed_save_review_notice' ) );
add_action( 'wp_ajax_woo_feed_hide_notice', array( $this, 'woo_feed_hide_notice' ) );
}
}
/**
* Cloning is forbidden.
* @since 1.0.2
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'woo-feed' ), '1.0.2' );
}
/**
* Initialize Insights
* @return void
*/
private function insightInit() {
global $wpdb;
$result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", "wf_feed_%"), 'ARRAY_A' ); // phpcs:ignore
if ( ! is_array( $result ) ) {
$result = array();
}
$catCount = wp_count_terms(
array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'parent' => 0,
)
);
if ( is_wp_error( $catCount ) ) {
$catCount = 0;
}
/**
* @TODO count products by type
* @see wc_get_product_types();
*/
// update_option( 'woo_feed_review_notice', $value );
// $notices = [ 'rp-wcdpd', 'wpml', 'rating', 'product_limit' ];
//
$hidden_notices = array();
foreach ( array( 'rp-wcdpd', 'wpml', 'rating', 'product_limit' ) as $which ) {
$hidden_notices[ $which ] = (int) get_option( sprintf( 'woo_feed_%s_notice_hidden', $which ), 0 );
}
$this->is_add_extra = apply_filters( 'woo_feed_woocommerce_add_extra', true );
if( $this->is_add_extra ) {
$tracker_extra = array(
'products' => $this->insights->get_post_count('product'),
'variations' => $this->insights->get_post_count('product_variation'),
'batch_limit' => get_option('woo_feed_per_batch'),
'feed_configs' => wp_json_encode($result),
'product_cat_num' => $catCount,
'review_notice' => wp_json_encode(get_option('woo_feed_review_notice', array())),
'hidden_notices' => $hidden_notices,
);
$this->insights->add_extra($tracker_extra);
}
$projectSlug = $this->client->getSlug();
add_filter( $projectSlug . '_what_tracked', array( $this, 'data_we_collect' ), 10, 1 );
add_filter(
"WebAppick_{$projectSlug}_Support_Ticket_Recipient_Email",
function() {
return 'sales@webappick.com';
},
10
);
add_filter( "WebAppick_{$projectSlug}_Support_Ticket_Email_Template", array( $this, 'supportTicketTemplate' ), 10 );
add_filter( "WebAppick_{$projectSlug}_Support_Request_Ajax_Success_Response", array( $this, 'supportResponse' ), 10 );
add_filter( "WebAppick_{$projectSlug}_Support_Request_Ajax_Error_Response", array( $this, 'supportErrorResponse' ), 10 );
add_filter(
"WebAppick_{$projectSlug}_Support_Page_URL",
function() {
return 'https://wordpress.org/support/plugin/webappick-product-feed-for-woocommerce/#new-topic-0';
},
10
);
$this->insights->init();
}
/**
* Generate Support Ticket Email Template
* @return string
*/
public function supportTicketTemplate() {
// dynamic variable format __INPUT_NAME__
/** @noinspection HtmlUnknownTarget */
$template = '
';
$template = sprintf( $template, $this->client->getName(), $this->client->getProjectVersion() );
$template .= '
';
$template .= '__SUBJECT__
';
$template .= '__MESSAGE__
';
$template .= '
';
$template .= sprintf(
'',
'Message Processed With WebAppick Service Library (v.' . $this->client->getClientVersion() . ')'
);
return $template;
}
/**
* Generate Support Ticket Ajax Response
* @return string
*/
public function supportResponse() {
$response = '';
$response .= sprintf( '%s
', esc_html__( 'Thank you -- Support Ticket Submitted.', 'woo-feed' ) );
$ticketSubmitted = esc_html__( 'Your ticket has been successfully submitted.', 'woo-feed' );
$twenty4Hours = sprintf( '%s', esc_html__( '24 hours', 'woo-feed' ) );
/* translators: %s: Approx. time to response after ticket submission. */
$notification = sprintf( esc_html__( 'You will receive an email notification from "support@webappick.com" in your inbox within %s.', 'woo-feed' ), $twenty4Hours );
$followUp = esc_html__( 'Please Follow the email and WebAppick Support Team will get back with you shortly.', 'woo-feed' );
$response .= sprintf( '%s %s %s
', $ticketSubmitted, $notification, $followUp );
$docLink = sprintf( ' %s', esc_html__( 'Documentation', 'woo-feed' ) );
$vidLink = sprintf( ' %s', esc_html__( 'Video Tutorials', 'woo-feed' ) );
$response .= sprintf( '%s %s
', $docLink, $vidLink );
$response .= '
';
$toc = sprintf( '%s', esc_html__( 'Terms & Conditions', 'woo-feed' ) );
$pp = sprintf( '%s', esc_html__( 'Privacy Policy', 'woo-feed' ) );
/* translators: 1: Link to the Trams And Condition Page, 2: Link to the Privacy Policy Page */
$policy = sprintf( esc_html__( 'Please read our %1$s and %2$s', 'woo-feed' ), $toc, $pp );
$response .= sprintf( '%s
', $policy );
return $response;
}
/**
* Set Error Response Message For Support Ticket Request
* @return string
*/
public function supportErrorResponse() {
return sprintf(
'',
esc_html__( 'Something Went Wrong. Please Try The Support Ticket Form On Our Website.', 'woo-feed' ),
sprintf( '%s', esc_html__( 'Get Support', 'woo-feed' ) ),
esc_html__( 'Support Ticket form will open in new tab in 5 seconds.', 'woo-feed' )
);
}
/**
* Set Data Collection description for the tracker
* @param $data
*
* @return array
*/
public function data_we_collect( $data ) {
$data = array_merge(
$data,
array(
esc_html__( 'Number of products in your site.', 'woo-feed' ),
esc_html__( 'Number of product categories in your site.', 'woo-feed' ),
esc_html__( 'Feed Configuration.', 'woo-feed' ),
esc_html__( 'Site name, language and url.', 'woo-feed' ),
esc_html__( 'Number of active and inactive plugins.', 'woo-feed' ),
esc_html__( 'Your name and email address.', 'woo-feed' ),
)
);
return $data;
}
/**
* Get Tracker Data Collection Description Array
* @return array
*/
public function get_data_collection_description() {
return $this->insights->get_data_collection_description();
}
/**
* Update Tracker OptIn
*
* @param bool $override optional. ignore last send datetime settings if true.
* @see Insights::send_tracking_data()
* @return void
*/
public function trackerOptIn( $override = false ) {
$this->insights->optIn( $override );
}
/**
* Update Tracker OptOut
* @return void
*/
public function trackerOptOut() {
$this->insights->optOut();
}
/**
* Check if tracking is enable
* @return bool
*/
public function is_tracking_allowed() {
return $this->insights->is_tracking_allowed();
}
public function premium_features() {
add_submenu_page( 'webappick-manage-feeds', esc_html__( 'Premium', 'woo-feed' ), '' . esc_html__( 'Premium', 'woo-feed' ) . '', 'manage_woocommerce', 'webappick-feed-pro-vs-free', array( $this, 'woo_feed_pro_vs_free' ) );
add_submenu_page( 'webappick-manage-feeds', esc_html__( 'Our Plugins', 'woo-feed' ), '' . esc_html__( 'Our Plugins', 'woo-feed' ) . '', 'manage_woocommerce', 'webappick-feed-our-plugins', array( $this, 'woo_feed_our_plugins' ) );
add_action( 'admin_head', array( $this, 'remove_admin_notices' ), 9999 );
}
/**
* Render Premium Feature Comparison Page
* @return void
*/
public function woo_feed_pro_vs_free() {
/** @define "WOO_FEED_FREE_ADMIN_PATH''./../../admin/" */ // phpcs:ignore
require WOO_FEED_FREE_ADMIN_PATH . 'partials/woo-feed-pro-vs-free.php';
}
/**
* Render Our Plugins Page
* @return void
*/
public function woo_feed_our_plugins() {
/** @define "WOO_FEED_FREE_ADMIN_PATH''./../../admin/" */ // phpcs:ignore
require WOO_FEED_FREE_ADMIN_PATH . 'partials/woo-feed-our-plugins.php';
}
/**
* Remove Admin Notice in pro features page.
* @global string $pagenow
* @global string $plugin_page
* @return void
*/
public function remove_admin_notices() {
global $pagenow, $plugin_page;
if ( 'admin.php' == $pagenow && 'webappick-feed-pro-vs-free' == $plugin_page ) {
remove_all_actions( 'admin_notices' );
}
}
/**
* Show Review And Compatibility Notice For Pro Features
* @global string $plugin_page
* @return void
*/
public function woo_feed_review_notice() {
global $plugin_page;
$user_id = get_current_user_id();
$nonce = wp_create_nonce( 'woo_feed_pro_notice_nonce' );
$pluginName = sprintf( '%s', esc_html__( 'CTX Feed', 'woo-feed' ) );
$proLink = sprintf( '%s', esc_html__( 'Premium', 'woo-feed' ) );
$has_notice = false;
//submit review notice form data
$this->woo_feed_save_review_notice();
//get review notice data
$next_timestamp = get_option( 'woo_feed_review_notice_next_show_time' );
$review_notice_dismissed = get_user_meta( $user_id, 'woo_feed_review_notice_dismissed', true );
if ( ! empty( $next_timestamp ) ) {
if ( ( time() > $next_timestamp ) ) {
$show_notice = true;
} else {
$show_notice = false;
}
} else {
if ( isset( $review_notice_dismissed ) && ! empty( $review_notice_dismissed ) ) {
$show_notice = false;
} else {
$show_notice = true;
}
}
// Review Notice.
if ( $show_notice ) {
$has_notice = true;
?>
' . esc_html__( 'WooCommerce Dynamic Pricing & Discounts', 'woo-feed' ) . '',
$proLink // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
?>
sanitize_text_field($notice), //phpcs:ignore
'updated_at' => time(),
);
update_option( 'woo_feed_review_notice', $value );
}
}
/**
* Ajax Action For Hiding Compatibility Notices
*/
public function woo_feed_hide_notice() {
check_ajax_referer( 'woo_feed_pro_notice_nonce' );
$notices = array( 'rp-wcdpd', 'wpml', 'rating', 'product_limit' );
if ( isset( $_REQUEST['which'] ) && ! empty( $_REQUEST['which'] ) && in_array( $_REQUEST['which'], $notices ) ) {
$which = sanitize_text_field( $_REQUEST['which'] ); //phpcs:ignore
update_option( sprintf( 'woo_feed_%s_notice_hidden', $which ), '1', false );
wp_send_json_success( esc_html__( 'Request Successful.', 'woo-feed' ) );
wp_die();
}
wp_send_json_error( esc_html__( 'Invalid Request.', 'woo-feed' ) );
wp_die();
}
}
}
// End of file class-woo-feed-webappick-api.php