{"id":1200,"date":"2019-05-19T14:56:52","date_gmt":"2019-05-19T17:56:52","guid":{"rendered":"https:\/\/felipeelia.com.br\/?p=1200"},"modified":"2019-05-19T15:20:34","modified_gmt":"2019-05-19T18:20:34","slug":"wordpress-recovery-mode-functions-filters-and-settings","status":"publish","type":"post","link":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/","title":{"rendered":"WordPress Recovery Mode: Functions, Filters, and Settings"},"content":{"rendered":"\n

While studying for my most recent video about the new resources for developers in WordPress 5.2 (in Brazilian Portuguese)<\/a>, I had to write a code to store the link sent via email by the new WordPress Recovery Mode<\/a>.<\/p>\n\n\n\n

Thanks to the new Fatal Error Handler resource, when your theme or a plugin throws an error, WordPress sends an email to the site administrator. This email contains an access link to the brand new Recovery Mode, but one of the URL parameters is encrypted before being stored in the database, i.e., this information is only available in the email. If you don’t receive the email you won’t be able to access the Recovery Mode.<\/p>\n\n\n\n

On my local tests, even with an SMTP plugin set, the email wasn’t delivered. So, I’ve created the plugin below, saved him as a must use plugin<\/em> \u2014 a plugin that can’t be deactivated. To create a plugin like that you have to put the PHP file in the mu-plugins<\/em> folder, inside wp-content<\/em>. It’ll be at the same level of plugins<\/em> and themes<\/em> directories and, if it doesn’t exist yet, you’ll have to create it.<\/p>\n\n\n\n

<?php\n\/*\n * Plugin name: Store Recovery Keys\n *\/\n\nadd_action(\n    'generate_recovery_mode_key',\n    function( $token, $key ) {\n        require_once( ABSPATH . 'wp-admin\/includes\/file.php' );\n        global $wp_filesystem;\n\n        WP_Filesystem();\n\n        $upload_dir = wp_upload_dir();\n\n        $php = '<?php \/\/ ' . add_query_arg(\n\t\t\tarray(\n\t\t\t\t'action'   => 'enter_recovery_mode',\n\t\t\t\t'rm_token' => $token,\n\t\t\t\t'rm_key'   => $key,\n\t\t\t),\n\t\t\twp_login_url()\n\t\t) . ' ?>';\n\n        $wp_filesystem->put_contents( trailingslashit( $upload_dir['basedir'] ) . 'recovery-links.php', $php, 0644 );\n    },\n    10,\n    2\n);<\/code><\/pre>\n\n\n\n

Worth mentioning the mu-plugins<\/em> work in a bit different way from normal plugins: the PHP files are kept in the directory root. Must use plugins<\/em> inside subfolders won’t be recognized.<\/strong> That said, I’ve created a file named as store-recovery-keys.php<\/em>, put the content above and saved. After that, the access link is saved in the recovery-links.php<\/em> file, inside the wp-content\/uploads<\/em> folder.<\/p>\n\n\n\n

How to change the WordPress Recovery Mode email address<\/h2>\n\n\n\n

WordPress 5.2 allows you to change the email address which will receive the Recovery Mode link in two different ways:<\/p>\n\n\n\n

The RECOVERY_MODE_EMAIL Constant<\/h3>\n\n\n\n

The first way, the simpler one, is setting the RECOVERY_MODE_EMAIL<\/code> constant inside your wp-config.php. Before the line containing \/* That's all, stop editing! Happy publishing. *\/<\/code>, you can insert something like this:<\/p>\n\n\n\n

define( 'RECOVERY_MODE_EMAIL', 'email@domain.com' );<\/code><\/pre>\n\n\n\n

The recovery_mode_email<\/em> filter<\/h3>\n\n\n\n

It’s also possible to change the Recovery Mode email address through the recovery_mode_email<\/em> filter:<\/p>\n\n\n\n

add_filter(\n    'recovery_mode_email',\n    function( $email_data ) {\n        $email_data['to'] = 'user@example.com';\n        return $email_data;\n    }\n);<\/code><\/pre>\n\n\n\n

How to change the interval between Recovery Mode<\/em> emails<\/h2>\n\n\n\n

By default, WordPress Recovery Mode waits a whole day before sending another email. You can change this interval using the recovery_mode_email_rate_limit<\/em> filter. I suggest you put this code in a separate plugin. If the code is inside your theme’s functions.php<\/em> file and your theme is paused due to an error, the code will be ignored.<\/p>\n\n\n\n

add_filter(\n    'recovery_mode_email_rate_limit',\n    function( $interval ) {\n        return 12 * DAY_IN_SECONDS;\n    }\n);<\/code><\/pre>\n\n\n\n

You can use the time constants provided by WordPress. I’ve already written about them in this post<\/a> (in pt_BR yet).<\/p>\n\n\n\n

Other functions and setting available<\/h2>\n\n\n\n

The new resource brings a lot of options and useful functions. I’ve spoken about them in the video but I’ll list them here as well. Some SEO won’t hurt, right? \ud83d\ude42<\/p>\n\n\n\n

wp_is_recovery_mode()<\/h3>\n\n\n\n

With the wp_is_recovery_mode()<\/a> function it’s possible to test if the Recovery Mode is running or not. It can be useful to show a message or perhaps make your plugin behave differently during a Recovery Mode session.<\/p>\n\n\n\n

WP_RECOVERY_MODE_SESSION_ID<\/h3>\n\n\n\n

Having this constant set in your wp-config.php<\/em> will force the Recovery Mode. In other words, if it’s not wrapped by a test, every user will always be in the Recovery Mode. Use carefully.<\/p>\n\n\n\n

php-error.php<\/em> and fatal-error-handler.php<\/em> drop-ins<\/h3>\n\n\n\n

Drop-ins are a type of WordPress extension with predefined names that are kept in the wp-content<\/em> folder. Probably, advanced-cache.php<\/em> is the most famous one.<\/p>\n\n\n

With the new drop-ins, you can change the error message displayed (php-error.php<\/em>) or change the way Wordpress will handle errors (fatal-error-handler.php<\/em>). To use the latter you have to extend the WP_Fatal_Error_Handler<\/code> class and return an instance of your class at the end of the file.<\/p>\n\n\n

Remember drop-ins<\/em> that change something displayed in the screen, like php-error.php<\/em> and db-error.php<\/em>, aren’t connected to the theme. WordPress possibly didn’t get to the point of including your theme during the execution. Have that in mind while defining screen elements, i.e., don’t count on anything of your theme.<\/p>\n\n\n\n

How to completely deactivate WordPress Recovery Mode<\/h3>\n\n\n\n

If you want to disable this resource completely, you can use the WP_DISABLE_FATAL_ERROR_HANDLER<\/code> constant. You have to set it in your wp-config.php<\/em>:<\/p>\n\n\n\n

define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );<\/code><\/pre>\n\n\n\n

It’s useful for hosting companies, for example, who handle errors in a custom different way.<\/p>\n\n\n\n

Check if Recovery Mode is available<\/h3>\n\n\n\n

It’s possible to check if the WordPress Recovery Mode is available with the wp_is_fatal_error_handler_enabled()<\/a> function. In other words, this function is useful to check if Recovery Mode wasn’t deactivated through the WP_DISABLE_FATAL_ERROR_HANDLER<\/code> constant. It is very different from wp_is_recovery_mode()<\/code>, that’s good for checking if the Recovery Mode is being executed in that exact moment.<\/p>\n\n\n\n


\n\n\n\n

If you still need help with something related to WordPress, give a look at my Codeable Profile<\/a> and click on the Hire button<\/a>!<\/p>\n\n\n\n

Do you want to help me? Share this content in your social networks! \ud83d\ude42 Also, if you noticed something wrong, feel free to contact me<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"

Read more about the new functions, filters, and settings for the WordPress Recovery Mode included in WP 5.2.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[91],"tags":[],"yoast_head":"\nWordPress Recovery Mode: Functions, Filters, and Settings | Felipe Elia<\/title>\n<meta name=\"description\" content=\"Read more about the new functions, filters, and settings for the WordPress Recovery Mode included in WP 5.2.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress Recovery Mode: Functions, Filters, and Settings | Felipe Elia\" \/>\n<meta property=\"og:description\" content=\"Read more about the new functions, filters, and settings for the WordPress Recovery Mode included in WP 5.2.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/\" \/>\n<meta property=\"og:site_name\" content=\"Felipe Elia\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/felipe.elia\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/felipe.elia\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-19T17:56:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-19T18:20:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/felipeelia.dev\/wp-content\/uploads\/2017\/09\/query-posts.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Felipe Elia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/felipe_elia\" \/>\n<meta name=\"twitter:site\" content=\"@felipe_elia\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Felipe Elia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/\"},\"author\":{\"name\":\"Felipe Elia\",\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292\"},\"headline\":\"WordPress Recovery Mode: Functions, Filters, and Settings\",\"datePublished\":\"2019-05-19T17:56:52+00:00\",\"dateModified\":\"2019-05-19T18:20:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/\"},\"wordCount\":824,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292\"},\"articleSection\":[\"WordPress\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/\",\"url\":\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/\",\"name\":\"WordPress Recovery Mode: Functions, Filters, and Settings | Felipe Elia\",\"isPartOf\":{\"@id\":\"https:\/\/felipeelia.com.br\/#website\"},\"datePublished\":\"2019-05-19T17:56:52+00:00\",\"dateModified\":\"2019-05-19T18:20:34+00:00\",\"description\":\"Read more about the new functions, filters, and settings for the WordPress Recovery Mode included in WP 5.2.\",\"breadcrumb\":{\"@id\":\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"In\u00edcio\",\"item\":\"https:\/\/felipeelia.dev\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress Recovery Mode: Functions, Filters, and Settings\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/felipeelia.com.br\/#website\",\"url\":\"https:\/\/felipeelia.com.br\/\",\"name\":\"Felipe Elia\",\"description\":\"Programa\u00e7\u00e3o com WordPress de um jeito f\u00e1cil, do b\u00e1sico ao avan\u00e7ado\",\"publisher\":{\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/felipeelia.com.br\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-BR\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292\",\"name\":\"Felipe Elia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/felipeelia.dev\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg\",\"contentUrl\":\"https:\/\/felipeelia.dev\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg\",\"width\":400,\"height\":400,\"caption\":\"Felipe Elia\"},\"logo\":{\"@id\":\"https:\/\/felipeelia.com.br\/#\/schema\/person\/image\/\"},\"description\":\"Associate Director of Platform Engineering na 10up, WordPress Core Contributor, Global Polyglots Mentor na comunidade internacional do WordPress e Locale Manager na comunidade WordPress Brasil.\",\"sameAs\":[\"https:\/\/www.facebook.com\/felipe.elia\",\"https:\/\/www.instagram.com\/felipe.elia\/\",\"https:\/\/www.linkedin.com\/in\/felipeelia\/\",\"https:\/\/twitter.com\/https:\/\/twitter.com\/felipe_elia\",\"https:\/\/www.youtube.com\/channel\/UCD_26rOE3ClALcZreTkyIoQ\"],\"url\":\"https:\/\/felipeelia.com.br\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress Recovery Mode: Functions, Filters, and Settings | Felipe Elia","description":"Read more about the new functions, filters, and settings for the WordPress Recovery Mode included in WP 5.2.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/","og_locale":"pt_BR","og_type":"article","og_title":"WordPress Recovery Mode: Functions, Filters, and Settings | Felipe Elia","og_description":"Read more about the new functions, filters, and settings for the WordPress Recovery Mode included in WP 5.2.","og_url":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/","og_site_name":"Felipe Elia","article_publisher":"https:\/\/www.facebook.com\/felipe.elia","article_author":"https:\/\/www.facebook.com\/felipe.elia","article_published_time":"2019-05-19T17:56:52+00:00","article_modified_time":"2019-05-19T18:20:34+00:00","og_image":[{"width":"1200","height":"630","url":"https:\/\/felipeelia.dev\/wp-content\/uploads\/2017\/09\/query-posts.jpg","type":"image\/jpeg"}],"author":"Felipe Elia","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/felipe_elia","twitter_site":"@felipe_elia","twitter_misc":{"Escrito por":"Felipe Elia","Est. tempo de leitura":"5 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/#article","isPartOf":{"@id":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/"},"author":{"name":"Felipe Elia","@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292"},"headline":"WordPress Recovery Mode: Functions, Filters, and Settings","datePublished":"2019-05-19T17:56:52+00:00","dateModified":"2019-05-19T18:20:34+00:00","mainEntityOfPage":{"@id":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/"},"wordCount":824,"commentCount":0,"publisher":{"@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292"},"articleSection":["WordPress"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/","url":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/","name":"WordPress Recovery Mode: Functions, Filters, and Settings | Felipe Elia","isPartOf":{"@id":"https:\/\/felipeelia.com.br\/#website"},"datePublished":"2019-05-19T17:56:52+00:00","dateModified":"2019-05-19T18:20:34+00:00","description":"Read more about the new functions, filters, and settings for the WordPress Recovery Mode included in WP 5.2.","breadcrumb":{"@id":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/felipeelia.dev\/wordpress-recovery-mode-functions-filters-and-settings\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"In\u00edcio","item":"https:\/\/felipeelia.dev\/"},{"@type":"ListItem","position":2,"name":"WordPress Recovery Mode: Functions, Filters, and Settings"}]},{"@type":"WebSite","@id":"https:\/\/felipeelia.com.br\/#website","url":"https:\/\/felipeelia.com.br\/","name":"Felipe Elia","description":"Programa\u00e7\u00e3o com WordPress de um jeito f\u00e1cil, do b\u00e1sico ao avan\u00e7ado","publisher":{"@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/felipeelia.com.br\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-BR"},{"@type":["Person","Organization"],"@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/927a99b6e1cde7fcf9f4f79a1638b292","name":"Felipe Elia","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/image\/","url":"https:\/\/felipeelia.dev\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg","contentUrl":"https:\/\/felipeelia.dev\/wp-content\/uploads\/2023\/06\/avatar-400x400-1.jpg","width":400,"height":400,"caption":"Felipe Elia"},"logo":{"@id":"https:\/\/felipeelia.com.br\/#\/schema\/person\/image\/"},"description":"Associate Director of Platform Engineering na 10up, WordPress Core Contributor, Global Polyglots Mentor na comunidade internacional do WordPress e Locale Manager na comunidade WordPress Brasil.","sameAs":["https:\/\/www.facebook.com\/felipe.elia","https:\/\/www.instagram.com\/felipe.elia\/","https:\/\/www.linkedin.com\/in\/felipeelia\/","https:\/\/twitter.com\/https:\/\/twitter.com\/felipe_elia","https:\/\/www.youtube.com\/channel\/UCD_26rOE3ClALcZreTkyIoQ"],"url":"https:\/\/felipeelia.com.br\/author\/admin\/"}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"ocean-thumb-m":false,"ocean-thumb-ml":false,"ocean-thumb-l":false,"yarpp-thumbnail":false},"uagb_author_info":{"display_name":"Felipe Elia","author_link":"https:\/\/felipeelia.com.br\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Read more about the new functions, filters, and settings for the WordPress Recovery Mode included in WP 5.2.","_links":{"self":[{"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/posts\/1200"}],"collection":[{"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/comments?post=1200"}],"version-history":[{"count":0,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/posts\/1200\/revisions"}],"wp:attachment":[{"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/media?parent=1200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/categories?post=1200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/felipeelia.dev\/wp-json\/wp\/v2\/tags?post=1200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}