<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	     xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:atom="http://www.w3.org/2005/Atom"
	     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>widget &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/widget/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Sat, 12 Jul 2025 08:01:26 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>widget &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[WordPress - Display hook action priority in the dashboard]]></title>
		<link>https://shkspr.mobi/blog/2024/08/wordpress-display-hook-action-priority-in-the-dashboard/</link>
					<comments>https://shkspr.mobi/blog/2024/08/wordpress-display-hook-action-priority-in-the-dashboard/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Sat, 31 Aug 2024 11:34:14 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=52230</guid>

					<description><![CDATA[If your WordPress site has lots of plugins, it&#039;s sometimes difficult to keep track of what is manipulating your content. Ever wondered what priority all your various actions and filters have? This is a widget which will show you which actions are registered to your blog&#039;s hooks, and their priority order.  It looks like this:    Stick this code in your theme&#039;s functions.php or in its own plugin. …]]></description>
										<content:encoded><![CDATA[<p>If your WordPress site has lots of plugins, it's sometimes difficult to keep track of what is manipulating your content. Ever wondered what priority all your various actions and filters have? This is a widget which will show you which actions are registered to your blog's hooks, and their priority order.</p>

<p>It looks like this:</p>

<img src="https://shkspr.mobi/blog/wp-content/uploads/2024/08/priorities-fs8.png" alt="List of actions with various priorities." width="600" height="599" class="aligncenter size-full wp-image-52231">

<p>Stick this code in your theme's <code>functions.php</code> or in its own plugin.</p>

<pre><code class="language-php">function edent_priority_dashboard_widget_contents() {
    global $wp_filter; 
    //  Change this to the hook you're interested in
    $hook_name = "the_content";
    if ( isset( $wp_filter[$hook_name] ) ) {

        //  Display the hook name in the widget
        echo "&lt;h3&gt;{$hook_name}&lt;/h3&gt;";

        //  Start a list
        echo "&lt;ul&gt;";

        //  Loop through the callbacks in priority order
        foreach ( $wp_filter[$hook_name]-&gt;callbacks as $priority =&gt; $callbacks ) {
            echo "&lt;li&gt;Priority: {$priority}&lt;ul&gt;";

            foreach ( $callbacks as $callback ) {
                //  Some callbacks are arrays
                if ( is_array( $callback["function"] ) ) {
                    if (is_object($callback["function"][0])) {
                        $callback_info = get_class($callback["function"][0]) . '::' . $callback["function"][1];
                    } else {
                        $callback_info = $callback["function"][0] . '::' . $callback["function"][1];
                    }
                } else {
                    $callback_info = $callback["function"];
                }
                //  Show the information
                echo "&lt;li&gt;Callback: {$callback_info}&lt;/li&gt;";
            }
            echo "&lt;/ul&gt;&lt;/li&gt;";
        }
        echo '&lt;/ul&gt;';

    } 
    else {
        echo "No filters found for hook: {$hook_name}";
    }

    //  Scrap of CSS to ensure list items display properly on the dashboard
    $priority_css_code = "#edent_dashboard_widget ul { list-style: circle; padding: 1em; }";
    //  Inline the CSS
    echo "&lt;link rel=\"stylesheet\" type=\"text/css\" href=\"data:text/css;base64," . 
        base64_encode($priority_css_code) . "\"&gt;";

}

//  Register the widget with the admin dashboard
function edent_register_dashboard_widget() {
    wp_add_dashboard_widget(
        "edent_dashboard_widget",   //  ID of the widget
        "Priorities",   //  Title of the widget
        "edent_priority_dashboard_widget_contents"  //  Function to run
    );
}
add_action( "wp_dashboard_setup", "edent_register_dashboard_widget" );
</code></pre>

<h2 id="why"><a href="https://shkspr.mobi/blog/2024/08/wordpress-display-hook-action-priority-in-the-dashboard/#why">Why?</a></h2>

<p>WordPress lets you <a href="https://developer.wordpress.org/plugins/hooks/">add actions and filters to hooks</a>.  For example, whenever your blog wants to show some content, a hook of <code>the_content</code> is run.</p>

<p>You can add an action to run a function when that happens. For example, if you want to make all the text in your blog posts uppercase, you could add this to your theme or plugin:</p>

<pre><code class="language-php">function lower_case_everything( $content ) {
   return strtolower( $content );
}
add_filter( 'the_content', 'lower_case_everything', 99 );
</code></pre>

<p>The <code>add_filter</code> says "When the hook called <code>the_content</code> is fired, run the function <code>lower_case_everything</code>, with a priority of 99".  The lower the number, the sooner the function is run.</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=52230&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2024/08/wordpress-display-hook-action-priority-in-the-dashboard/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[HOWTO: Android Audio Widget]]></title>
		<link>https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/</link>
					<comments>https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Tue, 09 Nov 2010 08:04:45 +0000</pubDate>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[NaBloPoMo]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[widget]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=2650</guid>

					<description><![CDATA[I&#039;ve recently released a couple of audio widgets.  Inspired by the Instant Rimshot and Sad Trombone sites, these are &#34;single serving&#34; widget.  For the &#34;Family Fortunes&#34; buzzer widget, you click the icon and you&#039;ll hear the famous &#34;EURGH-ERRRR&#34; noise.  I&#039;m also selling a &#34;Dramatic Sound Effect&#34; Widget - download it by scanning this code.  Go on, it&#039;s a mere 50p!   This is a quick tutorial showing…]]></description>
										<content:encoded><![CDATA[<p>I've recently released a couple of audio widgets.  Inspired by the <a href="http://instantrimshot.com/">Instant Rimshot</a> and <a href="http://www.sadtrombone.com/">Sad Trombone</a> sites, these are "<a href="http://kottke.org/08/02/single-serving-sites">single serving</a>" widget.</p>

<p>For the "Family Fortunes" buzzer widget, you click the icon and you'll hear the famous "EURGH-ERRRR" noise.</p>

<p>I'm also selling a "Dramatic Sound Effect" Widget - download it by scanning this code.  Go on, it's a mere 50p!
<img src="https://shkspr.mobi/blog/wp-content/uploads/2010/11/Dramatic-Widget-QR-Code.png" alt="Dramatic Widget QR Code" title="Dramatic Widget QR Code" width="150" height="150" class="aligncenter size-full wp-image-2857"></p>

<p>This is a quick tutorial showing how to build a sound playing widget in Android.  It assumes you've already set up Eclipse and know how to create your own projects.</p>

<h2 id="the-source-code"><a href="https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/#the-source-code">The Source Code</a></h2>

<p>Here's the main Java source code - with comments.</p>

<pre><code>package mobi.shkspr.android.ButtonWidget;

import mobi.shkspr.android.ButtonWidget.R;

//All the Androidy bits and bobs you need to import.
import android.media.*;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

public class ButtonWidget extends AppWidgetProvider {
    public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        //First up, the icon. I've created a file called h_yellow_x.png and placed it in /res/drawable
                int drawableResourse = R.drawable.h_yellow_x;
                //Set Up the widget
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
                //Set the image which will appear on the screen
        remoteViews.setImageViewResource(R.id.ImageView01, drawableResourse );
        Intent active = new Intent(context, ButtonWidget.class);
        active.setAction(ACTION_WIDGET_RECEIVER);
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
        remoteViews.setOnClickPendingIntent(R.id.ImageView01, actionPendingIntent);
        appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // v1.5 fix that doesn't call onDelete Action
        final String action = intent.getAction();
        if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
            //The widget is being deleted off the desktop
            final int appWidgetId = intent.getExtras().getInt(
                    AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
                this.onDeleted(context, new int[] { appWidgetId });
            }
        } else {
            // check, if our Action was called
            if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {

                //Play the audio file
                                //The audio file is in /res/raw/ and is an OGG file
                MediaPlayer mPlay = MediaPlayer.create(context, R.raw.ff);
                mPlay.start();
            } else {
                // do nothing
            }


            super.onReceive(context, intent);
        }
    }
}

</code></pre>

<p>Also</p>

<h2 id="the-manifest"><a href="https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/#the-manifest">The Manifest</a></h2>

<p>The XML you'll need to get everything configured.</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mobi.shkspr.android.ButtonWidget"
    android:versionCode="1"
    android:versionName="1.0"&gt;

    &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;

        &lt;!-- Broadcast Receiver that will process AppWidget updates --&gt;
        &lt;receiver android:name=".ButtonWidget" android:label="@string/app_name"&gt;
            &lt;intent -filter&gt;
                &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
                &lt;!-- Broadcast Receiver that will also process our self created action --&gt;
                &lt;action android:name="my.package.name.ButtonWidget.ACTION_WIDGET_RECEIVER"/&gt;
            &lt;/intent&gt;
            &lt;meta -data android:name="android.appwidget.provider" android:resource="@xml/widget_def" /&gt;
        &lt;/receiver&gt;

    &lt;/application&gt;

    &lt;uses -sdk android:minSdkVersion="3" /&gt;
&lt;/manifest&gt;
</code></pre>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=2650&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title><![CDATA[Android Tutorial - Clickable Widgets]]></title>
		<link>https://shkspr.mobi/blog/2010/07/android-tutorial-clickable-widgets/</link>
					<comments>https://shkspr.mobi/blog/2010/07/android-tutorial-clickable-widgets/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Mon, 12 Jul 2010 10:09:42 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[widget]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=2149</guid>

					<description><![CDATA[Another quick Android tutorial.  I couldn&#039;t find an easy or correct method of launching a browser when you click on a homescreen widget.  Well, here it is...  public class clickWidget extends AppWidgetProvider { @Override public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds ) { RemoteViews remoteViews =    new RemoteViews( context.getPackageName(),…]]></description>
										<content:encoded><![CDATA[<p>Another quick Android tutorial.  I couldn't find an easy or correct method of launching a browser when you click on a homescreen widget.  Well, here it is...</p>

<pre lang="java">public class clickWidget extends AppWidgetProvider
{
@Override
public void onUpdate( Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds )
{
RemoteViews remoteViews =
   new RemoteViews( context.getPackageName(), R.layout.widget );
remoteViews.setImageViewResource(R.id.ImageView01, drawableResourse);

ComponentName myWidget =
   new ComponentName( context, clickWidget.class );

// Create an Intent to launch Browser
Intent intent =
   new Intent(
      Intent.ACTION_VIEW, Uri.parse("http://example.com")
   );
PendingIntent pendingIntent =
   PendingIntent.getActivity(context, 0, intent, 0);

remoteViews.setOnClickPendingIntent(R.id.ImageView01, pendingIntent);
appWidgetManager.updateAppWidget( myWidget, remoteViews);
}
</pre>

<p>I've used this as the basis of a demo widget - "MI5 Terror Threat Level".  The widget displays the UK's Threat Level on your homescreen.  Clicking on it takes you to the <a href="https://web.archive.org/web/20101014002748/ttps://www.mi5.gov.uk/output/threat-levels.html">MI5 page discussing the threat level</a>.</p>

<p>The threat level is determined by parsing the <a href="https://web.archive.org/web/20101014003201/https://www.mi5.gov.uk/output/threat-level-rss.html">RSS that the security services so helpfully provide</a>.  At the moment, the widget keeps a local copy of the graphics because the <a href="http://www.mi5.gov.uk/UKThreatLevel/UKThreatLevel.xml">RSS feed</a> contains references to "localhost" images.</p>

<p>You can download the widget by scanning in this QR code.
</p><div id="attachment_2155" style="width: 174px" class="wp-caption aligncenter"><img aria-describedby="caption-attachment-2155" src="https://shkspr.mobi/blog/wp-content/uploads/2010/07/mi5.png" alt="MI5 Widget - QR Code" title="MI5 Widget - QR Code" width="164" height="164" class="size-full wp-image-2155"><p id="caption-attachment-2155" class="wp-caption-text">MI5 Widget - QR Code</p></div><p></p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=2149&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2010/07/android-tutorial-clickable-widgets/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
