{"id":6286622,"date":"2015-07-01T14:31:49","date_gmt":"2015-07-01T14:31:49","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/add-admin-notices-when-using-wordpress-filters\/"},"modified":"2016-08-30T15:02:26","modified_gmt":"2016-08-30T15:02:26","slug":"add-admin-notices-when-using-wordpress-filters","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/add-admin-notices-when-using-wordpress-filters\/","title":{"rendered":"Add admin notices when using WordPress filters"},"content":{"rendered":"<p>I&#8217;m calling my plugin&#8217;s function via a filter (wp_handle_upload_prefilter), so I can&#8217;t just directly write a notice as output, correct? At least, when I tried doing that, it interrupted WordPress and would not continue processing the upload.<\/p>\n<p>I&#8217;m currently trying to nest a function within the main function, which actually works slightly better, but still doesn&#8217;t seem to allow WordPress to continue processing the upload either (it just uploads it, then gets stuck on &#8220;Crunching&#8221;). So how can I write a notice or error to the user?<\/p>\n<p>Here&#8217;s some relevant code I&#8217;m working on.<\/p>\n<pre><code>function aou_upload_file($file) {\n\n    $file_no_ext = preg_replace(&#039;\/\\\\.[^.\\\\s]{3,4}$\/&#039;, &#039;&#039;, $file[&#039;name&#039;]);\n\n    \/\/ Determine if the file can be uploaded\n    if (strpos($file[&#039;type&#039;],&#039;video&#039;) !== false) {\n        $mediatype = &#039;movies&#039;;\n        }\n    elseif (strpos($file[&#039;type&#039;],&#039;audio&#039;) !== false) {\n        $mediatype = &#039;audio&#039;;\n        }\n    else {\n        function aou_not_supported_notice(){\n            echo &#039;&lt;div class=&quot;error&quot;&gt;&lt;p&gt;File type not supported.&lt;\/p&gt;&lt;\/div&gt;&#039;;\n            }\n        add_action(&#039;add_attachment&#039;, &#039;aou_not_supported_notice&#039;);\n        return $file;\n        }\n    }\n\nadd_filter(&#039;wp_handle_upload_prefilter&#039;,&#039;aou_upload_file&#039;);<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-6286622","topic","type-topic","status-closed","hentry","topic-tag-functions"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6286622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6286622\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=6286622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}