Webbsajterna A-Z

Hög tid för en uppdatering av det här inlägget från 2008

Skriv in hela alfabetet a till z, bokstav för bokstav, i webbläsarens adressruta och notera det första alternativet som kommer upp som förslag.

Här är mina och de ger en kusligt välomfattande bild av min vardag.

aftonbladet.se
beta.facebook.com
customer.glesys.com
dn.se
expressen.se
facebook.com
gmail.com
hd.se
iis.se
jonasnordstrom.se
kiva.org
landskronabois.com
momondo.com
netflix.se
ombord.sj.se
paypal.com
reddit.com
sj.se
tomattrick.org
uk.hotels.com
viaplay.se
youtube.com
zapier.com

Jonas tipsar 25 Mars 2013

 

[fastsocial]

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.

<?php
class MyClass {
	function admin_init() {
		wp_register_style( 'my_css', get_stylesheet_directory_uri() . 
			'/css/my_class.css' );
		wp_register_script( 'my_js', get_stylesheet_directory_uri() . 
			'/js/my_class.js', 'jquery', '1.0.6', true );
	}
 
	function enqueue_css() {
		wp_enqueue_style( 'my_css' );
	}
 
	function enqueue_js() {
		wp_enqueue_script( 'my_js' );
 
		// Add current post id as a javascript variable.
		global $post;
		$current_id = empty( $post ) ? '' : $post->ID;
		$my_params = array(
		  'postid' => $current_id,
		);
		wp_localize_script( 'my_js', 'MyParams', $my_params );
	}
}
 
if ( class_exists( "MyClass" ) ) 
	$my_class = new MyClass();
else
	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') );

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 …

<?php 
function ${1:function_name}_page() {

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

    <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}" />
    </form>
    <?php
}
function $1() {
    if ( isset(\$_POST['action']) && \$_POST['action'] == '$3') {
        // Do your magic here
        $0;

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

        \$status = 302;
        wp_redirect( \$location, \$status );
        exit;
    }
}
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' );
Sida 1 av 2012345...1020...Sista »