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-unsubscribe.php
144 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Hustle_GHBlock_Unsubscribe class |
| 4 | * |
| 5 | * @package Hustle |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Class Hustle_GHBlock_Unsubscribe |
| 10 | * |
| 11 | * @since 4.5 Gutenberg Addon |
| 12 | */ |
| 13 | class Hustle_GHBlock_Unsubscribe extends Hustle_GHBlock_Abstract { |
| 14 | |
| 15 | /** |
| 16 | * Block identifier |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | protected $slug = 'unsubscribe'; |
| 21 | |
| 22 | /** |
| 23 | * Constructor. |
| 24 | */ |
| 25 | public function __construct() { |
| 26 | // Initialize block. |
| 27 | $this->init(); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Render block markup on front-end |
| 32 | * |
| 33 | * @param array $properties Block properties. |
| 34 | * @return string |
| 35 | */ |
| 36 | public function render_block( $properties = array() ) { |
| 37 | $ids = isset( $properties['id'] ) && is_array( $properties['id'] ) ? implode( ', ', $properties['id'] ) : ''; |
| 38 | |
| 39 | $skip = ! empty( $properties['skipConfirmation'] ) ? ' skip_confirmation="true"' : ''; |
| 40 | |
| 41 | return '[wd_hustle_unsubscribe id="' . esc_attr( $ids ) . '"' . $skip . ' /]'; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Enqueue assets ( scritps / styles ) |
| 46 | * Should be overriden in block class |
| 47 | */ |
| 48 | public function load_assets() { |
| 49 | // Scripts. |
| 50 | wp_enqueue_script( |
| 51 | 'hustle-block-unsubscribe', |
| 52 | Hustle_Gutenberg::get_plugin_url() . '/js/unsubscribe-block.min.js', |
| 53 | array( 'wp-blocks', 'wp-i18n', 'wp-element' ), |
| 54 | filemtime( Hustle_Gutenberg::get_plugin_dir() . 'js/unsubscribe-block.min.js' ), |
| 55 | true |
| 56 | ); |
| 57 | |
| 58 | // Localize scripts. |
| 59 | wp_localize_script( |
| 60 | 'hustle-block-unsubscribe', |
| 61 | 'hustle_unsubscribe_data', |
| 62 | array( |
| 63 | 'popups' => $this->get_popups(), |
| 64 | 'slideins' => $this->get_slideins(), |
| 65 | 'embeds' => $this->get_embeds(), |
| 66 | 'settings_url' => add_query_arg( |
| 67 | array( |
| 68 | 'page' => 'hustle_settings', |
| 69 | 'section' => 'unsubscribe', |
| 70 | ), |
| 71 | admin_url( 'admin.php' ) |
| 72 | ), |
| 73 | 'nonce' => wp_create_nonce( 'hustle_gutenberg_get_unsubscribe_form' ), |
| 74 | 'shortcode_tag' => 'wd_hustle_unsubscribe', |
| 75 | 'l10n' => $this->localize(), |
| 76 | ) |
| 77 | ); |
| 78 | |
| 79 | wp_enqueue_style( |
| 80 | 'hustle-block-unsubscribe', |
| 81 | Hustle_Gutenberg::get_plugin_url() . '/css/unsubscribe-block.css', |
| 82 | array(), |
| 83 | filemtime( Hustle_Gutenberg::get_plugin_dir() . 'css/unsubscribe-block.css' ) |
| 84 | ); |
| 85 | |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Get popups |
| 90 | * |
| 91 | * @return array |
| 92 | */ |
| 93 | public function get_popups() { |
| 94 | $module_list = $this->get_modules_by_type( 'popup' ); |
| 95 | unset( $module_list[0] ); |
| 96 | return $module_list; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Get slide-ins |
| 101 | * |
| 102 | * @return array |
| 103 | */ |
| 104 | public function get_slideins() { |
| 105 | $module_list = $this->get_modules_by_type( 'slidein' ); |
| 106 | unset( $module_list[0] ); |
| 107 | return $module_list; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Get Embeds |
| 112 | * |
| 113 | * @return array |
| 114 | */ |
| 115 | public function get_embeds() { |
| 116 | $module_list = $this->get_modules_by_type( 'embedded' ); |
| 117 | unset( $module_list[0] ); |
| 118 | return $module_list; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Get texts |
| 123 | * |
| 124 | * @return array |
| 125 | */ |
| 126 | private function localize() { |
| 127 | return array( |
| 128 | 'popups' => esc_html__( 'Pop-ups', 'hustle' ), |
| 129 | 'slideins' => esc_html__( 'Slide-ins', 'hustle' ), |
| 130 | 'embeds' => esc_html__( 'Embeds', 'hustle' ), |
| 131 | 'modules' => esc_html__( 'Modules', 'hustle' ), |
| 132 | 'customize_settings' => esc_html__( 'Customize Settings', 'hustle' ), |
| 133 | 'rendering' => esc_html__( 'Rendering...', 'hustle' ), |
| 134 | 'block_name' => esc_html__( 'Unsubscribe', 'hustle' ), |
| 135 | /* translators: Plugin name */ |
| 136 | 'block_description' => esc_html( sprintf( __( 'Display %s Unsubscribe form.', 'hustle' ), Opt_In_Utils::get_plugin_name() ) ), |
| 137 | 'skip_confirmation' => esc_html__( 'Skip confirmation step', 'hustle' ), |
| 138 | 'block_instruction' => esc_html__( 'By default, the Unsubscribe form allows users to unsubscribe from all modules, but you can specify the modules you want to enable the unsubscribe option for.', 'hustle' ), |
| 139 | ); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | new Hustle_GHBlock_Unsubscribe(); |
| 144 |