| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Block Editor: Reverse Columns on Mobile |
| 4 |
Description: Adds a "Reverse on Mobile" option to the Columns, Row, Stack and Media & Text blocks in Gutenberg. |
| 5 |
Version: 1.0.14 |
| 6 |
Author: Mickaƫl Larguier |
| 7 |
Author URI: https://mickaellarguier.com |
| 8 |
License: GPL2 |
| 9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 10 |
Text Domain: block-editor-columns-reverse |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
define( 'MLRG_COLUMNS_REVERSE_VERSION', '1.0.14' ); |
| 18 |
|
| 19 |
/** |
| 20 |
* Enqueue necessary scripts and styles. |
| 21 |
*/ |
| 22 |
function mlrg_enqueue_block_editor_assets() { |
| 23 |
wp_enqueue_script( |
| 24 |
'mlrg-columns-reverse-script', |
| 25 |
plugins_url( 'block-extend.js', __FILE__ ), |
| 26 |
['wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor'], |
| 27 |
MLRG_COLUMNS_REVERSE_VERSION, |
| 28 |
true |
| 29 |
); |
| 30 |
|
| 31 |
wp_set_script_translations( |
| 32 |
'mlrg-columns-reverse-script', |
| 33 |
'block-editor-columns-reverse' |
| 34 |
); |
| 35 |
|
| 36 |
wp_enqueue_style( |
| 37 |
'mlrg-columns-reverse-editor-style', |
| 38 |
plugins_url( 'style.css', __FILE__ ), |
| 39 |
[], |
| 40 |
MLRG_COLUMNS_REVERSE_VERSION |
| 41 |
); |
| 42 |
} |
| 43 |
add_action( 'enqueue_block_editor_assets', 'mlrg_enqueue_block_editor_assets' ); |
| 44 |
|
| 45 |
/** |
| 46 |
* Enqueue front-end styles only when a block uses reverseOnMobile. |
| 47 |
*/ |
| 48 |
function mlrg_maybe_enqueue_frontend_styles( $block_content, $block ) { |
| 49 |
if ( strpos( $block_content, 'mlrg-reverse-mobile' ) !== false ) { |
| 50 |
wp_enqueue_style( |
| 51 |
'mlrg-columns-reverse-frontend', |
| 52 |
plugins_url( 'style.css', __FILE__ ), |
| 53 |
[], |
| 54 |
MLRG_COLUMNS_REVERSE_VERSION |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
return $block_content; |
| 59 |
} |
| 60 |
add_filter( 'render_block', 'mlrg_maybe_enqueue_frontend_styles', 10, 2 ); |
| 61 |
|
| 62 |
/** |
| 63 |
* Add custom links to the plugin list page. |
| 64 |
*/ |
| 65 |
function mlrg_plugin_row_meta( $links, $file ) { |
| 66 |
if ( strpos( $file, 'block-editor-columns-reverse.php' ) !== false ) { |
| 67 |
$new_links = array( |
| 68 |
'donate' => '<a href="' . esc_url( 'https://ko-fi.com/mickaellrg' ) . '" target="_blank"><span class="dashicons dashicons-heart" aria-hidden="true" style="font-size:12px;line-height:1.6"></span>' . __( 'Support this plugin', 'block-editor-columns-reverse' ) . '</a>' |
| 69 |
); |
| 70 |
$links = array_merge( $links, $new_links ); |
| 71 |
} |
| 72 |
return $links; |
| 73 |
} |
| 74 |
add_filter( 'plugin_row_meta', 'mlrg_plugin_row_meta', 10, 2 ); |
| 75 |
|