lundi 25 avril 2016

Metabox save method dont work for me

I am trying to make a metabox class, everything is ok in my function method but my save method in my class dont work, someone please give me a solution where is the problem in my save function ? my code is given bellow

    <?php

if ( ! class_exists( 'Metabox_Library') ) :

/**
 * All Types Meta Box class.
 *
 * @package All Types Meta Box
 * @since 1.0
 *
 * @todo Nothing.
 */

class Metabox_Library
{

      /**
   * Holds meta box object
   *
   * @var object
   * @access protected
   */
    protected $meta_box;

  /**
   * Holds meta box fields.
   *
   * @var array
   * @access protected
   */
    protected $_prefix;

  /**
   * Holds Prefix for meta box fields.
   *
   * @var array
   * @access protected
   */
    public $fields = array();

  /**
   * Use local images.
   *
   * @var bool
   * @access protected
   */

   /**
   * $field_types  holds used field types
   * @var array
   * @access public
   * @since 2.9.7
   */
    public $field_types = array();



    public function __construct($metabox,$meta_fields) {
        // Assign meta box values to local variables and add it's missed values.
        $this->meta_box = $metabox;
        $this->prefix = (isset($metabox['prefix'])) ? $metabox['prefix'] : '';
        $this->fields = $meta_fields;

        foreach ($this->fields as $field) {
            $this->field_types = $field['type'];
        }
        // If we are not in admin area exit.
        if ( ! is_admin() )
          return;

        // Add metaboxes
        add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) );


            add_action('save_post', array($this, 'save_custom_meta'));
            // Must enqueue for all pages as we need js for the media upload, too.
        if ($this->is_edit_page()) {
            add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ) );
            add_action( 'admin_head', array($this,'add_custom_scripts'));
            }       


    }

    public function fields_type() {
        foreach ($this->fields as $field) {
            $this->field_types = $field['type'];
        }
    }

    public function add_metabox($postType) {
        if (in_array($postType, $this->meta_box['pages'])) {


            add_meta_box( $this->meta_box['id'], $this->meta_box['title'], array( $this, 'show_fields' ),$postType, $this->meta_box['context'], $this->meta_box['priority'] );


        }
    }

    public function show_fields() {

        global $post;
        $fields = $this->fields;
    // Use nonce for verification
    echo '<input type="hidden" id="custom_meta_box_nonce" name="custom_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';

        // Begin the field table and loop
        echo '<table class="form-table">';
        if (is_array($fields) || is_object($fields)) {

            foreach ($fields as $field) {
                // get value of this field if it exists for this post
                $meta = get_post_meta($post->ID, $field['id'], true);
                // begin a table row with
                echo '<tr>
                        <th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
                        <td>';
                        switch($field['type']) {

                            // text
                            case 'text':
                                echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
                                    <br /><span class="description">'.$field['desc'].'</span>';
                            break;
                            // textarea
                        case 'textarea':
                            echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
                                <br /><span class="description">'.$field['desc'].'</span>';
                        break;

                        // select
                        case 'select':
                            echo '<select name="'.$field['id'].'" id="'.$field['id'].'">';
                            foreach ($field['options'] as $option) {
                                echo '<option', $meta == $option['value'] ? ' selected="selected"' : '', ' value="'.$option['value'].'">'.$option['label'].'</option>';
                            }
                            echo '</select><br /><span class="description">'.$field['desc'].'</span>';
                        break;

                        // checkbox
                        case 'checkbox':
                            echo '<input type="checkbox" name="'.$field['id'].'" id="'.$field['id'].'" ',$meta ? ' checked="checked"' : '','/>
                                <label for="'.$field['id'].'">'.$field['desc'].'</label>';
                        break;

                        // radio
                        case 'radio':
                            foreach ( $field['options'] as $option ) {
                                echo '<input type="radio" name="'.$field['id'].'" id="'.$option['value'].'" value="'.$option['value'].'" ',$meta == $option['value'] ? ' checked="checked"' : '',' />
                                        <label for="'.$option['value'].'">'.$option['label'].'</label><br />';
                            }
                        break;
                        // checkbox_group
                        case 'checkbox_group':
                            foreach ($field['options'] as $option) {
                                echo '<input type="checkbox" value="'.$option['value'].'" name="'.$field['id'].'[]" id="'.$option['value'].'"',$meta && in_array($option['value'], $meta) ? ' checked="checked"' : '',' /> 
                                        <label for="'.$option['value'].'">'.$option['label'].'</label><br />';
                            }
                            echo '<span class="description">'.$field['desc'].'</span>';
                        break;
                        // tax_select
                        case 'tax_select':
                            echo '<select name="'.$field['id'].'" id="'.$field['id'].'">
                                    <option value="">Select One</option>'; // Select One
                            $terms = get_terms($field['id'], 'get=all');
                            $selected = wp_get_object_terms($post->ID, $field['id']);
                            foreach ($terms as $term) {
                                if (!empty($selected) && !strcmp($term->slug, $selected[0]->slug)) 
                                    echo '<option value="'.$term->slug.'" selected="selected">'.$term->name.'</option>'; 
                                else
                                    echo '<option value="'.$term->slug.'">'.$term->name.'</option>'; 
                            }
                            $taxonomy = get_taxonomy($field['id']);
                            echo '</select><br /><span class="description"><a href="'.get_bloginfo('url').'/wp-admin/edit-tags.php?taxonomy='.$field['id'].'">Manage '.$taxonomy->label.'</a></span>';
                        break;


                        } //end switch
                echo '</td></tr>';
            } 
        }// end foreach
        echo '</table>'; // end table
    }


    public  function save_custom_meta($post_id) {
            global $post_id;

            // verify nonce
            if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__))) 
                return $post_id;
            // check autosave
            if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
                return $post_id;
            // check permissions
            if (isset($_POST['page']) == isset($_POST['post_type'])) {
                if (!current_user_can('edit_page', $post_id))
                    return $post_id;
                } elseif (!current_user_can('edit_post', $post_id)) {
                    return $post_id;
            }

            // loop through fields and save the data
            foreach ($this->fields as $field) {
                $old = get_post_meta($post_id, $field['id'], true);
                $new = isset($_POST[$field['id']]);
                if ($new && $new != $old) {
                    update_post_meta($post_id, $field['id'], $new);
                } elseif ('' == $new && $old) {
                    delete_post_meta($post_id, $field['id'], $old);
                }
            } // end foreach
            if($field['type'] == 'tax_select') continue;
            // save taxonomies
          $post = get_post($post_id);
          $category = $_POST['category'];
          wp_set_object_terms( $post_id, $category, 'category' );
        }



    /**
   * Check if current page is edit page.
   *
   * @since 1.0
   * @access public
   */
     public function is_edit_page() {
        global $pagenow;
        return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
      }







}


 // End Class
endif; // End Check Class Exists



via Chebli Mohamed

WooCommerce plugin - AJAX and $_SESSION issues

I'm trying to build a plugin that adds some custom data to a WooCommerce order.

Essentially I'm loading a specific product page from a custom button where I have a url variable set (&my_post_var={INTEGER}). This var is then processed in the product page, displaying some specific information available within WordPress, and is working as intended.

From hereon, after pressing Add to Cart, some of the custom data is pushed to the cart session. The AJAX jQuery and PHP callback are both correctly ran and the jQuery response is also correctly populated using PHP $_SESSION variable.

The issue is after that, when the Cart page displays, where the data displayed is the one from the previous &my_post_var={INTEGER} value, not the last value that was being passed.

I'm not using any cache plugins, this is a local development wordpress installation.

Can someone help me out pinpointing what might be wrong here?

This is the part of the code that is probably more pertinent:

function __construct() {

    // AJAX callback    
    function my_ajax_custom_data_callback_inline () {
        session_start();
        print_r ($_POST);

        write_log ( 'Data inside AJAX callback: ');
        write_log ( ' - DEBUG: _POST data: '. $_POST['my_post_data'][0] ); // This outputs the expected value

        $_SESSION['my_meta_data'] = $_POST['my_post_data'];
        print_r ($_SESSION);

        write_log ( ' - DEBUG: _SESSION DATA: ' . $_SESSION['my_meta_data'][0] ); // This outputs the expected value

        wp_die();
    }

    // AJAX hooks
    add_action('wp_ajax_' . 'my_custom_data', 'my_ajax_custom_data_callback_inline', 1);
    add_action('wp_ajax_nopriv_' . 'my_custom_data', 'my_ajax_custom_data_callback_inline', 1);


    if ( isset( $_SESSION['my_meta_data'] ) ) { // this is not being verified as TRUE

        add_filter( 'woocommerce_add_cart_item_data', 'my_add_cart_item_data', 10, 2 );

        add_filter( 'woocommerce_get_cart_item_from_session', 'my_get_cart_items_from_session', 10, 3 );

        add_filter( 'woocommerce_get_item_data', 'my_get_item_data',  10, 2 );

        add_action('woocommerce_add_order_item_meta', 'my_add_values_to_order_item_meta',10,2 );

        add_action('woocommerce_before_cart_item_quantity_zero', 'my_remove_user_custom_data',10,1 );

    }

}

Thank you very much



via Chebli Mohamed

How to convert http to https

1st i want to convert my http domain to https domain and also yo non www to www domain through .htacccess.

1- http://ift.tt/1Tswiid ----> http://ift.tt/1VxbDNz

2- http://ift.tt/1VxbDNz ----> http://ift.tt/1Tswiif

i was coded:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^quickassignmenthelp\.co.uk$ [NC]
RewriteRule ^(.*)$ http://ift.tt/1VxbCcj [R=301,L]

# BEGIN EXPIRES
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 10 days"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/plain "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES



via Chebli Mohamed

Not working checkbox shortcode for wordpress visual composer

I'am making my own and first shortcode for visual composer, and in my functions.php I have:

add_shortcode( 'firsttag', 'firsttag_func' );
function firsttag_func( $atts ) {
   extract( shortcode_atts( array(
      // not important code,
      'checkboxRight' => !empty($checkboxRight) ? '' : 'pull-right',
   ), $atts ) );

   return   "<div class='col-md-12'>".
                "<div class='container container-about'>".
                    "<div class='row'>".
                        "<div class='container'>".
                            "<div class='col-md-6 {$checkboxRight}'>".
                                "<p class='subtitle'>{$beforefoo}</p>".
                                "<p class='title' style='color:{$color};' data-foo='${foo}'>{$foo}</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>";}

add_action( 'vc_before_init', 'your_name_integrateWithVC' );
function your_name_integrateWithVC() {
   vc_map( array(
      "name" => __( "PlayFair Heading box", "my-text-domain" ),
      "base" => "firsttag",
      "class" => "",
      "category" => __( "Content", "my-text-domain"),
      'admin_enqueue_css' => array(get_template_directory_uri().'/style.css'),
      "params" => array(
         array(
            "type" => "textfield",
            "holder" => "",
            "class" => "",
            "heading" => __( "PreHeading", "my-text-domain" ),
            "param_name" => "beforefoo",
            "value" => __( "", "my-text-domain" ),
            "description" => __( "Example: Before Name of the text block", "my-text-domain" )
         ),
         // not important arrays,
         array(
            "type" => "checkbox",
            "holder" => "div",
            "class" => "",
            "heading" => __( "Right screen position", "my-text-domain" ),
            "param_name" => "checkboxRight",
            "admin_label" => '',
            "value" =>  array( 'Yes please' => '1'),
            "description" => __( "", "my-text-domain" )
         ).......

I have checked my function part

'checkboxRight' => !empty($checkboxRight) ? ' ' : 'pull-right',

and it's working, but seems that I don't get good value from checkbox array

"admin_label" => '',
"value" => array( 'Yes please' => '1'),

any ideas why ?



via Chebli Mohamed

How to create a QR code Generator using php that has logo in its center, custon color and instead of bars it is made of dots?

I would like to create a wordpress plugin that will generate a qr code that instead of tiny bars it is made up of dots, and there will be a logo in its center. I have a php library to make a qr-code but it only create black and white traditional qr code.

Image

any one help pls.

respect pls



via Chebli Mohamed

Display subcategories in the filter on CPT

I have a little problem with my CPT. I created some categories with subcategories, and I wish display the subcategories in the select filter. Actually, the categories filter display only the first level of categories. I use this plugin, Custom Content Type Manager.

Categories filter:

enter image description here

Categories list:

enter image description here



via Chebli Mohamed

dimanche 24 avril 2016

Wordpress plugin to translate content of post or page

I want to find a plugin to translate content of post or page like base on .po file , not WPML because lot of paragraph has to reuse.



via Chebli Mohamed