This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$header = array('Accept-Language: en'); | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl, CURLOPT_HEADER, false); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); | |
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query1 = new WP_Query($arg1); | |
$query2 = new WP_Query($arg2); | |
$query = new WP_Query(); | |
$query->posts = array_merge( $query1->posts, $query2->posts ); | |
// we also need to set post count correctly so as to enable the looping |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
require_once( ABSPATH . 'wp-admin/includes/image.php' ); | |
if(isset($_FILES['photo']['name']) && !empty($_FILES['photo']['name'])){ | |
//Upload la photo dans le dossier | |
$uploadedfile = $_FILES['photo']; | |
$movefile = wp_handle_upload($uploadedfile, array('test_form' => false)); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function custom_excerpt_length( $length ) { | |
return 30; | |
} | |
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Compter le nombre de view | |
// Utiliser wpb_set_post_views($postID) dans toutes les pages à compter les views (single.php) | |
function wpb_set_post_views($postID) { | |
$count_key = 'wpb_post_views_count'; | |
$count = get_post_meta($postID, $count_key, true); | |
if($count==''){ | |
$count = 0; | |
delete_post_meta($postID, $count_key); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function truncate($str, $len){ | |
$strArray = explode(' ', $str); | |
if(count($strArray) > $len){ | |
$str = array_slice($strArray, 0, $len); | |
return implode(' ', $str) . '...'; | |
}else{ | |
return $str; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function dirToArray($dir) { | |
$result = array(); | |
$cdir = scandir($dir); | |
foreach ($cdir as $key => $value){ | |
if (!in_array($value,array(".",".."))){ | |
if (is_dir($dir . DIRECTORY_SEPARATOR . $value)){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//1. Add a new form element... | |
add_action('register_form','myplugin_register_form'); | |
function myplugin_register_form (){ | |
$first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: ''; | |
?> | |
<p> | |
<label for="first_name"><?php _e('First Name','mydomain') ?><br /> | |
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wp_get_productcat_postcount($id) { | |
//return $count; | |
$args = array( | |
'post_type' => 'product', //post type, I used 'product' | |
'post_status' => 'publish', // just tried to find all published post | |
'posts_per_page' => -1, //show all | |
'tax_query' => array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function catCount($slug){ | |
global $wpdb; | |
$query = " | |
SELECT COUNT( DISTINCT cat_posts.ID ) AS post_count | |
FROM gh_term_taxonomy AS cat_term_taxonomy INNER JOIN gh_terms AS cat_terms ON | |
cat_term_taxonomy.term_id = cat_terms.term_id | |
INNER JOIN gh_term_relationships AS cat_term_relationships |