Product URL without Type

Produkte in WooCommerce aufrufen, ohne den /product Slug in der URL.

Um Produkte in WooCommerce direkt aufzurufen, ohne den /product Slug in der URL zu haben, kann folgender Schnipsel verwendet werden:

add_filter('post_type_link',function($permalink, $post, $leavename){
    if (!gettype($post) == 'post') {
        return $permalink;
    }
  
    switch ($post->post_type) {
        case 'product':
            if( !strpos($permalink,'?') ){
                $permalink = get_home_url() . '/' . $post->post_name . '/';
            }
            break;
    }
 
    return $permalink;
},10,3);

add_action('pre_get_posts',function( $query ){
    global $wpdb;
 
    if(!$query->is_main_query()) {
        return;
    }
    $post_name = $query->get('pagename');

    $post_type = $wpdb->get_var(
        $wpdb->prepare(
            'SELECT post_type FROM ' . $wpdb->posts . ' WHERE post_name = %s AND post_type != \'attachment\' LIMIT 1',
            $post_name
        )
    );
 
    switch($post_type) {
        case 'product':
            $query->set('product', $post_name);
            $query->set('post_type', $post_type);
            $query->is_single = true;
            $query->is_page = false;
            break;
    }
});

Posts „Privat“ by Default – iOS App

Die Sichtbarkeit neuer Posts die aus der WordPress App erstellt werden automatisch auf Privat setzen:

add_action('post_submitbox_misc_actions',function(){
  global $post;
  
  if( 'publish' == $post->post_status ){
    $visibility = 'public';
    $i18n = __('Public');
    
  } elseif( !empty( $post->post_password ) ){
    $visibility = 'password';
    $i18n = __('Password protected');
    
  } elseif ( $post_type == 'post' && is_sticky( $post->ID ) ) {
    $visibility = 'public';
    $i18n = __('Public, Sticky');

  } else {
    $post->post_password = '';
    $visibility = 'private';
    $i18n = __('Private');
  }
  
  echo '<script type="text/javascript">(function($){'.
    'try{'.
      '$("#post-visibility-display").text("'.$i18n.'");'.
      '$("#hidden-post-visibility").val("'.$visibility.'");'.
      '$("#visibility-radio-'.$visibility.'").prop("checked", true);'.
    '} catch(err){}'.
  '})(jQuery);</script>';
});

Beleuchtung Dimmen

Das iPhone schnell in den Nachtmodus setzen um seinen Augen etwas gutes zu tun und obendrein auch noch die Akkulaufzeit zu verbessern:

  • Einstellungen / Allgemein / Bedienungshilfen / Zoom
    • Zoom aktivieren, mit drei Fingern dreimal auf das Display tippen.
    • Filter wählen, Dunkle Umgebung.
    • Zoomfenster, Vollbildzoom.
  • Einstellungen / Allgemein / Bedienungshilfen / Kurzbefehl
    • „Zoom“ wählen.

In Zukunft nun einfach dreimal hintereinander den Home Button drücken um schnell zwischen Nacht- und Tagmodus zu wechseln.

@import media query

CSS Code in Dateien auslagern und anhand von media queries anwenden.

CSS Code in Dateien auslagern und anhand von media queries anwenden. Übersichtliches Responsive Design!

@import url('css/global.css');

/* Small Portrait */
@import url('css/small-portrait.css') only screen and (max-width: 479px);

/* Small Landscape */
@import url('css/small-landscape.css') only screen and (min-width: 480px) and (max-width: 767px);

/* Medium Portrait */
@import url('css/medium-portrait.css') only screen and (min-width: 768px) and (max-width: 959px);

/* Normal */
@import url('css/normal.css') only screen and (min-width: 960px);

Details und Kompatibilität im Mozilla Developer Network

Code Snippets Shortcode

Ein Shortcode für das fantastische Code Snippets Plugin um Snippets aus diesem Plugin auch im Frontend darzustellen.

UPDATE: Fixed in Version 2.6.0

Ein Shortcode für das fantastische Code Snippets Plugin um Snippets aus diesem Plugin auch im Frontend darzustellen:

add_shortcode('snippet', function( $atts ){
  if( isset($atts['id']) ){
    $snippet = get_snippet( $atts['id'] );
  
      if( isset($snippet) ){
        if( class_exists('CrayonWP') ){
          return CrayonWP::highlight('<pre>'.htmlentities($snippet->code).'</pre>');
          
        } else {
            return '<pre>'.htmlentities($snippet->code).'</pre>';
        }
      }
  }
  
  return '';
});

Und der Feature Request, dieses Feature direkt in das Plugin zu integrieren.

Eureka ContactRow in Swift

A custom row for the elegant iOS form builder in Swift 2 called Eureka:

ContactRow

Select an existing contact from the iOS AddressBook using the new iOS 9 CNContact API – request for integration pending.

import Foundation
import Contacts
import ContactsUI
import Eureka


public class _ContactRow: Row<String,ContactCell> {
    required public init(tag: String?){
        super.init(tag: tag)
    }
}


public final class ContactRow: _ContactRow, RowType{

    required public init(tag: String?) {
        super.init(tag: tag)
        self.displayValueFor = nil
    }
}

public class ContactCellOf<T: Equatable>: Cell<T>, CellType, CNContactPickerDelegate {
    required public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }


    public override func setup(){
        super.setup()
        self.bindContact()
    }


    public override func update() {
        super.update()
        self.bindContact()
    }


    private func bindContact(){
        switch CNContactStore.authorizationStatusForEntityType(.Contacts){
        case .Authorized: //Update our UI if the user has granted access to their Contacts
            selectionStyle = row.isDisabled ? .None : .Default

            if let id = self.row.value as? String, let contact = contactFromIdentifier(id){
                detailTextLabel?.text = CNContactFormatter.stringFromContact(contact, style: .FullName)
            }

        case .NotDetermined: //Prompt the user for access to Contacts if there is no definitive answer
            CNContactStore().requestAccessForEntityType(.Contacts) { granted, error in
                dispatch_async(dispatch_get_main_queue()){
                    self.row.disabled = Condition.init(booleanLiteral: !granted)
                    self.selectionStyle = self.row.isDisabled ? .None : .Default

                    if granted, let id = self.row.value as? String, let contact = self.contactFromIdentifier(id){
                        self.detailTextLabel?.text = CNContactFormatter.stringFromContact(contact, style: .FullName)
                    }
                }
            }

        case .Denied, .Restricted:
            self.row.disabled = true
            selectionStyle = row.isDisabled ? .None : .Default
        }
    }


    private func contactFromIdentifier(identifier: String) -> CNContact?{
        do{
            return try CNContactStore().unifiedContactWithIdentifier(identifier, keysToFetch: [CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName)])

        } catch let error as NSError{
            NSLog(error.localizedDescription)
            return nil
        }
    }


    public override func didSelect() {
        super.didSelect()

        let controller = CNContactPickerViewController()
        controller.delegate = self

        self.formViewController()?.presentViewController(controller, animated: true, completion: nil)
    }


    public func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty){
        if contactProperty.contact.isKeyAvailable(CNContactIdentifierKey), let id = contactProperty.contact.valueForKey(CNContactIdentifierKey) as? T{
            self.row.value = id

        } else {
            self.row.value = nil
        }
    }
}
public typealias ContactCell = ContactCellOf<String>