/*
* Initial statuses
*
* publish public
* future protected
* draft protected
* pending protected
* private private
* trash internal ( show_in_admin_status_list )
* auto-draft internal
* inherit internal ( ! exlude_from_search )
*/
// Custom Statuses
register_post_status('custom-publish', array(
'label' => 'Custom publié',
'label_count' => _n_noop('Custom publié <span class="count">(%s)</span>', 'Custom publié <span class="count">(%s)</span>'),
'public' => true,
));
register_post_status('custom-draft', array(
'label' => 'Custom brouillon',
'label_count' => _n_noop('Custom brouillon <span class="count">(%s)</span>', 'Custom brouillon <span class="count">(%s)</span>'),
'protected' => true,
//'show_in_admin_status_list' => false, // list "All (x) | Published (x) | ..."
//'show_in_admin_all_list' => false, // not listed on backend
));
// Prise en charge des custom statuses dans la box de publication
add_filter('admin_head', 'custom_statuses_in_submit_meta_box', 0);
function custom_statuses_in_submit_meta_box() {
global $wp_meta_boxes;
foreach(array_keys($wp_meta_boxes) as $key) {
if (isset($wp_meta_boxes[ $key ]['side']) && isset($wp_meta_boxes[ $key ]['side']['core'])
&& isset($wp_meta_boxes[ $key ]['side']['core']['submitdiv']) ) {
$wp_meta_boxes[ $key ]['side']['core']['submitdiv']['callback'] = 'post_submit_meta_box_with_custom_statuses';
}
}
}
function post_submit_meta_box_with_custom_statuses($post, $args) {
global $action;
ob_start();
call_user_func_array('post_submit_meta_box', func_get_args());
$html = ob_get_contents();
ob_end_clean();
// Récupération des status possible
$post_statuses = get_post_stati(array(
'internal' => false,
), 'objects');
unset($post_statuses['future']);
unset($post_statuses['private']);
// Mise à jour de la liste des status possible
$select_options = array();
foreach($post_statuses as $post_status) {
$selected = '';
if ($post->post_status == $post_status->name) {
$selected = 'selected="selected"';
}
$select_options[] = sprintf('<option value="%s" %s>%s</option>',
$post_status->name,
$selected,
$post_status->label
);
}
$select_options = implode("\n", $select_options);
$html = preg_replace(
'`' .
'(<select[^>]*post_status[^>]*>)' .
'.*' .
'(</select>)' .
'`Usm',
'$1' . $select_options . '$2',
$html
);
// Mise à jour du status actuel
if (isset($post_statuses[ $post->post_status ])) {
$html = preg_replace(
'`' .
'(<span[^>]*post-status-display[^>]*>)' .
'.*' .
'(</span>)' .
'`Usm',
'$1' . $post_statuses[ $post->post_status ]->label . '$2',
$html
);
}
echo $html;
}
// Affichage des custom statuses dans les listes de posts
add_filter('display_post_states', 'display_custom_post_states', 10, 1);
function display_custom_post_states($post_states ) {
global $post;
$post_status = (isset($_GET['post_status']) ? $_GET['post_status'] : 'publish');
if (empty($post_states) && $post->post_status != $post_status) {
if ($status = get_post_status_object($post->post_status)) {
$post_states[ $status->name ] = $status->label;
}
}
return $post_states;
}WP Custom Statuses support
WP Custom Post Type with archives per dates
/**
* Same arguments that `register_post_type()`
*
* -ttp://codex.wordpress.org/Function_Reference/register_post_type
* -ttp://seebz.net/notes/?note_id=145
*/
class Custom_Post_Type_With_Dates {
protected $_post_type;
protected $_args;
public function __construct( $post_type, $args = array() ) {
$this->_post_type = $post_type;
$this->_args = $args;
add_action('init', array(&$this, 'register_post_type'));
add_action('rewrite_rules_array', array(&$this, 'rewrite_rules_array'));
add_action('wp_loaded', array(&$this, 'wp_loaded'));
}
public function register_post_type() {
register_post_type($this->_post_type, $this->_args);
}
public function rewrite_rules_array( $rules ) {
$post_type = $this->_post_type;
if ( isset($this->_args['rewrite']) && is_array($this->_args['rewrite'])
&& isset($this->_args['rewrite']['slug']) ) {
$slug = $this->_args['rewrite']['slug'];
} else {
$slug = $post_type;
}
$new_rules = $this->_get_new_rules();
return ($new_rules + $rules);
}
public function wp_loaded() {
$test_key = current(array_keys($this->_get_new_rules()));
$rules = get_option('rewrite_rules');
if (!array_key_exists($test_key, $rules)) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
protected function _get_new_rules() {
$post_type = $this->_post_type;
if ( isset($this->_args['rewrite']) && is_array($this->_args['rewrite'])
&& isset($this->_args['rewrite']['slug']) ) {
$slug = $this->_args['rewrite']['slug'];
} else {
$slug = $post_type;
}
return array(
"{$slug}/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$" => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$" => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$" => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$" => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$" => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$" => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$" => 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/([0-9]{1,2})/?$" => 'index.php?year=$matches[1]&monthnum=$matches[2]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$" => 'index.php?year=$matches[1]&feed=$matches[2]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$" => 'index.php?year=$matches[1]&feed=$matches[2]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/page/?([0-9]{1,})/?$" => 'index.php?year=$matches[1]&paged=$matches[2]' . '&post_type=' . $post_type,
"{$slug}/([0-9]{4})/?$" => 'index.php?year=$matches[1]' . '&post_type=' . $post_type,
);
}
}
// Usage
new Custom_Post_Type_With_Dates('my-post-type', array(
'label' => 'My Posts Type',
'public' => true,
'show_in_menu' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'my-posts'),
'has_archive' => true,
)
);WordPress Tips (again)
Un plugin pour gérer les `Custom post type`
http://wordpress.org/extend/plugins/custom-post-type-ui/
Afficher les `Custom post type` et `Custom taxonomies` dans le widget `Aujourd'hui` du `tableau de bord`.
http://wpsnipp.com/index.php/functions-php/include-custom-post-types-in-right-now-admin-dashboard-widget/
Valeurs par défaut des `terms` d'un `(custom) post`
http://wordpress.mfields.org/2010/set-default-terms-for-your-custom-taxonomies-in-wordpress-3-0/
Afficher une date selon les préférences du site
<?php
echo date_i18n(get_option('date_format'), $mon_timestamp);
?>
Wordpress 3.1.3 a un bug au niveau des Média, le plugin suivant le corrige :
http://wordpress.org/extend/plugins/hotfix/
Afficher les requêtes SQL (debug mode) :
http://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis
WordPress Tip : `Custom post type` per page
/**
* Permet d'afficher un nombre différent d'éléments par page selon le post_type.
* Cette méthode permet le support de la pagination de Wordpress
*
* Il est aussi possible de spécifier le nombre d'éléments par page selon une
* taxonomie en testant l'existance (ou encore la valeur) de :
* $query->query['my_custom_taxonomy']
*/
function myCustomPostType_per_page($query) {
if (isset($query->query['post_type'])
&& $query->query['post_type'] == 'my_custom_post_type'
) {
$query->query_vars['posts_per_page'] = 5;
}
return $query;
}
add_filter('pre_get_posts', 'myCustomPostType_per_page');SSH/RSA
- Création des clés ssh-keygen -t rsa -C commentaire_de_cle - Soumissions des clés au serveur ssh-copy-id -i chemin_de_la_cle_rsa utilisateur@server_distant
"Get count of link shares" on Google Buzz
Working with shared links
Get count of link shares
http://code.google.com/intl/fr/apis/buzz/v1/using_rest.html#shared-links
ex: https://www.googleapis.com/buzz/v1/activities/count?alt=json&url=http://seebz.net/
Wordpress Theme Options
/**
* themeOptions
*/
if ( ! class_exists('themeOptions') ) :
class themeOptions {
/**
* @var string $name Le nom du thème
*/
var $name = 'My Theme';
/**
* @var string $prefix Prefix des options
*/
var $prefix = '_themeoptions_';
/**
* @var array $options Tableau des options du thème
*/
var $options = array(
array(
'name' => "Text",
'description' => "Ceci est une option `text`",
'id' => 'text',
'default' => 'text default value',
'type' => 'text', // text|textarea|nothing|radio|checkbox|select
'options' => array(
'size' => 20,
),
),
array(
'name' => "Textarea",
'description' => "Ceci est une option `textarea`",
'id' => 'textarea',
'default' => 'textarea default value',
'type' => 'textarea', // text|textarea|nothing|radio|checkbox|select
'options' => array(
'rows' => 5,
'cols' => 80,
),
),
array(
'name' => "Nothing",
'description' => "Ceci est une option `nothing`",
'type' => 'nothing', // text|textarea|nothing|radio|checkbox|select
),
array(
'name' => "Radio",
'description' => "Ceci est une option `radio`",
'id' => 'radio',
'default' => 'value2',
'type' => 'radio', // text|textarea|nothing|radio|checkbox|select
'options' => array(
'value1' => 'label 1',
'value2' => 'label 2',
),
),
array(
'name' => "Checkbox",
'description' => "Ceci est une option `checkbox`",
'id' => 'checkbox',
'default' => true,
'type' => 'checkbox', // text|textarea|nothing|radio|checkbox|select
),
array(
'name' => "Select",
'description' => "Ceci est une option `select`",
'id' => 'select',
'default' => '',
'type' => 'select', // text|textarea|nothing|radio|checkbox|select
'options' => array(
'' => '',
'value1' => 'label 1',
'value2' => 'label 2',
),
),
);
/**
* PHP 4 Compatible Constructor
*/
function themeOptions($options = array()) { $this->__construct($options); }
/**
* PHP 5 Constructor
*/
function __construct($options = array()) {
$this->options += $options;
add_action( 'admin_menu' , array( &$this, 'mytheme_add_admin' ) );
}
/**
* Thème Options - Affichage
*/
function mytheme_admin() {
$themename = $this->name;
$shortname = $this->prefix;
$options = $this->options;
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>' . $themename . ' settings saved . </strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>' . $themename . ' settings reset . </strong></p></div>';
if ( $_REQUEST['reset_widgets'] ) echo '<div id="message" class="updated fade"><p><strong>' . $themename . ' widgets reset . </strong></p></div>';
?>
<div class="wrap">
<h2><?php echo $themename; ?> Options</h2>
<form action="" method="post">
<table class="form-table">
<?php
foreach( $options as $value )
{
switch ( $value['type'] )
{
case 'text':
$opts = ( isset($value['options']) && is_array($value['options']) ? $value['options'] : array() );
$opts += array(
'type' => 'text',
'style' => 'width:100%',
'name' => $value['id'],
'id' => $value['id'],
'value' => htmlspecialchars(stripslashes($this->get_option($value['id']))),
);
$opts_str = '';
foreach($opts as $k => $v) {
$opts_str .= sprintf(' %s="%s"', $k, htmlspecialchars($v));
}
?>
<tr valign="top">
<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
<td>
<input <?php echo $opts_str; ?>/>
<?php echo $value['description']; ?>
</td>
</tr>
<?php
break;
case 'textarea':
$opts = ( isset($value['options']) && is_array($value['options']) ? $value['options'] : array() );
$opts += array(
'rows' => 5,
'cols' => 50,
'style' => 'width:100%',
'name' => $value['id'],
'id' => $value['id'],
'value' => htmlspecialchars(stripslashes($this->get_option($value['id']))),
);
$opts_str = '';
?>
<tr valign="top">
<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
<td><textarea <?php echo $opts_str; ?>><?php
echo htmlspecialchars(stripslashes($this->get_option($value['id'])));
?></textarea><br /><?php echo $value['description']; ?></td>
</tr>
<?php
break;
case 'nothing':
?>
<tr valign="top">
<th scope="row"><label><?php echo $value['name']; ?></label></th>
<td>
<?php echo $value['description']; ?>
</td>
</tr>
<?php
break;
case 'radio':
?>
<tr valign="top">
<th scope="row"><?php echo $value['name']; ?></th>
<td>
<?php
$current_value = $this->get_option($value['id']);
foreach( $value['options'] as $key => $option )
{
$checked = ($current_value == $key ? 'checked="checked"' : '');
?>
<input type="radio" name="<?php echo $value['id']; ?>" id="<?php echo $value['id'] . $key; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><label for="<?php echo $value['id'] . $key; ?>"><?php echo $option; ?></label><br />
<?php
}
?>
<?php echo $value['description']; ?></td>
</tr>
<?php
break;
case 'checkbox':
?>
<tr valign="top">
<th scope="row"><?php echo $value['name']; ?></th>
<td>
<?php
$checked = ($this->get_option( $value['id'] ) ? 'checked="checked"' : '');
?>
<input type="hidden" name="<?php echo $value['id']; ?>" value="" />
<input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="1" <?php echo $checked; ?> />
<label for="<?php echo $value['id']; ?>"><?php echo $value['description']; ?></label>
</td>
</tr>
<?php
break;
case 'select':
?>
<tr valign="top">
<th scope="row"><?php echo $value['name']; ?></th>
<td>
<select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
<?php
$current_value = $this->get_option($value['id']);
foreach( $value['options'] as $key => $option )
{
$selected = ($current_value == $key ? 'selected="selected"' : '');
?>
<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo htmlspecialchars($option); ?></option>
<?php
}
?>
</select>
<br /><?php echo $value['description']; ?>
</td>
</tr>
<?php
break;
default:
break;
}
}
?>
</table>
<p class="submit">
<input name="save" type="submit" value="Save changes" />
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post" action="">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
</div>
<?php
}
/**
* Thème Options - Sauvegarde
*/
function mytheme_add_admin() {
$themename = $this->name;
$shortname = $this->prefix;
$options = $this->options;
if( $_GET['page']==basename( __FILE__ ) )
{
if( 'save'==$_REQUEST['action'] ) {
foreach( $options as $value ) {
update_option( $this->prefix . $value['id'], $_REQUEST[ $value['id'] ] );
}
foreach( $options as $value ) {
if( isset( $_REQUEST[ $value['id'] ] ) ) {
update_option( $this->prefix . $value['id'], $_REQUEST[ $value['id'] ] );
} else {
delete_option( $this->prefix . $value['id'] );
}
}
header("Location: themes.php?page=functions.php&saved=true");
die;
} elseif( 'reset'==$_REQUEST['action'] ) {
foreach ($options as $value) {
delete_option( $this->prefix . $value['id'] );
}
header("Location: themes.php?page=functions.php&reset=true");
die;
} elseif ( 'reset_widgets'==$_REQUEST['action'] ) {
$null = null;
update_option( 'sidebars_widgets', $null );
header("Location: themes.php?page=functions.php&reset=true");
die;
}
}
add_theme_page( "{$themename} Options", "{$themename} Options", 'edit_themes', basename( __FILE__ ), array( &$this, 'mytheme_admin' ) );
}
/**
* Récuération d'un `themeOption`
*/
function get_option($id) {
$value = get_option($this->prefix . $id, null);
if (is_null($value)) {
foreach($this->options as $option) {
if ($option['id'] == $id) {
return $option['default'];
}
}
}
return $value;
}
} // End Class
endif;
// Chargement des `themeOptions`
if ( class_exists('themeOptions') ) :
$themeOptions_var = new themeOptions();
endif;
// Récupération d'un `themeOption`
if ( ! function_exists( 'get_theme_option' ) ) :
function get_theme_option($id) {
global $themeOptions_var;
return $themeOptions_var->get_option($id);
}
endif;
/**
* Fin `themeOptions`
*
*********************************************************************************************** */Wordpress Custom Fields
/**
* themeCustomFields
*
* -ttp://sltaylor.co.uk/blog/control-your-own-wordpress-custom-fields/
*/
if ( !class_exists('themeCustomFields') ) :
class themeCustomFields {
/**
* @var string $prefix The prefix for storing custom fields in the postmeta table
*/
var $prefix = '_customfields_';
/**
* @var array $postTypes An array of public custom post types, plus the standard "post" and "page" - add the custom types you want to include here
*/
var $postTypes = array( 'page', 'post' );
/**
* @var array $customFields Defines the custom fields available
*/
var $customFields = array(
array(
'name' => 'field_id',
'title' => "Nom du champs",
'description' => "description du champs.",
'type' => 'wysiwyg',
'scope' => array( 'page', 'post' ),
'capability' => 'edit_pages',
),
);
/**
* PHP 4 Compatible Constructor
*/
function themeCustomFields() { $this->__construct(); }
/**
* PHP 5 Constructor
*/
function __construct() {
add_action( 'admin_menu', array( &$this, 'createCustomFields' ) );
add_action( 'save_post', array( &$this, 'saveCustomFields' ), 1, 2 );
// Comment this line out if you want to keep default custom fields meta box
add_action( 'do_meta_boxes', array( &$this, 'removeDefaultCustomFields' ), 10, 3 );
}
/**
* Remove the default Custom Fields meta box
*/
function removeDefaultCustomFields( $type, $context, $post ) {
foreach ( array( 'normal', 'advanced', 'side' ) as $context ) {
foreach ( $this->postTypes as $postType ) {
remove_meta_box( 'postcustom', $postType, $context );
}
}
}
/**
* Create the new Custom Fields meta box
*/
function createCustomFields() {
if ( function_exists( 'add_meta_box' ) ) {
foreach ( $this->postTypes as $postType ) {
add_meta_box( 'my-custom-fields', 'Champs spéciaux', array( &$this, 'displayCustomFields' ), $postType, 'normal', 'high' );
}
}
}
/**
* Display the new Custom Fields meta box
*/
function displayCustomFields() {
global $post;
?>
<div class="form-wrap">
<?php
wp_nonce_field( 'my-custom-fields', 'my-custom-fields_wpnonce', false, true );
foreach ( $this->customFields as $customField ) {
// Check scope
$scope = $customField[ 'scope' ];
$output = false;
foreach ( $scope as $scopeItem ) {
switch ( $scopeItem ) {
default: {
if ( $post->post_type == $scopeItem )
$output = true;
break;
}
}
if ( $output ) break;
}
// Check capability
if ( !current_user_can( $customField['capability'], $post->ID ) )
$output = false;
// Output if allowed
if ( $output ) { ?>
<div class="form-field form-required">
<?php
switch ( $customField[ 'type' ] ) {
case "checkbox": {
// Checkbox
echo '<label for="' . $this->prefix . $customField[ 'name' ] .'" style="display:inline;"><b>' . $customField[ 'title' ] . '</b></label> ';
echo '<input type="checkbox" name="' . $this->prefix . $customField['name'] . '" id="' . $this->prefix . $customField['name'] . '" value="yes"';
if ( get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) == "yes" )
echo ' checked="checked"';
echo '" style="width: auto;" />';
break;
}
case "textarea":
case "wysiwyg": {
// Text area
echo '<label for="' . $this->prefix . $customField[ 'name' ] .'"><b>' . $customField[ 'title' ] . '</b></label>';
// WYSIWYG
if ( $customField[ 'type' ] == "wysiwyg" ) { echo '<div style="border:1px solid #DFDFDF;">'; }
echo '<textarea name="' . $this->prefix . $customField[ 'name' ] . '" id="' . $this->prefix . $customField[ 'name' ] . '" columns="30" rows="3">' . htmlspecialchars( get_post_meta( $post->ID, $this->prefix . $customField[ 'name' ], true ) ) . '</textarea>';
// WYSIWYG
if ( $customField[ 'type' ] == "wysiwyg" ) { echo '</div>'; }
// WYSIWYG
if ( $customField[ 'type' ] == "wysiwyg" ) { ?>
<script type="text/javascript">
jQuery( document ).ready( function() {
jQuery( "<?php echo $this->prefix . $customField[ 'name' ]; ?>" ).addClass( "mceEditor" );
if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
tinyMCE.execCommand( "mceAddControl", false, "<?php echo $this->prefix . $customField[ 'name' ]; ?>" );
}
});
</script>
<?php }
break;
}
default: {
// Plain text field
echo '<label for="' . $this->prefix . $customField[ 'name' ] .'"><b>' . $customField[ 'title' ] . '</b></label>';
echo '<input type="text" name="' . $this->prefix . $customField[ 'name' ] . '" id="' . $this->prefix . $customField[ 'name' ] . '" value="' . htmlspecialchars( get_post_meta( $post->ID, $this->prefix . $customField[ 'name' ], true ) ) . '" />';
break;
}
}
?>
<?php if ( $customField[ 'description' ] ) echo '<p>' . $customField[ 'description' ] . '</p>'; ?>
</div>
<?php
}
} ?>
</div>
<?php
}
/**
* Save the new Custom Fields values
*/
function saveCustomFields( $post_id, $post ) {
if ( !isset( $_POST[ 'my-custom-fields_wpnonce' ] ) || !wp_verify_nonce( $_POST[ 'my-custom-fields_wpnonce' ], 'my-custom-fields' ) )
return;
if ( !current_user_can( 'edit_post', $post_id ) )
return;
if ( ! in_array( $post->post_type, $this->postTypes ) )
return;
foreach ( $this->customFields as $customField ) {
if ( current_user_can( $customField['capability'], $post_id ) ) {
if ( isset( $_POST[ $this->prefix . $customField['name'] ] ) && trim( $_POST[ $this->prefix . $customField['name'] ] ) ) {
$value = $_POST[ $this->prefix . $customField['name'] ];
// Auto-paragraphs for any WYSIWYG
if ( $customField['type'] == "wysiwyg" ) $value = wpautop( $value );
update_post_meta( $post_id, $this->prefix . $customField[ 'name' ], $value );
} else {
delete_post_meta( $post_id, $this->prefix . $customField[ 'name' ] );
}
}
}
}
} // End Class
endif;
// Chargement des `themeCustomField`
if ( class_exists('themeCustomFields') ) :
$themeCustomFields_var = new themeCustomFields();
endif;
// Récupération d'un `themeCustomField`
if ( ! function_exists( 'get_theme_custom_field' ) ) :
function get_theme_custom_field($field, $inherit = false, $post_id = null) {
global $themeCustomFields_var;
$custom_field = $themeCustomFields_var->prefix . $field;
if (is_null($post_id)) {
$post_id = the_ID();
}
while ($current_post = get_post($post_id)) {
$ret = get_post_custom_values($custom_field, $current_post->ID);
$ret = (is_array($ret) ? $ret[0] : $ret);
if (trim(strip_tags($ret)) != '') {
return $ret;
}
$post_id = $current_post->post_parent;
if (!$inherit || !$post_id) {
break;
}
}
}
endif;
/**
* Fin `themeCustomFields`
*
*********************************************************************************************** */Wordpress, forcer l'installation d'extension si problèmes de droits
/** Forcer l’accès au système de fichiers direct
* Voir http://core.trac.wordpress.org/ticket/10205
*/
define('FS_METHOD', 'direct');
(à placer dans /wp-config.php)
Avoid the '32bits issues' with intval() in PHP
To convert a string to a number, and avoid the 32 bit issues of intval you can use:
<?php
$no = "214742780440" + 0;
var_dump($no); // float(214742780440)
?>
I used to intval() everything before entering it into the DB, but it seems impractical with values over 2147483647.
To get even better idea of how it validates, try this:
<?php
$no = "qwerty1234" + 0;
var_dump($no); // int(0)
?>
(source: http://www.php.net/manual/en/function.intval.php#89293)
HTML5 * Boilerplate
HTML5 Boilerplate est un template HTML/CSS/JS de tueurs pour développer des sites rapides, robustes et éprouvés pour le futur.
Après plus de deux ans de développement itératif, vous avez à disposition les meilleures des meilleures pratiques concernant : la normalisation cross-browser, les optimisations de performance mais également des fonctionnalités optionnelles comme l'Ajax cross-domain ou Flash. Un fichier .htaccess de base pour Apache vous fournit d'emblée les règles nécessaires pour la mise en cache et prépare votre site à servir des vidéos HTML5, utiliser @font-face, et active le gzip automatique.
Boilerplate n'est pas un framework, il ne vous force dans aucune philosophe de développement, il contient juste de bonnes astuces pour que votre projet démarre rapidement et du bon pied.
http://html5boilerplate.com/
http://html5boilerplate.com/mobile/
Wordpress WPML 2.0.4.1 - Gestion des menus traduits
Le bug est présent dans l'admin : `Apparence > Menus`
(les champs WPML ne fonctionnent pas correctement)
1) Editer le fichier `inc/wp_nav_menus/iclNavMenu.class.php`
2) Rechercher la méthode `nav_menu_language_controls()`
3) Dans la partie JS vers la fin de la fonction,
remplacer `jQuery('#update-nav-menu .publishing-action').before('...`
par `jQuery('#update-nav-menu .publishing-action').first().before('...`[Facebook] <fb:visible-to-connection> pour onglet iFrame
<?php
require 'facebook.php';
$app_id = "ID APPLI";
$app_secret = "CLE SECRETE";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
));
$signed_request = $facebook->getSignedRequest();
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
echo 'INTEGRATION QUAND L UTILISATEUR A LIKE';
} else {
echo 'INTE QUAND L'UTILISATEUR N'A PAS LIKE';
}
}
?>Récupérer facilement la favicon d'un site
Ctrl+D like Notepad++ in Komodo Edit
1) Afficher la fenêtre "Toolbox" : View > Tabs & Sidebars > Toolbox
2) Créer une macro : Clic droit dans Toolbox > Add > New Macro...
3) Titre : "Duplicate line/selection" (ou autre selon préférence)
4) Insérer la Macro (langage Javascript) :
// Duplicate Line or Duplicate Selection
komodo.assertMacroVersion(3);
if (komodo.view) {
komodo.view.setFocus();
}
var ke = komodo.editor;
if (ko.views.manager.currentView.scimoz.selText) {
// Copy the current selection
var selectionText = komodo.interpolate('%s');
var posStart = ke.currentPos;
ke.insertText(posStart, selectionText);
ke.setSel(posStart, posStart+selectionText.length);
} else {
ke.lineDuplicate();
}
5) Onglet "Key Binding" > "New Key Sequence" > "Ctrl+D" > "Add"Classement par pays/régions/provinces/communes - Google Geocoding API
http://forum.webrankinfo.com/classement-par-pays-regions-provinces-communes-google-geocoding-api-t128887.html
Geocode with Google Maps API v3
http://tech.cibul.org/geocode-with-google-maps-api-v3/
Address Component Types
http://code.google.com/intl/fr/apis/maps/documentation/geocoding/index.html#Types
Google Weather API
http://www.ycerdan.fr/developpement/google-weather-api/
http://www.google.com/ig/api?weather=Paris&hl=fr
http://www.google.com/ig/api?oe=utf-8&weather=Brussels,Belgium&hl=en
Obtenir des stats d'une url raccourcie GOO.GL
API non-officiel d'après les infos recueillies par @abraham (http://blog.abrah.am/2010/10/googls-shorten-api.html)
http://api.seebz.net/google/googl-history/?url=http://goo.gl/Sp8J
Installer WebSVN sur un hébergement mutualisé OVH
Générer facilement le QR Code d'une URL ...
... en utilisant la Google Chart API
http://chart.apis.google.com/chart?cht=qr&chs=100x100&choe=UTF-8&chld=H%7C0&chl=http://seebz.net/
http://chart.apis.google.com/chart?cht=qr&chs=100x100&chl=http://seebz.net/
List of Chart Parameters :
http://code.google.com/intl/fr/apis/chart/docs/chart_params.html
QR Code
http://fr.wikipedia.org/wiki/Code_QR
How to create QRcode
http://www.swetake.com/qr/qr1_en.html
Pattern PHP et caractères accentués
$str = 'Sébastien';
$pattern = '`^[a-zA-Z0-9]*$`';
preg_match($pattern, $str); // false
$str = 'Sébastien';
$pattern = '`^[\p{L}0-9]*$`';
preg_match($pattern, $str); // true
http://fr.php.net/manual/fr/regexp.reference.unicode.php
DOMContentLoaded and ondocumentready and onreadystatechange!
minmax.js : (min|max)-(width|height) CSS Property for IE6
JavaScript Getters and Setters
JavaScript Getters and Setters
http://ejohn.org/blog/javascript-getters-and-setters/
Experiment: JS Getters/Setters in IE7, IE6, etc.
http://antimatter15.com/wp/2010/02/experiment-cross-browser-javascript-getters-and-setters/
http://jsbin.com/oriqo/15/edit
http://msdn.microsoft.com/en-us/library/dd229916%28VS.85%29.aspx
