Print

Actions and Filters

Developers can tweak WP Staging using its available actions and filters. This article documents the current hooks and shows example usage to customize the cloning and pushing process to your needs.

If it’s not additionally mentioned you need to add these sample code snippets into the functions.php of your active theme.

Red colored numbers or strings can be changed to your custom use case.

Cloning: Exclude Rows From Search & Replace in wp_options

function wpstg_clone_searchreplace_excl_rows($default){
$rows = array('siteurl', 'home'); 
return array_merge($default, $rows);
}
add_filter('wpstg_clone_searchreplace_excl_rows','wpstg_clone_searchreplace_excl_rows');

Cloning: Exclude Strings From Search & Replace

function wpstg_clone_searchreplace_excl(){
return array('blog.localhost.com','blog1.localhost.com');
}
add_filter('wpstg_clone_searchreplace_excl','wpstg_clone_searchreplace_excl');

Cloning: Change Search & Replace Parameters

function wpstg_cloning_custom_params($args){
      // Default values - Can be changed
         $args['search_for'] = array_merge(
         $args['search_for'],
         array('SEARCHSTRING', 'SEARCHSTRING')
         );
         $args['replace_with'] = array_merge(
         $args['replace_with'],
         array('REPLACESTRING','REPLACESTRING2')
       );
      $args['replace_guids'] = 'off'; 
      $args['dry_run'] = 'off'; 
      $args['case_insensitive'] = false;
      $args['replace_guids'] = 'off';
      $args['replace_mails'] = 'off';
      $args['skip_transients'] = 'on';
      return $args;
}
add_filter('wpstg_clone_searchreplace_params', 'wpstg_cloning_custom_params');

Cloning: Exclude Folders

function wpstg_exclude_folders_custom($args){
$folders = array('wordpress-seo', 'custom-folder');
     return array_merge($args, $folders);
}
add_filter('wpstg_clone_excl_folders', 'wpstg_exclude_folders_custom');

Cloning Multisite: Exclude Folders

**
* Excluded folders relative to the wp-content folder
*/
function wpstg_exclude_folders_custom($args){
$folders = array('plugins/wordpress-seo', 'themes/custom-folder');
     return array_merge($args, $folders);
}
add_filter('wpstg_clone_mu_excl_folders', 'wpstg_exclude_folders_custom');

Cloning: Do not Modify Table Prefix from option_name in wp_options

function wpstg_excl_option_name_custom($args){
$cols = array('wp_mail_smtp', 'wp_mail_smtp_version');
     return array_merge($args, $cols);
}
add_filter('wpstg_data_excl_rows', 'wpstg_excl_option_name_custom');

Pushing: Change Search & Replace Parameters

function wpstg_push_custom_params($args){
      // Default values - Can be changed
         $args['search_for'] = array_merge(
         $args['search_for'],
         array('SEARCHSTRING', 'SEARCHSTRING2')
         );
         $args['replace_with'] = array_merge(
         $args['replace_with'],
         array('REPLACESTRING','REPLACESTRING2')
       );
      $args['replace_guids'] = 'off'; 
      $args['dry_run'] = 'off'; 
      $args['case_insensitive'] = false;
      $args['replace_guids'] = 'off';
      $args['replace_mails'] = 'off';
      $args['skip_transients'] = 'on';
      return $args;
}
add_filter('wpstg_push_searchreplace_params', 'wpstg_push_custom_params');

Pushing: Exclude Tables From Being Pushed

function wpstg_push_excluded_tables($tables){
$customTables = array('_options', '_posts'); 
return array_merge($tables, $customTables);
}
add_filter('wpstg_push_excluded_tables','wpstg_push_excluded_tables');

This excludes the tables wp_posts and wp_options from being pushed to the live site.

Pushing: Exclude Folders From Being Pushed

function wpstg_push_directories_excl($default){
$dirs = array('custom-folder', 'custom-folder2'); 
return array_merge($default, $dirs);
}
add_filter('wpstg_push_excl_folders_custom','wpstg_push_directories_excl');

Pushing: Exclude Options From wp_options Being Pushed

The example below preserves the value ‘siteurl’ .
Any number of additional options may be added.

function wpstg_push_options_excl($options){
$options[] = 'siteurl'
return $options;
}
add_filter('wpstg_preserved_options','wpstg_push_options_excl');