balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

notice-bar.php (1833B)


      1 <?php
      2 namespace Elementor\Core\Editor;
      3 
      4 use Elementor\Core\Base\Base_Object;
      5 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
      6 use Elementor\Plugin;
      7 use Elementor\Utils;
      8 
      9 if ( ! defined( 'ABSPATH' ) ) {
     10 	exit; // Exit if accessed directly
     11 }
     12 
     13 class Notice_Bar extends Base_Object {
     14 
     15 	protected function get_init_settings() {
     16 		if ( Plugin::$instance->get_install_time() > strtotime( '-30 days' ) ) {
     17 			return [];
     18 		}
     19 
     20 		return [
     21 			'muted_period' => 90,
     22 			'option_key' => '_elementor_editor_upgrade_notice_dismissed',
     23 			'message' => sprintf(
     24 				/* translators: %1$s Link open tag, %2$s: Link close tag. */
     25 				esc_html__( 'Love using Elementor? %1$sLearn how you can build better sites with Elementor Pro.%2$s', 'elementor' ),
     26 				'<a href="%s">',
     27 				'</a>'
     28 			),
     29 			'action_title' => esc_html__( 'Go Pro', 'elementor' ),
     30 			'action_url' => Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=editor-notice-bar&utm_campaign=gopro&utm_medium=wp-dash' ),
     31 		];
     32 	}
     33 
     34 	final public function get_notice() {
     35 		if ( ! current_user_can( 'manage_options' ) ) {
     36 			return null;
     37 		}
     38 
     39 		$settings = $this->get_settings();
     40 
     41 		if ( empty( $settings['option_key'] ) ) {
     42 			return null;
     43 		}
     44 
     45 		$dismissed_time = get_option( $settings['option_key'] );
     46 
     47 		if ( $dismissed_time ) {
     48 			if ( $dismissed_time > strtotime( '-' . $settings['muted_period'] . ' days' ) ) {
     49 				return null;
     50 			}
     51 
     52 			$this->set_notice_dismissed();
     53 		}
     54 
     55 		return $settings;
     56 	}
     57 
     58 	public function __construct() {
     59 		add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
     60 	}
     61 
     62 	public function set_notice_dismissed() {
     63 		update_option( $this->get_settings( 'option_key' ), time() );
     64 	}
     65 
     66 	public function register_ajax_actions( Ajax $ajax ) {
     67 		$ajax->register_ajax_action( 'notice_bar_dismiss', [ $this, 'set_notice_dismissed' ] );
     68 	}
     69 }