widgets
4 months ago
base.php
9 months ago
rtTPGElementorHelper.php
3 months ago
rtTPGElementorQuery.php
4 months ago
base.php
126 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Base Abstract Class |
| 4 | * |
| 5 | * @package RT_TPG |
| 6 | */ |
| 7 | |
| 8 | use Elementor\Widget_Base; |
| 9 | use RT\ThePostGrid\Helpers\Fns; |
| 10 | use RT\ThePostGrid\Helpers\Options; |
| 11 | |
| 12 | |
| 13 | // Do not allow directly accessing this file. |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit( 'This script cannot be accessed directly.' ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Base Abstract Class |
| 20 | */ |
| 21 | abstract class Custom_Widget_Base extends Widget_Base { |
| 22 | public $tpg_name; |
| 23 | public $tpg_base; |
| 24 | public $tpg_category; |
| 25 | public $tpg_archive_category; |
| 26 | public $tpg_icon; |
| 27 | public $tpg_dir; |
| 28 | public $tpg_pro_dir; |
| 29 | public $is_post_layout; |
| 30 | public $pro_label; |
| 31 | public $get_pro_message; |
| 32 | public $prefix; |
| 33 | public $last_post_id; |
| 34 | |
| 35 | /** |
| 36 | * Class Constructor |
| 37 | * @param $data |
| 38 | * @param $args |
| 39 | * |
| 40 | * @throws Exception |
| 41 | */ |
| 42 | public function __construct( $data = [], $args = null ) { |
| 43 | $this->tpg_category = RT_THE_POST_GRID_PLUGIN_SLUG . '-elements'; // Category /@dev. |
| 44 | $this->tpg_archive_category = 'tpg-block-builder-widgets'; |
| 45 | $this->tpg_icon = 'eicon-gallery-grid tpg-grid-icon'; |
| 46 | $this->tpg_dir = dirname( ( new ReflectionClass( $this ) )->getFileName() ); |
| 47 | $this->tpg_pro_dir = null; |
| 48 | $this->pro_label = null; |
| 49 | $this->is_post_layout = null; |
| 50 | $this->get_pro_message = null; |
| 51 | $this->last_post_id = Fns::get_last_post_id(); |
| 52 | |
| 53 | if ( ! rtTPG()->hasPro() ) { |
| 54 | $this->pro_label = sprintf( '<span class="tpg-pro-label">%s</span>', esc_html__( 'Pro', 'the-post-grid' ) ); |
| 55 | $this->is_post_layout = ' the-post-grid-pro-needed'; |
| 56 | $this->get_pro_message = 'Please <a target="_blank" href="' . esc_url( rtTpg()->proLink() ) . '">upgrade</a> to pro for more options'; |
| 57 | } |
| 58 | |
| 59 | parent::__construct( $data, $args ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get Pro Message with markup |
| 64 | * |
| 65 | * @param $message |
| 66 | * |
| 67 | * @return string|void |
| 68 | */ |
| 69 | public function get_pro_message( $message = 'more options.' ) { |
| 70 | if ( rtTPG()->hasPro() ) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | return 'Please <a target="_blank" href="' . esc_url( rtTpg()->proLink() ) . '">upgrade</a> to pro for ' . esc_html( $message ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get Name |
| 79 | * |
| 80 | * @return string |
| 81 | */ |
| 82 | public function get_name() { |
| 83 | return $this->tpg_base; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Get Title |
| 88 | * |
| 89 | * @return string |
| 90 | */ |
| 91 | public function get_title() { |
| 92 | return $this->tpg_name; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Get Icon |
| 97 | * |
| 98 | * @return string |
| 99 | */ |
| 100 | public function get_icon() { |
| 101 | return $this->tpg_icon; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Get Categories |
| 106 | * |
| 107 | * @return string[] |
| 108 | */ |
| 109 | public function get_categories() { |
| 110 | return [ $this->tpg_category ]; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Return Pro Label |
| 115 | * |
| 116 | * @return string |
| 117 | */ |
| 118 | public function pro_label() { |
| 119 | if ( ! rtTPG()->hasPro() ) { |
| 120 | return esc_html__( 'Pro', 'the-post-grid' ); |
| 121 | } |
| 122 | |
| 123 | return ''; |
| 124 | } |
| 125 | } |
| 126 |