wpseo_kill_blocking_files

Function used to delete blocking files, dies on exit.

Description

wpseo_kill_blocking_files(); 

Usage

  1. if ( !function_exists( 'wpseo_kill_blocking_files' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yoast-seo/admin/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wpseo_kill_blocking_files(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/admin/ajax.php  
  1. function wpseo_kill_blocking_files() { 
  2. if ( ! current_user_can( 'manage_options' ) ) { 
  3. die( '-1' ); 
  4.  
  5. check_ajax_referer( 'wpseo-blocking-files' ); 
  6.  
  7. $message = 'success'; 
  8. $errors = array(); 
  9.  
  10. // Todo: Use WP_Filesystem, but not so easy to use in AJAX with credentials form still internal. 
  11. $options = get_option( 'wpseo' ); 
  12. if ( is_array( $options['blocking_files'] ) && $options['blocking_files'] !== array() ) { 
  13. foreach ( $options['blocking_files'] as $file ) { 
  14. if ( is_file( $file ) ) { 
  15. if ( ! @unlink( $file ) ) { 
  16. $errors[] = sprintf( 
  17. /** translators: %s expands to the file path and name. */ 
  18. __( 'The file %s could not be removed. Please remove it via FTP.', 'wordpress-seo' ),  
  19. '<code>' . $file . '</code>' 
  20. ); 
  21.  
  22. if ( is_dir( $file ) ) { 
  23. if ( ! @ rmdir( $file ) ) { 
  24. $errors[] = sprintf( 
  25. /** translators: %s expands to the directory path and name. */ 
  26. __( 'The directory %s could not be removed. Please remove it via FTP.', 'wordpress-seo' ),  
  27. '<code>' . $file . '</code>' 
  28. ); 
  29.  
  30. if ( $errors ) { 
  31. $message = implode( '<br />', $errors ); 
  32. wp_send_json_error( array( 'message' => $message ) ); 
  33. else { 
  34. $message = __( 'Files successfully removed.', 'wordpress-seo' ); 
  35. wp_send_json_success( array( 'message' => $message ) );