Affichage des articles dont le libellé est Recent Questions - WordPress Development Stack Exchange. Afficher tous les articles
Affichage des articles dont le libellé est Recent Questions - WordPress Development Stack Exchange. Afficher tous les articles

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

Send email to different users depending on the field selected in woocommerce?

So, I've been searching high and low and I don't know if this is possible, but I figure this is the best place to try and see..

I have a checkout field added to my checkout page in woocommerce. It works great, the fields show up in the emails.

However, what I was hoping was that I could get it so that the emails could be sent out to various addresses depending on what field they chose... is that possible?

For example, if someone chose "contractor a" in a checkout page email, I would then want it to send to the woocommmerce admin (which it already does) AND contractoremail@email.com.

PLEASE let me know if any one has any ideas. I would greatly appreciate it.



via Chebli Mohamed

Access methods in plugin template

I'm new to PHP and trying to learn my way through Wordpress. Within my theme's functions.php file, I wanted to access a method available inside bbPress's plugin template.php file. I'm getting "Unexpected token ['

Inside bbPress plugin template.php:

function bbp_topic_reply_count( $topic_id = 0, $integer = false ) {
    echo bbp_get_topic_reply_count( $topic_id, $integer );
}

I'm accessing this function in my current theme's functions.php:

$count = bbp_topic_reply_count(125);

Do I have to include anything from the plugin (i.e bbpress/template.php)?

Thanks.



via Chebli Mohamed

Cannot change hover color for links

I am using twentytwelve and a child theme at http://ift.tt/1VA80aj.

I would like all links in my website to have this dark blue color on hover: #0f3647

The only links where this color is working is the post titles. These links, however, stay #21759b on hover no matter what I try:

  • After a post, the links for "Continue reading" and "X Replies"
  • The links under the "Recent Posts" widget on the right
  • The "Reply" links in the comment area under a post

Below is the exhaustive list I've tried adding to my child theme's style.css, and none of them have any effect. Somewhere, deep the soul-sucking abyss of CSS, the hover property is being overridden.

I tried a giant hammer:

a:hover {
    color: #0f3647 !important;
}

And I tried these (where #0fs647 is #21759b in the parent):

For "Continue reading" and "X Replies":

.more-link a:hover {
    color: #0f3647;
}

.leave-reply a:hover { 
    color: #0f3647;    
}

.reply-count a:hover {
    color: #0f3647;  
}

For the Recent Posts widget:

.widget-area .widget a:hover {
    color: #0f3647;
}

For the "Reply" in the comments area:

.comments-link a:hover {
    color: #0f3647;
}

I also tried:

.site-header h1 a:hover,
.site-header h2 a:hover {
    color: #0f3647;
}

.main-navigation a:hover,
.main-navigation a:focus {
    color: #0f3647;
}

Any suggestions?



via Chebli Mohamed

Making menu link open in new tab?

I'm trying to add a top level menu to the left sidebar of the WordPress admin panel.

Here's the code I currently have:

add_action( 'admin_menu', 'linked_url' );
function linked_url() {
add_menu_page( 'linked_url', 'Menu Title', 'read', 'my_slug', '', 'dashicons-text', 1 );
}

add_action( 'admin_menu' , 'linkedurl_function' );
function linkedurl_function() {
global $menu;
$menu[1][2] = "https://www.example.com";
}

This code DOES work and links the menu to an external page (https://www.example.com).

I learned how to do this from here: http://ift.tt/1OUiBbT

However, I can't figure out how to make the external link open in a new tab. I'd prefer than a new tab/window is opened so people don't lose what they already have open in their admin area.

Is there something I need to change or add? Or is it just not possible?



via Chebli Mohamed

Changing post status with js

I'm having issues grabbing some actions inside a navigation menu..

So it's going like this(for the publish button) HTML

 <a href="javascript:updatepost()" class="menu-item fa fa-facebook">Save</a>

 <script>
    function updatepost()
        {
          jQuery('#publish').click();
        };
 </script>

What i can't find tho it's to do the same(or something similar) for the "Move to Trash" and change the post status to 'pin_featured'

Any guidance it's much apreciated!



via Chebli Mohamed

Downloading File from Outside Web Root

I've set up some code to download zip files that exist in a folder above the web root. The download will be triggered from a user account page within WordPress. They don't need to be bank-level secure, but I'd like to prevent direct file access from outside the site and make them accessible only for users with the correct permission levels, and only from the appropriate user's account page. The site is entirely https.

The folder where the zip files reside is protected via htaccess.

Each user that's assigned to a specific user role will see a download link on their "Account" page:

if(current_user_can('download_these_files')){
    $SESSION['check'] = 'HVUKfb0IG1HIzHxJj5fZ';
    ?>
        <form class="user-file-download-form" action="/download.php" method="POST">
            <input type="submit" name="submit" value="Download File">
        </form>
    <?php
}

This form submits to download.php, which sits in the web root and includes some code that I've pieced together with help from Google.

session_start();
if( isset( $_POST['submit'] ) ){
    $check = $_SESSION['check'];
    if( $check === 'HVUKfb0IG1HIzHxJj5fZ' ){
        $file = /path/to/file/above/root.zip;
        header('Content-Description: File Transfer');
        header('Content-Type: application/zip');
        header('Content-Disposition: attachment; filename=' . basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile( $file );
        exit;
    }else{
        header( 'Location: http://ift.tt/1L3fW9F' );
}else{
    header( 'Location: http://ift.tt/1L3fW9F' );
}

This works perfectly. But I can't help but wonder if I should be doing something differently. I was hoping to get input on whether or not this implementation is prodcution-ready, or if I'm missing something important as this is the first time I'm attempting something like this.

Thank you.



via Chebli Mohamed

What would Repair and Optimize Wordpress Database do?

Recently I am getting an error establishing a database connection in a clients Wordpress site. I googled for a solution and an article suggested to enable Wordpress Repairs by adding this to the wp-config.php file:

define('WP_ALLOW_REPAIR', true);

After that, visit the link:

http://ift.tt/1ab1nSy

And allowing repair as follow:

WordPress Database Repair Tool UI

So my question is. What does optimization mean? What are those scenarios or situations that Wordpress fix? Can I do this procedure in existing and non problematic Wordpress websites to enhance performance?



via Chebli Mohamed

How to force acceptance of site terms on first login?

I want to force users to accept the terms and conditions of the site when they log in for the first time. I found a couple plugins that would show the terms, but they don't prevent you from ignoring the form and moving on to other site pages. Is there a way to prevent the user from going anywhere until they have accepted the terms?



via Chebli Mohamed

Wordpress loop, most recent post from multiple category in custom category order?

I have a site with posts in 16 categories ("departments"). The home page is a grid of the current (newest) post in each category.

I would like to create the HTML for displaying a department's current post and use a word press loop to repeat this 16 times to get the grid.

ALSO - and her is the part I need help with - the client wants to specify the categories AND the order they appear.

So, my page is the newest post from "Dining", then the newest from "travel", etc.

Here's the site currently where the previous designer did this by hand in a table every month, which is silly.



via Chebli Mohamed

Can someone tell me where I've gone wrong with this plugin's Settings page?

I've been trying to learn how to make a plugin in my spare time. I'd previously done all of the coding pertaining to the settings page and it all appeared to work well. Having completed some other parts of the test plugin I returned (a few weeks later) and now when I save adjustments to the settings I get shown a long list of database field names with associated input/textarea values returned but adjustments are not saved. I'm confident that nothing else is using add_action('admin_menu/admin_init')

The plugin is built as a class. Here's all the code relating to the settings page

class rifh_tester{

 public function __construct(){
  /* admin */
  if(is_admin()){
   add_action('admin_menu', array($this, 'settings_add_menu'));
   add_action('admin_init', array($this, 'settings_admin_init'));
  }
 }

 public function settings_add_menu(){
  add_options_page('RifH Tester Settings', 'RifH Tester', 'manage_options', 'rifh_tester', array($this, 'settings_opts_page'));
 }

 public function settings_opts_page(){
  echo '<div id="rifh-tester-setup"><form action="options.php" method="post">
       ' . settings_fields("rifh_tester_options") . do_settings_sections("rifh_tester") . '
       <input name="submit" type="submit" value="Save Changes">
       </form>
       </div>';
 }

 public function settings_admin_init(){
  register_setting('rifh_tester_options', 'rifh_tester_options', array($this, 'rifh_tester_options_validate'));
  add_settings_section('rifh_tester_options_main', __('Welcome to the RifH Tester Setup Page'), array($this, 'rifh_tester_options_text'), 'rifh_tester');
  add_settings_field('rifh_tester_option_image_generate', __('Test Creating An Image?'), array($this, 'rifh_tester_option_image_generate'), 'rifh_tester', 'rifh_tester_options_main');
  add_settings_field('rifh_tester_option_image_limit', __('Test Define An Image Size'), array($this, 'rifh_tester_option_image_limit'),  'rifh_tester', 'rifh_tester_options_main');
  add_settings_field('rifh_tester_option_appears_on', __('Where Should Test Images Show?'), array($this, 'rifh_tester_option_appears_on'),  'rifh_tester', 'rifh_tester_options_main');
  add_settings_field('rifh_tester_option_image_type', __('Preferred Format For Test Images?'), array($this, 'rifh_tester_option_image_type'), 'rifh_tester', 'rifh_tester_options_main');
 }

 public function rifh_tester_option_image_generate(){
  echo "<label><input id='rifh_tester_option_image_generate' name='rifh_tester_options[image_gen]' type='checkbox' ".($this->options['image_gen'] ? 'checked>Yes' : '>No')."</label>";
 }

 public function rifh_tester_option_image_limit(){
  echo "<label><input id='rifh_tester_option_image_limit' name='rifh_tester_options[image_lim]' type='text' value='{$this->options['image_lim']}'> Width of each Linky box in pixels.</label>";
 }

 public function rifh_tester_option_appears_on(){
  echo "<label><input id='rifh_tester_option_appears_on' name='rifh_tester_options[single]' type='checkbox' ".($this->options['single'] ? "checked>Yes" : ">No")."</label>";
 }

 public function rifh_tester_option_image_type(){
  $html = "<select id='rifh_tester_option_image_type' name='rifh_tester_options[image_type]'>";
  $values = array('png','jpg','gif');
  foreach($values as $format){
   $html .= "<option value='$format'";
   if($format == $this->options['image_type']){
    $html .= " selected";
   }
   $html .= ">$format</option>";
  }
  $html .= "</select>";
  echo $html;
 }

 public function rifh_tester_options_validate($input){
  $newinput = array();
  $newinput['image_gen'] = false;
  if(isset($input['image_gen'])){
   $newinput['image_gen'] = true;
  }

  if(isset($input['image_lim']) && preg_match('#^([1-9]([0-9]{1,2})?|1000)$#', $input['image_lim'])){
   // I've excluded private isFloat function as it's a basic function of the class
   if($this->isfloat($input['image_lim'])){
    $input['image_lim'] = round($input['image_lim'], 4);
   }
   $newinput['image_lim'] = $input['image_lim'];
  }

  if(isset($input['image_type']) && preg_match('#^(jpg|png|gif)$#', $input['image_type'], $match)){
   $newinput['image_type'] = $match[1];
  }

  $newinput['single'] = false;
  if(isset($input['single'])){
   $newinput['single'] = true;
  }
  return $newinput;
 }

 public function rifh_tester_options_text($args){
  echo "<div id='{$args['id']}'></div>";
 }
}

When I actually look at the HTML generated on the settings page it appears also that the <form> appears after all the fields and only has a Submit input. Making me think that the error is with the settings_opts_page function defined in the class but I can't see what it would be.

I've re-read all the guidance I can find on the Settings-API for WP, I can't understand what I'm doing wrong. Can anyone point me in the right direction?



via Chebli Mohamed

wpmu_new_user hook not firing

I have a WP Multisite setup with woocommerce on each of the sites. I am trying to hook into wpmu_new_user to send customer info to our CRM when they register at the checkout.

add_action('wpmu_new_user', 'send_to_crm',10,1);
function send_to_crm($user_id) {
    //function sends data to CRM, have tested this works by placing code direct into functions.php with hard coded $user_id variable
}

With this added to my child theme's functions.php and going through the checkout process nothing is submitted to the CRM but the order goes through as normal.

So a couple of questions: 1. Is this the right hook to use? 2. If yes, is there something wrong with my code?

Thanks in advance!



via Chebli Mohamed

WC - change From email only in the new order email

I want to change the From email when email about a new order is sending in WooCommerce. I know that I can use wp_mail_from filter but my issue is that I don't know how to determine that the WC_Email_New_Order email is sending and not some other one.

I tried something like this:

function prefix_set_from_email( $email ) {
    $mailer = WC()->mailer();
    $new_order_email = $mailer->emails['WC_Email_New_Order'];
    if ( null !== $new_order_email->object && is_email( $_POST['billing_email'] ) ) {
        $email = $_POST['billing_email'];
    }
    return $email;
}
add_filter( 'wp_mail_from', 'prefix_set_from_email', 50 );

But it change the address when WC_Email_Customer_Completed_Order email is sending too. Any advice? :)



via Chebli Mohamed

Remove Categories and Tags from Admin Dashboard

I'm using my own taxonomy for blog posts and would like to remove Categories and Tags from the Dashboard. I've removed them from the Admin Menu and the meta boxes on the Edit Posts page from this question here: Remove Categories / Tags From Admin Menu

But now I'm trying to remove it from the All Posts page in the Dashboard where it shows a list of all the posts in a table and across the top are Title, Author, Categories, Tags, Date, etc. I can't seem to find how to do this.



via Chebli Mohamed