<?xml version="1.0" encoding="UTF-8"?>
<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>WP Engineer &#187; backend</title>
	<atom:link href="http://wpengineer.com/tag/backend/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Mon, 21 May 2012 22:48:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WP_List_Table &#8211; a step by step guide</title>
		<link>http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/</link>
		<comments>http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/#comments</comments>
		<pubDate>Tue, 27 Mar 2012 08:47:32 +0000</pubDate>
		<dc:creator>Latz</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2426</guid>
		<description><![CDATA[Throughout WordPress the class WP_List_Table is used to display data, e.g. users, plugins, comments, or posts. The class contains almost all necessary methods for displaying, sorting, paginating, and searching data and and what is more obvious than to use it for your own plugins? This article tries to give you a comprehensive walk-through all necessary [...]]]></description>
			<content:encoded><![CDATA[<p>Throughout WordPress the class <code>WP_List_Table</code> is used to display data, e.g. users, plugins, comments, or posts. The class contains almost all necessary methods for displaying, sorting, paginating, and searching data and and what is more obvious than to use it for your own plugins?</p>
<p>This article tries to give you a comprehensive walk-through all necessary steps to create a table tailored to your needs.</p>
<ol>
<li><a href="#preliminary">Preliminary work</a></li>
<li><a href="#basics">Basics</a></li>
<li><a href="#sorting">Sorting</a></li>
<li><a href="#actions">Actions</a></li>
<li><a href="#bulk">Bulk actions</a></li>
<li><a href="#pagination">Pagination</a></li>
<li><a href="#searching">Searching</a></li>
<li><a href="#screen-options">Screen options</a></li>
<li><a href="#styling">Styling the table</a></li>
<li><a href="#other">Other customizations</a></li>
<li><a href="#links">Weblinks</a></li>
</ol>
<h3 id="preliminary">Preliminary work</h3>
<p>For testing purposes we create a small plugin which adds a menu item:</p>
<pre lang="php">
&lt;?php
/*
Plugin Name: My List Table Example
*/
?&gt;
&lt;div class=&quot;wrap&quot;&gt;
&lt;div id=&quot;icon-users&quot; class=&quot;icon32&quot;&gt;&lt;/div&gt;
&lt;h2&gt;My List Table Test/h2&gt;
&lt;/div&gt;
&lt;?php
</pre>
<h3 id="basics">Basics</h3>
<p>For a start we're creating a list table with only the basic functionality. First we have to make sure that the necessary class is available since the <code>WP_List_Table</code> isn't loaded automatically:</p>
<pre class="brush: php">if( ! class_exists( &#039;WP_List_Table&#039; ) ) {
    require_once( ABSPATH . &#039;wp-admin/includes/class-wp-list-table.php&#039; );
}</pre>
<p>To create a table to your needs you have to derive a class from <code>WP_List_Table</code>:</p>
<pre lang="PHP">class My_List_Table extends WP_List_Table {
}

$myListTable = new My__List_Table();</pre>
<p>For demonstration purposes we create some sample data. Usually this data would be read from the database:</p>
<pre lang="PHP">var $example_data = array(
  array(&#039;ID&#039; =&gt; 1,&#039;booktitle&#039; =&gt; &#039;Quarter Share&#039;, &#039;author&#039; =&gt; &#039;Nathan Lowell&#039;,
        &#039;isbn&#039; =&gt; &#039;978-0982514542&#039;),
  array(&#039;ID&#039; =&gt; 2, &#039;booktitle&#039; =&gt; &#039;7th Son: Descent&#039;,&#039;author&#039; =&gt; &#039;J. C. Hutchins&#039;,
        &#039;isbn&#039; =&gt; &#039;0312384378&#039;),
  array(&#039;ID&#039; =&gt; 3, &#039;booktitle&#039; =&gt; &#039;Shadowmagic&#039;, &#039;author&#039; =&gt; &#039;John Lenahan&#039;,
        &#039;isbn&#039; =&gt; &#039;978-1905548927&#039;),
  array(&#039;ID&#039; =&gt; 4, &#039;booktitle&#039; =&gt; &#039;The Crown Conspiracy&#039;, &#039;author&#039; =&gt; &#039;Michael J. Sullivan&#039;,
        &#039;isbn&#039; =&gt; &#039;978-0979621130&#039;),
  array(&#039;ID&#039; =&gt; 5, &#039;booktitle&#039;     =&gt; &#039;Max Quick: The Pocket and the Pendant&#039;, &#039;author&#039;    =&gt; &#039;Mark Jeffrey&#039;,
        &#039;isbn&#039; =&gt; &#039;978-0061988929&#039;),
  array(&#039;ID&#039; =&gt; 6, &#039;booktitle&#039; =&gt; &#039;Jack Wakes Up: A Novel&#039;, &#039;author&#039; =&gt; &#039;Seth Harwood&#039;,
        &#039;isbn&#039; =&gt; &#039;978-0307454355&#039;)
);</pre>
<p>Before we can display the data in the table we have to define some methods and variables:</p>
<pre lang="PHP">
function get_columns(){
  $columns = array(
    &#039;booktitle&#039; =&gt; &#039;Title&#039;,
    &#039;author&#039;    =&gt; &#039;Author&#039;,
    &#039;isbn&#039;      =&gt; &#039;ISBN&#039;
  );
  return $columns;
}

function prepare_items() {
  $columns = $this-&gt;get_columns();
  $hidden = array();
  $sortable = array();
  $this-&gt;_column_headers = array($columns, $hidden, $sortable);
  $this-&gt;items = $this-&gt;example_data;;
}</pre>
<p>The method <code>get_columns()</code> is needed to label the columns on the top and bottom of the table. The keys in the array have to be the same as in the data array otherwise the respective columns aren't displayed.</p>
<p><code>prepare_items</code> defines two arrays controlling the behaviour of the table:</p>
<ul>
<li>$hidden defines the hidden columns (see <a href="#screen-options">Screen Options</a>),</li>
<li>$sortable defines if the table can be sorted by this column.</li>
</ul>
<p>Finally the method assigns the example data to the class' data representation variable <code>items</code>.</p>
<p>Before actually displaying each column WordPress looks for methods called <code>column_{key_name}</code>, e.g. <code>function column_booktitle</code>. There has to be such a method for every defined column. To avoid the need to create a method for each column there is <code>column_default</code> that will process any column for which no special method is defined:</p>
<pre lang="php">
function column_default( $item, $column_name ) {
  switch( $column_name ) {
    case &#039;booktitle&#039;:
    case &#039;author&#039;:
    case &#039;isbn&#039;:
      return $item&#091; $column_name &#093;;
    default:
      return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
  }
}
</pre>
<p>In our example the method will return the title for every column and if the column is not found it displays the content of the $item array for debugging purposes.</p>
<p>These are the essential ingredients to define a custom list table class. All you have to do now is to add an admin page to the backend, create an instance of our class, prepare the items and call <code>display()</code> to actually display the table:</p>
<pre class="brush: php">
function my_add_menu_items(){
    add_menu_page( &#039;My Plugin List Table&#039;, &#039;My List Table Example&#039;, &#039;activate_plugins&#039;, &#039;my_list_test&#039;, &#039;my_render_list_page&#039; );
}
add_action( &#039;admin_menu&#039;, &#039;my_add_menu_items&#039; );

function my_render_list_page(){
  $myListTable = new My_Example_List_Table();
  echo &#039;&lt;div class=&quot;wrap&quot;&gt;&lt;h2&gt;My List Table Test&lt;/h2&gt;&#039;;
  $myListTable-&gt;prepare_items();
  $myListTable-&gt;display();
  echo &#039;&lt;/div&gt;&#039;;
}
</pre>
<p>This is the minimal version of a WP_List_Table possible:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-13-23-07.png" alt="" title="Minimal WP_List_Table" width="646" height="276" class="aligncenter size-full wp-image-2427" /><br />
<a href="https://gist.github.com/gists/2147390/download">Download minimal WP_List_Table example</a> (gist)</p>
<h3 id="sorting">Sorting</h3>
<p>At the moment the items appear in the order they are defined in the code since the WP_List_Table class does not contain any code for sorting. What it does contain is some code to mark certain columns as sortable. In section "Basics" there already was a line <code>$sortable = array();</code> which now will be changed to:</p>
<pre lang="PHP">$sortable = $this-&gt;get_sortable_columns();</pre>
<p>Additionally we need the method:</p>
<pre lang="PHP">function get_sortable_columns() {
  $sortable_columns = array(
    &#039;booktitle&#039;  =&gt; array(&#039;booktitle&#039;,false),
    &#039;author&#039; =&gt; array(&#039;author&#039;,false),
    &#039;isbn&#039;   =&gt; array(&#039;isbn&#039;,false)
  );
  return $sortable_columns;
}</pre>
<p>This way the above mentioned column headers are changed to links and display small triangles if the mouse hovers over them. The second parameter in the value array of <code>$sortable_columns</code> takes care of a possible pre-ordered column. If the value is <code>true</code> the column is assumed to be ordered ascending, if the value is <code>false</code> the column is assumed descending or unordered. This is needed for the small triangle beside the column name indicating the sort order to show in the correct direction:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/22.02.014.png" alt="" title="Sorting" width="450" height="78" class="aligncenter size-full wp-image-2428" /></p>
<p>If you click on the column header the page is reloaded and <code>$_GET</code> contains something like this:</p>
<pre lang="PHP">array
  &#039;page&#039; =&gt; string &#039;my_list_test&#039; (length=12)
  &#039;orderby&#039; =&gt; string &#039;booktitle&#039; (length=5)
  &#039;order&#039; =&gt; string &#039;asc&#039; (length=3)</pre>
<p>With this information you can write a method for sorting our example data:</p>
<pre lang="PHP">function usort_reorder( $a, $b ) {
  // If no sort, default to title
  $orderby = ( ! empty( $_GET&#091;&#039;orderby&#039;&#093; ) ) ? $_GET&#091;&#039;orderby&#039;&#093; : &#039;booktitle&#039;;
  // If no order, default to asc
  $order = ( ! empty($_GET&#091;&#039;order&#039;&#093; ) ) ? $_GET&#091;&#039;order&#039;&#093; : &#039;asc&#039;;
  // Determine sort order
  $result = strcmp( $a&#091;$orderby&#093;, $b&#091;$orderby&#093; );
  // Send final sort direction to usort
  return ( $order === &#039;asc&#039; ) ? $result : -$result;
}</pre>
<p>To actually sort the data we have to extend <code>prepare_items()</code>:</p>
<pre lang="PHP">function prepare_items() {
  &#091;..&#093;
  usort( $this-&gt;example_data, array( &amp;$this, &#039;usort_reorder&#039; ) );
  $this-&gt;items = $this-&gt;example_data;
}</pre>
<p>If you're retrieving the data from the database (which is most likely) it's of course best to use SQL's <code>ORDERBY</code> directly.</p>
<h3 id="actions">Actions</h3>
<p>If you not only want to display the items but also want to manipulate them you have to define some actions:
<pre lang="PHP">
function column_booktitle($item) {
  $actions = array(
            &#039;edit&#039;      =&gt; sprintf(&#039;&lt;a href=&quot;?page=%s&amp;action=%s&amp;book=%s&quot;&gt;Edit&lt;/a&gt;&#039;,$_REQUEST&#091;&#039;page&#039;&#093;,&#039;edit&#039;,$item&#091;&#039;ID&#039;&#093;),
            &#039;delete&#039;    =&gt; sprintf(&#039;&lt;a href=&quot;?page=%s&amp;action=%s&amp;book=%s&quot;&gt;Delete&lt;/a&gt;&#039;,$_REQUEST&#091;&#039;page&#039;&#093;,&#039;delete&#039;,$item&#091;&#039;ID&#039;&#093;),
        );

  return sprintf(&#039;%1$s %2$s&#039;, $item&#091;&#039;booktitle&#039;&#093;, $this-&gt;row_actions($actions) );
}
</pre>
<p>These actions will appear if the user hovers the mouse cursor over the table:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/actions4.png" alt="" title="Actions" width="427" height="126" class="aligncenter size-full wp-image-2429" /></p>
<p>If you click on one of the action links the form will return for example the following data in <code>$_GET</code>:</p>
<pre lang="PHP">array
  &#039;page&#039; =&gt; string &#039;my_list_test&#039; (length=12)
  &#039;action&#039; =&gt; string &#039;delete&#039; (length=6)
  &#039;book&#039; =&gt; string &#039;2&#039; (length=1)</pre>
<h3 id="bulk">Bulk actions</h3>
<p>Bulk action are implemented by overwriting the method <code>get_bulk_actions()</code> and returning an associated array:</p>
<pre lang="PHP">function get_bulk_actions() {
  $actions = array(
    &#039;delete&#039;    =&gt; &#039;Delete&#039;
  );
  return $actions;
}</pre>
<p>This only puts the dropdown menu and the apply button above and below the table:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-17-08-00.png" alt="" title="21-03-2012 17-08-00" width="477" height="219" class="aligncenter size-full wp-image-2436" /></p>
<p>The checkboxes for the rows have to be defined separately. As mentioned above there is a method column_{column} for rendering a column. The <code>cb</code>-column is a special case:</p>
<pre lang="PHP">
function column_cb($item) {
        return sprintf(
            &#039;&lt;input type=&quot;checkbox&quot; name=&quot;book&#091;&#093;&quot; value=&quot;%s&quot; /&gt;&#039;, $item&#091;&#039;ID&#039;&#093;
        );
    }
</pre>
<p>This method currently will not be processed because we have to tell the class about the new column by extending the method <code>get_columns()</code>:</p>
<pre lang="php">
function get_columns() {
  $columns = array(
    &#039;cb&#039;        =&gt; &#039;&lt;input type=&quot;checkbox&quot; /&gt;&#039;,
&#091;..&#093;
}
</pre>
<p>This will also put the "select all" checkbox in the title bar:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-17-14-30.png" alt="" title="Bulk 1" width="491" height="236" class="aligncenter size-full wp-image-2430" /></p>
<p>If you don't want to display the checkbox in the title you simply set the value to an empty string. Nevertheless you still have to define the key/value pair otherwise no checkboxes are shown at all:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/22-03-2012-15-11-51.png" alt="" title="22-03-2012 15-11-51" width="503" height="233" class="aligncenter size-full wp-image-2438" /></p>
<p>If "Apply" is pressed the form will return various variables: <code>action</code> and <code>action2</code> contain the selected action or <code>-1</code> if the user chose no action, and if any checkbox was selected the marked rows, in our case <code>books</code>, for example:</p>
<pre class="brush: php">
&#039;action&#039; =&gt; string &#039;delete&#039; (length=6)
&#039;book&#039; =&gt;
  array
    0 =&gt; string &#039;2&#039; (length=1)
    1 =&gt; string &#039;6&#039; (length=1)
&#039;action2&#039; =&gt; string &#039;-1&#039; (length=2)
</pre>
<p><code>action</code> contains the selection from the upper select box, <code>action2</code> the selection from the lower select box, and <code>book</code> the id of the selected rows, if any. You can  use the method <code>current_action()</code> to query <code>action/action2</code>:</p>
<pre lang="php">
$action = $this-&gt;current_action();
</pre>
<p>It will return <code>action</code> if it's set, otherwise <code>action2</code>. If nothing is set the method returns <code>FALSE</code>.</p>
<h3 id="pagination">Pagination</h3>
<p>First things first: WordPress does not paginate your data in any way. It only contains a method to display a navigation bar on the top and bottom right of the table:</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-17-38-38.png" alt="" title="Pagination" width="392" height="206" class="aligncenter size-full wp-image-2432" /></p>
<p>You have to tell the method how many items you have in total, how many items shall be displayed on a page, and most important, the data to be displayed on the page:</p>
<pre lang="PHP">function prepare_items() {
  &#091;...&#093;
  $per_page = 5;
  $current_page = $this-&gt;get_pagenum();
  $total_items = count($this-&gt;example_data);

  // only ncessary because we have sample data
  $this-&gt;found_data = array_slice($this-&gt;example_data,(($current_page-1)*$per_page),$per_page);

  $this-&gt;set_pagination_args( array(
    &#039;total_items&#039; =&gt; $total_items,                  //WE have to calculate the total number of items
    &#039;per_page&#039;    =&gt; $per_page                     //WE have to determine how many items to show on a page
  ) );
  $this-&gt;items = $this-&gt;found_data;
}</pre>
<p>As pointed out in the comment the <code>array_slice</code> is only necessary because we use sample data. If you're retrieving the data from a database you only need to load the necessary data by using SQL's <code>LIMIT</code>.</p>
<h3 id="searching">Searching</h3>
<p>If you have a huge amount of data a search field will simplify accessing certain items:</p>
<pre lang="PHP">$myListTable-&gt;search_box(&#039;search&#039;, &#039;search_id&#039;);</pre>
<p>The button text <code>search</code> is defined by the first parameter, the id of the input by the second parameter. The method creates the following output:</p>
<pre lang="xhtml">
&lt;p class=&quot;search-box&quot;&gt;
&lt;label class=&quot;screen-reader-text&quot; for=&quot;search_id-search-input&quot;&gt;
search:&lt;/label&gt;
&lt;input id=&quot;search_id-search-input&quot; type=&quot;text&quot; name=&quot;s&quot; value=&quot;&quot; /&gt;
&lt;input id=&quot;search-submit&quot; class=&quot;button&quot; type=&quot;submit&quot; name=&quot;&quot; value=&quot;search&quot; /&gt;
&lt;/p&gt;
</pre>
<p>The method will place the input field and the search button on the right side and style it correctly. The <code>&lt;form></code> element is not generated. You have to add it manually, in our case this would be:</p>
<pre lang="xhtml">
&lt;form method=&quot;post&quot;&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;page&quot; value=&quot;my_list_test&quot; /&gt;
  &lt;?php $this-&gt;search_box(&#039;search&#039;, &#039;search_id&#039;); ?&gt;
&lt;/form&gt;
</pre>
<p>(The hidden element is needed to load the right page.)<br />
To react to the search command you need to check the content of <code>$_POST['s']</code> and filter your data accordingly before displaying the table.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-18-17-33.png" alt="" title="Searching" width="381" height="151" class="aligncenter size-full wp-image-2433" /></p>
<h3 id="screen-options">Screen options</h3>
<p>All core backend pages containing a <code>WP_List_Table</code> provide a "Screen Options" slide-in where the user can adjust the columns to be shown and the number of rows to be displayed.<br />
To add options to your plugin you need to change your current code. First you have to make sure that the screen options are displayed only on the current page:</p>
<pre lang="PHP">$hook = add_menu_page(&#039;My Plugin List Table&#039;, &#039;My List Table Example&#039;, &#039;activate_plugins&#039;, &#039;my_list_test&#039;, &#039;my_render_list_page&#039;);
add_action( &quot;load-$hook&quot;, &#039;add_options&#039; );

function add_options() {
  $option = &#039;per_page&#039;;
  $args = array(
         &#039;label&#039; =&gt; &#039;Books&#039;,
         &#039;default&#039; =&gt; 10,
         &#039;option&#039; =&gt; &#039;books_per_page&#039;
         );
  add_screen_option( $option, $args );
}</pre>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-18-25-17.png" alt="" title="Screen options 1" width="568" height="116" class="aligncenter size-full wp-image-2434" /></p>
<p>This only displays the option field and apply button, saving and loading the data has to be defined separately. WordPress provides a filter called <code>set-screen-option</code> to take care of this:</p>
<pre lang="php">
add_filter(&#039;set-screen-option&#039;, &#039;test_table_set_option&#039;, 10, 3);
function test_table_set_option($status, $option, $value) {
  return $value;
}
</pre>
<p>The option is stored in the table <code>usermeta</code> in the database so each user has his own setting. To retrieve the option and adjust the table display accordingly the method <code>prepare_items</code> has to be altered (excerpt):</p>
<pre lang="php">
function prepare_items() {
&#091;..&#093;

  //paging
  $per_page = $this-&gt;get_items_per_page(&#039;books_per_page&#039;, 5);
  $current_page = $this-&gt;get_pagenum();

  &#091;...&#093;
</pre>
<p>Instead of simply assigning a number the user specified value is loaded. If the user hasn't changed the value there is no such option stored in the database and a default value is taken.</p>
<p>Adding the checkboxes for hiding/showing the columns is done by WordPress automatically. You just have to make sure that your derived class is instantiated before the screen option panel is rendered so that the parent class can retrieve the column names. To accomplish this the corresponding code is moved into the method <code>add_options()</code>:</p>
<pre lang="php">
function add_options() {
    global $myListTable;

    $option = &#039;per_page&#039;;
    $args = array(
        &#039;label&#039; =&gt; &#039;Books&#039;,
        &#039;default&#039; =&gt; 10,
        &#039;option&#039; =&gt; &#039;books_per_page&#039;
    );
    add_screen_option( $option, $args );

    $myListTable = new My_Example_List_Table;
}</pre>
<p><img src="http://wpengineer.com/wp-content/uploads/21-03-2012-18-32-02.png" alt="" title="Screen options 2" width="574" height="170" class="aligncenter size-full wp-image-2435" /></p>
<p>The user's selections are automatically saved via Ajax functions. Nevertheless you have take care by yourself that the columns are hidden if the page is loaded initially. The method <code>get_column_info()</code> returns all, the hidden and the sortable columns. In the method <code>prepare_items()</code> instead of</p>
<pre lang="php">
$columns = $this-&gt;get_columns();
$hidden = array();
$sortable = $this-&gt;get_sortable_columns();
$this-&gt;_column_headers = array($columns, $hidden, $sortable);
</pre>
<p>it's now</p>
<pre lang="php">
$this-&gt;_column_headers = $this-&gt;get_column_info();
</pre>
<p>and the columns are set according to the screen options.</p>
<p>Annotation: you should avoid some strings as keynames since they are treated by WordPress specially:</p>
<pre lang="php">
$special = array(&#039;_title&#039;, &#039;cb&#039;, &#039;comment&#039;, &#039;media&#039;, &#039;name&#039;, &#039;title&#039;, &#039;username&#039;, &#039;blogname&#039;);
</pre>
<p>Your table would still work, but you won't be able to show/hide the columns.</p>
<h3 id="styling">Styling the table</h3>
<p>Currently the table is styled to the WordPress defaults. To change this you have to adapt the CSS classes which are automatically assigned to each column. The class name consists of the string "column-" and the key name of the <code>$columns</code> array, e.g. "column-isbn" or "column-author". As an example the width of the columns will be redefined (for simplicity the style data is written directly into the HTML header):</p>
<pre lang="php">
function _construct() {
  &#091;...&#093;
  add_action( &#039;admin_head&#039;, array( &amp;$this, &#039;admin_header&#039; ) );
  &#091;...&#093;
}

function admin_header() {
  $page = ( isset($_GET&#091;&#039;page&#039;&#093; ) ) ? esc_attr( $_GET&#091;&#039;page&#039;&#093; ) : false;
  if( &#039;my_list_test&#039; != $page )
    return; 

  echo &#039;&lt;style type=&quot;text/css&quot;&gt;&#039;;
  echo &#039;.wp-list-table .column-id { width: 5%; }&#039;;
  echo &#039;.wp-list-table .column-booktitle { width: 40%; }&#039;;
  echo &#039;.wp-list-table .column-author { width: 35%; }&#039;;
  echo &#039;.wp-list-table .column-isbn { width: 20%; }&#039;;
  echo &#039;&lt;/style&gt;&#039;;
}
</pre>
<h3 id="other">Other customizations</h3>
<p>If there are no items in the list the standard message is "No items found." is displayed. If you want to change this message you can overwrite the method <code>no_items()</code>:</p>
<pre lang="php">
function no_items() {
  _e( &#039;No books found, dude.&#039; );
}
</pre>
<p><a href="https://gist.github.com/gists/7f923479a4ed135e35b2/download" title="Download Gist">Download complete WP_List_Table example</a> (gist) or <a href="https://gist.github.com/7f923479a4ed135e35b2" title="Gist: Sample plugin for usage of WP_List_Table class (complete version)">see the Gist</a></p>
<h3 id="links">Weblinks</h3>
<ul>
<li><a href="http://wp.smashingmagazine.com/2011/11/03/native-admin-tables-wordpress/">Create Native Admin Tables In WordPress The Right Way</a> (Smashing Magazine)</li>
<li><a href="http://wordpress.org/extend/plugins/custom-list-table-example/">Custom List Table Example plugin</a> (wordpress.org)</li>
</ul>
</li>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Register Settings on WordPress Multisite</title>
		<link>http://wpengineer.com/2324/register-settings-on-wordpress-multisite/</link>
		<comments>http://wpengineer.com/2324/register-settings-on-wordpress-multisite/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 07:08:59 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2324</guid>
		<description><![CDATA[The use of WordPress for several blogs in the network can be useful to simplify several steps and is becoming increasingly popular. Whether you want the classical scenarios of blog hosting service or like to create multilingual websites or other ideas. Therefore, it is also important for plugin developers to use the functions and to [...]]]></description>
			<content:encoded><![CDATA[<p>The use of WordPress for several blogs in the network can be useful to simplify several steps and is becoming increasingly popular. Whether you want the classical scenarios of blog hosting service or like to create multilingual websites or other ideas. Therefore, it is also important for plugin developers to use the functions and to expand or develop their own Plugins for it specifically.</p>
<p>Much is the same, but not all, and in this small article I would like to briefly explain how you set settings in the database when you activate a Plugin. <span id="more-2324"></span> </p>
<p>The best case for this is a Function of WordPress, which is triggered when activating a plugin <code>register_activation_hook()</code>. This Function will be called in init or constructor of the Plugin. In the called Function are the functions to store the settings of WordPress in the table options - <code>add_option()</code>. In Multisite there is also a function for it - <code>add_site_option()</code>.</p>
<p>Now you have to separate, if the Plugin is activated within the Network, in the management of Multisite installation, or if it is only used in one of the blogs in the network or a single installation. There are currently no functions, but a value that is passed. The following example illustrates it:</p>
<pre>
register_activation_hook( __FILE__, &#039;fb_add_config&#039; );
function fb_add_config() {

	$data = array(
		&#039;active&#039; =&gt; 0,
		&#039;radio&#039;  =&gt; 0,
		&#039;link&#039;   =&gt; 1,
		&#039;theme&#039;  =&gt; 1,
		&#039;role&#039;   =&gt; &#039;administrator&#039;,
		&#039;unit&#039;   =&gt; 1,
	);
	// if is active in network of multisite
	if ( is_multisite() &amp;&amp; isset($_GET&#091;&#039;networkwide&#039;&#093;) &amp;&amp; 1 == $_GET&#091;&#039;networkwide&#039;&#093; ) {
		add_site_option( &#039;my_settings_id&#039;, $data );
	} else {
		add_option( &#039;my_settings_id&#039;, $data );
	}
}
</pre>
<p>The query of the value in the global <code>GET</code> can be integrated in the long time ago <a href="http://wpengineer.com/2221/wordpress-multisite-plugins-and-activation/">mentioned solution for Multisite</a> and settings.</p>
<p>To solve other queries in a Multisite environment and to remove the setup or integrate menus in the admin area, the function <code>is_plugin_active_for_network()</code> is useful.</p>
<pre>
if ( is_multisite() &amp;&amp; is_plugin_active_for_network( plugin_basename( __FILE__ ) ) )
	$values = get_site_option( &#039;my_settings_id&#039; );
else
	$values = get_option( &#039;my_settings_id&#039; );
</pre>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2324/register-settings-on-wordpress-multisite/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Restrict Mime Types on WordPress Media Upload</title>
		<link>http://wpengineer.com/2369/restrict-mime-types-on-wordpress-media-upload/</link>
		<comments>http://wpengineer.com/2369/restrict-mime-types-on-wordpress-media-upload/#comments</comments>
		<pubDate>Sat, 17 Dec 2011 07:05:00 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[mediathek]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2369</guid>
		<description><![CDATA[WordPress has changed the library in version 3.3 - which I think is an improvement. The restrictions in terms of file types remains and you can control them via hook. So you can limit or extend the file-types. Via two hooks, this is done quickly and there is a notification displayed in your backend which [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress has changed the library in version 3.3  - which I think is an improvement. The restrictions in terms of file types remains and you can control them via hook. So you can limit or extend the file-types. Via two hooks, this is done quickly and there is a notification displayed in your backend which lists the allowed file types.</p>
<p><span id="more-2369"></span><br />
<a href="http://wpengineer.com/wp-content/uploads/restrict-mime-type.png"><img src="http://wpengineer.com/wp-content/uploads/restrict-mime-type-300x187.png" alt="Screenshot Example for restrive the mime type" title="restrict-mime-type" width="300" height="187" class="aligncenter size-medium wp-image-2370" /></a></p>
<p>The following small Plugin may extend to different roles or authorization objects, so that you can upload, depending on the role, different types of files in the system - <a href="http://wpengineer.com/?s=current_user_can"><code>current_user_can()</code></a>.</p>
<p>Anyone interested in the currently allowed types, you can return the array of the first function or look into the function <code>get_allowed_mime_types()</code> in <code>wp-includes/functions.php</code>.</p>
<p><a href="http://wpengineer.com/wp-content/uploads/restrict-mime-type-hint.png"><img src="http://wpengineer.com/wp-content/uploads/restrict-mime-type-hint-300x65.png" alt="Screenshot for Hint about allowed Mime Types" title="restrict-mime-type-hint" width="300" height="65" class="aligncenter size-medium wp-image-2371" /></a></p>
<pre>
&lt;?php
/**
 * Plugin Name: Restrict mime types
 * Plugin URI:  http://wpengineer.com/?p=2369
 * Description: Restrict list of allowed mime types and file extensions.
 * Version:     1.0.0
 * License:     GPLv3
 * Author:      Frank B&uuml;ltge
 * Author URI:  http://bueltge.de/
 */

 // This file is not called from WordPress. We don&#039;t like that.
! defined( &#039;ABSPATH&#039; ) and exit;

// If the function exists this file is called as upload_mimes.
// We don&#039;t do anything then.
if ( ! function_exists( &#039;fb_restrict_mime_types&#039; ) ) {

	add_filter( &#039;upload_mimes&#039;, &#039;fb_restrict_mime_types&#039; );
	/**
	 * Retrun allowed mime types
	 *
	 * @see     function get_allowed_mime_types in wp-includes/functions.php
	 * @param   array Array of mime types
	 * @return  array Array of mime types keyed by the file extension regex corresponding to those types.
	 */
	function fb_restrict_mime_types( $mime_types ) {

		$mime_types = array(
			&#039;pdf&#039; =&gt; &#039;application/pdf&#039;,
			&#039;doc|docx&#039; =&gt; &#039;application/msword&#039;,
		);

		return $mime_types;
	}
}

// If the function exists this file is called as post-upload-ui.
// We don&#039;t do anything then.
if ( ! function_exists( &#039;fb_restrict_mime_types_hint&#039; ) ) {
	// add to wp
	add_action( &#039;post-upload-ui&#039;, &#039;fb_restrict_mime_types_hint&#039; );
	/**
	 * Get an Hint about the allowed mime types
	 *
	 * @return  void
	 */
	function fb_restrict_mime_types_hint() {

		echo &#039;&lt;br /&gt;&#039;;
		_e( &#039;Accepted MIME types: PDF, DOC/DOCX&#039; );
	}
}
</pre>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2369/restrict-mime-types-on-wordpress-media-upload/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Activate WordPress Plugins Automatically via a Function</title>
		<link>http://wpengineer.com/2300/activate-wordpress-plugins-automatically-via-a-function/</link>
		<comments>http://wpengineer.com/2300/activate-wordpress-plugins-automatically-via-a-function/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 07:11:17 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2300</guid>
		<description><![CDATA[WordPress stores the active Plugins in the database table options, field activate_plugins, so it is easy to change this value to activate various Plugins by WordPress; either as a Plugin solution after setting up a new installation or because some Plugins need some other Plugins. I show you as an example a solution. It is [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress stores the active Plugins in the database table <code>options</code>, field <code>activate_plugins</code>, so it is easy to change this value to activate various Plugins by WordPress; either as a Plugin solution after setting up a new installation or because some Plugins need some other Plugins.<br />
<span id="more-2300"></span><br />
I show you as an example a solution. It is important that you don't use the Plugin names, but the string of the file, which is also required in various hooks. Below you will also find a simple solution to get to this string in your backend.</p>
<pre>
// example on admin init, control about register_activation_hook()
add_action( &#039;admin_init&#039;, &#039;fb_activate_plugins&#039; );
// the exmple function
function fb_activate_plugins() {

	if ( ! current_user_can(&#039;activate_plugins&#039;) )
		wp_die(__(&#039;You do not have sufficient permissions to activate plugins for this site.&#039;));
	$plugins = FALSE;
	$plugins = get_option(&#039;active_plugins&#039;); // get active plugins

	if ( $plugins ) {
		// plugins to active
		$pugins_to_active = array(
			&#039;hello.php&#039;, // Hello Dolly
			&#039;adminimize/adminimize.php&#039;, // Adminimize
			&#039;akismet/akismet.php&#039; // Akismet
		);

		foreach ( $pugins_to_active as $plugin ) {
			if ( ! in_array( $plugin, $plugins ) ) {
				array_push( $plugins, $plugin );
				update_option( &#039;active_plugins&#039;, $plugins );
			}
		}

	} // end if $plugins

}
</pre>
<p>The following function and its hook provides a direct output of the string of the Plugin file on the Plugin page in your backend, so please use it only for a quick finding.</p>
<pre>
add_filter( &#039;plugin_row_meta&#039;, &#039;fb_get_plugin_string&#039;, 10, 4 );
function fb_get_plugin_string( $plugin_meta, $plugin_file, $plugin_data, $status ) {
	// echo plugin file string
	echo &#039;&lt;code&gt;&#039; . $plugin_file . &#039;&lt;/code&gt;&lt;br&gt;&#039;;
	return $plugin_meta;
}
</pre>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2300/activate-wordpress-plugins-automatically-via-a-function/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Advent Calendar – WordPress, WPCron and the right Time</title>
		<link>http://wpengineer.com/2350/advent-calendar-wordpress-wpcron-and-the-right-time/</link>
		<comments>http://wpengineer.com/2350/advent-calendar-wordpress-wpcron-and-the-right-time/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 07:52:59 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2350</guid>
		<description><![CDATA[WordPress offers a pseudo-cronjob functionality, which allows the developer to execute scheduled events. For example, the whole Update Notification does it. In these so-called Scheduled Events you can define your own jobs. Thereby you should however pay attention to one important thing: time. The wp-cron.php works outside the core and loads only the most important [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress offers a pseudo-cronjob functionality, which allows the developer to execute scheduled events. For example, the whole Update Notification does it. In these so-called <em>Scheduled Events</em> you can define your own jobs. Thereby you should however pay attention to one important thing: time.<br />
<span id="more-2350"></span><br />
The <code>wp-cron.php</code> works outside the core and loads only the most important things and leaves all settings of WordPress open. In the <em>Settings -> General</em> set time zone is not included. <code>wp-cron.php</code> runs on UTC.</p>
<p>That means: Are we in the time zone of Berlin, the local time is UTC +1. Are we performing a scheduled event, it will always be one hour after the actual time we like to execute. To change this, we use the following function:</p>
<pre>
function get_offset_to_gmt_in_seconds() {

	$current_timezone_offset = get_option( &#039;gmt_offset&#039; );
	$offset = $current_timezone_offset * 3600;

	return $offset;
}
</pre>
<div class="incontent">
<h4>Guest Post</h4>
<p><img src="http://wpengineer.com/wp-content/uploads/dasllama-150x150.png" alt="" title="dasllama" width="150" height="150" class="alignleft size-thumbnail wp-image-2223" />This post is written by Thomas Herzog - <a href="http://hughwillfayle.de/">hughwillfayle.de</a> and is a guest post on WP Engineer about WordPress.<br />
Thank you very much from my part to Thomas. Please see <a href="http://profiles.wordpress.org/users/hughwillfayle/">his nice plugins</a> on the official WordPress repository.<br />
If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!
</div>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2350/advent-calendar-wordpress-wpcron-and-the-right-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Advent Calendar – WordPress Editor: Preserve the scroll position</title>
		<link>http://wpengineer.com/2340/advent-calendar-%e2%80%93-wordpress-editor-preserve-the-scroll-position/</link>
		<comments>http://wpengineer.com/2340/advent-calendar-%e2%80%93-wordpress-editor-preserve-the-scroll-position/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 06:59:38 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2340</guid>
		<description><![CDATA[WordPress has a nice editor, with which are several hundreds of articles written daily. But in my opinion the editor has an usability issue. Every time you save a post the scroll position of the editor will be on top again. If you want to continue writing the post you have first to find he [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress has a nice editor, with which are several hundreds of articles written daily.</p>
<p>But in my opinion the editor has an usability issue.<br />
Every time you save a post the scroll position of the editor will be on top again. If you want to continue writing the post you have first to find he old position again. This can be time-consuming.<br />
<span id="more-2340"></span><br />
<div id="attachment_2342" class="wp-caption aligncenter" style="width: 510px"><img src="http://wpengineer.com/wp-content/uploads/wp-editor-preserve-scroll-position.png" alt="" title="wp-editor-preserve-scroll-position" width="500" height="225" class="size-full wp-image-2342" /><p class="wp-caption-text">Save editor scroll position on saving</p></div></p>
<p>To avoid this behavior I have written a snippet which I want to share now with you.</p>
<pre>
&lt;?php
/**
 * The class will help you to recover the old scoll position in your Editor.
 * Either HTML or visuel editor.
 */
final class Preserve_Editor_Scroll_Position {
	/**
	 * Init
	 */
	public static function init() {
		add_filter( &#039;redirect_post_location&#039;, array( __CLASS__, &#039;add_query_arg&#039; ) );
		add_action( &#039;edit_form_advanced&#039;, array( __CLASS__, &#039;add_input_field&#039; ) );
		add_action( &#039;edit_page_form&#039;, array( __CLASS__, &#039;add_input_field&#039; ) );
		add_filter( &#039;tiny_mce_before_init&#039;, array( __CLASS__, &#039;extend_tiny_mce&#039; ) );
	}

	/**
	 * Adds a hidden input field for scrolltop value
	 */
	public static function add_input_field() {
		$position = ! empty( $_GET&#091;&#039;scrollto&#039;&#093; ) ? $_GET&#091;&#039;scrollto&#039;&#093; : 0;

		printf( &#039;&lt;input type=&quot;hidden&quot; id=&quot;scrollto&quot; name=&quot;scrollto&quot; value=&quot;%d&quot;/&gt;&#039;, esc_attr( $position ) );

		// Print Javascript data
		add_action( &#039;admin_print_footer_scripts&#039;, array( __CLASS__, &#039;print_js&#039; ), 55 ); // Print after Editor JS.
	}

	/**
	 * Extend TinyMCE config with a setup function
	 */
	public static function extend_tiny_mce( $init ) {
		if ( &#039;tinymce&#039; == wp_default_editor() )
			$init&#091;&#039;setup&#039;&#093; = &#039;rich_scroll&#039;;

		return $init;
	}

	/**
	 * Returns redirect url with query arg for scroll position
	 */
	public static function add_query_arg( $location ) {
		if ( ! empty( $_POST&#091;&#039;scrollto&#039;&#093; ) )
			$location = add_query_arg( &#039;scrollto&#039;, (int) $_POST&#091;&#039;scrollto&#039;&#093;, $location );

		return $location;
	}

	/**
	 * Prints Javascript data
	 */
	public static function print_js() {
		?&gt;
	&lt;script&gt;
	( function( $ ) {
		$( &#039;#post&#039; ).submit( function() {
			scrollto =
				$( &#039;#content&#039; ).is( &#039;:hidden&#039; ) ?
				$( &#039;#content_ifr&#039; ).contents().find( &#039;body&#039; ).scrollTop() :
				$( &#039;#content&#039; ).scrollTop();

			$( &#039;#scrollto&#039; ).val( scrollto );
		} );

		$( &#039;#content&#039; ).scrollTop( $( &#039;#scrollto&#039; ).val() );
	} )( jQuery );

	function rich_scroll( ed ) {
		ed.onInit.add( function() {
			jQuery( &#039;#content_ifr&#039; ).contents().find( &#039;body&#039; ).scrollTop( jQuery( &#039;#scrollto&#039; ).val() );
		} );
	};
	&lt;/script&gt;
		&lt;?php
	}
}
add_action( &#039;plugins_loaded&#039;, array( &#039;Preserve_Editor_Scroll_Position&#039;, &#039;init&#039; ) );
</pre>
<p>If you want you can create your own plugin with this snippet or you can download the plugin <a href="http://wordpress.org/extend/plugins/preserve-editor-scroll-position/">Preserve Editor Scroll Position</a>.</p>
<div class="incontent">
<h4>Guest Post</h4>
<p><img src="http://wpengineer.com/wp-content/uploads/dominik-schilling-g+.png" alt="Dominik Schilling Avatar" title="selbst" width="150" height="150" class="alignleft" />This post is written by Dominik Schilling - <a href="http://wpgrafie.de/">wpgrafie.de</a> and is a post in our Advent Calendar on WP Engineer about WordPress. Dominik is Student, Web Developer, WordPress Contributing Developer - <a href="http://profiles.wordpress.org/users/ocean90">ocean90</a> and he ♥ WordPress.<br />
Thank you very much from my part to <a href="https://plus.google.com/101675293278434581718/about" title="see his G+ rofile">Dominik</a>.<br />
If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!
</div>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2340/advent-calendar-%e2%80%93-wordpress-editor-preserve-the-scroll-position/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Use Constants for deactivate the Editor in WordPress Backend</title>
		<link>http://wpengineer.com/2261/use-constants-for-deactivate-the-editor-in-wordpress-backend/</link>
		<comments>http://wpengineer.com/2261/use-constants-for-deactivate-the-editor-in-wordpress-backend/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 10:22:40 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>
		<category><![CDATA[WP3.0]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2261</guid>
		<description><![CDATA[WordPress is known for, that several constants lie dormant in the core and often provide quick solutions. In this context I have recently come across two little strings in the core of the backend editor of WordPress and in the core for updating the system as well. As far as I know, all constants mentioned [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress is known for, that several constants lie dormant in the core and often provide quick solutions. In this context I have recently come across two little strings in the core of the backend editor of WordPress and in the core for updating the system as well. As far as I know, all constants mentioned here are in the system since version 3.0.<br />
<span id="more-2261"></span><br />
The first constant takes off the editors of the backend and does not allow access to it. This makes the editing of Theme and Plugin files of the backend with standard solutions not possible.</p>
<pre class="php">
// for enabling/disabling theme/plugin editor
define( &#039;DISALLOW_FILE_EDIT&#039;, TRUE );
</pre>
<p>The second constant presented here prohibits editing, modifying or changing the core files, Plugins or Themes. In this context the menu entries in the backend are not visible or usable. Thus the update is not so easy to do and clients and unauthenticated users are blocked quickly.</p>
<pre>
// Disallow anything that creates, deletes, or edits core, plugin, or theme files.
// Files in uploads are excepted.
define( &#039;DISALLOW_FILE_MODS&#039;, TRUE );
</pre>
<p>In this context there are two constants that are useful now and then.</p>
<p>In various contexts it is very useful that all users have the option of: to write unfiltered HTML, in all aspects and this can also be easily implemented via constants:</p>
<pre>// Disallow unfiltered_html for all users, even admins and super admins
DISALLOW_UNFILTERED_HTML
</pre>
<p>Similar existing for uploads:</p>
<pre>// Allow uploads of filtered file types to users with administrator role
ALLOW_UNFILTERED_UPLOADS
</pre>
<p>The constants belong in the <code>wp-config.php</code> of the installation.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2261/use-constants-for-deactivate-the-editor-in-wordpress-backend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Add and Deactivate the new Feature Pointer in WordPress 3.3</title>
		<link>http://wpengineer.com/2272/how-to-add-and-deactivate-the-new-feature-pointer-in-wordpress-3-3/</link>
		<comments>http://wpengineer.com/2272/how-to-add-and-deactivate-the-new-feature-pointer-in-wordpress-3-3/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 11:36:46 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress News]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>
		<category><![CDATA[wp3.3]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2272</guid>
		<description><![CDATA[With WordPress version 3.3 comes with the Feature Pointer a well-known idea from other tools. We know this for example from Gmail or Google Doc where they notice you of new features, in which they point with bubbles to these new features. In WordPress 3.3, the Admin Bar has been redesigned successfully - I think [...]]]></description>
			<content:encoded><![CDATA[<p>With WordPress version 3.3 comes with the Feature Pointer a well-known idea from other tools. We know this for example from Gmail or Google Doc where they notice you of new features, in which they point with bubbles to these new features. In WordPress 3.3, the Admin Bar has been redesigned successfully - I think - and this is the first time the feature pointer points to it.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/wp-pointer.png" alt="" title="wp-pointer" width="600" height="149" class="aligncenter size-medium wp-image-2273" /> <span id="more-2272"></span><br />
If you are in the environment of customers, it may be that you don't want the feature pointer - different scenarios are possible. But here it also relies on the WordPress hooks so you can intervene in various ways. One idea is to adjust the user settings of the user, as the feature pointer is using Javascript to drop an option in the table, so that the user does not read the instructions again. Alternatively, you can disable it via hook, following solution paste into a small Plugin or the functions.php of your theme (whereas the second solution isn't the best).</p>
<pre>&lt;code&gt;
add_filter( &#039;show_wp_pointer_admin_bar&#039;, &#039;__return_false&#039; );
&lt;/code&gt;</pre>
<p>If you don't have the admin bar not active, then it won't show a feature pointer to it.</p>
<p>Also you can use the hooks to create your own feature pointer. Without adjustment in the design and position is the following simple example conceivable. If the position is changed, it is sufficient to adapt the script section JS-function <code>pointer()</code> in the PHP function <code>get_content_in_wp_pointer()</code>. The function <code>pointer()</code> can be controlled by various parameters (<code>content, position, arrow</code>) .</p>
<pre>
function get_content_in_wp_pointer() {
	$pointer_content  = &#039;&lt;h3&gt;&#039; . __( &#039;WP Pointer with version 3.3.&#039;, &#039;my_textdomain&#039; ) . &#039;&lt;/h3&gt;&#039;;
	$pointer_content .= &#039;&lt;p&gt;&#039; . __( &#039;Add your own informations to WP Pointer.&#039;, &#039;my_textdomain&#039; ) . &#039;&lt;/p&gt;&#039;;

?&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
//&lt;!&#091;CDATA&#091;
jQuery(document).ready( function($) {
	$(&#039;#wpadminbar&#039;).pointer({
		content: &#039;&lt;?php echo $pointer_content; ?&gt;&#039;,
		position: {
			my: &#039;left top&#039;,
			at: &#039;center bottom&#039;,
			offset: &#039;-25 0&#039;
		},
		close: function() {
			setUserSetting( &#039;p1&#039;, &#039;1&#039; );
		}
	}).pointer(&#039;open&#039;);
});
//&#093;&#093;&gt;
&lt;/script&gt;
&lt;?php
}

function fb_enqueue_wp_pointer( $hook_suffix ) {
	$enqueue = FALSE;

	$admin_bar = get_user_setting( &#039;p1&#039;, 0 ); // check settings on user
	// check if admin bar is active and default filter for wp pointer is true
	if ( ! $admin_bar &amp;&amp; apply_filters( &#039;show_wp_pointer_admin_bar&#039;, TRUE ) ) {
		$enqueue = TRUE;
		add_action( &#039;admin_print_footer_scripts&#039;, &#039;get_content_in_wp_pointer&#039; );
	}
	// in true, include the scripts
	if ( $enqueue ) {
		wp_enqueue_style( &#039;wp-pointer&#039; );
		wp_enqueue_script( &#039;wp-pointer&#039; );
		wp_enqueue_script( &#039;utils&#039; ); // for user settings
	}
}
add_action( &#039;admin_enqueue_scripts&#039;, &#039;fb_enqueue_wp_pointer&#039; );
</pre>
<p><a href="http://wpengineer.com/wp-content/uploads/wp-pointer-2.png"><img src="http://wpengineer.com/wp-content/uploads/wp-pointer-2-300x96.png" alt="" title="wp-pointer-2" width="300" height="96" class="aligncenter size-medium wp-image-2274" /></a></p>
<p><strong>Please note:</strong> The implementation is based on a nightly build of WordPress, not the final Release 3.3 and thus might have some changes or other solutions are possible in a later version. Therefore, please validate according to the version of WordPress the solution. As a tip this should be enough - anything else is creativity and your skills.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2272/how-to-add-and-deactivate-the-new-feature-pointer-in-wordpress-3-3/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Remove Menu Item in WordPress Admin Panel</title>
		<link>http://wpengineer.com/2233/remove-menu-item-in-wordpress-admin-panel/</link>
		<comments>http://wpengineer.com/2233/remove-menu-item-in-wordpress-admin-panel/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 05:50:40 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp3.1]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2233</guid>
		<description><![CDATA[With WordPress Version 3.1 two new functions were added which makes it easier to remove menu- and submenu-entries in WordPress Admin Panel. These functions removing entries of the menu-tree remove_menu_page or submenus - remove_submenu_page. /** * Remove a top level admin menu * * @param string $menu_slug The slug of the menu * @return array&#124;bool [...]]]></description>
			<content:encoded><![CDATA[<p>With WordPress Version 3.1 two new functions were added which makes it easier to remove menu- and submenu-entries in WordPress Admin Panel. These functions removing entries of the menu-tree <code>remove_menu_page</code> or submenus - <code>remove_submenu_page</code>.<br />
<span id="more-2233"></span></p>
<pre>
/**
 * Remove a top level admin menu
 *
 * @param string $menu_slug The slug of the menu
 * @return array|bool The removed menu on success, False if not found
 */
remove_menu_page( $menu_slug )
</pre>
<pre>
/**
 * Remove an admin submenu
 *
 * @param string $menu_slug The slug for the parent menu
 * @param string $submenu_slug The slug of the submenu
 * @return array|bool The removed submenu on success, False if not found
 */
remove_submenu_page( $menu_slug, $submenu_slug ) {
</pre>
<p>It's easy to remove menu entries and it is not necessary anymore to read the arrays $menu and $submenu. Until now you had to search for them in the array and remove them via unset() from the array. Alternatively you were also able to find the entry on the basis of a key - the above new features make this unnecessary and as a parameter value only the "slug" is passed, which can be found in the link or the URL of the backend. A small example, where we remove the entries to the comments and the submenu-page discussion will show the new possibilities.</p>
<pre>
function fb_remove_menu_entries () {
	// with WP 3.1 and higher
	if ( function_exists( &#039;remove_menu_page&#039; ) ) {
		remove_menu_page( &#039;edit-comments.php&#039; );
		remove_submenu_page( &#039;options-general.php&#039;, &#039;options-discussion.php&#039; );
	} else {
		// unset comments
		unset( $GLOBALS&#091;&#039;menu&#039;&#093;&#091;25&#093; );
		// unset menuentry Discussion
		unset( $GLOBALS&#091;&#039;submenu&#039;&#093;&#091;&#039;options-general.php&#039;&#093;&#091;25&#093; );
	}
}
add_action( &#039;admin_menu&#039;, &#039;fb_remove_menu_entries&#039; );
</pre>
<p>The above code provides a simple solution, removed the two entries and also has a fallback for WordPress, smaller version 3.1. It is also conceivable that the removal is also connected with user rights</p>
<pre>if ( function_exists( &#039;remove_menu_page&#039; ) &amp;&amp; ! current_user_can( &#039;manage_options&#039; ) ) {</pre>
<p>so it would be possible to optimize the menu explicitly for a user.  Alternatively, the plug <a href="http://wordpress.org/extend/plugins/adminimize/">Adminimize</a> helps and facilitates the job via admin area.<br />
You can also read about this topic on <a href="http://devpress.com/blog/removing-menu-pages-from-the-wordpress-admin/">Justin's post</a>, but my post was an older draft and now was published - the topic is worth it.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2233/remove-menu-item-in-wordpress-admin-panel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Plugin to Style your Plugin on WordPress Admin with Default Styles!</title>
		<link>http://wpengineer.com/2226/new-plugin-to-style-your-plugin-on-wordpress-admin-with-default-styles/</link>
		<comments>http://wpengineer.com/2226/new-plugin-to-style-your-plugin-on-wordpress-admin-with-default-styles/#comments</comments>
		<pubDate>Tue, 31 May 2011 08:51:52 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2226</guid>
		<description><![CDATA[WordPress is developing fast - this also applies to the design of the backend. So it is important not to use your own styles in the admin area and use tags and classes of WordPress. This is the best way you can simplify your work as a developer and you don't have to test the [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress is developing fast - this also applies to the design of the backend. So it is important not to use your own styles in the admin area and use tags and classes of WordPress. This is the best way you can simplify your work as a developer and you don't have to test the design with every update. Unfortunately, there are quite extensive opportunities in the backend to implement the requirements. Several different classes and HTML structures are used. To be able to look up something this simple, I have developed a small Plugin, which tinkers in the development environment and quickly represents the necessary elements. Here you see two screenshots with the differences between version 3.1 and 3.2 of WordPress and the current contained elements of the Plugin.<br />
<span id="more-2226"></span><br />
<a href="http://wpengineer.com/wp-content/uploads/screenshot-1.png"><img src="http://wpengineer.com/wp-content/uploads/screenshot-1-201x1024.png" alt="" title="screenshot-1" width="201" height="1024" class="alignnone size-large wp-image-2227" /></a> <a href="http://wpengineer.com/wp-content/uploads/screenshot-2.png"><img src="http://wpengineer.com/wp-content/uploads/screenshot-2-204x1024.png" alt="" title="screenshot-2" width="204" height="1024" class="alignnone size-large wp-image-2228" /></a></p>
<p>You can find the Plugin in <a href="https://github.com/bueltge/WordPress-Admin-Style">Github</a> and it would be great if you expand it, add new ideas and possibilities to it: - <a href="https://github.com/bueltge/WordPress-Admin-Style">github.com/bueltge/WordPress-Admin-Style</a><br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2226/new-plugin-to-style-your-plugin-on-wordpress-admin-with-default-styles/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

