lundi 5 octobre 2015

my wordpress site showing Out of memory error frequently

I have a WordPress site which is frequently showing out of memory error

i have also increased memory in config file

define('WP_MEMORY_LIMIT', '384M');

My php info file showing :

PHP Version 5.4.36 memory_limit 512M post_max_size 8M upload_max_filesize 4M

my error_log file showing below info. Please guide me how to resolve the issue of out of memory

[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 6029312) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/link-template.php on line 2533
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 8912896) (tried to allocate 78 bytes) in xxxxxxxx/public_html/wp-includes/kses.php on line 1750
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 4718592) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/class-wp-theme.php on line 256
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 7340032) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/category-template.php on line 519
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 6291456) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/post.php on line 1029
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 7602176) (tried to allocate 13440 bytes) in xxxxxxxx/public_html/wp-includes/comment.php on line 788
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 8126464) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 2309
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 9961472) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/taxonomy.php on line 822
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 6553600) (tried to allocate 4480 bytes) in xxxxxxxx/public_html/wp-includes/post.php on line 3233
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 8912896) (tried to allocate 78 bytes) in xxxxxxxx/public_html/wp-includes/kses.php on line 1750
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 2097152) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/default-filters.php on line 108
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 9437184) (tried to allocate 196608 bytes) in xxxxxxxx/public_html/wp-includes/script-loader.php on line 248
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 262144) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-load.php on line 56
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 262144) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-load.php on line 56
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 4718592) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/class-wp-theme.php on line 256
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 11272192) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/media.php on line 3020
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 11534336) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/class-http.php on line 1396
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 4456448) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/theme.php on line 591
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 14942208) (tried to allocate 1920 bytes) in xxxxxxxx/public_html/wp-content/plugins/wordpress-importer/wordpress-importer.php on line 420
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 10223616) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/taxonomy.php on line 2769
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 4980736) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/user.php on line 1149
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 12320768) (tried to allocate 87 bytes) in xxxxxxxx/public_html/wp-includes/post.php on line 1717
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 10223616) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/taxonomy.php on line 2769
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Out of memory (allocated 15990784) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-content/plugins/wp-postratings/postratings-stats.php on line 424
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Call to undefined function is_user_logged_in() in xxxxxxxx/public_html/wp-content/plugins/wp-fastest-cache/inc/cache.php on line 146
[05-Oct-2015 00:45:42 UTC] PHP Fatal error:  Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0
[05-Oct-2015 02:05:02 UTC] PHP Fatal error:  Out of memory (allocated 20447232) (tried to allocate 196608 bytes) in xxxxxxxx/public_html/wp-content/plugins/all-in-one-seo-pack/aioseop_utility.php on line 352
[05-Oct-2015 02:05:02 UTC] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/pdo_mysql.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/pdo_mysql.so: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 18874368) (tried to allocate 3840 bytes) in xxxxxxxx/public_html/wp-content/themes/hdwallpapers/functions.php on line 221
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 15466496) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-content/plugins/wp-postratings/wp-postratings.php on line 464
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 9961472) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/taxonomy.php on line 822
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 10747904) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/update.php on line 141
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Call to undefined function is_user_logged_in() in xxxxxxxx/public_html/wp-content/plugins/wp-fastest-cache/inc/cache.php on line 146
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 15990784) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-content/plugins/wp-postratings/postratings-stats.php on line 424
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Call to undefined function is_user_logged_in() in xxxxxxxx/public_html/wp-content/plugins/wp-fastest-cache/inc/cache.php on line 146
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 7602176) (tried to allocate 13440 bytes) in xxxxxxxx/public_html/wp-includes/comment.php on line 788
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 10223616) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/taxonomy.php on line 2769
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 18612224) (tried to allocate 32 bytes) in xxxxxxxx/public_html/wp-content/plugins/all-in-one-seo-pack/aioseop_class.php on line 620
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 10747904) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/update.php on line 141
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 11796480) (tried to allocate 9600 bytes) in xxxxxxxx/public_html/wp-includes/class-http.php on line 1526
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 8912896) (tried to allocate 78 bytes) in xxxxxxxx/public_html/wp-includes/kses.php on line 1750
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 14942208) (tried to allocate 1920 bytes) in xxxxxxxx/public_html/wp-content/plugins/wordpress-importer/wordpress-importer.php on line 420
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 10223616) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/taxonomy.php on line 2769
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 7864320) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 281
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 11796480) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/widgets.php on line 1391
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 13107200) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-content/plugins/ewww-image-optimizer/common.php on line 493
[05-Oct-2015 02:05:04 UTC] PHP Fatal error:  Out of memory (allocated 8650752) (tried to allocate 33280 bytes) in xxxxxxxx/public_html/wp-includes/kses.php on line 733
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 8388608) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/feed.php on line 529
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 7602176) (tried to allocate 13440 bytes) in xxxxxxxx/public_html/wp-includes/comment.php on line 788
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 7864320) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 281
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 7077888) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/post-template.php on line 1600
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 8388608) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/feed.php on line 529
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 7864320) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 281
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 7864320) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 281
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 12582912) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-content/plugins/ewww-image-optimizer/ewww-image-optimizer.php on line 511
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 11010048) (tried to allocate 196608 bytes) in xxxxxxxx/public_html/wp-includes/canonical.php on line 264
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 6815744) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/post.php on line 4961
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 1835008) (tried to allocate 690 bytes) in xxxxxxxx/public_html/wp-includes/wp-db.php on line 2146
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 8912896) (tried to allocate 72 bytes) in xxxxxxxx/public_html/wp-includes/kses.php on line 1750
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 12320768) (tried to allocate 72 bytes) in xxxxxxxx/public_html/wp-includes/post.php on line 1714
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 9175040) (tried to allocate 4480 bytes) in xxxxxxxx/public_html/wp-includes/deprecated.php on line 2223
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 9961472) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/taxonomy.php on line 822
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 8388608) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/feed.php on line 529
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 8126464) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 2309
[05-Oct-2015 02:09:36 UTC] PHP Fatal error:  Out of memory (allocated 6291456) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/post.php on line 993
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 2883584) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/formatting.php on line 183
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 3145728) (tried to allocate 196608 bytes) in xxxxxxxx/public_html/wp-includes/formatting.php on line 1158
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 4718592) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/class-wp-theme.php on line 256
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 5767168) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/link-template.php on line 141
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 4194304) (tried to allocate 196608 bytes) in xxxxxxxx/public_html/wp-includes/query.php on line 2794
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 3670016) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/capabilities.php on line 1235
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 3407872) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/formatting.php on line 3166
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 4980736) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/user.php on line 1300
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 2883584) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/formatting.php on line 183
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 8126464) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 2309
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 10747904) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/update.php on line 141
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 7077888) (tried to allocate 1280 bytes) in xxxxxxxx/public_html/wp-includes/post-template.php on line 1579
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 8650752) (tried to allocate 33280 bytes) in xxxxxxxx/public_html/wp-includes/kses.php on line 733
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 11796480) (tried to allocate 8960 bytes) in xxxxxxxx/public_html/wp-includes/class-http.php on line 1518
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 8126464) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 2309
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 9699328) (tried to allocate 79360 bytes) in xxxxxxxx/public_html/wp-includes/script-loader.php on line 532
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 9437184) (tried to allocate 196608 bytes) in xxxxxxxx/public_html/wp-includes/script-loader.php on line 248
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 8126464) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 2309
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 7077888) (tried to allocate 1280 bytes) in xxxxxxxx/public_html/wp-includes/post-template.php on line 1579
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 8912896) (tried to allocate 72 bytes) in xxxxxxxx/public_html/wp-includes/kses.php on line 1750
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 7864320) (tried to allocate 3072 bytes) in xxxxxxxx/public_html/wp-includes/comment-template.php on line 244
[05-Oct-2015 03:16:57 UTC] PHP Fatal error:  Out of memory (allocated 6029312) (tried to allocate 1280 bytes) in xxxxxxxx/public_html/wp-includes/link-template.php on line 2524
[05-Oct-2015 03:16:58 UTC] PHP Fatal error:  Out of memory (allocated 19660800) (tried to allocate 32 bytes) in xxxxxxxx/public_html/wp-includes/functions.php on line 1602
[05-Oct-2015 03:16:58 UTC] PHP Fatal error:  Out of memory (allocated 18087936) (tried to allocate 640 bytes) in xxxxxxxx/public_html/wp-content/plugins/all-in-one-seo-pack/aioseop_module_class.php on line 597
[05-Oct-2015 03:16:58 UTC] PHP Fatal error:  Out of memory (allocated 17825792) (tried to allocate 49152 bytes) in xxxxxxxx/public_html/wp-content/plugins/all-in-one-seo-pack/aioseop_class.php on line 2863
[05-Oct-2015 03:16:58 UTC] PHP Fatal error:  Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0
[05-Oct-2015 03:16:58 UTC] PHP Fatal error:  Out of memory (allocated 18612224) (tried to allocate 89 bytes) in xxxxxxxx/public_html/wp-content/plugins/all-in-one-seo-pack/aioseop_class.php on line 612
[05-Oct-2015 03:16:58 UTC] PHP Fatal error:  Out of memory (allocated 19922944) (tried to allocate 12288 bytes) in xxxxxxxx/public_html/wp-includes/template-loader.php on line 48



via Chebli Mohamed

Disable Garbage Collection?

I have a WP site which creates 500's errors for about 2% of Apache requests (mostly bots and crawlers). I'm not able to stack trace most of those requests with 500's neither to PHP or MySQL errors.

Is it good idea to disable a garbage collection (gc_disable()) for the whole WP site to prevent any memory leak caused by a theme or plugins?



via Chebli Mohamed

I want login using email not username wordpress front end

I want login using email not username wordpress front end

remove_filter('authenticate', 'wp_authenticate_username_password', 20);
function login_with_email_address($username) {
    $user = get_user_by_email($username);
    if(!empty($user->user_login))
        $username = $user->user_login;
    return $username;
}
add_action('wp_authenticate','login_with_email_address');



via Chebli Mohamed

Wordpress SMS API integration without plugin

I am struggling with SMS sending in WordPress without plugin, I have a, API, but that API is not working. Example:

function mysite_woocommerce_order_status_processing( $order_id ) {

$mobile="123456";

$url="****/api.php?username=******&password=1234&source=UPDATE&dmobile=".$mobile."&message='.$msg.' ";

$response = wp_remote_get( $url ); //print_r($response);

} add_action( 'woocommerce_order_status_processing','mysite_woocommerce_order_status_processing' );

I am struggling with above hook, I can send Email through that hook, but not SMS. It would be great if any WordPress developer help me out !

Getting SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data



via Chebli Mohamed

Is there a way to optimize function that is used for returning data in an ajax-call?

I've started creating some plugins (not offically deployed yet) (feel free to use it you want to), and now my goal is to include a custom post type and taxonomy and being able to use Advanced Custom Fields if wanted. The purpose of the plugin is to create a list based on custom taxonomy / custom post types and being able to put that anywhere on any page (with a shortcode) and when selecting anything from that list fetch content from the selected custom post type) and put it into another div without page reload.

This is my code (forgive the swedish part, but it's not neccessary I think for the actual question):

<?php
/*
Plugin Name: ListAjax
Plugin URI: http://ift.tt/1VAqyY1
Description: Display a list and display returned content (from ajax-call) into a div
Version: 0.8.0
Author: Wibergs Web
Author URI: http://ift.tt/1MVBmIx
License: GPL
Copyright: Wibergs Web
*/
defined( 'ABSPATH' ) or die( 'No access allowed!' );

if( !class_exists('listajax') ) {

class listajax
{
    private $errormessage = null;


    /*
    *  Constructor
    *
    *  This function will construct all the neccessary actions, filters and functions for the listajax plugin to work
    *
    *
    *  @param   N/A
    *  @return  N/A
    */  
    public function __construct() {                        
        //These are needed and should only register custom post types when really neccessary
        register_activation_hook( __FILE__, array( $this, 'activate' ) );                        
        add_action( 'init', array( $this, 'register_post_types' ) );

        //Iniate jquery and css
        add_action( 'wp_enqueue_scripts', array($this, 'js_css' ) );                             
    }


    /*
     *  error_notice
     * 
     *  This function is used for handling administration notices when user has done something wrong when initiating this object
     *  Shortcode-equal to: No shortcode equavilent
     * 
     *  @param N/A
     *  @return N/A
     *                 
     */                 
    public function error_notice() {
            $message = $this->errormessage;
            echo "<div class=\"error\"><strong>ListAjax error:</strong><p>$message</p></div>"; 
    }


    public function activate() {
            $this->register_post_types();
            flush_rewrite_rules(); 
    }


    /*
     *  register_post_types
     * 
     *  This function register post types and taxonomies
     * 
     *  @param N/A
     *  @return N/A
     *                 
     */                    
    public function register_post_types() {
        $municipality_labels = array(
              'name' => 'Kommun',
              'singular_name' => 'Kommun',
              'add_new' => 'Lägg till',
              'add_new_item' => 'Lägg till ny kommun',
              'edit_item' => 'Redigera kommun',
              'new_item' => 'Ny kommun',
              'all_items' => 'Alla kommuner',
              'view_item' => 'Visa kommun',
              'search_items' => 'Sök kommuner',
              'not_found' => 'Inga kommuner funna',
              'not_found_in_trash' => 'Inga kommuner funna i sopkorgen',
              'parent_item_colon'  => '',
              'menu_name' => 'Kommuner'
            );
            $municipality_args = array(
              'labels' => $municipality_labels,
              'public' => true,
              'publicly_queryable' => true,
              'show_ui' => true,
              'show_in_menu' => true,
              'query_var' => true,
              'rewrite' => array( 'slug' => 'kommun' ),
              'capability_type' => 'post',
              'has_archive' => 'kommuner',
              'hierarchical' => false,
              'menu_position' => null,
              'supports' => array('title','editor','author','comments'),      
            );
            register_post_type( 'municipality', $municipality_args );


            //Register custom taxonomy for distict
            $district_cat_labels = array(
              'name' => 'Område',
              'singular_name' => 'Område',
              'search_items' => 'Sök område',
              'all_items' => 'Alla områden',
              'parent_item' => 'Område - förälder',
              'parent_item_colon' => 'Föräldra område:',
              'edit_item' => 'Redigera område',
              'update_item' => 'Uppdatera område',
              'add_new_item' => 'Lägg till nytt område',
              'new_item_name' => 'Namn på nytt område',
              'menu_name' => 'Områden'     
            );
            $district_cat_args = array(
              'hierarchical' => true,
              'labels' => $district_cat_labels,
              'show_ui' => true,
              'show_admin_column' => true,
              'query_var' => true,
              'rewrite' => array('slug' => 'omraden')
            );
            register_taxonomy( 'district', array('municipality'), $district_cat_args );                        
    }

    /*
     *  init
     * 
     *  This function initiates the actual shortcodes (at each pageload)
     * 
     *  @param N/A
     *  @return N/A
     *                 
     */        
    public function init() {                           
        //Add shortcode
        add_shortcode( 'lajax-show', array($this, 'show') );
        add_shortcode( 'lajax-contactinfo', array($this, 'show_contactinfoblock') );

        //Initate ajax-functionality
        add_action( 'wp_ajax_set_contactinfo', array ( $this, 'set_resultdiv') );
        add_action( 'wp_ajax_nopriv_set_contactinfo', array ( $this, 'set_resultdiv') );
    }



    public function set_resultdiv() {                    
        $post_id = $_POST['post_id'];
        $post_info = get_post($post_id, ARRAY_A); //Array for better performance
        $post_content = $post_info['post_content']; //If there any content in post , then show this first

        $html .= $post_content;                        

        //If using ACF (Advanced Custom Fields plugin) with get_fields()-function
        if( function_exists( 'get_fields' ) ) {                            
            $fields_cpt = get_fields($post_id);

            if (is_array($fields_cpt)) {

                //Loop through fields of current post
                foreach($fields_cpt as $field_key => $field_value) {
                        //If field value starts with http, then take for granted it should be linked
                        if (substr($field_value, 0,4) === 'http') {
                                $new_fieldvalue = '<a target="_blank" href="' . $field_value . '">' . $field_value . '</a>'; 
                        }
                        else {
                                $new_fieldvalue = $field_value; //"Normal" value
                        }

                        //Get the label that user has typed in administration
                        $field = get_field_object($field_key, $post_id, array('load_value' => false));                                                        
                        $label = $field['label'];

                        //Do the actual output of each label and value 
                        //that is defined in ACF for the custom post type
                        $html .= '<span class="lajax-wrapper">';
                        $html .= '<span class="lajax-title">' . $label. '</span>';
                        $html .= '<span class="lajax-value">' . $new_fieldvalue . '</span>';
                        $html .= '</span>';
                }
            }              

        }

        echo $html;                        
        wp_die();
        return;
    }                

    public function js_css() {                       
       wp_enqueue_script(
               'listajaxjs',
               plugins_url( '/js/wibergsweb.js' , __FILE__)
       );                          
   }            

    public function show_contactinfoblock() {
        $html = '<div class="lajax-container">';
        $html .= '<div id="contactinfo"></div>';
        $html .= '</div>';
        return $html;
    }

    /*
     *  show
     * 
     *  This functions shows a list  based on a taxonomy (that is identified by slug)
     * 
     *  @param N/A
     *  @return string      date
     *                 
     */      
    public function show( $attrs ) {
        $defaults = array(
                'slug' => null, //Must be set by user!
                'result_div' => '#contactinfo'
        );                        

        //Extract values from shortcode and if not set use defaults above
        $args = wp_parse_args( $attrs, $defaults );
        extract( $args ); //slug = $args{'slug'] etc

        //Validation
        if ($args['slug'] === null) {
                $this->errormessage = 'Slug of district must be set - show()';
                add_action( 'admin_notices', array( $this,'error_notice' ) ); 
                return;
        }

        //Get posts of selected municaplity
        $posts_array = get_posts(
            array(
                'posts_per_page' => -1,
                'post_type' => 'municipality',
                'tax_query' => array(
                    array(
                        'taxonomy' => 'district',
                        'field' => 'slug',
                        'terms' =>  $args['slug']
                    )
                )
            )
        );

        //Create the actual selectlist based on selected district
        $result_div = $args['result_div'];

        $html = '<form name="ajaxlistform" class="ajaxlistform">';
        $html .= '<select class="ajaxlist" data-resultdiv="' . $result_div . '">';
        foreach($posts_array as $pa) {
            $id = $pa->ID;
            $title = $pa->post_title;
            $html .= '<option value="' . $id . '">' . $title . '</option>';                            
        }
        $html .= '</select></form>';

        return $html;             
    }

}        
$listajax = new listajax();
$listajax->init(); //Execute AFTER user defined settings are set
}

The result_div() - function is returning data to the javascript:

jQuery(function ($) {
    //Ajax-retrieve value from selected custom post type (that is shown in list)          
    $('.ajaxlistform').on('change', '.ajaxlist', function(e) {   
       var t = $(this);
       var post_id = $(this).val();  //Value from selectlist

        var listajaxvalues = $.ajax({            
            type: 'POST',
            data:{
                action: 'set_contactinfo',    
                post_id: post_id
            },
            url: '/wp-admin/admin-ajax.php',
            dataType: 'html'
        });

        //Put data into resultdata div that is set inte data-resultdiv attribute
        listajaxvalues.done(function(data) {
                var result_data = t.data('resultdiv');
                $(result_data).html(data);
                return;
        });                        

        listajaxvalues.fail(function(ts) {           
            alert(ts.responseText);
       });


    });

});

Is there a way to optimize (in terms of speed) the result_div() - function? It takes about a second to retrieve information. It does not sound like a lot of time, but when selecting from the selectlist, it seems like forever ;-)



via Chebli Mohamed

How to get popular post tags

I need to get post popular tags. Here what I found from http://ift.tt/1MVBmsj

$tag = wp_tag_cloud( 'smallest=8&largest=22&number=2&orderby=count&format=array' );

Here is an example from Wordpress site:

Cloud displayed under Popular Tags title

<?php if ( function_exists( 'wp_tag_cloud' ) ) : ?>    
<h2>Popular Tags</h2>
<ul>
<li><?php wp_tag_cloud( 'smallest=8&largest=22' ); ?></li>
</ul>    
<?php endif; ?>

I did not understand this parameters meaning smallest=8&largest=22 and does this example what I need?



via Chebli Mohamed

Give me some opinion about this theme!

Can anyone give me some suggestion about the the name of this theme or something like that on http://min.st319.vn ? Thank you so much!!!



via Chebli Mohamed