Testar Gutenberg

Ius no idque invidunt, cotidieque comprehensam sit cu. Vim in illum erant feugiat, ne nobis timeam percipitur mei. Vel aliquip perfecto reprimique ex, putant legimus qui ad. Te pertinax electram nam, te melius sapientem disputando sea, quod inermis ei nam. Pri at enim quodsi, graecis perpetua sea ne. Mel odio aliquip eu, in nam prima equidem.

Ut oratio malorum his, vix commune honestatis ea. Nam melius perfecto rationibus ne, quo no hinc patrioque sententiae, eos ancillae quaerendum conclusionemque ad. Utinam officiis conceptam vim an, paulo complectitur ei mea. Eu usu officiis consetetur. An est aliquam fabellas sententiae, at vero nominavi quo. Vis ei partem deterruisset delicatissimi.

testbild jag lånat från iis.se

tack o hej

Add custom javascript and CSS to WordPress admin

A conceptual example of how you could add css or javascript to your ”edit post” page in the WordPress dashboard.
I included an example of how you can ”send parameters” to the javascript file.

		$my_params = array(
		  'postid' => $current_id,
		wp_localize_script( 'my_js', 'MyParams', $my_params );

if ( class_exists( "MyClass" ) ) 
	$my_class = new MyClass();
	error_log( "MyClass missing" );

add_action( 'admin_init', array(&$my_class, 'admin_init') );
add_action( 'admin_print_styles-post.php', array(&$my_class, 'enqueue_css') );
add_action( 'admin_print_scripts-post.php', array(&$my_class, 'enqueue_js') );

WP Infobox

WP Infobox

Add an info box to current post. You can specify title, text and a bullet list, the info box will be automatically added to all single pages that display the_content.
Example of the result (That’s the ”More applications”-box):

Example of configuration from ”Write post”:


Shortcode Usage, another WordPress plugin by windyjonas

Have you ever been in a situation where you have site with lots of content, a theme with lots of shortcodes and you have no idea where those shortcodes are used and if it is safe to remove any of them?

With this plugin you can search through all content and list the posts, pages and CPTs that use a specific shortcode, with direct links to edit each post.

Download Shortcode Usage from wordpress.org

maxitems = 500;
	public function init() {
		add_management_page( __('Shortcode Usage', 'busu'), __('Shortcode Usage', 'busu'), 'read', 'shortcode-usage', array(&$this, 'shortcode_page') );

	public function shortcode_page() { ?>

posts " . "where post_content like '%[{$shortcode}%' " . "and post_status in ('publish', 'draft') " . "and post_type not in ('revision', 'attachment', 'nav_menu_item') " . "order by post_title " . "limit {$this->maxitems}"; $myrows = $wpdb->get_results( $q ); if ( ! empty( $myrows ) ) : ?>

Usage of shortcode []

post_type; ?> ID, '', '', $row->ID); ?> <a target="_blank" href="ID); ?>">post_title; ?> post_status; ?> post_date; ?>

<input type="text" name="shortcode" value="" /> <input type="submit" value="" />

Registered shortcodes

$function ) : ?>

<a href="">

<?php } } $bu_shortcode_usage = new BuShortcodeUsage(); add_action( 'admin_menu', array(&$bu_shortcode_usage, 'init') );

TextMate snippet for PRG-pattern in WordPress

This is free TextMate snippet day here at jonasnordstrom.se. Enjoy, and please let me know if there are any errors.

From wikipedia:

Post/Redirect/Get (PRG) is a web development design pattern that prevents 
some duplicate form submissions, creating a more intuitive interface for 
user agents (users). PRG implements bookmarks and the refresh button in a 
predictable way that does not create duplicate form submissions. 

image from wikipedia

PRG is the pattern to aim for when creating functionality for the WordPress backend (wp-admin). But it’s a pain to keep track of which hooks to use, how the redirection works and stuff like that.
Here’s a TextMate snippet that hopefully will be of some help.

Note: I will add nonce and update this post, just wanted to save the code somewhere when it was in front of me, you know how it is …

function ${1:function_name}_page() {

    if ( isset( $POST['action'] ) && !current_user_can( '${2:edit_page}' ) ) {
    } ?>

    <form action="edit.php" method="post">
        <input type="hidden" name="page" value="${1/\_/-/}-page" />
        <input type="hidden" name="action" value="${3:action-name}" />
        <input type="submit" value="${4:Button Text}" />
function $1() {
    if ( isset(\$_POST['action']) && \$_POST['action'] == '$3') {
        // Do your magic here

        \$location = admin_url() . "edit.php?page=" . $_POST['page'] . "&feedback=${5:Feedback+here}";

        \$status = 302;
        wp_redirect( \$location, \$status );
function add_$1_page() {
    add_management_page( '${6:Page Title}', '${7:Menu Title}', '${8:manage_options}', 
                  '${9:menu-slug}', '${1:function_name}_page' );

add_action( 'admin_init', '$1' );
add_action( 'admin_menu', 'add_$1_page' );

wpdb->delete() i WordPress 3.4

En av nyheterna i WordPress 3.4 är att metoden delete har tillkommit till wpdb-klassen. Tidigare fanns av någon anledning bara insert och update.
Enkelt exempel på hur den kan användas:
Vad jag vet finns det ingen inbyggd funktion för att ta bort alla förekomster av ett custom field, före WordPress 3.4 var man tvungen att göra en query direkt i databasen för att få till den funktionaliteten.

  function delete_post_meta_for_all( $meta_key ) {  
     global $wpdb; 
     return $wpdb->query( 
        $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s ",
           $meta_key ) ); 

Tyvärr måste man fortfarande göra något liknande, men syntaxen är lite mer ”WordPress”:

function delete_post_meta_for_all( $meta_key ) { 
   global $wpdb; 
   $result = $wpdb->delete( "$wpdb->postmeta" , 
      array( "meta_key" => $meta_key) , array( '%s' ) ); 


function delete( $table, $where, $where_format = null )
$table: table name
$where: A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be ”raw”.
$where_format Optional: An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of ’%d’, ’%f’, ’%s’ (integer, float, string). If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types.
return int|false The number of rows updated, or false on error.

Mer info här