| @@ -1,0 +1,196 @@ | ||
| 1 | +<?php | |
| 2 | +/* | |
| 3 | + * License: GPLv3 | |
| 4 | + * License URI: https://www.gnu.org/licenses/gpl.txt | |
| 5 | + * Copyright 2012-2026 Jean-Sebastien Morisset (https://wpsso.com/) | |
| 6 | + */ | |
| 7 | + | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + | |
| 10 | + die( 'These aren\'t the droids you\'re looking for.' ); | |
| 11 | +} | |
| 12 | + | |
| 13 | +if ( ! class_exists( 'WpssoSubmenuTools' ) && class_exists( 'WpssoAdmin' ) ) { | |
| 14 | + | |
| 15 | + class WpssoSubmenuTools extends WpssoAdmin { | |
| 16 | + | |
| 17 | + public function __construct( &$plugin, $id, $name, $lib, $ext ) { | |
| 18 | + | |
| 19 | + $this->p =& $plugin; | |
| 20 | + | |
| 21 | + if ( $this->p->debug->enabled ) { | |
| 22 | + | |
| 23 | + $this->p->debug->mark(); | |
| 24 | + } | |
| 25 | + | |
| 26 | + $this->menu_id = $id; | |
| 27 | + $this->menu_name = $name; | |
| 28 | + $this->menu_lib = $lib; | |
| 29 | + $this->menu_ext = $ext; | |
| 30 | + } | |
| 31 | + | |
| 32 | + protected function add_form_buttons( &$form_button_rows ) { | |
| 33 | + | |
| 34 | + $role_label = _x( 'Person', 'user role', 'wpsso' ); | |
| 35 | + | |
| 36 | + /* | |
| 37 | + * Row #0. | |
| 38 | + */ | |
| 39 | + $count_cache_files = $this->p->util->cache->count_cache_files(); | |
| 40 | + $count_ignored_urls = $this->p->util->cache->count_ignored_urls(); | |
| 41 | + $count_db_transients_no_short = $this->p->util->cache->count_db_transients( $key_prefix = '', $incl_shortened = false ); | |
| 42 | + $count_db_transients_expired = $this->p->util->cache->count_db_transients_expired(); | |
| 43 | + $count_db_transients_shortened = $this->p->util->cache->count_db_transients( $key_prefix = 'wpsso_s_', $incl_shortened = true ); | |
| 44 | + $count_cron_jobs = $this->p->util->count_cron_jobs(); | |
| 45 | + | |
| 46 | + $refresh_cache_transl = _x( 'Refresh Cache', 'submit button', 'wpsso' ) . ' *'; | |
| 47 | + | |
| 48 | + $clear_cache_files_transl = sprintf( _nx( 'Clear %s Cached File', 'Clear %s Cached Files', | |
| 49 | + $count_cache_files, 'submit button', 'wpsso' ), number_format_i18n( $count_cache_files ) ); | |
| 50 | + | |
| 51 | + $clear_ignored_urls_transl = sprintf( _nx( 'Clear %s Failed URL Connection', 'Clear %s Failed URL Connections', | |
| 52 | + $count_ignored_urls, 'submit button', 'wpsso' ), number_format_i18n( $count_ignored_urls ) ); | |
| 53 | + | |
| 54 | + $clear_db_transients_no_short_transl = sprintf( _nx( 'Clear %s Database Transient', 'Clear %s Database Transients', | |
| 55 | + $count_db_transients_no_short, 'submit button', 'wpsso' ), number_format_i18n( $count_db_transients_no_short ) ) . ' **'; | |
| 56 | + | |
| 57 | + $clear_db_transients_shortened_transl = sprintf( _nx( 'Clear %s Short URL DB Transient', 'Clear %s Short URL DB Transients', | |
| 58 | + $count_db_transients_shortened, 'submit button', 'wpsso' ), number_format_i18n( $count_db_transients_shortened ) ); | |
| 59 | + | |
| 60 | + $clear_db_transients_expired_transl = sprintf( _nx( 'Clear %s Expired DB Transient', 'Clear %s Expired DB Transients', | |
| 61 | + $count_db_transients_expired, 'submit button', 'wpsso' ), number_format_i18n( $count_db_transients_expired ) ); | |
| 62 | + | |
| 63 | + $clear_cron_jobs_transl = sprintf( _nx( 'Clear %s WordPress Cron Job', 'Clear %s WordPress Cron Jobs', | |
| 64 | + $count_cron_jobs, 'submit button', 'wpsso' ), number_format_i18n( $count_cron_jobs ) ); | |
| 65 | + | |
| 66 | + $flush_rewrite_rules_transl = _x( 'Flush WordPress Rewrite Rules', 'submit button', 'wpsso' ); | |
| 67 | + | |
| 68 | + /* | |
| 69 | + * Row #1. | |
| 70 | + */ | |
| 71 | + $export_settings_transl = _x( 'Export Plugin and Add-on Settings', 'submit button', 'wpsso' ); | |
| 72 | + $import_settings_transl = _x( 'Import Plugin and Add-on Settings', 'submit button', 'wpsso' ); | |
| 73 | + | |
| 74 | + /* | |
| 75 | + * Row #2. | |
| 76 | + */ | |
| 77 | + $add_persons_transl = sprintf( _x( 'Add %s Role to Content Creators', 'submit button', 'wpsso' ), $role_label ) . ' ***'; | |
| 78 | + $remove_persons_transl = sprintf( _x( 'Remove %s Role from All Users', 'submit button', 'wpsso' ), $role_label ); | |
| 79 | + $reload_image_sizes_transl = _x( 'Reload Default Image Sizes', 'submit button', 'wpsso' ); | |
| 80 | + | |
| 81 | + /* | |
| 82 | + * Row #3. | |
| 83 | + */ | |
| 84 | + $change_show_next_key = SucomUtil::next_key( WpssoUser::show_opts(), $this->p->cf[ 'form' ][ 'show_options' ] ); | |
| 85 | + $change_show_next_transl = _x( $this->p->cf[ 'form' ][ 'show_options' ][ $change_show_next_key ], 'option value', 'wpsso' ); | |
| 86 | + $change_show_transl = sprintf( _x( 'Change to "%s" View', 'submit button', 'wpsso' ), $change_show_next_transl ); | |
| 87 | + | |
| 88 | + $form_button_rows = array( | |
| 89 | + | |
| 90 | + /* | |
| 91 | + * Row #0. | |
| 92 | + */ | |
| 93 | + array( | |
| 94 | + 'refresh_cache' => $refresh_cache_transl, | |
| 95 | + 'clear_cache_files' => $clear_cache_files_transl, // Clear Cached Files. | |
| 96 | + 'clear_ignored_urls' => $clear_ignored_urls_transl, // Clear Failed URL Connections. | |
| 97 | + 'clear_db_transients_no_short' => $clear_db_transients_no_short_transl, // Clear Database Transients. | |
| 98 | + 'clear_db_transients_shortened' => $clear_db_transients_shortened_transl, // Clear Short URL DB Transients. | |
| 99 | + 'clear_db_transients_expired' => $clear_db_transients_expired_transl, // Clear Expired DB Transients. | |
| 100 | + 'clear_cron_jobs' => $clear_cron_jobs_transl, // Clear WordPress Cron Jobs. | |
| 101 | + 'flush_rewrite_rules' => $flush_rewrite_rules_transl, // Flush WordPress Rewrite Rules. | |
| 102 | + ), | |
| 103 | + | |
| 104 | + /* | |
| 105 | + * Row #1. | |
| 106 | + */ | |
| 107 | + array( | |
| 108 | + 'export_plugin_settings_json' => $export_settings_transl, | |
| 109 | + 'import_plugin_settings_json' => array( | |
| 110 | + 'html' => ' | |
| 111 | + <form enctype="multipart/form-data" action="' . $this->p->util->get_admin_url() . '" method="post">' . | |
| 112 | + wp_nonce_field( WpssoAdmin::get_nonce_action(), WPSSO_NONCE_NAME ) . ' | |
| 113 | + <input type="hidden" name="wpsso-action" value="import_plugin_settings_json" /> | |
| 114 | + <input type="submit" class="button-secondary button-alt" | |
| 115 | + value="' . $import_settings_transl . '" style="display:inline-block;" /> | |
| 116 | + <input type="file" name="file" accept="application/x-gzip" /> | |
| 117 | + </form> | |
| 118 | + ', | |
| 119 | + ), | |
| 120 | + ), | |
| 121 | + | |
| 122 | + /* | |
| 123 | + * Row #2. | |
| 124 | + */ | |
| 125 | + array( | |
| 126 | + 'add_persons' => $add_persons_transl, | |
| 127 | + 'remove_persons' => $remove_persons_transl, | |
| 128 | + 'reload_default_image_sizes' => $reload_image_sizes_transl, | |
| 129 | + ), | |
| 130 | + | |
| 131 | + /* | |
| 132 | + * Row #3. | |
| 133 | + */ | |
| 134 | + array( | |
| 135 | + 'change_show_options&show-opts=' . $change_show_next_key => $change_show_transl, | |
| 136 | + 'reset_user_dismissed_notices' => _x( 'Reset Dismissed Notices', 'submit button', 'wpsso' ), | |
| 137 | + 'reset_user_metabox_layout' => _x( 'Reset Metabox Layout', 'submit button', 'wpsso' ), | |
| 138 | + ), | |
| 139 | + ); | |
| 140 | + } | |
| 141 | + | |
| 142 | + /* | |
| 143 | + * Called from WpssoAdmin->show_settings_page(). | |
| 144 | + */ | |
| 145 | + protected function show_post_body_settings_form() { | |
| 146 | + | |
| 147 | + $refresh_max_time = human_time_diff( 0, WPSSO_CACHE_REFRESH_MAX_TIME ); // 30 mins by default. | |
| 148 | + | |
| 149 | + echo '<div id="tools-content">' . "\n"; | |
| 150 | + | |
| 151 | + echo $this->get_form_buttons(); | |
| 152 | + | |
| 153 | + echo '<p class="status-msg smaller left">'; | |
| 154 | + echo '* '; | |
| 155 | + echo sprintf( __( 'The maximum execution time for this background task is currently set to %s.', 'wpsso' ), $refresh_max_time ) . ' '; | |
| 156 | + echo '</p>' . "\n"; | |
| 157 | + | |
| 158 | + echo '<p class="status-msg smaller left">'; | |
| 159 | + echo '** '; | |
| 160 | + echo __( 'All database transients are cleared, except for the shortened URL database transients.', 'wpsso' ) . ' '; | |
| 161 | + | |
| 162 | + if ( wp_using_ext_object_cache() ) { | |
| 163 | + | |
| 164 | + echo sprintf( __( '<a href="%1$s">Using an external object cache</a> for WordPress transients is <code>%2$s</code>.', 'wpsso' ), | |
| 165 | + __( 'https://developer.wordpress.org/reference/functions/wp_using_ext_object_cache/', 'wpsso' ), | |
| 166 | + wp_using_ext_object_cache() ? 'true' : 'false' ) . ' '; | |
| 167 | + echo __( 'All database transient counts should be 0.', 'wpsso' ) . ' '; | |
| 168 | + } | |
| 169 | + | |
| 170 | + echo '</p>' . "\n"; | |
| 171 | + | |
| 172 | + echo '<p class="status-msg smaller left">'; | |
| 173 | + echo '*** '; | |
| 174 | + echo __( 'Members of the role are used for some Schema property selections.', 'wpsso' ) . ' '; | |
| 175 | + echo __( 'Content Creators are administrators, editors, authors, and contributors.', 'wpsso' ); | |
| 176 | + echo '</p>' . "\n"; | |
| 177 | + | |
| 178 | + if ( $this->p->util->cache->count_ignored_urls() > 0 ) { | |
| 179 | + | |
| 180 | + $ignored_urls = $this->p->util->cache->get_ignored_urls(); | |
| 181 | + $count_ignored_urls = count( $ignored_urls ); | |
| 182 | + | |
| 183 | + echo '<h4>' . sprintf( __( '%s Failed URL Connections:', 'wpsso' ), | |
| 184 | + number_format_i18n( $count_ignored_urls ) ) . '</h4>'; | |
| 185 | + | |
| 186 | + echo '<p class="status-msg smaller left">'; | |
| 187 | + | |
| 188 | + foreach ( $ignored_urls as $url => $ts ) { echo '<a href="' . $url . '">' . $url . '</a></br>'; } | |
| 189 | + | |
| 190 | + echo '</p>' . "\n"; | |
| 191 | + } | |
| 192 | + | |
| 193 | + echo '</div><!-- #tools-content -->' . "\n"; | |
| 194 | + } | |
| 195 | + } | |
| 196 | +} | |