block-embeds.php
3 years ago
block-popup-trigger.php
3 years ago
block-slidein-trigger.php
3 years ago
block-social-share.php
3 years ago
block-unsubscribe.php
3 years ago
block-popup-trigger.php
118 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Hustle_GHBlock_Popup_Trigger class |
| 4 | * |
| 5 | * @package Hustle |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Class Hustle_GHBlock_Popup_Trigger |
| 10 | * |
| 11 | * @since 1.0 Gutenberg Addon |
| 12 | */ |
| 13 | class Hustle_GHBlock_Popup_Trigger extends Hustle_GHBlock_Abstract { |
| 14 | |
| 15 | /** |
| 16 | * Block identifier |
| 17 | * |
| 18 | * @since 1.0 Gutenberg Addon |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | protected $slug = 'popup-trigger'; |
| 23 | |
| 24 | /** |
| 25 | * Hustle_GHBlock_Popup_Trigger constructor. |
| 26 | * |
| 27 | * @since 1.0 Gutenberg Addon |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | // Initialize block. |
| 31 | $this->init(); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Render block markup on front-end |
| 36 | * |
| 37 | * @since 1.0 Gutenberg Addon |
| 38 | * @param array $properties Block properties. |
| 39 | * |
| 40 | * @return string |
| 41 | */ |
| 42 | public function render_block( $properties = array() ) { |
| 43 | |
| 44 | $content = isset( $properties['content'] ) ? $properties['content'] : __( 'Click here', 'hustle' ); |
| 45 | $css_class = isset( $properties['css_class'] ) ? $properties['css_class'] : ''; |
| 46 | |
| 47 | if ( isset( $properties['id'] ) ) { |
| 48 | return '[wd_hustle id="' . esc_attr( $properties['id'] ) . '" type="popup" css_class="' . esc_attr( $css_class ) . '"]' . $content . '[/wd_hustle]'; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Enqueue assets ( scritps / styles ) |
| 54 | * Should be overriden in block class |
| 55 | * |
| 56 | * @since 1.0 Gutenberg Addon |
| 57 | */ |
| 58 | public function load_assets() { |
| 59 | // Scripts. |
| 60 | wp_enqueue_script( |
| 61 | 'hustle-block-popup-trigger', |
| 62 | Hustle_Gutenberg::get_plugin_url() . '/js/popup-trigger-block.min.js', |
| 63 | array( 'wp-blocks', 'wp-i18n', 'wp-element' ), |
| 64 | filemtime( Hustle_Gutenberg::get_plugin_dir() . '/js/popup-trigger-block.min.js' ), |
| 65 | true |
| 66 | ); |
| 67 | |
| 68 | // Localize scripts. |
| 69 | wp_localize_script( |
| 70 | 'hustle-block-popup-trigger', |
| 71 | 'hustle_popup_trigger_data', |
| 72 | array( |
| 73 | 'wizard_page' => Hustle_Data::POPUP_WIZARD_PAGE, |
| 74 | 'modules' => $this->get_modules(), |
| 75 | 'admin_url' => admin_url( 'admin.php' ), |
| 76 | 'nonce' => wp_create_nonce( 'hustle_gutenberg_get_module' ), |
| 77 | 'shortcode_tag' => Hustle_Module_Front::SHORTCODE, |
| 78 | 'text_domain' => 'hustle', |
| 79 | 'l10n' => $this->localize(), |
| 80 | ) |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Get modules |
| 86 | * |
| 87 | * @return array |
| 88 | */ |
| 89 | public function get_modules() { |
| 90 | $module_list = $this->get_modules_by_type( 'popup' ); |
| 91 | return $module_list; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Get texts for localize |
| 96 | * |
| 97 | * @return array |
| 98 | */ |
| 99 | private function localize() { |
| 100 | return array( |
| 101 | 'module' => esc_html__( 'Module', 'hustle' ), |
| 102 | 'additional_css_classes' => esc_html__( 'Additional CSS Classes', 'hustle' ), |
| 103 | 'click_here' => esc_html__( 'Click here', 'hustle' ), |
| 104 | 'content_here' => esc_html__( 'Add the clickable text that will trigger the module.', 'hustle' ), |
| 105 | 'advanced' => esc_html__( 'Advanced', 'hustle' ), |
| 106 | 'trigger_content' => esc_html__( 'Trigger Content', 'hustle' ), |
| 107 | 'name' => esc_html__( 'Name', 'hustle' ), |
| 108 | 'customize_module' => esc_html__( 'Customize Popup', 'hustle' ), |
| 109 | 'rendering' => esc_html__( 'Rendering...', 'hustle' ), // Unused. |
| 110 | 'block_name' => esc_html__( 'Popup Trigger', 'hustle' ), |
| 111 | 'block_description' => esc_html__( 'Embed the trigger button for a popup module.', 'hustle' ), |
| 112 | 'block_more_description' => esc_html__( 'Note: the Trigger property of the Popup should be set to Click to embed the trigger button for the module.', 'hustle' ), |
| 113 | ); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | new Hustle_GHBlock_Popup_Trigger(); |
| 118 |