| @@ -55,77 +55,20 @@ | ||
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - // Scripts | |
| 60 | - wp_enqueue_script( | |
| 61 | - 'ayg-block-js', | |
| 62 | - plugins_url( '/block/dist/blocks.build.js', dirname( __FILE__ ) ), | |
| 63 | - array( 'wp-blocks', 'wp-i18n', 'wp-element' ), | |
| 64 | - filemtime( plugin_dir_path( __DIR__ ) . 'block/dist/blocks.build.js' ), | |
| 65 | - true | |
| 66 | - ); | |
| 67 | - | |
| 68 | 59 | wp_localize_script( |
| 69 | - 'ayg-block-js', | |
| 70 | - 'ayg_block', | |
| 60 | + 'wp-block-editor', | |
| 61 | + 'ayg_block', | |
| 71 | 62 | array( |
| 72 | 63 | 'options' => $fields, |
| 73 | 64 | 'i18n' => array( |
| 74 | - 'block_description' => __( 'Create automated YouTube galleries.', 'automatic-youtube-gallery' ), | |
| 75 | - 'block_title' => __( 'Automatic YouTube Gallery', 'automatic-youtube-gallery' ), | |
| 76 | - 'selected_color' => __( 'Selected Color', 'automatic-youtube-gallery' ), | |
| 77 | - 'spinner_message' => __( 'Waiting to finish your block configuration. This delay is to avoid frequent YouTube API calls.', 'automatic-youtube-gallery' ) | |
| 65 | + 'selected_color' => __( 'Selected Color', 'automatic-youtube-gallery' ) | |
| 78 | 66 | ) |
| 79 | - ) | |
| 80 | - ); | |
| 67 | + ) | |
| 68 | + ); | |
| 81 | 69 | } |
| 82 | - | |
| 83 | - /** | |
| 84 | - * Enqueue Gutenberg block assets for both frontend + backend. | |
| 85 | - * | |
| 86 | - * @since 1.0.0 | |
| 87 | - */ | |
| 88 | - public function enqueue_block_assets() { | |
| 89 | - if ( wp_script_is( AYG_SLUG . '-public', 'registered' ) ) { | |
| 90 | - wp_enqueue_style( AYG_SLUG . '-public' ); | |
| 91 | - wp_enqueue_script( AYG_SLUG . '-public' ); | |
| 92 | - } else { | |
| 93 | - // Styles | |
| 94 | - wp_enqueue_style( | |
| 95 | - AYG_SLUG . '-public', | |
| 96 | - AYG_URL . 'public/assets/css/public.css', | |
| 97 | - array(), | |
| 98 | - AYG_VERSION, | |
| 99 | - 'all' | |
| 100 | - ); | |
| 101 | 70 | |
| 102 | - // Scripts | |
| 103 | - wp_enqueue_script( | |
| 104 | - AYG_SLUG . '-public', | |
| 105 | - AYG_URL . 'public/assets/js/public.js', | |
| 106 | - array( 'jquery' ), | |
| 107 | - AYG_VERSION, | |
| 108 | - false | |
| 109 | - ); | |
| 110 | - | |
| 111 | - wp_localize_script( | |
| 112 | - AYG_SLUG . '-public', | |
| 113 | - 'ayg_public', | |
| 114 | - array( | |
| 115 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 116 | - 'i18n' => array( | |
| 117 | - 'show_more' => __( 'Show More', 'automatic-youtube-gallery' ), | |
| 118 | - 'show_less' => __( 'Show Less', 'automatic-youtube-gallery' ) | |
| 119 | - ), | |
| 120 | - 'players' => array() | |
| 121 | - ) | |
| 122 | - ); | |
| 123 | - } | |
| 124 | - | |
| 125 | - do_action( 'ayg_enqueue_scripts' ); | |
| 126 | - } | |
| 127 | - | |
| 128 | 71 | /** |
| 129 | 72 | * Register our custom block. |
| 130 | 73 | * |
| 131 | 74 | * @since 1.0.0 |
| @@ -130,39 +73,43 @@ | ||
| 130 | 73 | * |
| 131 | 74 | * @since 1.0.0 |
| 132 | 75 | */ |
| 133 | 76 | public function register_block_type() { |
| 134 | - // Hook the post rendering to the block | |
| 135 | - if ( function_exists( 'register_block_type' ) ) { | |
| 136 | - $attributes = array( | |
| 137 | - 'is_admin' => array( | |
| 138 | - 'type' => 'boolean' | |
| 139 | - ) | |
| 140 | - ); | |
| 77 | + if ( ! function_exists( 'register_block_type' ) ) { | |
| 78 | + return false; | |
| 79 | + } | |
| 80 | + | |
| 81 | + $attributes = array( | |
| 82 | + 'is_admin' => array( | |
| 83 | + 'type' => 'boolean' | |
| 84 | + ), | |
| 85 | + 'uid' => array( | |
| 86 | + 'type' => 'string' | |
| 87 | + ) | |
| 88 | + ); | |
| 141 | 89 | |
| 142 | - $fields = ayg_get_editor_fields(); | |
| 90 | + $fields = ayg_get_editor_fields(); | |
| 143 | 91 | |
| 144 | - foreach ( $fields as $key => $section ) { | |
| 145 | - foreach ( $section['fields'] as $field ) { | |
| 146 | - $type = 'string'; | |
| 92 | + foreach ( $fields as $key => $section ) { | |
| 93 | + foreach ( $section['fields'] as $field ) { | |
| 94 | + $type = 'string'; | |
| 147 | 95 | |
| 148 | - if ( 'number' == $field['type'] ) { | |
| 149 | - $type = 'number'; | |
| 150 | - } elseif ( 'checkbox' == $field['type'] ) { | |
| 151 | - $type = 'boolean'; | |
| 152 | - } | |
| 96 | + if ( 'number' == $field['type'] ) { | |
| 97 | + $type = 'number'; | |
| 98 | + } elseif ( 'checkbox' == $field['type'] ) { | |
| 99 | + $type = 'boolean'; | |
| 100 | + } | |
| 153 | 101 | |
| 154 | - $attributes[ $field['name'] ] = array( | |
| 155 | - 'type' => $type | |
| 156 | - ); | |
| 157 | - } | |
| 102 | + $attributes[ $field['name'] ] = array( | |
| 103 | + 'type' => $type | |
| 104 | + ); | |
| 158 | 105 | } |
| 106 | + } | |
| 159 | 107 | |
| 160 | - register_block_type( 'automatic-youtube-gallery/block', array( | |
| 161 | - 'attributes' => $attributes, | |
| 162 | - 'render_callback' => array( $this, 'render_block' ), | |
| 163 | - )); | |
| 164 | - } | |
| 108 | + register_block_type( __DIR__ . '/build', array( | |
| 109 | + 'attributes' => $attributes, | |
| 110 | + 'render_callback' => array( $this, 'render_block' ), | |
| 111 | + ) ); | |
| 165 | 112 | } |
| 166 | 113 | |
| 167 | 114 | /** |
| 168 | 115 | * Render the block frontend. |
| @@ -171,19 +118,31 @@ | ||
| 171 | 118 | * @param array $atts An associative array of attributes. |
| 172 | 119 | * @return string HTML output. |
| 173 | 120 | */ |
| 174 | 121 | public function render_block( $atts ) { |
| 175 | - // If this is an autosave, our form has not been submitted, so we don't want to do anything | |
| 176 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
| 177 | - return; | |
| 122 | + if ( ! empty( $atts['is_admin'] ) ) { | |
| 123 | + $atts['autoplay'] = false; | |
| 178 | 124 | } |
| 179 | 125 | |
| 180 | - if ( ! empty( $atts['is_admin'] ) ) { | |
| 181 | - $atts['autoplay'] = false; | |
| 182 | - $atts['autoadvance'] = false; | |
| 126 | + // Deprecated since v2.5.8. Retained for backward compatibility. | |
| 127 | + if ( ! empty( $atts['uid'] ) ) { | |
| 128 | + $atts['deprecated_uid'] = md5( $atts['uid'] ); | |
| 129 | + unset( $atts['uid'] ); | |
| 183 | 130 | } |
| 184 | 131 | |
| 185 | - return ayg_build_gallery( $this->clean_attributes( $atts ) ); | |
| 132 | + // If popup is enabled and type is video, force theme to popup | |
| 133 | + if ( isset( $atts['popup'] ) && ! empty( $atts['popup'] ) ) { | |
| 134 | + if ( isset( $atts['type'] ) && 'video' == $atts['type'] ) { | |
| 135 | + $atts['theme'] = 'popup'; | |
| 136 | + } | |
| 137 | + } | |
| 138 | + | |
| 139 | + // Output | |
| 140 | + $output = '<div ' . get_block_wrapper_attributes() . '>'; | |
| 141 | + $output .= ayg_build_gallery( $this->clean_attributes( $atts ) ); | |
| 142 | + $output .= '</div>'; | |
| 143 | + | |
| 144 | + return $output; | |
| 186 | 145 | } |
| 187 | 146 | |
| 188 | 147 | /** |
| 189 | 148 | * Clean attributes array. |