Admin
4 years ago
Hooks
4 years ago
AjaxController.php
4 years ago
ElementorController.php
4 years ago
GutenBergController.php
4 years ago
ScriptController.php
4 years ago
ShortcodeController.php
4 years ago
WidgetController.php
4 years ago
ElementorController.php
156 lines
| 1 | <?php |
| 2 | |
| 3 | namespace RT\ThePostGrid\Controllers; |
| 4 | |
| 5 | if ( ! defined( 'WPINC' ) ) { |
| 6 | die; |
| 7 | } |
| 8 | |
| 9 | use Elementor\Plugin; |
| 10 | |
| 11 | if ( ! class_exists( 'ElementorController' ) ): |
| 12 | |
| 13 | class ElementorController { |
| 14 | |
| 15 | public $el_cat_id; |
| 16 | private $version; |
| 17 | |
| 18 | function __construct() { |
| 19 | $this->version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RT_THE_POST_GRID_VERSION; |
| 20 | $this->el_cat_id = RT_THE_POST_GRID_PLUGIN_SLUG . '-elements'; |
| 21 | |
| 22 | if ( did_action( 'elementor/loaded' ) ) { |
| 23 | add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] ); |
| 24 | add_action( 'elementor/elements/categories_registered', [ $this, 'widget_category' ] ); |
| 25 | //add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'editor_style' ] ); |
| 26 | add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'el_editor_script' ] ); |
| 27 | add_action( 'wp_footer', [ $this, 'tpg_el_scripts' ] ); |
| 28 | add_action( 'wp_enqueue_scripts', [ $this, 'tpg_el_style' ] ); |
| 29 | //add_action( "elementor/frontend/after_enqueue_scripts", [ $this, 'tpg_frontend_scripts' ] ); |
| 30 | add_filter( 'elementor/editor/localize_settings', [ $this, 'promotePremiumWidgets' ] ); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public function tpg_frontend_scripts() { |
| 35 | //wp_enqueue_script( 'imagesloaded' ); |
| 36 | //wp_enqueue_script( 'tpg-el-script', rtTPG()->get_assets_uri( 'js/el-frontend.js' ), [ 'jquery' ], $this->version, true ); |
| 37 | } |
| 38 | |
| 39 | public function tpg_el_style() { |
| 40 | //Custom CSS From Settings |
| 41 | $css = isset( $settings['custom_css'] ) ? stripslashes( $settings['custom_css'] ) : null; |
| 42 | if ( $css ) { |
| 43 | wp_add_inline_style( 'rt-tpg-elementor', $css ); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public function tpg_el_scripts() { |
| 48 | |
| 49 | $ajaxurl = ''; |
| 50 | if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) { |
| 51 | $ajaxurl .= admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE ); |
| 52 | } else { |
| 53 | $ajaxurl .= admin_url( 'admin-ajax.php' ); |
| 54 | } |
| 55 | $variables = [ |
| 56 | 'nonceID' => rtTPG()->nonceId(), |
| 57 | 'nonce' => wp_create_nonce( rtTPG()->nonceText() ), |
| 58 | 'ajaxurl' => $ajaxurl, |
| 59 | ]; |
| 60 | wp_localize_script( 'rt-tpg', 'rttpg', $variables ); |
| 61 | } |
| 62 | |
| 63 | public function el_editor_script() { |
| 64 | wp_enqueue_script( 'tgp-el-editor-scripts', rtTPG()->get_assets_uri( 'js/tpg-el-editor.js' ), [ 'jquery' ], $this->version, true ); |
| 65 | wp_enqueue_style( 'tgp-el-editor-style', rtTPG()->get_assets_uri( 'css/admin/tpg-el-editor.css' ), [], $this->version ); |
| 66 | } |
| 67 | |
| 68 | public function editor_style() { |
| 69 | $css = ""; |
| 70 | wp_add_inline_style( 'elementor-editor', $css ); |
| 71 | } |
| 72 | |
| 73 | public function init_widgets( $widgets_manager ) { |
| 74 | require_once( RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/base.php' ); |
| 75 | require_once( RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/rtTPGElementorHelper.php' ); |
| 76 | |
| 77 | // dir_name => class_name |
| 78 | $widgets = [ |
| 79 | 'grid-layout' => '\TPGGridLayout', |
| 80 | 'list-layout' => '\TPGListLayout', |
| 81 | 'grid-hover-layout' => '\TPGGridHoverLayout', |
| 82 | 'slider-layout' => '\TPGSliderLayout', |
| 83 | 'default' => '\RtElementorWidget', |
| 84 | ]; |
| 85 | |
| 86 | $widgets = apply_filters( 'tpg_el_widget_register', $widgets ); |
| 87 | |
| 88 | foreach ( $widgets as $file_name => $class ) { |
| 89 | if ( ! rtTPG()->hasPro() && 'slider-layout' == $file_name ) { |
| 90 | continue; |
| 91 | } |
| 92 | $template_name = 'the-post-grid/elementor/' . $file_name . '.php'; |
| 93 | if ( file_exists( STYLESHEETPATH . $template_name ) ) { |
| 94 | $file = STYLESHEETPATH . $template_name; |
| 95 | } elseif ( file_exists( TEMPLATEPATH . $template_name ) ) { |
| 96 | $file = TEMPLATEPATH . $template_name; |
| 97 | } else { |
| 98 | $file = RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/widgets/' . $file_name . '.php'; |
| 99 | } |
| 100 | require_once $file; |
| 101 | |
| 102 | $widgets_manager->register( new $class ); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | public function widget_category( $elements_manager ) { |
| 107 | $categories['tpg-elementor-builder-widgets'] = [ |
| 108 | 'title' => __( 'TPG Template Builder Element', 'the-post-grid' ), |
| 109 | 'icon' => 'fa fa-plug', |
| 110 | ]; |
| 111 | |
| 112 | $categories[ RT_THE_POST_GRID_PLUGIN_SLUG . '-elements' ] = [ |
| 113 | 'title' => __( 'The Post Grid', 'the-post-grid' ), |
| 114 | 'icon' => 'fa fa-plug', |
| 115 | ]; |
| 116 | |
| 117 | $get_all_categories = $elements_manager->get_categories(); |
| 118 | $categories = array_merge( $categories, $get_all_categories ); |
| 119 | $set_categories = function ( $categories ) { |
| 120 | $this->categories = $categories; |
| 121 | }; |
| 122 | |
| 123 | $set_categories->call( $elements_manager, $categories ); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | public function promotePremiumWidgets( $config ) { |
| 128 | if ( rtTPG()->hasPro() ) { |
| 129 | return $config; |
| 130 | } |
| 131 | |
| 132 | if ( ! isset( $config['promotionWidgets'] ) || ! is_array( $config['promotionWidgets'] ) ) { |
| 133 | $config['promotionWidgets'] = []; |
| 134 | } |
| 135 | |
| 136 | $category = RT_THE_POST_GRID_PLUGIN_SLUG . '-elements'; |
| 137 | |
| 138 | $pro_widgets = [ |
| 139 | [ |
| 140 | 'name' => 'tpg-slider-layout', |
| 141 | 'title' => __( 'TPG - Slider Layout', 'the-post-grid' ), |
| 142 | 'description' => __( 'TPG - Slider Layout', 'the-post-grid' ), |
| 143 | 'icon' => 'eicon-post-slider tpg-grid-icon tss-promotional-element', |
| 144 | 'categories' => '[ "the-post-grid-elements" ]', |
| 145 | ], |
| 146 | ]; |
| 147 | |
| 148 | $config['promotionWidgets'] = array_merge( $config['promotionWidgets'], $pro_widgets ); |
| 149 | |
| 150 | return $config; |
| 151 | } |
| 152 | |
| 153 | |
| 154 | } |
| 155 | |
| 156 | endif; |