| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Module Name: WP.me Shortlinks |
| 4 | - * Module Description: Generates shorter links using the wp.me domain. | |
| 4 | + * Module Description: Share short, easy-to-remember links to your posts and pages. | |
| 5 | 5 | * Sort Order: 8 |
| 6 | 6 | * First Introduced: 1.1 |
| 7 | 7 | * Requires Connection: Yes |
| 8 | 8 | * Auto Activate: No |
| @@ -12,8 +12,12 @@ | ||
| 12 | 12 | * |
| 13 | 13 | * @package automattic/jetpack |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 17 | + exit( 0 ); | |
| 18 | +} | |
| 19 | + | |
| 16 | 20 | add_filter( 'pre_get_shortlink', 'wpme_get_shortlink_handler', 1, 4 ); |
| 17 | 21 | |
| 18 | 22 | if ( ! function_exists( 'wpme_dec2sixtwo' ) ) { |
| 19 | 23 | /** |
| @@ -32,11 +36,11 @@ | ||
| 32 | 36 | $num = abs( $num ); |
| 33 | 37 | } |
| 34 | 38 | |
| 35 | 39 | for ( $t = floor( log10( $num ) / log10( 62 ) ); $t >= 0; $t-- ) { |
| 36 | - $a = floor( $num / pow( 62, $t ) ); | |
| 37 | - $out = $out . substr( $index, $a, 1 ); | |
| 38 | - $num = $num - ( $a * pow( 62, $t ) ); | |
| 40 | + $a = (int) floor( $num / pow( 62, $t ) ); | |
| 41 | + $out .= substr( $index, $a, 1 ); | |
| 42 | + $num -= $a * pow( 62, $t ); | |
| 39 | 43 | } |
| 40 | 44 | |
| 41 | 45 | return $out; |
| 42 | 46 | } |
| @@ -170,9 +174,10 @@ | ||
| 170 | 174 | * |
| 171 | 175 | * @return string |
| 172 | 176 | */ |
| 173 | 177 | function wpme_rest_get_shortlink( $object ) { |
| 174 | - return wpme_get_shortlink( $object['id'], array() ); | |
| 178 | + $object_id = $object['id'] ?? 0; | |
| 179 | + return wpme_get_shortlink( $object_id, array() ); | |
| 175 | 180 | } |
| 176 | 181 | |
| 177 | 182 | // Add shortlinks to the REST API Post response. |
| 178 | 183 | add_action( 'rest_api_init', 'wpme_rest_register_shortlinks' ); |
| @@ -180,8 +185,11 @@ | ||
| 180 | 185 | /** |
| 181 | 186 | * Set the Shortlink Gutenberg extension as available. |
| 182 | 187 | */ |
| 183 | 188 | function wpme_set_extension_available() { |
| 184 | - Jetpack_Gutenberg::set_extension_available( 'jetpack/shortlinks' ); | |
| 189 | + Jetpack_Gutenberg::set_extension_available( 'shortlinks' ); | |
| 185 | 190 | } |
| 186 | 191 | |
| 187 | 192 | add_action( 'init', 'wpme_set_extension_available' ); |
| 193 | + | |
| 194 | +require_once __DIR__ . '/shortlinks/abilities/class-shortlinks-abilities.php'; | |
| 195 | +\Automattic\Jetpack\Plugin\Abilities\Shortlinks_Abilities::init(); | |