├── README.md ├── class-command.php ├── composer.json └── revslider-search-replace.php /README.md: -------------------------------------------------------------------------------- 1 | # Revolution Slider Search Replace CLI 2 | WP CLI Command to search replace the website URLs in the Revolution sliders 3 | 4 | ### Installation 5 | 6 | - Download the plugin [zip](https://github.com/Nikschavan/revslider-search-replace/archive/master.zip) file from Github. 7 | - Upload the zip file to WordPress dashboard in Plugins -> Add new and activate the plugin. 8 | 9 | ### Usage 10 | 11 | ##### OPTIONS 12 | 13 | - `` 14 | ID of the slider, also takes "all" as option where it will search accross all the sliders 15 | 16 | - `` 17 | Source URL 18 | 19 | - `` 20 | destination URL 21 | 22 | - [`--network`] 23 | Search Replace the strings in Revolution sliders throughout all the sites in multisite network 24 | 25 | ##### EXAMPLES 26 | 27 | 1. `wp rsr 2 ` 28 | - This will search replace the strings in the slider with is "2" 29 | 2. `wp rsr all ` 30 | - This will search replace the strings on all the sliders on the site 31 | 3. `wp rsr all --network` 32 | - This command will will search replace the strings on all sliders accross all the sites in multisite network. 33 | -------------------------------------------------------------------------------- /class-command.php: -------------------------------------------------------------------------------- 1 | 15 | * ID of the slider, also takes "all" as option where it will search accross all the sliders 16 | * 17 | * 18 | * Source URL 19 | * 20 | * 21 | * destination URL 22 | * 23 | * [--network] 24 | * Search Replace the strings in Revolution sliders throughout all the sites in multisite network 25 | * 26 | * ## EXAMPLES 27 | * 28 | * 1. wp rsr 2 29 | * - This will search replace the strings in the slider with is "2" 30 | * 2. wp rsr all 31 | * - This will search replace the strings on all the sliders on the site 32 | * 3. wp rsr all --network 33 | * - This command will will search replace the strings on all sliders accross all the sites in multisite network. 34 | * 35 | */ 36 | 37 | public $slider; 38 | 39 | public function __invoke( $args, $assoc_args ) { 40 | 41 | $network = false; 42 | 43 | if ( ! class_exists( 'RevSliderSlider' ) ) { 44 | WP_CLI::error( "Revolution slider is not active" ); 45 | 46 | return false; 47 | } 48 | 49 | $default = array( 50 | 0 => '', 51 | 1 => '', 52 | 2 => '', 53 | ); 54 | 55 | 56 | if ( ! isset( $args[0] ) ) { 57 | $args[0] = $default[0]; 58 | } 59 | 60 | if ( ! isset( $args[1] ) ) { 61 | $args[1] = $default[1]; 62 | } 63 | 64 | if ( ! isset( $args[2] ) ) { 65 | $args[2] = $default[2]; 66 | } 67 | 68 | $id = $args[0]; 69 | $source = $args[1]; 70 | $destination = $args[2]; 71 | 72 | if ( isset( $assoc_args['network'] ) && $assoc_args['network'] == true && is_multisite() ) { 73 | $network = true; 74 | } 75 | 76 | if ( $id == "" ) { 77 | WP_CLI::error( "Plese enter ID of the slider which you want to search-replace into or 'all' to select all the sliders" ); 78 | 79 | return false; 80 | } 81 | 82 | if ( $source == "" ) { 83 | WP_CLI::error( "Please enter source URL" ); 84 | 85 | return false; 86 | } 87 | 88 | if ( $destination == "" ) { 89 | WP_CLI::error( "Please enter destination URL" ); 90 | 91 | return false; 92 | } 93 | 94 | $data = array( 95 | 'url_from' => $source, 96 | 'url_to' => $destination 97 | ); 98 | 99 | $this->slider = new RevSliderSlider(); 100 | 101 | if ( $network == true ) { 102 | 103 | if ( function_exists( 'get_sites' ) ) { 104 | $blogs = get_sites(); 105 | } else { 106 | $blogs = wp_get_sites(); 107 | } 108 | 109 | foreach ( $blogs as $keys => $blog ) { 110 | 111 | // Cast $blog as an array instead of WP_Site object 112 | if ( is_object( $blog ) ) { 113 | $blog = (array) $blog; 114 | } 115 | 116 | $blog_id = $blog['blog_id']; 117 | switch_to_blog( $blog_id ); 118 | WP_CLI::success( "Switched to the blog " . get_option( 'home' ) ); 119 | $this->set_id_and_replace( $id, $data ); 120 | restore_current_blog(); 121 | } 122 | } else { 123 | $this->set_id_and_replace( $id, $data ); 124 | } 125 | 126 | } 127 | 128 | public function set_id_and_replace( $id, $data ) { 129 | 130 | if ( $id == 'all' ) { 131 | $arrSliders = $this->slider->getArrSliders(); 132 | foreach ( $arrSliders as $key => $value ) { 133 | $data["sliderid"] = $value->getID(); 134 | $this->replace_revslider_urls( $data ); 135 | } 136 | } else { 137 | $data["sliderid"] = $id; 138 | $this->replace_revslider_urls( $data ); 139 | } 140 | 141 | } 142 | 143 | public function replace_revslider_urls( $data ) { 144 | 145 | $this->slider->replaceImageUrlsFromData( $data ); 146 | WP_CLI::success( "Search Replace complete for slider with id : " . $data['sliderid'] ); 147 | 148 | } 149 | 150 | } 151 | 152 | WP_CLI::add_command( 'rsr', 'Revslider_Search_Replace' ); 153 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nikschavan/revslider-search-replace", 3 | "description": "WP CLI Command to Search Replace Strings in revolution slider", 4 | "type": "wp-cli-package", 5 | "homepage": "https://github.com/Nikschavan/revslider-search-replace", 6 | "license": "MIT", 7 | "require": { 8 | "php": ">=5.4" 9 | }, 10 | "autoload": { 11 | "files": [ "class-command.php" ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /revslider-search-replace.php: -------------------------------------------------------------------------------- 1 |