Cleaning a filename after image sideloading a url that contains `%20`
rawurldecode fixes the issue. $src = media_sideload_image(rawurldecode($url), $post_id, $desc, $return);
rawurldecode fixes the issue. $src = media_sideload_image(rawurldecode($url), $post_id, $desc, $return);
You can read data on your server with file_get_contents(). If you want to make sure the file exists and is readable then use is_readable(). You don’t really need to use trailingslashit() in this case because you’re constructing the URI yourself. // path to file under current theme $json_file = get_template_directory() . ‘/inc/includes/acf-fonticonpicker/icons/selection.json’; // make sure … Read more
There is no need to use the WP filesystem API if you are trying to access directories to which the web server has full access. It is needed mainly only when you want to write to directories which have limited access like the plugin directory. From that point of view the two snippets are the … Read more
It is definitely bad practice to try to move themes (or uploads or plugins) outside of the wp-content folder. WP’s structure ensures that WP can find all the necessary resources. Anytime you move things outside of its structure, odd quirks and broken bits tend to appear. So, stick with /wp-content/themes/your-theme-slug/ and make things more dynamic. … Read more
Woocommerce use locate_template for checking if file exists in theme or not
Preface It would be best to see what kind of caching options are available through your host. If you can use an object cache, CDN, or anything like that, you could decrease the load on your server. If your database and webserver are the same host, then storing this in the database won’t necessarily mean … Read more
WordPress includes many functions for determining paths and URLs to files or directories within plugins, themes, and WordPress itself. $plugin_dir = plugin_dir_path( __DIR__ ); // wp-content/plugins/ require_once($plugin_dir.’WPNonce/WPNonce.php’); While using plugin_dir_path(), keep in mind that the “plugin” part of the name is misleading – it can be used for any file, and will not return the … Read more
You could accomplish this by setting up a redirect. If you’re using an Apache server, for your example, you would add this to .htaccess above the WordPress block: RewriteEngine On RewriteRule somepost.php ^/somepost/ It’s much more common, and recommended, to create a PHP file and a Page (or other post type) within wp-admin). This will … Read more
First of all, search this site. This questions has been answered many times in the past: https://wordpress.stackexchange.com/search?q=clean+wp_head and https://wordpress.stackexchange.com/search?q=security+obscurity Secondly, there is a difference in what WP loads and what a theme and a plugin will load. Look in the theme functions file to see what the theme loads, i.e. javascripts and CSS. Look in … Read more
By default, WordPress will automatically generate a few different sizes of images. You can adjust the sizes here: Dashboard -> Settings -> Media -> Image Sizes. If you want to prevent certain image sizes from generating upon your uploaded images, you could use the filter intermediate_image_sizes to remove the generation of certain image sizes. Example … Read more