block-embeds.php
3 years ago
block-popup-trigger.php
3 years ago
block-slidein-trigger.php
3 years ago
block-social-share.php
7 months ago
block-unsubscribe.php
7 months ago
block-social-share.php
138 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Hustle_GHBlock_Social_Share class |
| 4 | * |
| 5 | * @package Hustle |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Class Hustle_GHBlock_Social_Share |
| 10 | * |
| 11 | * @since 1.0 Gutenberg Addon |
| 12 | */ |
| 13 | class Hustle_GHBlock_Social_Share extends Hustle_GHBlock_Abstract { |
| 14 | |
| 15 | /** |
| 16 | * Block identifier |
| 17 | * |
| 18 | * @since 1.0 Gutenberg Addon |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | protected $slug = 'social-share'; |
| 23 | |
| 24 | /** |
| 25 | * Hustle_GHBlock_Social_Share 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 | $css_class = isset( $properties['css_class'] ) ? $properties['css_class'] : ''; |
| 44 | |
| 45 | if ( isset( $properties['id'] ) ) { |
| 46 | return '[wd_hustle id="' . esc_attr( $properties['id'] ) . '" type="social_sharing" css_class="' . esc_attr( $css_class ) . '"/]'; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Enqueue assets ( scritps / styles ) |
| 52 | * Should be overriden in block class |
| 53 | * |
| 54 | * @since 1.0 Gutenberg Addon |
| 55 | */ |
| 56 | public function load_assets() { |
| 57 | |
| 58 | Hustle_Module_Front::add_hui_scripts(); |
| 59 | |
| 60 | // Scripts. |
| 61 | wp_enqueue_script( |
| 62 | 'hustle-block-social-share', |
| 63 | Hustle_Gutenberg::get_plugin_url() . '/js/social-share-block.min.js', |
| 64 | array( 'wp-blocks', 'wp-i18n', 'wp-element', 'hui_scripts' ), |
| 65 | filemtime( Hustle_Gutenberg::get_plugin_dir() . '/js/social-share-block.min.js' ), |
| 66 | true |
| 67 | ); |
| 68 | |
| 69 | // Localize scripts. |
| 70 | wp_localize_script( |
| 71 | 'hustle-block-social-share', |
| 72 | 'hustle_ss_data', |
| 73 | array( |
| 74 | 'modules' => $this->get_modules(), |
| 75 | 'admin_url' => admin_url( 'admin.php' ), |
| 76 | 'shortcode_tag' => Hustle_Module_Front::SHORTCODE, |
| 77 | 'nonce' => wp_create_nonce( 'hustle_gutenberg_get_module' ), |
| 78 | 'l10n' => $this->localize(), |
| 79 | ) |
| 80 | ); |
| 81 | |
| 82 | wp_enqueue_style( |
| 83 | 'hustle_icons', |
| 84 | Opt_In::$plugin_url . 'assets/hustle-ui/css/hustle-icons.min.css', |
| 85 | array(), |
| 86 | Opt_In::VERSION |
| 87 | ); |
| 88 | |
| 89 | wp_enqueue_style( |
| 90 | 'hustle_social', |
| 91 | Opt_In::$plugin_url . 'assets/hustle-ui/css/hustle-social.min.css', |
| 92 | array(), |
| 93 | Opt_In::VERSION |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Get modules |
| 99 | * |
| 100 | * @return array |
| 101 | */ |
| 102 | public function get_modules() { |
| 103 | $module_list = $this->get_modules_by_type( 'social_sharing' ); |
| 104 | return $module_list; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Get texts for localize |
| 109 | * |
| 110 | * @return array |
| 111 | */ |
| 112 | private function localize() { |
| 113 | return array( |
| 114 | 'advanced' => esc_html__( 'Advanced', 'hustle' ), |
| 115 | 'additional_css_classes' => esc_html__( 'Additional CSS Classes', 'hustle' ), |
| 116 | 'name' => esc_html__( 'Name', 'hustle' ), |
| 117 | 'module' => esc_html__( 'Module', 'hustle' ), |
| 118 | 'customize_module' => esc_html__( 'Customize Social Share', 'hustle' ), |
| 119 | 'rendering' => esc_html__( 'Rendering...', 'hustle' ), |
| 120 | 'block_name' => esc_html__( 'Social Share', 'hustle' ), |
| 121 | /* translators: Plugin name */ |
| 122 | 'block_description' => esc_html( sprintf( __( 'Display your %s Social Share module in this block.', 'hustle' ), Opt_In_Utils::get_plugin_name() ) ), |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Is module included |
| 128 | * |
| 129 | * @param Hustle_Model $module Module. |
| 130 | * @return bool |
| 131 | */ |
| 132 | protected function is_module_included( Hustle_Model $module ) { |
| 133 | return $module->is_display_type_active( Hustle_Module_Model::SHORTCODE_MODULE ); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | new Hustle_GHBlock_Social_Share(); |
| 138 |