| @@ -136,9 +136,10 @@ | ||
| 136 | 136 | try { |
| 137 | 137 | switch_to_blog( $site_id ); |
| 138 | 138 | update_option( $this->parent->_token . '_settings', $this->caught_option_value, true ); |
| 139 | 139 | } catch ( Exception $ex ) { |
| 140 | - /* Empty, intentionally. Don't crash on asset cleanup. */ | |
| 140 | + /* Avoid crashes on option propagation */ | |
| 141 | + error_log( 'SQLite Object Cache problem propagaging option value. Blog ' . $site_id . ':' . $ex->getMessage() ); | |
| 141 | 142 | } finally { |
| 142 | 143 | restore_current_blog(); |
| 143 | 144 | } |
| 144 | 145 | } |
| @@ -157,14 +158,13 @@ | ||
| 157 | 158 | if ( $this->plugin_file !== $plugin_file ) { |
| 158 | 159 | return $plugin_meta; |
| 159 | 160 | } |
| 160 | 161 | |
| 161 | - if ( is_multisite() && ( is_network_admin() || ! is_main_site() ) ) { | |
| 162 | + if ( is_multisite() && (is_network_admin() || ! is_main_site() ) ) { | |
| 162 | 163 | $plugin_meta[] = |
| 163 | 164 | esc_html__( 'See the main site\'s dashboard for settings.', 'sqlite-object-cache' ); |
| 164 | 165 | } |
| 165 | 166 | |
| 166 | - /** @noinspection HtmlUnknownTarget */ | |
| 167 | 167 | $plugin_meta[] = sprintf( |
| 168 | 168 | '<a href="%1$s"><span class="dashicons dashicons-star-filled" aria-hidden="true" style="font-size:14px;line-height:1.3"></span>%2$s</a>', |
| 169 | 169 | 'https://github.com/sponsors/OllieJones', |
| 170 | 170 | esc_html_x( 'Sponsor', 'verb', 'sqlite-object-cache' ) |
| @@ -183,9 +183,9 @@ | ||
| 183 | 183 | $fields = array( |
| 184 | 184 | array( |
| 185 | 185 | 'id' => 'flush', |
| 186 | 186 | 'label' => __( 'Flush now', 'sqlite-object-cache' ), |
| 187 | - 'description' => __( 'Check to flush the cache (delete all its entries, including all transients) now.', 'sqlite-object-cache' ) . ' ' . | |
| 187 | + 'description' => __( 'Check to flush the cache (delete all its entries) now.', 'sqlite-object-cache' ) . ' ' . | |
| 188 | 188 | __( 'This briefly puts your site into maintenance mode.', 'sqlite-object-cache' ), |
| 189 | 189 | 'type' => 'checkbox', |
| 190 | 190 | 'default' => '', |
| 191 | 191 | 'reset' => '', |
| @@ -246,15 +246,8 @@ | ||
| 246 | 246 | 'min' => 0.1, |
| 247 | 247 | 'step' => 'any', |
| 248 | 248 | 'cssclass' => 'narrow', |
| 249 | 249 | 'placeholder' => __( 'Hours to retain.', 'sqlite-object-cache' ), |
| 250 | - ), | |
| 251 | - array( | |
| 252 | - 'id' => 'adminbarflush', | |
| 253 | - 'label' => __( 'Show', 'sqlite-object-cache' ), | |
| 254 | - 'description' => __( 'Flush Object Cache button in the admin bar.', 'sqlite-object-cache' ), | |
| 255 | - 'type' => 'checkbox', | |
| 256 | - 'default' => '', | |
| 257 | 250 | ) |
| 258 | 251 | ); |
| 259 | 252 | |
| 260 | 253 | if ( $this->parent->apcu_extension_is_enabled() ) { |
| @@ -268,12 +261,9 @@ | ||
| 268 | 261 | |
| 269 | 262 | } |
| 270 | 263 | |
| 271 | 264 | $settings['standard'] = array( |
| 272 | - // Using core I18n. | |
| 273 | - // phpcs:ignore WordPress.WP.I18n.MissingArgDomain | |
| 274 | 265 | 'title' => __( 'Settings' ), |
| 275 | - // phpcs:ignore WordPress.WP.I18n.MissingArgDomain | |
| 276 | 266 | 'submit' => __( 'Save Changes' ), |
| 277 | 267 | 'description' => '', |
| 278 | 268 | 'render_section_header' => array( $this, 'settings_section_header' ), |
| 279 | 269 | 'form_post_callback' => array( $this, 'validate_settings' ), |
| @@ -286,9 +276,9 @@ | ||
| 286 | 276 | 'render_section_header' => array( $this, 'stats_section_header' ), |
| 287 | 277 | 'form_post_callback' => array( $this, 'validate_reset_stats' ), |
| 288 | 278 | ); |
| 289 | 279 | |
| 290 | - return apply_filters( 'sqlite_object_cache_settings_fields', $settings ); | |
| 280 | + return apply_filters( $this->parent->_token . '_settings_fields', $settings ); | |
| 291 | 281 | } |
| 292 | 282 | |
| 293 | 283 | /** |
| 294 | 284 | * Validate the options presented to the Settings tab. |
| @@ -450,9 +440,9 @@ | ||
| 450 | 440 | private function menu_settings() { |
| 451 | 441 | $this->complain_if_sqlite3_unavailable(); |
| 452 | 442 | |
| 453 | 443 | return apply_filters( |
| 454 | - 'sqlite_object_cachemenu_settings', | |
| 444 | + $this->base . 'menu_settings', | |
| 455 | 445 | array( |
| 456 | 446 | 'location' => 'options', // Possible settings: options, menu, submenu. |
| 457 | 447 | 'parent_slug' => 'options-general.php', |
| 458 | 448 | 'page_title' => __( 'SQLite Persistent Object Cache', 'sqlite-object-cache' ), |
| @@ -556,9 +546,8 @@ | ||
| 556 | 546 | |
| 557 | 547 | if ( is_array( $this->settings ) ) { |
| 558 | 548 | |
| 559 | 549 | /* get the tab chosen by the user ('standard' or 'stats') */ |
| 560 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 561 | 550 | $tab = isset ( $_REQUEST['tab'] ) ? sanitize_key( $_REQUEST['tab'] ) : 'standard'; |
| 562 | 551 | |
| 563 | 552 | $default_option = array(); |
| 564 | 553 | $option_name = $this->base . 'settings'; |
| @@ -593,9 +582,9 @@ | ||
| 593 | 582 | // Add field to page. |
| 594 | 583 | add_settings_field( |
| 595 | 584 | $field['id'], |
| 596 | 585 | $field['label'], |
| 597 | - array( $this, 'echo_field' ), | |
| 586 | + array( $this->parent->admin, 'echo_field' ), | |
| 598 | 587 | $this->parent->_token . '_settings', |
| 599 | 588 | $section, |
| 600 | 589 | array( |
| 601 | 590 | 'field' => $field, |
| @@ -703,21 +692,14 @@ | ||
| 703 | 692 | ? phpversion( "apcu" ) |
| 704 | 693 | : __( 'unavailable', 'sqlite-object-cache' ); |
| 705 | 694 | |
| 706 | 695 | if ( method_exists( $wp_object_cache, 'sqlite_get_version' ) ) { |
| 707 | - $server_software = 'unk'; | |
| 708 | - // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 709 | - if ( isset( $_SERVER['SERVER_SOFTWARE'] ) && is_string( $_SERVER['SERVER_SOFTWARE'] ) ) { | |
| 710 | - $server_software = $_SERVER['SERVER_SOFTWARE']; | |
| 711 | - } | |
| 712 | - // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 713 | 696 | echo '<p>' . esc_html( sprintf( |
| 714 | 697 | /* translators: 1: version for sqlite 2: version for php 3: webserver version 4: version for plugin 5: igbinary 6:APCu 7:WordPress */ |
| 715 | 698 | __( 'Versions: WordPress: %7$s SQLite: %1$s php: %2$s Server: %3$s Plugin: %4$s APCu: %6$s igbinary: %5$s.', 'sqlite-object-cache' ), |
| 716 | 699 | $wp_object_cache->sqlite_get_version(), |
| 717 | 700 | PHP_VERSION, |
| 718 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 719 | - $server_software, | |
| 701 | + $_SERVER['SERVER_SOFTWARE'], | |
| 720 | 702 | $this->parent->_version, |
| 721 | 703 | $igbinary, |
| 722 | 704 | $apcu_version, |
| 723 | 705 | $wp_version ) ) . '</p>'; |
| @@ -752,9 +734,8 @@ | ||
| 752 | 734 | public function settings_page() { |
| 753 | 735 | |
| 754 | 736 | $this->enqueue_assets(); |
| 755 | 737 | /* get the tab chosen by the user ('standard' by default or 'stats') */ |
| 756 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 757 | 738 | $tab = isset ( $_REQUEST['tab'] ) ? sanitize_key( $_REQUEST['tab'] ) : 'standard'; |
| 758 | 739 | |
| 759 | 740 | // Build page HTML. |
| 760 | 741 | echo '<div class="wrap" id="' . esc_attr( $this->parent->_token . '_settings' ) . '">' . PHP_EOL; |
| @@ -795,10 +776,10 @@ | ||
| 795 | 776 | /** @noinspection HtmlUnknownTarget */ |
| 796 | 777 | echo '<form method="post" action="options.php" enctype="multipart/form-data">' . PHP_EOL; |
| 797 | 778 | |
| 798 | 779 | // Get settings fields. |
| 799 | - settings_fields( 'sqlite_object_cache_settings' ); | |
| 800 | - do_settings_sections( 'sqlite_object_cache_settings' ); | |
| 780 | + settings_fields( $this->parent->_token . '_settings' ); | |
| 781 | + do_settings_sections( $this->parent->_token . '_settings' ); | |
| 801 | 782 | |
| 802 | 783 | echo '<p class="submit">' . PHP_EOL; |
| 803 | 784 | echo '<input type="hidden" name="tab" value="' . esc_attr( $tab ) . '" />' . PHP_EOL; |
| 804 | 785 | echo '<input name="Submit" type="submit" class="button-primary" value="' . esc_attr( $submit_caption ) . '" />' . PHP_EOL; |
| @@ -841,9 +822,9 @@ | ||
| 841 | 822 | * @return void |
| 842 | 823 | */ |
| 843 | 824 | private function exit_maintenance_mode() { |
| 844 | 825 | $maintenanceFileName = ABSPATH . '.maintenance'; |
| 845 | - wp_delete_file( $maintenanceFileName ); | |
| 826 | + unlink( $maintenanceFileName ); | |
| 846 | 827 | } |
| 847 | 828 | |
| 848 | 829 | /** |
| 849 | 830 | * Update a variable in the wp-config.php file. |
| @@ -952,9 +933,9 @@ | ||
| 952 | 933 | $counts [ $salt ] += 1; |
| 953 | 934 | $totalcount += 1; |
| 954 | 935 | } |
| 955 | 936 | |
| 956 | - $apcusalt = trim( property_exists( $wp_object_cache, 'apcusalt' ) && is_string( $wp_object_cache->apcusalt ) ? $wp_object_cache->apcusalt : '', '|' ); | |
| 937 | + $apcusalt = trim( property_exists( $wp_object_cache, 'apcusalt' ) ? $wp_object_cache->apcusalt : '', '|' ); | |
| 957 | 938 | $settings = array(); |
| 958 | 939 | $settings ['salt'] = $apcusalt; |
| 959 | 940 | $settings ['total'] = "$totalsize($totalcount)"; |
| 960 | 941 | $siteno = 1; |
| @@ -1027,9 +1008,8 @@ | ||
| 1027 | 1008 | if ( is_array( $v ) ) { |
| 1028 | 1009 | if ( array_key_exists( 'local_value', $v ) ) { |
| 1029 | 1010 | $v = $v['local_value']; |
| 1030 | 1011 | } else { |
| 1031 | - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export | |
| 1032 | 1012 | $v = var_export( $v, true ); |
| 1033 | 1013 | } |
| 1034 | 1014 | } |
| 1035 | 1015 | $result [] = $k . ':' . $v; |
| @@ -1034,130 +1014,8 @@ | ||
| 1034 | 1014 | } |
| 1035 | 1015 | $result [] = $k . ':' . $v; |
| 1036 | 1016 | } |
| 1037 | 1017 | return implode( '; ', $result ); |
| 1038 | - } | |
| 1039 | - | |
| 1040 | - /** | |
| 1041 | - * Generate HTML for displaying fields. | |
| 1042 | - * | |
| 1043 | - * @param mixed $idata Data array. | |
| 1044 | - * @param object $post Post object. | |
| 1045 | - */ | |
| 1046 | - public function echo_field( $idata = array(), $post = null ) { | |
| 1047 | - | |
| 1048 | - // Get field info. | |
| 1049 | - if ( isset( $idata['field'] ) ) { | |
| 1050 | - $field = $idata['field']; | |
| 1051 | - } else { | |
| 1052 | - $field = $idata; | |
| 1053 | - } | |
| 1054 | - | |
| 1055 | - $option_name = ''; | |
| 1056 | - if ( isset( $idata['option'] ) ) { | |
| 1057 | - $option_name = $idata['option']; | |
| 1058 | - } | |
| 1059 | - | |
| 1060 | - /* Get saved data. */ | |
| 1061 | - $field_id = $field['id']; | |
| 1062 | - $data = null; | |
| 1063 | - | |
| 1064 | - /* Data to display, if set */ | |
| 1065 | - $option = get_option( $option_name, array() ); | |
| 1066 | - if ( is_array( $option ) && array_key_exists( $field_id, $option ) ) { | |
| 1067 | - $data = $option[ $field_id ]; | |
| 1068 | - } | |
| 1069 | - | |
| 1070 | - /* the reset element sets the value of the field, overriding whatever is in the option */ | |
| 1071 | - if ( array_key_exists( 'reset', $field ) ) { | |
| 1072 | - $data = $field['reset']; | |
| 1073 | - } | |
| 1074 | - | |
| 1075 | - /* Show default data if no option saved and default is supplied. */ | |
| 1076 | - if ( null === $data && isset( $field['default'] ) ) { | |
| 1077 | - $data = $field['default']; | |
| 1078 | - } elseif ( null === $data ) { | |
| 1079 | - $data = ''; | |
| 1080 | - } | |
| 1081 | - | |
| 1082 | - /* CSS class array */ | |
| 1083 | - $classes = array(); | |
| 1084 | - if ( array_key_exists( 'cssclass', $field ) ) { | |
| 1085 | - $classes = is_array( $field['cssclass'] ) ? $field['cssclass'] : array( $field['cssclass'] ); | |
| 1086 | - } | |
| 1087 | - | |
| 1088 | - echo '<input '; | |
| 1089 | - echo 'id="' . esc_attr( $field['id'] ) . '" '; | |
| 1090 | - $this->echo_classes( $classes ) . ' '; | |
| 1091 | - echo 'name="' . esc_attr( $option_name ) . '[' . esc_attr( $field_id ) . ']" '; | |
| 1092 | - if ( array_key_exists( 'placeholder', $field ) ) { | |
| 1093 | - echo 'placeholder="' . esc_attr( $field['placeholder'] ) . '" '; | |
| 1094 | - } | |
| 1095 | - switch ( $field['type'] ) { | |
| 1096 | - | |
| 1097 | - case 'text': | |
| 1098 | - case 'url': | |
| 1099 | - case 'email': | |
| 1100 | - echo 'type="text" '; | |
| 1101 | - echo 'value="' . esc_attr( $data ) . '" '; | |
| 1102 | - break; | |
| 1103 | - | |
| 1104 | - case 'number': | |
| 1105 | - echo 'type="number" '; | |
| 1106 | - echo 'value="' . esc_attr( $data ) . '" '; | |
| 1107 | - if ( isset( $field['min'] ) ) { | |
| 1108 | - echo 'min="' . esc_attr( $field['min'] ) . '" '; | |
| 1109 | - } | |
| 1110 | - if ( isset( $field['max'] ) ) { | |
| 1111 | - echo 'max="' . esc_attr( $field['max'] ) . '" '; | |
| 1112 | - } | |
| 1113 | - if ( isset( $field['step'] ) ) { | |
| 1114 | - echo 'step="' . esc_attr( $field['step'] ) . '" '; | |
| 1115 | - } | |
| 1116 | - break; | |
| 1117 | - | |
| 1118 | - case 'password': | |
| 1119 | - case 'hidden': | |
| 1120 | - echo 'type="' . esc_attr( $field['type'] ) . '" '; | |
| 1121 | - echo 'value="' . esc_attr( $data ) . '" '; | |
| 1122 | - break; | |
| 1123 | - | |
| 1124 | - case 'checkbox': | |
| 1125 | - echo 'type="checkbox" '; | |
| 1126 | - if ( 'on' === $data ) { | |
| 1127 | - echo 'checked="checked" '; | |
| 1128 | - } | |
| 1129 | - break; | |
| 1130 | - } | |
| 1131 | - echo '>' . PHP_EOL; | |
| 1132 | - | |
| 1133 | - if ( ! $post ) { | |
| 1134 | - echo '<label for="' . esc_attr( $field['id'] ) . '">' . PHP_EOL; | |
| 1135 | - } | |
| 1136 | - | |
| 1137 | - echo '<span class="description">' . esc_html( $field['description'] ) . '</span>' . PHP_EOL; | |
| 1138 | - | |
| 1139 | - if ( ! $post ) { | |
| 1140 | - echo '</label>' . PHP_EOL; | |
| 1141 | - } | |
| 1142 | - } | |
| 1143 | - | |
| 1144 | - /** | |
| 1145 | - * Given an array of CSS class names ['foo', 'bar'] echo class="foo bar". | |
| 1146 | - * | |
| 1147 | - * If the array is empty just echo a space. | |
| 1148 | - * | |
| 1149 | - * @param array $classes | |
| 1150 | - * | |
| 1151 | - * @return void | |
| 1152 | - */ | |
| 1153 | - private function echo_classes( array $classes ) { | |
| 1154 | - if ( count( $classes ) > 0 ) { | |
| 1155 | - echo 'class="'; | |
| 1156 | - echo esc_html( implode( ' ', array_map( 'esc_attr', $classes ) ) ); | |
| 1157 | - echo '"'; | |
| 1158 | - } | |
| 1159 | - echo ' '; | |
| 1160 | 1018 | } |
| 1161 | 1019 | |
| 1162 | 1020 | |
| 1163 | 1021 | } |