PluginProbe
Snippet Shortcodes / 2.2
Snippet Shortcodes v2.2
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
← All changes | includes/functions.php +31 -3 2.02.2 View file →
@@ -9,9 +9,9 @@
9 9 */
10 10 function sh_cd_shortcodes_save_post() {
11 11
12 12 // Capture the raw $_POST fields, the save functions will process and validate the data
13 - $shortcode = sh_cd_get_values_from_post( [ 'id', 'slug', 'data', 'disabled' ] );
13 + $shortcode = sh_cd_get_values_from_post( [ 'id', 'slug', 'previous_slug', 'data', 'disabled' ] );
14 14
15 15 return sh_cd_db_shortcodes_save( $shortcode );
16 16 }
17 17
@@ -43,9 +43,9 @@
43 43 * @param $slug
44 44 *
45 45 * @return string
46 46 */
47 -function sh_cd_slug_generate( $slug ) {
47 +function sh_cd_slug_generate( $slug, $exising_id = NULL ) {
48 48
49 49 if ( true === empty( $slug ) ) {
50 50 return NULL;
51 51 }
@@ -56,9 +56,9 @@
56 56
57 57 $try = 1;
58 58
59 59 // Ensure the slug is unique
60 - while ( false === sh_cd_slug_is_unique( $slug ) ) {
60 + while ( false === sh_cd_slug_is_unique( $slug, $exising_id ) ) {
61 61
62 62 $slug = sprintf( '%s_%d', $original_slug, $try );
63 63
64 64 $try++;
@@ -64,8 +64,36 @@
64 64 $try++;
65 65 }
66 66
67 67 return $slug;
68 +}
69 +
70 +/**
71 + * Clone an existing shortcode!
72 + *
73 + * @param $id
74 + *
75 + * @return bool
76 + */
77 +function sh_cd_clone( $id ) {
78 +
79 + if( false === sh_cd_license_is_premium() ) {
80 + return true;
81 + }
82 +
83 + if ( false === is_numeric( $id ) ) {
84 + return false;
85 + }
86 +
87 + $to_be_cloned = sh_cd_db_shortcodes_by_id( $id );
88 +
89 + if ( true === empty( $to_be_cloned ) ) {
90 + return false;
91 + }
92 +
93 + unset( $to_be_cloned['id'] );
94 +
95 + return sh_cd_db_shortcodes_save( $to_be_cloned );
68 96 }
69 97
70 98 /**
71 99 * Display message in admin UI