PluginProbe ʕ •ᴥ•ʔ
External Links – nofollow, noopener & new window / 2.50
External Links – nofollow, noopener & new window v2.50
0.31 0.32 0.33 0.34 0.35 1.01 1.02 1.03 1.10 1.20 1.21 1.30 1.31 1.40 1.41 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.60 1.61 1.62 1.70 1.80 1.81 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 2.3 2.32 2.35 2.40 2.42 2.43 2.45 2.46 2.47 2.48 2.50 2.51 2.55 2.56 2.57 2.58 2.59 2.60 2.61 2.62 2.63 2.64 2.65 trunk 0.10 0.11 0.12 0.20 0.21 0.30
wp-external-links / includes / class-wpel-update.php
wp-external-links / includes Last commit date
admin 5 years ago register-hooks 7 years ago class-wpel-front-ignore.php 7 years ago class-wpel-front.php 5 years ago class-wpel-link.php 7 years ago class-wpel-linkhero.php 5 years ago class-wpel-plugin.php 5 years ago class-wpel-register-scripts.php 5 years ago class-wpel-template-tags.php 7 years ago class-wpel-update.php 5 years ago index.php 6 years ago
class-wpel-update.php
146 lines
1 <?php
2 /**
3 * Class WPEL_Update
4 *
5 * @package WPEL
6 * @category WordPress Plugin
7 * @version 2.3
8 * @link https://www.webfactoryltd.com/
9 * @license Dual licensed under the MIT and GPLv2+ licenses
10 */
11 final class WPEL_Update extends WPRun_Base_1x0x0
12 {
13
14 /**
15 * Initialize
16 */
17 protected function init()
18 {
19 $this->update_to_v2();
20 }
21
22 /**
23 * Action for "admin_init"
24 */
25 protected function action_admin_init()
26 {
27 $this->update_version();
28 }
29
30 /**
31 * Update version
32 * @return void
33 */
34 private function update_version()
35 {
36 $plugin_data = get_plugin_data( WPEL_Plugin::get_plugin_file() );
37
38 $current_version = $plugin_data[ 'Version' ];
39 $saved_version = get_option( 'wpel-version' );
40
41 if ( $current_version !== $saved_version ) {
42 update_option( 'wpel-version', $current_version );
43 }
44
45 $first_install = get_option( 'wpel-first-install', 0 );
46 if ( empty( $first_install ) ) {
47 update_option( 'wpel-first-install', current_time( 'timestamp' ) );
48 }
49 }
50
51 /**
52 * Update procedure to v2.x
53 * @return void
54 */
55 private function update_to_v2()
56 {
57 $site_already_set = get_option( 'wpel-external-link-settings' );
58
59 if ( $site_already_set ) {
60 return;
61 }
62
63 // get default values
64 $external_link_values = WPEL_External_Link_Fields::get_instance()->get_default_values();
65 $internal_link_values = WPEL_Internal_Link_Fields::get_instance()->get_default_values();
66 $excluded_link_values = WPEL_Excluded_Link_Fields::get_instance()->get_default_values();
67 $exceptions_link_values = WPEL_Exceptions_Fields::get_instance()->get_default_values();
68 $admin_link_values = WPEL_Admin_Fields::get_instance()->get_default_values();
69
70 // Upgrade to version 2
71 // check for old option values version < 2.0.0
72 $old_main = get_option( 'wp_external_links-main' );
73 $old_seo = get_option( 'wp_external_links-seo' );
74 $old_style = get_option( 'wp_external_links-style' );
75 $old_extra = get_option( 'wp_external_links-extra' );
76 $old_screen = get_option( 'wp_external_links-screen' );
77
78 // convert old to new db option values
79 if ( ! empty( $old_main ) || ! empty( $old_seo ) || ! empty( $old_style ) || ! empty( $old_extra ) || ! empty( $old_screen ) ) {
80 // helper function
81 $val = function ( $arr, $key, $default = '' ) {
82 if ( ! isset( $arr[ $key ] ) ) {
83 return $default;
84 }
85
86 return (string) $arr[ $key ];
87 };
88
89 // mapping
90 if ( ! empty( $old_main ) ) {
91 $target = $val( $old_main, 'target' );
92 $external_link_values[ 'target' ] = str_replace( '_none', '_self', $target );
93
94 $exceptions_link_values[ 'apply_all' ] = $val( $old_main, 'filter_page' );
95 $exceptions_link_values[ 'apply_post_content' ] = $val( $old_main, 'filter_posts' );
96 $exceptions_link_values[ 'apply_comments' ] = $val( $old_main, 'filter_comments' );
97 $exceptions_link_values[ 'apply_widgets' ] = $val( $old_main, 'filter_widgets' );
98 $exceptions_link_values[ 'exclude_urls' ] = $val( $old_main, 'ignore' );
99 $exceptions_link_values[ 'subdomains_as_internal_links' ] = $val( $old_main, 'ignore_subdomains' );
100 }
101 if ( ! empty( $old_seo ) ) {
102 $external_link_values[ 'rel_follow' ] = ( '1' == $val( $old_seo, 'nofollow' ) ) ? 'nofollow' : 'follow';
103 $external_link_values[ 'rel_follow_overwrite' ] = $val( $old_seo, 'overwrite_follow' );
104 $external_link_values[ 'rel_external' ] = $val( $old_seo, 'external' );
105
106 $title = $val( $old_seo, 'title' );
107 $external_link_values[ 'title' ] = str_replace( '%title%', '{title}', $title );
108 }
109 if ( ! empty( $old_style ) ) {
110 if ( $old_style[ 'icon' ] ) {
111 $external_link_values[ 'icon_type' ] = 'image';
112 $external_link_values[ 'icon_image' ] = $val( $old_style, 'icon', '1' );
113 }
114 $external_link_values[ 'class' ] = $val( $old_style, 'class_name' );
115 $external_link_values[ 'no_icon_for_img' ] = $val( $old_style, 'image_no_icon' );
116 }
117 /*
118 if ( ! empty( $old_extra ) ) {
119 // nothing
120 }
121 */
122 if ( ! empty( $old_screen ) ) {
123 $admin_link_values[ 'own_admin_menu' ] = ( 'admin.php' == $val( $old_screen, 'menu_position' ) ) ? '1' : '';
124 }
125
126 // delete old values
127 delete_option( 'wp_external_links-meta' );
128 delete_option( 'wp_external_links-main' );
129 delete_option( 'wp_external_links-seo' );
130 delete_option( 'wp_external_links-style' );
131 delete_option( 'wp_external_links-extra' );
132 delete_option( 'wp_external_links-screen' );
133 }
134
135 // update new values
136 update_option( 'wpel-external-link-settings', $external_link_values );
137 update_option( 'wpel-internal-link-settings', $internal_link_values );
138 update_option( 'wpel-excluded-link-settings', $excluded_link_values );
139 update_option( 'wpel-exceptions-settings', $exceptions_link_values );
140 update_option( 'wpel-admin-settings', $admin_link_values );
141 }
142
143 }
144
145 /*?>*/
146