• Hello,

    In order to optimize db, I added this line to my functions.php file:

    remove_filter( ‘wp_read_image_metadata’ );

    and got a critical error:

    [17-Jun-2021 16:23:40 UTC] PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function remove_filter(), 1 passed in /home/rabbitr1/public_html/wp-content/themes/hello-elementor/functions.php on line 277 and at least 2 expected in /home/rabbitr1/public_html/wp-includes/plugin.php:282
    Stack trace:
    #0 /home/rabbitr1/public_html/wp-content/themes/hello-elementor/functions.php(277): remove_filter('wp_read_image_m...')
    #1 /home/rabbitr1/public_html/wp-settings.php(528): include('/home/rabbitr1/...')
    #2 /home/rabbitr1/public_html/wp-config.php(116): require_once('/home/rabbitr1/...')
    #3 /home/rabbitr1/public_html/wp-load.php(37): require_once('/home/rabbitr1/...')
    #4 /home/rabbitr1/public_html/wp-blog-header.php(13): require_once('/home/rabbitr1/...')
    #5 /home/rabbitr1/public_html/index.php(17): require('/home/rabbitr1/...')
    #6 {main}
      thrown in /home/rabbitr1/public_html/wp-includes/plugin.php on line 282

    That line in plugin.php says:

    *
     * This function removes a function attached to a specified filter hook. This
     * method can be used to remove default functions attached to a specific filter
     * hook and possibly replace them with a substitute.
     *
     * To remove a hook, the $function_to_remove and $priority arguments must match
     * when the hook was added. This goes for both filters and actions. No warning
     * will be given on removal failure.
     *
     * @since 1.2.0
     *
     * @global WP_Hook[] $wp_filter Stores all of the filters and actions.
     *
     * @param string   $tag                The filter hook to which the function to be removed is hooked.
     * @param callable $function_to_remove The name of the function which should be removed.
     * @param int      $priority           Optional. The priority of the function. Default 10.
     * @return bool    Whether the function existed before it was removed.
     */
    function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
    	global $wp_filter;
    
    	$r = false;
    	if ( isset( $wp_filter[ $tag ] ) ) {
    		$r = $wp_filter[ $tag ]->remove_filter( $tag, $function_to_remove, $priority );
    		if ( ! $wp_filter[ $tag ]->callbacks ) {
    			unset( $wp_filter[ $tag ] );
    		}
    	}
    
    	return $r;
    }

    How could I prevent from storing exif and iptc data in db? And is there a way to remove the already stored?

    Regards,

    Julia

    • This topic was modified 3 years, 5 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 2 replies - 1 through 2 (of 2 total)
  • Topher

    (@topher1kenobe)

    Instead of trying to remove the filter, try making it return nothing.

    add_filter( 'wp_read_image_metadata', '__return_false' );

    To remove the stuff already in the database you’d need to find which field it’s stored in. If that’s the only thing in there, you can delete it. If it’s embedded in some serialized data you’ll need to write a script to do it.

    Thread Starter julia77

    (@julia77)

    Hello Topher,

    Thanks for the filter. It′s working.

    Images metadata are stored in wp_postmeta meta_key=’_wp_attachment_metadata’ and serialized.

    I′ve found this query to unserialize it but I don′t know if it′s safe to run it.

    `# replace ‘file’ with the array key you want to extract
    SELECT
    SUBSTRING_INDEX(
    SUBSTRING_INDEX(
    SUBSTRING(pm.meta_value, ( INSTR( pm.meta_value, CONCAT( ‘file’, ‘”;’ ) ) + CHAR_LENGTH( ‘file’) + 1 ) ),
    ‘”‘, 2 ),
    ‘”‘, -1 ) as attachment_file
    FROM wp_posts p
    INNER JOIN wp_postmeta pm
    ON p.ID = pm.post_id
    AND pm.meta_key = ‘_wp_attachment_metadata’
    WHERE post_type = ‘attachment’`

    Do you have a safe way to unserialize and delete it?

    Regards,

    Julia

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Image metadata filter’ is closed to new replies.