{"id":3890,"date":"2019-08-17T08:47:34","date_gmt":"2019-08-17T08:47:34","guid":{"rendered":"https:\/\/puvox.software\/blog\/?p=3890"},"modified":"2021-11-14T13:45:48","modified_gmt":"2021-11-14T13:45:48","slug":"include-wordpress-wp-core-without-database","status":"publish","type":"post","link":"https:\/\/puvox.software\/blog\/include-wordpress-wp-core-without-database\/","title":{"rendered":"Include WordPress (WP) Core without database"},"content":{"rendered":"<div class=\"default-content-clss content_3890 type_post \"><div class=\"wpLinkHere\">Remember short-link to MUST-HAVE WP plugins: <a href=\"https:\/\/puvox.software\/wordpress\">puvox.software\/wordpress<\/a>&nbsp; <\/div><div style=\"clear:both;\"><\/div><p><img fetchpriority=\"high\" decoding=\"async\" class=\"size-medium wp-image-3893 aligncenter\" src=\"https:\/\/puvox.software\/blog\/wp-content\/uploads\/sites\/2\/2019\/08\/wordpress-1-1-300x300.png\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/puvox.software\/blog\/wp-content\/uploads\/sites\/2\/2019\/08\/wordpress-1-1-300x300.png 300w, https:\/\/puvox.software\/blog\/wp-content\/uploads\/sites\/2\/2019\/08\/wordpress-1-1-150x150.png 150w, https:\/\/puvox.software\/blog\/wp-content\/uploads\/sites\/2\/2019\/08\/wordpress-1-1.png 684w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<h1 style=\"text-align: center;\">Use WP core functionality without MySQL\/DB<\/h1>\n<p>In very rare case, some people might want to use <a href=\"http:\/\/wordpress.org\">WP<\/a>&#8216;s nice functions in their projects, but without need of any Database. Unfortunately, WP is not meant to be used in that way, however there can be made some hacks.<\/p>\n<h2 style=\"text-align: center;\">Step 1<\/h2>\n<p>Create i.e.\u00a0<code><strong>my_wp_loader.php<\/strong><\/code>\u00a0and insert this code (just\u00a0<strong>change wordpress path<\/strong>):<\/p>\n<div>\n<div>\n<pre>&lt;?php\ndefine( 'WP_PATH_', __DIR__.'\/hidden_wordpress_path\/' );\n\nfunction include_wp_without_db()\n{\n    define( 'SHORTINIT', true );\n    define( 'SHORTINIT_WITHOUT_DB', true );\n    $wp_config_PATH = WP_PATH_ .'\/wp-config.php';\n\n    \/\/ check if needed modification is already done\n    $wp_settings_PATH = WP_PATH_ .'\/wp-settings.php';\n    $addition = ' if (SHORTINIT_WITHOUT_DB) return false;';\n    $target_hint = 'require_wp_db();';\n    $content = file_get_contents($wp_settings_PATH);\n    if (strpos($content, $target_hint.  $addition) === false )\n        file_put_contents($wp_settings_PATH, str_replace($target_hint, $target_hint.$addition, $content));\n\n    \/\/check if wp-config exists\n    if (!file_exists($wp_config_PATH)) \n        copy(WP_PATH_ .'\/wp-config-sample.php', $wp_config_PATH);\n    require_once( $wp_config_PATH );\n}\ninclude_wp_without_db();\n?&gt;<\/pre>\n<\/div>\n<h2 style=\"text-align: center;\">Step 2<\/h2>\n<p>Now, in any your project file, you can call <strong>basic WP functions<\/strong> like this:<\/p>\n<div>\n<div>\n<pre>&lt;?php\nrequire(__DIR__.'\/my_wp_loader.php');\n\necho <strong>sanitize_key<\/strong>('asdg:?\/2\\'fdewrgoff3-rfj');<\/pre>\n<\/div>\n<\/div>\n<p>And you will have sanitized output!<\/p>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<div class=\"default-content-clss excerpt_3890 type_post \"><p>Remember short-link to MUST-HAVE WP plugins: puvox.software\/wordpress&nbsp; Use WP core functionality without MySQL\/DB In very rare case, some people might want to use WP&#8216;s nice functions in their projects, but<a class=\"excerpt-read-more\" href=\"https:\/\/puvox.software\/blog\/include-wordpress-wp-core-without-database\/\">(Continue Reading)<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3893,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[17,13,8],"tags":[],"class_list":["post-3890","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-website","category-wordpress"],"_links":{"self":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts\/3890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/comments?post=3890"}],"version-history":[{"count":0,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts\/3890\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/media\/3893"}],"wp:attachment":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/media?parent=3890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/categories?post=3890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/tags?post=3890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}