better_search_replace = $better_search_replace; $this->version = $version; } /** * Register any CSS and JS used by the plugin. * @since 1.0.0 * @access public * @param string $hook Used for determining which page(s) to load our scripts. */ public function enqueue_scripts( $hook ) { if ( 'tools_page_better-search-replace' === $hook ) { wp_enqueue_style( 'better-search-replace', BSR_URL . 'assets/css/better-search-replace.css', array(), $this->version, 'all' ); wp_enqueue_style( 'jquery-style', BSR_URL . 'assets/css/jquery-ui.min.css', array(), $this->version, 'all' ); wp_enqueue_script( 'jquery-ui-slider' ); wp_enqueue_script( 'better-search-replace', BSR_URL . 'assets/js/better-search-replace.min.js', array( 'jquery' ), $this->version, true ); wp_enqueue_style( 'thickbox' ); wp_enqueue_script( 'thickbox' ); wp_localize_script( 'better-search-replace', 'bsr_object_vars', array( 'page_size' => get_option( 'bsr_page_size' ) ? absint( get_option( 'bsr_page_size' ) ) : 20000, 'endpoint' => BSR_AJAX::get_endpoint(), 'ajax_nonce' => wp_create_nonce( 'bsr_ajax_nonce' ), 'no_search' => __( 'No search string was defined, please enter a URL or string to search for.', 'better-search-replace' ), 'no_tables' => __( 'Please select the tables that you want to update.', 'better-search-replace' ), 'unknown' => __( 'An error occurred processing your request. Try decreasing the "Max Page Size", or contact support.', 'better-search-replace' ), 'processing' => __( 'Processing...', 'better-search-replace' ) ) ); } } /** * Register any menu pages used by the plugin. * @since 1.0.0 * @access public */ public function bsr_menu_pages() { $cap = apply_filters( 'bsr_capability', 'install_plugins' ); add_submenu_page( 'tools.php', __( 'Better Search Replace', 'better-search-replace' ), __( 'Better Search Replace', 'better-search-replace' ), $cap, 'better-search-replace', array( $this, 'bsr_menu_pages_callback' ) ); } /** * The callback for creating a new submenu page under the "Tools" menu. * @access public */ public function bsr_menu_pages_callback() { require_once BSR_PATH . 'templates/bsr-dashboard.php'; } /** * Renders the result or error onto the better-search-replace admin page. * @access public */ public static function render_result() { if ( isset( $_GET['result'] ) && $result = get_transient( 'bsr_results' ) ) { if ( isset( $result['dry_run'] ) && $result['dry_run'] === 'on' ) { $msg = sprintf( __( '

DRY RUN: %d tables were searched, %d cells were found that need to be updated, and %d changes were made.

Click here for more details, or use the form below to run the search/replace.

', 'better-search-replace' ), $result['tables'], $result['change'], $result['updates'], get_admin_url() . 'admin-post.php?action=bsr_view_details&TB_iframe=true&width=800&height=500' ); } else { $msg = sprintf( __( '

During the search/replace, %d tables were searched, with %d cells changed in %d updates.

Click here for more details.

', 'better-search-replace' ), $result['tables'], $result['change'], $result['updates'], get_admin_url() . 'admin-post.php?action=bsr_view_details&TB_iframe=true&width=800&height=500' ); } echo '
' . $msg . '
'; } } /** * Prefills the given value on the search/replace page (dry run, live run, from profile). * @access public * @param string $value The value to check for. * @param string $type The type of the value we're filling. */ public static function prefill_value( $value, $type = 'text' ) { // Grab the correct data to prefill. if ( isset( $_GET['result'] ) && get_transient( 'bsr_results' ) ) { $values = get_transient( 'bsr_results' ); } else { $values = array(); } // Prefill the value. if ( isset( $values[$value] ) ) { if ( 'checkbox' === $type && 'on' === $values[$value] ) { echo 'checked'; } else { echo str_replace( '#BSR_BACKSLASH#', '\\', esc_attr( htmlentities( $values[$value] ) ) ); } } } /** * Loads the tables available to run a search replace, prefilling if already * selected the tables. * @access public */ public static function load_tables() { // Get the tables and their sizes. $tables = BSR_DB::get_tables(); $sizes = BSR_DB::get_sizes(); echo ''; } /** * Loads the result details (via Thickbox). * @access public */ public function load_details() { if ( get_transient( 'bsr_results' ) ) { $results = get_transient( 'bsr_results' ); $min = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min'; $bsr_styles = BSR_URL . 'assets/css/better-search-replace.css?v=' . BSR_VERSION; ?>
$report ) { $time = $report['end'] - $report['start']; if ( $report['change'] !== 0 ) { $report['change'] = '' . $report['change'] . ''; } if ( $report['updates'] !== 0 ) { $report['updates'] = '' . $report['updates'] . ''; } printf( '', $table_name, $report['change'], $report['updates'], round( $time, 3 ), __( 'seconds', 'better-search-replace' ) ); } ?>
%s%s%s%s %s


' . __( 'Upgrade to Pro', 'better-search-replace' ) . '' ) ); } return $links; } }