How do you find a file in the media library using the file URL?

Based on my research, you would need to run a query on directly on the database using WPDB. So you would do something like this: Add this in your functions.php file: // retrieves the attachment ID from the file URL function get_image_id($image_url) { global $wpdb; $the_attachment = $wpdb->get_col($wpdb->prepare(“SELECT ID FROM $wpdb->posts WHERE guid=’%s’;”, $image_url )); … Read more

unzip_file not working with the remote file

As @Buttered_Toast and @Sébastien Serre mentioned I first need to save file to a local directory before unzipping. So here is my final code: $source=”http://downloads.wordpress.org/theme/ona-creative.1.0.0.zip”; $file = get_theme_root() . “https://wordpress.stackexchange.com/” . $slug . ‘.zip’; file_put_contents( $file, file_get_contents( $source )); $unzipfile = unzip_file( $file, get_theme_root() );

WP_Filesystem in custom customize control

To cache something you can use the Transients API (thanks @Otto), get_transient() to see if it exists already exists, if not then fetch the data and store it in a transient with set_transient(). if (get_transient(‘mytheme_webfonts’)) { $content = get_transient(‘mytheme_webfonts’); } else{ $googleApi = ‘https://www.googleapis.com/webfonts/v1/webfonts?sort=alpha&key={API_KEY}’; $fontContent = wp_remote_get( $googleApi, array(‘sslverify’ => false) ); $content = json_decode($fontContent[‘body’]); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)