*/ class Pro_Upgrade { use Date; public $slug; protected $data = array(); protected $modes = array( 'development' => array( 'sheet_id' => '1VLpfKspHHNM6JIFOQtohqDRyHR85J3KR5RLF4jqlz0Q', 'tab_id' => 0, ), 'production' => array( 'sheet_id' => '1VLpfKspHHNM6JIFOQtohqDRyHR85J3KR5RLF4jqlz0Q', 'tab_id' => 0, ), ); /** * Construct method */ public function __construct() { $this->slug = Helper::jltwp_adminify_slug_cleanup(); $this->maybe_sync_remote_data(); $this->register_sync_hook(); $this->set_data(); add_action( 'admin_footer', array($this, 'display_popup') ); add_action( 'wp_dashboard_setup', array($this, 'dashboard_widget') ); add_action( 'wp_network_dashboard_setup', array($this, 'dashboard_widget') ); } /** * Register Dashboard widget * * @return void * @author Jewel Theme */ public function dashboard_widget() { wp_add_dashboard_widget( 'jltwp_adminify_dashboard_widget', // Widget slug. esc_html__( 'WP Adminify News & Updates', 'adminify' ), // Title. array($this, 'dashboard_widget_render') ); // Globalize the metaboxes array, this holds all the widgets for wp-admin. global $wp_meta_boxes; // Get the regular dashboard widgets array // (which already has our new widget but appended at the end). if ( is_network_admin() ) { $default_dashboard = $wp_meta_boxes['dashboard-network']['normal']['core']; } else { $default_dashboard = $wp_meta_boxes['dashboard']['normal']['core']; } // Backup and delete our new dashboard widget from the end of the array. $example_widget_backup = array( 'jltwp_adminify_dashboard_widget' => $default_dashboard['jltwp_adminify_dashboard_widget'], ); unset($default_dashboard['jltwp_adminify_dashboard_widget']); // Merge the two arrays together so our widget is at the beginning. $sorted_dashboard = array_merge( $example_widget_backup, $default_dashboard ); // Save the sorted array back into the original metaboxes . if ( is_network_admin() ) { $wp_meta_boxes['dashboard-network']['normal']['core'] = $sorted_dashboard; } else { $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; } } /** * Render dashboard widget * * @author Jewel Theme */ public function dashboard_widget_render() { include_once ABSPATH . WPINC . '/feed.php'; $feed_url = 'https://jeweltheme.com/feed.xml'; // Get a SimplePie feed object from the specified feed source . $rss = fetch_feed( $feed_url ); $maxitems = 0; if ( !is_wp_error( $rss ) ) { // Checks that the object is created correctly . // Figure out how many total items there are, and choose a limit . $maxitems = $rss->get_item_quantity( 5 ); // Build an array of all the items, starting with element 0 (first element). $rss_items = $rss->get_items( 0, $maxitems ); // Get RSS title . $rss_title = '' . strtoupper( $rss->get_title() ) . ''; } // Display the container . echo '
'; if ( wp_validate_boolean( $this->get_content( 'is_campaign' ) ) ) { ?> tag // Check items . if ( !empty( $maxitems ) ) { echo '
    '; // Loop through each feed item and display each item as a hyperlink. foreach ( $rss_items as $item ) { // Uncomment line below to display non human date // $item_date = $item->get_date( get_option('date_format').' @ '.get_option('time_format') ); . // Get human date (comment if you want to use non human date) . // $item_date = human_time_diff( $item->get_date( 'U' ), current_time( 'timestamp' ) ) . ' ' . __( 'ago', 'adminify' ); // Start displaying item content within a
  • tag . echo '
  • '; // create item link . echo ''; // Get item title . echo esc_html( $item->get_title() ); echo ''; // Display date . // echo ' ' . esc_html( $item_date ) . '
    '; // Get item content . $content = $item->get_content(); // Shorten content . $content = wp_html_excerpt( $content, 120 ) . ' '; // Display content . echo esc_html( $content ); // End
  • tag . echo '
  • '; } echo '
'; // End
    tag . } ?> '; } /** * Set merged data * * @return void * @author Jewel Theme */ public function set_data() { $this->data = Helper::get_merged_data( self::get_data() ); } /** * Get Sheet data * * @author Jewel Theme */ public static function get_data() { return get_option( 'jltwp_adminify_sheet_promo_data' ); } /** * Get Contents * * @param [type] $key . * * @author Jewel Theme */ public function get_content( $key ) { return $this->data[$key]; } /** * Get Option has data * * @author Jewel Theme */ public function get_data_hash() { return get_option( 'jltwp_adminify_sheet_promo_data_hash' ); } /** * Sync to remote data * * @author Jewel Theme */ public function maybe_sync_remote_data() { $data = self::get_data(); if ( empty( $data ) ) { $this->sheet_data_remote_sync(); } } /** * Register Sync hook * * @return void * @author Jewel Theme */ public function register_sync_hook() { $hook_action = 'jltwp_adminify_sheet_promo_data_remote_sync'; add_action( $hook_action, array($this, 'sheet_data_remote_sync') ); if ( !wp_next_scheduled( $hook_action ) ) { wp_schedule_event( time(), 'daily', $hook_action ); } register_deactivation_hook( WP_ADMINIFY_FILE, array($this, 'clear_register_sync_hook') ); } /** * Clear register sync hook * * @return void * @author Jewel Theme */ public function clear_register_sync_hook() { wp_clear_scheduled_hook( 'jltwp_adminify_sheet_promo_data_remote_sync' ); } /** * Data sync with remote * * @return void * @author Jewel Theme */ public function sheet_data_remote_sync() { $data = self::get_data(); $force = false; if ( empty( $data ) ) { $force = true; } $sheet_hash_data = $this->get_data_hash(); $remote_data = $this->get_sheet_promo_remote_data(); $sheet_data_hash = base64_encode( json_encode( $remote_data ) ); if ( $force || $sheet_hash_data !== $sheet_data_hash ) { update_option( 'jltwp_adminify_sheet_promo_data', $remote_data ); update_option( 'jltwp_adminify_sheet_promo_data_hash', $sheet_data_hash ); do_action( 'jltwp_adminify_sheet_promo_data_reset' ); } } /** * Get Environment mode * * @author Jewel Theme */ public function get_mode() { return ( defined( 'WP_DEBUG' ) && WP_DEBUG ? 'development' : 'production' ); } /** * Get Sheet URL * * @author Jewel Theme */ public function get_sheet_url() { $sheet_id = $this->modes[$this->get_mode()]['sheet_id']; $tab_id = $this->modes[$this->get_mode()]['tab_id']; return "https://docs.google.com/spreadsheets/export?format=csv&id={$sheet_id}&gid={$tab_id}"; } /** * Promotional remote data * * @author Jewel Theme */ public function get_sheet_promo_remote_data() { $transient_key = $this->slug . '_sheet_promo_data'; $data = get_transient( $transient_key ); if ( $data !== false ) { return $data; } $url = $this->get_sheet_url(); $response = wp_remote_get( $url ); if ( is_wp_error( $response ) ) { return false; } $response = wp_remote_retrieve_body( $response ); if ( !$response ) { return false; } $data = array_map( function ( $line ) { return str_getcsv( $line, ',', '"', '' ); }, explode( "\n", $response ) ); $header = array_shift( $data ); $data = array_map( function ( array $row ) use($header) { return array_combine( $header, $row ); }, $data ); // filter plugin is not empty . $data = array_filter( $data, function ( $row ) { return !empty( $row['name'] ); } ); $plugin_slug = Helper::jltwp_adminify_slug_cleanup(); $data = wp_list_filter( $data, array( 'product_slug' => $plugin_slug, ) ); if ( !empty( $data ) ) { $data = array_values( $data )[0]; } set_transient( $transient_key, $data, HOUR_IN_SECONDS ); return $data; } /** * Display popup contents * * @author Jewel Theme */ public function display_popup() { if ( 'FALSE' === $this->get_content( 'is_campaign' ) ) { $image_url = WP_ADMINIFY_ASSETS_IMAGE . 'promo-image.png'; $notice = 'Use "SPECIAL40" to Get Flat 40% OFF'; $btn_url = 'https://wpadminify.com/pricing/'; $btn_text = 'GET THE DEAL'; } else { $image_url = $this->get_content( 'image_url' ); $notice = $this->get_content( 'notice' ); $btn_url = $this->get_content( 'button_url' ); $btn_text = $this->get_content( 'button_text' ); } ?> */ public function counter_date() { $endDate = $this->get_content( 'end_date' ); $is_active = $this->date_is_current_or_next( $endDate ); if ( $is_active ) { return $endDate; } return $this->date_increment( $this->current_time(), 3 ); } }