lundi 30 novembre 2015

WP body classes are removed

After installing several components to speed up my WP project, my body classes are removed (eg. page-id-1452). It says "lp-none" for every page.

I am suspicious of mod_pagespeed Apache module.

Anyone has seen something like this before?



via Chebli Mohamed

Uploading images to plugins/my_plugin/images

I'm writing a plugin (my first) that needs to let a user upload images to an images folder within the plugin folder. I'm not finding the tools to do this though, like the prompt to browse the local machine for the image. I know I can upload images with the dashboard Media function, but those images end up in wp-content/uploads folder.

I'd also like to create a thumbnail of the image, so the upload would put two images into the folder.

Can someone suggest the best way to do this?

Thanks



via Chebli Mohamed

Update WordPress Yoast SEO term meta

I need to update the term_meta for Yoast SEO. I can get it through the function wpseo_get_term_meta() but I can't find a function to update this value. Any ideas?



via Chebli Mohamed

Wordpress youtube JS on load blocks loading time

Ok so its finally my turn to make a post: Right now I have a theme with youtube slider, fact is the youtube slider has 12 videos, and that makes the website load in about 10-12 seconds, which is crazy as hell. Now looking simply at GTmetrix I have realized even tho its only pictures that open the videos on-click (you know, after you click that funny youtube video and it starts playing), youtube loads around 1MB of JS at page load per video in the slider, all at once. Imagine my surprise realizing I have extra 12MB on page load... from outer source that is not even my server. Long story short, is there any NORMAL plugin, that can show on a page 12 videos, while only loading 1 video per time, after page load, without downloading the entire 1MB of crazyness as outer source from youtube, but just showing a picture and then just on-click downloading those sources?

PLEASE SAVE ME? You'll get cookies



via Chebli Mohamed

PHP: Issues with rename() and move_upload_file() functions

I have a fairly simple file up-loader I've built for WordPress. I have an issue with the conditional statement below.

Strangely this condition is met with uploads which are small in size, however when I attempt to upload a larger file the function breaks on this condition.

if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $fullPath)) {
  echo "The file " .  basename($_FILES['uploadedfile']['name']) . " has been uploaded";
} else {
  echo "Unknown error uploading file";
}

I have various other conditions which are all being met, including a file size check. Does anyone have any clues as to what is wrong here? I've also tried the rename() function in place of move_uploaded_file().



via Chebli Mohamed

Wordpress unexpected $wpdb error

I am trying to develop my first WP full plugin / widget example. My problem occurs when I added a function to delete pluguin table from database. But when I delete my plugin an error shown unexpected $wpdb. I didn't understand exactly the problem, I used almostthe same function to create table.

I am sorry because I am new in the Wordpress developement plugins.



via Chebli Mohamed

How can I automatically post on my wordpress website photos that I took in my iPad?

The idea is to post into a Gallery on my website photos that I took with my iPad automatically using plugins. Or a workaround to achieve that functionality.

Thank you!



via Chebli Mohamed

how to turn off sliding responsive menu in wordpress responsive select menu plugin?

I am using WP Responsive Select Menu plugin in wordpress and I have responsive menu while watching the website in the mobile devices.

In my IOS based phone, the responsive menu opens automatically when I scroll the screen to left (and sometimes also when I scroll down).

I don't want the menu to load on sliding the screen to left or right. Any idea how to do that??



via Chebli Mohamed

Prevent translation of wordpress plugin from being updated

I translated a plugin of wordpress into Japanese by myself and I am afraid that when I update the plugin, I have to translate these codes again and it takes very long time. Is there a way to prevent these codes from being updated?



via Chebli Mohamed

Remove portfolio & portfolio_tag from Wordpress URL

I am using WordPress Finanza theme but my custom post url are http://ift.tt/1OpVZPY and we added posts in custom tag so those pages are visible on http://ift.tt/1NidVXu. I dont want 'portfolio' or 'portfolio_tag' in the URL.

I have tried different plugins but nothing worked.



via Chebli Mohamed

Creating product page in wordpress

First: I have very little knowledge in WordPress, but i'm doing fine with frontend, PHP and mySQL.

What I have, is a list of products, each product belongs to a category and has:

  1. name
  2. picture
  3. description
  4. list of specifications
  5. list of links

I want to create posts or pages(?) for these products (no need to .

Where and how do I begin to create a "system" that will add this ability to my wordpress them?
My theme is an empty one, the most basic them.

I don't ask for the code of course, but i have no idea where to start? What terms to google? How to approach it?

thanks



via Chebli Mohamed

Select ID and post_title using WP_Query using post_fields filter

My Wp_query Is followin

$args = array(
    'post_type' => DR_QUES_POST_TYPE_QUESTIONNAIRE,
    'posts_per_page' => -1,
    'post_status' => 'publish',
    'tax_query' => array(
        array(
            'taxonomy' => 'course-data',
            'field'    => 'slug',
            'terms'    => $name
        ),
    ),
);
$query = new WP_Query( $args );

I want you fetch only Post ID and post_title fields using posts_fields filter.

If any suggestion then give me idea.



via Chebli Mohamed

dimanche 29 novembre 2015

Grab all specific articles (regarding health) in the top search results of google

I'm using a wordpress and would like to know if it's possible to grab some top articles based on search result of google.

I only know RSS. Is there an API for it?



via Chebli Mohamed

subporduct is not adding into cart in woocommrece product bundle

I am using woocommerce Product Bundles extension and I have a parent (bundle) product with two sub-products.

1 of them is simple product but other is variable product having 2 attributes and 12 variations

I am having difficulties in adding parent product into cart due to this variable product.

I get this error "PARENT_PRODUCT" cannot be added to the cart. Please choose "SUB_PRODUCT" options…

that is weired because for this sub product I have set variations defaults. and if I add this sub product individually it adds to cart successfully.

anyone know what I am doing wrong?



via Chebli Mohamed

Adding property tag to link rel='stylesheet'

Would appreciate some help from the coding ninjas here.

I've been trying to get HTML validation and have been getting one last error.

A plugin is inserting this line of code into the area:

<link rel='stylesheet' id='comments_evolved_tabs_css-css' href='http://ift.tt/1Pmwro4' type='text/css' media='all'/>

To pass validation I just need to add the property='stylesheet' tag within that line. However for the life of me I can't figure out how to do that.

If you need access to the plugin files, they are located at http://ift.tt/1jsDm0I

Please help!



via Chebli Mohamed

Wordpress - mysql_query(): Access denied for user 'www-data'@'localhost' (using password: NO) error on production server

I'm getting a warning message when I enable wordpress debug mode.

Warning: mysql_query(): Access denied for user 'www-data'@'localhost' (using password: NO) in /var/www/html/blog/wp-content/plugins/test/manage_registrations.php on line 46

Warning: mysql_query(): A link to the server could not be established in /var/www/html/blog/wp-content/plugins/test/manage_registrations.php on line 46

PHP code:

$extrawhere1=" order by id desc LIMIT $start, $limit";
$sqlSearch="select * from visa where 1=1 $extrawhere $extrawhere1";
$query="select * from visa where 1=1 $extrawhere order by id desc ";
$_SESSION['export_data']=$query;

$num=@mysql_num_rows(mysql_query($query));
$select_product=mysql_query($sqlSearch);

I tried using

$select_product=$wpdb->query($sqlSearch);

But i'm still getting error message. This error is only appearing on production server and not on local server.



via Chebli Mohamed

wordpress rewrite rule added to custom plugin functions.php not work

Hello in my custom plugin i want to set custom rewrite rules. First i trying make this with one rule, so i create functions.php file in my plugin folder and i paste into this code:

    function xnineres_rewrite_rules() {
        add_rewrite_rule('^xnineres/([a-z]+)/?$','index.php?page_id=63&action=$matches[1]','top');
    }
    add_action('init', 'xnineres_rewrite_rules');

My custom plugin frontpage url was create thru wp-admin adding page and he look like this

http://ift.tt/1LHgZLw

When i go to rewrite target page via simple url http://ift.tt/1PlW0Wg WP automatically change url in browser address bar to http://ift.tt/1LHgZLz and loaded page is correct.

But why when i use in address bar url from rewrite_rule [http://ift.tt/1PlW0Wi] i got 404 page?

Also when i try do this thru .htaccess file (when rewrite is still enabled in WP), not everything is good. Using http://ift.tt/1PlW0Wi url WP automatically redirect to http://ift.tt/1LHgZLw so he completly skips the variables of url query. This also it happens when i change in my .htaccess file rule from ^xnineres/([a-z]+)/$ to ^([a-z]+)/$. Now when i use http://ift.tt/1LHh1TK WP automatically redirect to page http://ift.tt/1LHgZLw

I really don't understand why this it happen. Can sombody help do this correctly?



via Chebli Mohamed

How is this plugin creating multiple pages within the same plugin?

I'm extending an already existing plugin called Anspress. I'm new to wordpress/web dev and I can't figure out how the author makes different pages show up without creating different page templates. These images show how there is only 1 page template in the dashboard using a single shortcode. Within this "page" created by the plugin, there are links to load other sections of the plugin, such as user profiles, individual questions and their responses, and the main question list.

In a nutshell, his code layout is as follows:

main.php
{
    require_once 'FileA.php'
    require_once 'FileB.php'
    require_once 'FileC.php'
    require_once 'FileD.php'
    /// Etc...


}

None of the files above are ask.php, which is the PHP file used to hold the HTML for the ask-question page. Yet he can still make this ask.php file somehow generate the page when a user clicks on the "Ask a question" button. How does this work? Below is the code for ask.php

<?php
// Some comment about the HTML code below


?>
<div id="ap-ask-page" class="clearfix">
    <?php if (ap_user_can_ask()): ?>
        <div id="answer-form-c">
            <div class="ap-avatar ap-pull-left">
                <a href="<?php echo ap_user_link(get_current_user_id()); ?>"<?php ap_hover_card_attributes(get_current_user_id()); ?>>
                    <?php echo get_avatar(get_current_user_id(), ap_opt('avatar_size_qquestion')); ?>
                </a>
            </div>
            <div class="ap-a-cells clearfix">
                <div class="ap-form-head">
                    <a href="#" class="apicon-screen-full pull-right ap-btn-fullscreen" data-action="ap_fullscreen_toggle"><?php _e('Toggle fullscreen', 'ap'); ?></a>
                    <ul class="ap-form-head-tab ap-ul-inline clearfix ap-tab-nav">
                        <li class="active"><a href="#ap-form-main"><?php _e('Write', 'ap'); ?></a></li>
                        <?php if(ap_opt('question_help_page') != '') : ?>
                            <li><a href="#ap-form-help"><?php _e('How to ask', 'ap'); ?></a></li>
                        <?php endif; ?>
                    </ul>
                </div>
                <div class="ap-tab-container">
                    <div id="ap-form-main" class="active ap-tab-item">
                        <?php ap_ask_form(); ?>
                    </div>
                    <div id="ap-form-help" class="ap-tab-item">
                        <?php if(ap_opt('question_help_page') != ''): ?>
                            <?php ap_how_to_ask(); ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    <?php elseif (is_user_logged_in()): ?>
        <div class="ap-no-permission">
            <?php _e('You don\'t have permission to ask question.', 'ap'); ?>
        </div>
    <?php endif; ?>
    <?php ap_get_template_part('login-signup'); ?>
</div>



via Chebli Mohamed

Wordpress - Own Plugin - Custom Table Search

I have created my own plugin in Wordpress. The plugin retrive data from the database and displays it in the Wordpress table.

Database table structure: (id, name, email, status)

I extend class WP_List_Table and I want to add search_box to my table. When I've added that and fill search input and click search button it's dupplicated (I have now two search_box form) and my search results displayed only in the first page, second generate results that not match to my search string.

How can I resolve this problem? - Don't show second search_box after click search button, - After click next page shows me a rest of search result instead records who don't match the search string

My plugin code:

index.php - http://ift.tt/1jr2hla
calss/config.php - http://ift.tt/1XoMUg1
class/recommend-list.php - http://ift.tt/1jr2hlc

PS. How can I change selected row status and update it in database. I have a few status string ('new', 'read', etc.) - maybe this status string be added by the admin panel (status taxonomy?)?



via Chebli Mohamed

unexpected $wpdb / unexpected '$row' (T_VARIABLE) in

I am using wordpress 4.3.1 and I want to develop a simple example of widget. So I started with creating a plugin and then my widget class that extends WP_Widget. Moreover, I tried to add new table in database when the plugin is activated. Until now everything is ok and the widget shown in the widget admin zone and the table is added in my database. But the uninstall function don't drop the table from my database.

Furthermore, I added a same mail function in my widget classe to save the user mail in the database, but an error shown :

Plugin could not be activated because it triggered a fatal error. Parse error: syntax error, unexpected '$row' (T_VARIABLE) in ...

This is my enter file code:

class Wis_Plugin extends WP_Widget{

    public function __construct(){      

        include_once plugin_dir_path( __FILE__ ).'/newsletter.php';
        include_once plugin_dir_path( __FILE__ ).'/newsletterwidget.php';
        register_activation_hook(__FILE__, array('Wise_Newsletter_Widget', 'install'));

        //add_action('wp_loaded', array('Wise_Newsletter_Widget', 'save_email'));

        new Wise_Newsletter();
        //define('WP_DEBUG', true);
        add_action('admin_menu', array('Wise_Newsletter', 'add_admin_menu'), 20);
        register_uninstall_hook(__FILE__,array('Wis_Plugin','uninstall') );
    }


    public static function uninstall(){
        global $wpdb;
        $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}another_wise_newsletter_email;");
    }
}

new Wis_Plugin();

This is the enter file plugin, I used Wis_Plugin() to execute this class constructor, this is a little bit weird to don't be executed automatically.

My newsletter.php file is the following:

    class Wise_Newsletter{
    public function __construct()
    {
        add_action('widgets_init', function(){register_widget('Wise_Newsletter_Widget');});
        register_activation_hook(__FILE__, array('Wise_Newsletter_Widget', 'install'));


}

My widget class looks like this:

class Wise_Newsletter_Widget extends WP_Widget{

public function __construct()
{

    parent::__construct('wise_newsletter', 'Newsletter', array('description' => 'newletter inscription fomr.'));
}


public function widget($args, $instance)
{
    echo $args['before_widget'];
    echo $args['before_title'];
    echo apply_filters('widget_title', $instance['title']);
    echo $args['after_title'];
    ?>
    <form action="" method="post">
        <p>
            <label for="wise_newsletter_email">Your email :</label>
            <input id="wise_newsletter_email" name="wise_newsletter_email" type="email"/>
        </p>
        <input type="submit"/>
    </form>
    <?php
    echo $args['after_widget'];
}
public function form($instance)
{
    $title = isset($instance['title']) ? $instance['title'] : '';
    ?>
    <p>
        <label for="<?php echo $this->get_field_name( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo  $title; ?>" />
    </p>
    <?php
}
public static function install()
{
    global $wpdb;
    $wpdb->query("CREATE TABLE IF NOT EXISTS {$wpdb->prefix}another_wise_newsletter_email (id INT PRIMARY KEY, email VARCHAR(255) NOT NULL);");
}


public function save_email()
{
    if (isset($_POST['wise_newsletter_email']) && !empty($_POST['wise_newsletter_email'])) {
        global $wpdb;
        $email = $_POST['wise_newsletter_email'];
 
        $row = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}another_wise_newsletter_email WHERE email = '$email'");
        if (is_null($row)) {
            $wpdb->insert("{$wpdb->prefix}another_wise_newsletter_email", array('email' => $email));
        }
    }
}

}

So to sum up my problems:

  1. Why wordpress did not execute automatically my plugin enter file (the folder and the file contains the same name).
  2. why the uninstall function does not work.
  3. And what is the probleme with unixpected $row error.

Thank you



via Chebli Mohamed

samedi 28 novembre 2015

Wordpress debugging in actions/filters

I am developing a custom plugin in Wordpress. My plugin is dependent on other plugin (Event Calendar). I am calling certain hooks and filters of Event Calendar in my hooks but I am not able to debug or print_r my variables in that function. I tried setting WP_DEBUG to TRUE in wp-config.php, but that didn't helped. Currently, I am using mail function to get variable values. Is there any other way to print the variables?



via Chebli Mohamed

Get sql data using search box in wordpress

i want to do,using search box find data in wordpress database and display it in page,using contact form 7 i upload data in wp database,i use some php code for display data in page,it works but,i dont know how to do it using search box

get_results( "SELECT * FROM it_testtable "); /*mulitple row results can be pulled from the database with get_results function and outputs an object which is stored in $result */ //echo "
"; print_r($result); echo "
"; /* If you require you may print and view the contents of $result object */ echo "ID"." "."Name"."

"; foreach($result as $row) { echo $row->id." ".$row->name."
"; } /* Print the contents of $result looping through each row returned in the result */ ?>

please help me get out of this..thank you



via Chebli Mohamed

How to remove path from Wordpress theme

first of all I want to keep clear that I search for the answer but without solution.

All Wordpress pages, below the title, we find:

Home/Services Home/About

How to remove this?



via Chebli Mohamed

how can I use php function link as html href tag

I downloaded wordpress plugin bmi-bmr-calculator. The plugin displays menu at the left side and saved history at the bottom.

I want to remove left menu. I check plugin files and found that this method of php is calling BMI link of left menu bar:

<li><a id="bmi" href="#" data-formPath="<?php echo plugins_url( 'includes/bmi_form.php' , __FILE__ ); ?>">BMI</a></li>

When I'll remove the left menu then I must need this link to call BMI calculator page.

How can I convert this link as an simple HTML

Best regards



via Chebli Mohamed

Upload files in wordpress dashboard

I have been testing a lot plugins but cant find the solution.

I want to upload files from entries editor, something simple as click on button browser the file and upload to /uploads/ folder.

SImple as that, but all the plugins are developed to do that from front-end(blog users can upload files).

Some files are more than 50mb.

Any hint?



via Chebli Mohamed

How to set request headers in WordPress Rest API calls

Hi am new to WP development, I would like to add request headers to WordPress Rest API calls but don't know how, can anyone help me in this?

I tried following code but no luck

$args = array( 'headers' => array( 'Authorization' => 'Basic ' . base64_encode( Fk-Affiliate-Id . ':' . YOUR_PASSWORD ) ) );

    $api_url = 'http://ift.tt/1Q4a6KB';
    global $affiliate;
    $response = wp_remote_request( add_query_arg( array(
        'Affiliate-Id' => $affiliate['aff-id'],
        'Affiliate-Token'     => $affiliate['aff-token']
    ), $api_url ) , array( 'timeout' => 10));



via Chebli Mohamed

PHP: need this exact position of string with a wildcard

First of all, thank you for reading this post and trying to help me. I am pretty new to php and i have some struggle.

I have created a filter in wordpress which should check two conditions. the filter is working fine however i have ran it some problems.

this is my code

     function em_validate($result, $EM_Event){

        if ($_REQUEST['em_tickets'] > 1 && $_REQUEST['booking_comment'] == ''){
        $EM_Event->add_error('Something');  
        $result = false; 
     }
     return $result;
    }

add_filter('em_booking_validate','em_validate', 1, 2);

This filter works fine, however the content of $_REQUEST['em_tickets']) is something like

<p><strong>23</strong></p><ul><li>5</li></ul><p></p>

can you come with some suggestions how i can read whats inbetween <li> and </li>

thank you for reading this post and coming with suggestions



via Chebli Mohamed

vendredi 27 novembre 2015

Wordpress using WP Printable Gift Certs, are gift certificates able to be customized?

I'm using WordPress 4.3.1 with plugin WP Printable Gift Certs. After purchase of a gift certificate the recipient is emailed a printable gift certificate that looks like this: enter image description here

My questions are:

  1. Are these sent to the recipients email from Paypal or the plugins php?
  2. And is it able to be customized with a logo and background in either case?

I've searched the php files for the plugin but I haven't found anything that I recognize as being a certificate (name fields, amount fields, etc,.) that is being assembled and emailed. I'm very lost but I want to customize the gift certificates.



via Chebli Mohamed

wp_head and wp_footer hook not working

I have make one custom theme options plugin and following code put in plugin file

add_action( 'init', 'test_head_footer_init' );
function test_head_footer_init() {
    add_action( 'wp_head', 'childtheme_favicon'); 
    add_action( 'wp_footer', 'childtheme_analytics');
}

function childtheme_favicon() {
        $shortname =  get_option('of_shortname'); 
        if (get_option($shortname . '_custom_favicon') != '') {
            echo '<link rel="shortcut icon" href="'.  get_option($shortname .'_custom_favicon')  .'"/>'."\n";
        }
}

function childtheme_analytics(){
    $shortname =  get_option('of_shortname');
    $output = get_option($shortname . '_google_analytics');
    if ( $output <> "" ) 
        echo stripslashes($output) . "\n";
}   

When i have run my code and check in home url page head tag nothing is print. same in footer.

Can you please guide me what i have mistake..

Thanks in advance.



via Chebli Mohamed

WP plugin isssue - Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App's settings

I have a Premium SEO Pack – Wordpress Plugin installed and with its Facebook planner, we are supposed to authorize app after providing the initial settings.

I have provided all the settings correctly. Provide app id, app secret, app domain, site url (through add platform), settings->advanced->enabled browser oAuth login, provided Valid OAuth redirect URI http://ift.tt/1XwL5bm .

But still I get the "Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains." error.

Also its not on localhost, but production server.

I know this is a duplicate thread but none of the solutions mentioned there helped me.

I would appreciate your help. Thank you!



via Chebli Mohamed

Wordpress: WpPageNavi only show first page

I have a custom page where I have two loops, I already tried WpPagiNavi and WpPaginate Plugin, the first one only appears when I set to "Always show pagination".

My query:

<?php 
  /* Template Name: Noticias */
  get_header(); 
?>
<!-- ================================== END HEADER -->
  <section id="content" class="row">
    <header class="column large-12 small-12">
      <h1 class="intTitle">Notícias</h1>
      <p class="siteLocal">Home > Notícias</p>
    </header>

    <section class="noticiasDestaque">

    <?php
      $taxonomy = 'category';
      $taxonomy_terms = get_terms( $taxonomy, array(
          'hide_empty' => 0,
          'fields' => 'ids',
          'slug' => 'destaque'
      ) );

      $loop = new WP_Query( array(
          'posts_per_page' => 3,
          'tax_query' => array(
              array(
                  'taxonomy' => $taxonomy,
                  'field' => 'id',
                  'terms' => $taxonomy_terms,
              ),
          ),
      ) );
      while ( $loop->have_posts() ) : $loop->the_post(); 
    ?>
      <a href="<?php the_permalink(); ?>">
        <article class="noticiaDestaque column large-4 medium-12 small-12">
          <div class="box">
            <div class="info">
              <p class="data"><?php the_time('d/m/Y'); ?></p>
              <h1><?php the_title(); ?></h1>
            </div>
            <div class="hover"></div>
            <?php if ( has_post_thumbnail()) : ?>
              <?php the_post_thumbnail( 'noticiadestaque-interna' ); ?>
            <?php endif; ?>
          </div>
        </article>
      </a>
      <!-- END ITEM -->
      <?php endwhile; ?>
      <?php wp_reset_query(); ?>



        <?php 
            $paged = get_query_var('paged') ? get_query_var('paged') : 1;
            #$paged = (get_query_var('paged')) ? get_query_var('paged') : (get_query_var('page') ? get_query_var('page') : 1 );

            $args = array(
                         //  'post_type' => 'post',
                           'posts_per_page' => 6,
                           'paged' => $paged,
                           'post_parent' => $parent
                        );
            $my_query = new WP_Query($args);

            if($my_query->have_posts()):
                while($my_query->have_posts()):$my_query->the_post();

          ?>
      <article class="listaNoticia column large-6 medium-6 small-12">
        <a href="<?php the_permalink(); ?>">
          <p class="data"><?php the_time('d/m/Y'); ?></p> <br><br>
          <h2><?php the_title(); ?></h2>
        </a>
      </article>
      <!-- END ITEM -->
<?php endwhile; endif; ?>

<div class="paginacao column large-12 medium-12 snall-12">
      <div>

        <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>

        <?php if(function_exists('wp_paginate')) { wp_paginate(); } ?>

        <?php wp_reset_query(); ?>


      </div>
    </div>

    </section>
  </section>
<!-- ================================== END CONTENT -->
<?php get_footer(); ?>

I'm tried already to put one at time, and both at the same time.

If I change the url for /page/2/ the pagition works when the page is loaded

Thanks!



via Chebli Mohamed

Change CSS values with WordPress backend UI elements

I have seen in most premium WordPress themes, backend user is allowed to change CSS properties such as background-color, font-color, font-family, just withing the backend using certain UI elements.

There's a color picker on the Appearance section and user can change the color of the particular element and save it.

I'm building a small wordpress theme, and I'd like my users also could change CSS values such way.

So, what's the way of doing it ?

Is it something like file writing ? Or dynamic ? (storing CSS in the database? )

`Thanks!



via Chebli Mohamed

How do I display the date format in custom post types?

Right now it displaying like this : 1447718400 I want it to display like this 04.12.2015

<span class="post-date"><?php echo(types_render_field('date', array('raw' => true) )); ?></span>



via Chebli Mohamed

Wordpress How to include a plugin

I am new to wordpress theme development. I have started creating a wordpress theme from scratch, just by creating a folder, an index, header,footer,functions,style pages. I have called the header and footer functions from index page and i have the header page as follows..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://ift.tt/pWm1pE">
<html xmlns="http://ift.tt/lH0Osb" <?php language_attributes() ?>>
<head profile="http://gmpg.org/xfn/11">
<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen,projection" />

<?php wp_head(); ?>

</head>

<body>

<div id="wrapper">

I have installed a plugin called WP Code Highlight.js .. i have activated it also.. but i cant use it in the page. Is there any code to include all activated plugins? Is there something i have missed?I need to have the activated plugins..



via Chebli Mohamed

designmodo qards plugin with custom types

I bought the absolutely awesome plugin for Wordpress called Qards. It works like a charm except I can't see how I can use it with custom post types. Anyone has a solution? Thanks. F



via Chebli Mohamed

jeudi 26 novembre 2015

How to modify table cart Woocomerce?

First image

I wonna modify cart-item-data to inline such as :
color : white
size : M
I have code below.
Second image



via Chebli Mohamed

Enqueue jquery-ui elements in Wordpress theme option page

Well, I know this is a commonly asked question, but almost all of them like '2 or 3 years ago'. Since Wordpress had some serious core changes recently, thought it'd be better to get an updated answer.

What I wanted to do is add this jquery slider to my wordpress custom admin page.

enter image description here

In today's Wordpress, is jquery-ui coming in built ? or I do need to include it using wp_enqueue_script or I should use some external url CDN?

Since I'm working on Wordpress 4.2, could you please tell me the proper way of adding this functionality?

Thanks!



via Chebli Mohamed

Create custom merge tag for Day, Month and Year of Date field in Gravity Forms

I'm using Gravity Forms Plugin for forms in WordPress site. Gravity Forms have have lots of merge tag by default for various field.

Gravity Forms have Date Field for inserting date but merge tag shows like this: {Date:1} but I need separate merge tag for Day Month and Year of Date field.

Is it possible?



via Chebli Mohamed

Wordpress: "permission denied in /home/xxx/public_html/" Installation Failed

Friends I am working on Education Oriented Website http://helpbase.in from past fews days and now i am edge of complate all aspects of this website but now i facing problem during time of installing plugins on my Wordpress website.

Error is: "Unable to install plugins, Permission Denied in /home/xxx/public_html/plugins" Installation Failed.

So i tried changing permissions manually and it also works until the next installation. Is there something i can do? i mean, it's not really proper solution to this error because it's consuming time lots every time of installing any kind of plugins. i want install plugins likes Facebook Plugin, Google Sitemaps, Table of Contents etc.

Website Development Environments: Wordpress: 4.3.1, Theme: Thesis 2.1, Server Permission: 577



via Chebli Mohamed

How to play m3u8 in wordpress

I know there is a jw player plugin for wordpress that can play m3u8 files. I know how to play mp4 files, but m3u8 is different. There are articles that say it can only play in iOS and android. But there are sites that i visited on windows and the video played.

Here is a link of site that does work

Can someone help me, i am stuck here for a wile.



via Chebli Mohamed

Posts not showing category and tag wise in wordpress

I am facing an issue in my wordpress theme! I am using Master study wordpress theme! Every thing is working fine , but when i click on categories or tag link it show me nothing on the clicked category/tag page

In this website woo-commerce is also installed, Product categories and tags are working fine, but in posts section i am facing this issue

I also tried with re-activating some plugins !

But nothing works! Give me some suggestion how can i fix it!

Plz help me ! Thanks



via Chebli Mohamed

mercredi 25 novembre 2015

WooCommerce add to cart not working on mobile site or loading description

Hey probably sounds like a repeat questions. Tried all the solutions on stackoverflow but seem not to get the answer.

http://ift.tt/1Q0lJ52 (no adult nudity on this site)

Only does not run on mobile . You cant add anything to the cart nor click anywhere on that page to load description for instance.



via Chebli Mohamed

How can i show woocomerce single product page in popup with these options

I need guidance please help. this is my first wp woocommerce customization project.

enter image description here



via Chebli Mohamed

paginate custom post type in single page WordPress

I have two custom posts type :

  • School
  • teacher

and there are connected using post 2 post plugin. so when I display a school single page school-single.php, it's show me school informations and list of teachers working in this school. everything working great. for me I want to display the list of teachers by pagination and this not working.

Register Custom Post Type

function school() {

    $labels = array(
        'name'                  => _x( 'schools', 'Post Type General Name', 'text_domain' ),
        'singular_name'         => _x( 'school', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'             => __( 'school', 'text_domain' ),
        'name_admin_bar'        => __( 'school', 'text_domain' ),
        'parent_item_colon'     => __( 'Parent Item:', 'text_domain' ),
        'all_items'             => __( 'All Items', 'text_domain' ),
        'add_new_item'          => __( 'Add New Item', 'text_domain' ),
        'add_new'               => __( 'Add New', 'text_domain' ),
        'new_item'              => __( 'New Item', 'text_domain' ),
        'edit_item'             => __( 'Edit Item', 'text_domain' ),
        'update_item'           => __( 'Update Item', 'text_domain' ),
        'view_item'             => __( 'View Item', 'text_domain' ),
        'search_items'          => __( 'Search Item', 'text_domain' ),
        'not_found'             => __( 'Not found', 'text_domain' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
        'items_list'            => __( 'Items list', 'text_domain' ),
        'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
        'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
    );
    $args = array(
        'label'                 => __( 'school', 'text_domain' ),
        'description'           => __( 'school Description', 'text_domain' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', ),
        'taxonomies'            => array( 'category', 'post_tag' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,        
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( 'school', $args );

}
add_action( 'init', 'school', 0 );

Pagination code : By wp_bs_pagination

<?php
/**
 * WordPress Bootstrap Pagination
 */

add_action( 'wp_loaded', 'the_pagination' );


// Bootstrap pagination function

function the_pagination($pages = '', $range = 1) {  

    $showitems = ($range * 2) + 1;  

    global $paged;

    if(empty($paged)) $paged = 1;

    if($pages == '') {

         global $wp_query; 

         $pages = $wp_query->max_num_pages;

         if(!$pages) {
            $pages = 1;
         }

    }   

    if(1 != $pages) {

        echo '<div class="text-center">'; 
        echo '<nav><ul class="pagination"><li class="disabled hidden-xs"><span><span aria-hidden="true">Page '.$paged.' of '.$pages.'</span></span></li>';

        if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."' aria-label='First'>&laquo;<span class='hidden-xs'> First</span></a></li>";

        if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."' aria-label='Previous'>&lsaquo;<span class='hidden-xs'> Previous</span></a></li>";



        for ($i=1; $i <= $pages; $i++) {

            if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {

                echo ($paged == $i)? "<li class=\"active\"><span>".$i." <span class=\"sr-only\">(current)</span></span>

                </li>":"<li><a href='".get_pagenum_link($i)."'>".$i."</a></li>";

            }
        }



        if ($paged < $pages && $showitems < $pages) echo "<li><a href=\"".get_pagenum_link($paged + 1)."\"  aria-label='Next'><span class='hidden-xs'>Next </span>&rsaquo;</a></li>";  

        if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."' aria-label='Last'><span class='hidden-xs'>Last </span>&raquo;</a></li>";

        echo "</ul></nav>";
        echo "</div>";

    }

}

The query that list teachers in school-single.php

<?php

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$connected = new WP_Query( array(
    'connected_type' => 'school-teacher',
    'connected_items' => get_queried_object_id(),
    'nopaging' => false,
    'posts_per_page' => 1,
    'paged' => $paged,
    ),
) );

if ( $connected->have_posts() ) :
    while ( $connected->have_posts() ) : $connected->the_post();
    ....
    endwhile;
endif;

/* Pagination */
the_pagination($connected->max_num_pages);

/* Restore original Post Data */
wp_reset_postdata();

The pagination displays correctly:

Pagination

the url of the page 2 is : http://ift.tt/1YuL0Yg when I click on it redirect me to same page. http://ift.tt/1YuL0Yj.

I think the single page doesn't accept parameter in url. Anyway can someone propose a solution !?



via Chebli Mohamed

Call to a member function get_cart_subtotal() on a non-object in config-woocommerce/config.php on line 790

i'm trying t login into my website and this the error that i'm getting while trying to login into wp-admin

Call to a member function get_cart_subtotal() on a non-object in /home/spicom/public_html/http://ift.tt/1XrhWON on line 790

this is my code at line 790

$cart_subtotal = $woocommerce->cart->get_cart_subtotal();

any help guys please ?



via Chebli Mohamed

Allow users to edit a Single page on Wordpress

i manage my company website which runs WordPress. There are several chapters across the USA. I have pages setup for them so that people can view our chapters content. I was wondering, instead of them emailing me the changes they want. Is there a way where i can allow the users to only be able to edit a single page, without giving them access to the entire WordPress admin page/ website. I would be willing to pay for a commercial plug if this option exists. Thanks for reading this.



via Chebli Mohamed

WordPress form verification email

I need to create a simple WordPress webform capable of verifying submitted email addresses. The submission process must be as streamlined as possible, so breaking this into a two-step problem where the user first signs up for an account on the site (email verification) before submitting the form data, for example, is out of the question.

The approach that seems obvious to me is to store the submitted forms in a database and send the submitter an automated email with a hyperlink containing a random token which, when clicked, updates the database to record that the submitted form's email address is bona fide.

Is there a well-supported WordPress plugin that can do this, or achieve the same result through some other strategy?



via Chebli Mohamed

Facebook like button integration

I am a wordpress developer and I am new to facebook api. I am creating an wordpress plugin using which users can just enter their facebook page url and insert the like button into the wordpress page.

What I would like to know is that can I use my facebook app id for including the javascript xdk for all users.

or

Is there any restriction or api limitation in doing so



via Chebli Mohamed

Cimy User Extra Fields hides error messages

the Wordpress plugin "Cimy User Extra Fields" seems to hide error messages. How can I show them again and add new ones for the fields I added with the "Cimy User Extra Fields" plugin.

See a picture below.

Thanks.

Cimy User Extra Fields No Error Messages



via Chebli Mohamed

how to disable/delete wordpress plugin in github?

Before few days I have added a plugin in WordPress directory.Then after few days WordPress removed it from its directory.But in between my plugin had been added to GitHub and it is visible there now though WordPress removed it from its plugin directory. All I want to delete that plugin from GitHub.

Here is the link

Can anyone help deleting this plugin?



via Chebli Mohamed

How to add custom field to buddypress profile?

How can I add custom fields to buddypress profile?



via Chebli Mohamed

Wordpress: Returning every term of a specific taxonomy

I'm attempting to return every term of a specific taxonomy. I just need to add terms to an object which I can loop through. I've been working on this for while but don't seem to be able to get anywhere.

So for example I have the Taxonomy 'Brand', I have several terms within this taxonomy. How can I return every term under this taxonomy.

Thanks

I have tried the following:

global $product
    $test_value = get_the_terms( $product->id, 'pa-brands');
        foreach($test_value as $test_values){
        echo $test_values->name;

        }

Only this shows an error int the log: 'Unexpected T_Variable'



via Chebli Mohamed

mardi 24 novembre 2015

wordpress plugin for get mysql data

can I know how to Use search method for this php code

   global $wpdb;

   $rows = $wpdb->get_results( "SELECT * FROM table_name WHERE roll_number = value");

   if( !empty($rows) ) {
      $roll_num = $rows->roll_number;
      $full_name = $rows->full_name;
      $percentage = $rows->percentage;
      $result = $rows->result; 
   }



?>

i am very confuse,i want to search data in mysql database using search box,i don't know how to use above code for doing search.



via Chebli Mohamed

Wordpress Plugins and theme data should be installed before import of xml or after?

Actually this question is based on another question on stackoverflow here Duplicate a wordpress site on new domain/subdomain

So based on above question What is the better way to do this: Plugin and Themes data (site data) should be installed/uploaded before import of xml file or after?

BTW: I think the better way is to install (it will auto create the tables) then, sql dump, Because i think sometimes if you dump first, the plugin might encounter conflict with existing table? But if you just copy the site files and then do the dump it should be linked automatic

Waiting for your answer if you know a better way to do the same?



via Chebli Mohamed

Duplicate a wordpress site on new domain/subdomain

Usually to duplicate a site on new domain/subdomain

  1. I export its content using WordPress export option in dashboard.
  2. I install WordPress on new domain/subdomain and connect it to its database as well
  3. I use import option in WordPress to import the xml file generated in point #1
  4. Then I manually install the plugins required (i.e. installed on live site)
  5. Activate the theme, menus and plugins.

Is it the right way to do this all or is there any other better way as well to do the same?



via Chebli Mohamed

Visual Composer query not working inside widget

Working with visual composer's post grid builder. When I setup my custom query shortcode and insert it into a page, it works just fine.

When I insert the same code into a widget however, the query returns no results. The only error I see is one thrown in my browser's console that says "No Results"

Not sure what to do, or what other information I need to provide to get some help



via Chebli Mohamed

WP: Woocommerce, getting custom attributes to foreach loop

I'm attempting to get a custom attribute in Woocommerce. In this case the custom attribute is called 'Brand'.

The following line of code attempts to get the 'Brand' attribute.

$brand = array_shift( wc_get_product_terms( $_product->id, 'pa_brand', array( 'fields' => 'names' ) ) );

I'm attempting to add each individual 'Brand' item to a for each loop which is picked up later in a drop down menu. I have the following code which attempts to add each instance of the $brand array to the associative $brands array. My question is how can I add these as associative values?

foreach($brand as $brands){
$values = array(
        'Label' => 'value' 

}

So for example, if the brad Ford existed in the $brand array, I'd like to add 'Ford' with the associative value 'ford' in the for each statement.



via Chebli Mohamed

how Insert for product and display it to the user specified in WooCommerce after login

Show him how to timely product for the user specified to the display after logging the user is



via Chebli Mohamed

Cannot modify header information - headers already... Error [duplicate]

This question already has an answer here:

Cannot modify header information - headers already sent by (output started at /home/xxxxx/public_html/wp-content/themes/xxxxxx/form.php:2) in /home/xxxxx/public_html/wp-includes/pluggable.php on line 1207.php

I got this error when i tried to run a front end form on my website. I didnt get this error in the webmatrix localhost. I got rid of this error by removing <?php get_header(); ?> in the form. Just as i removed the <?php get_header(); ?> and reloaded the form the post was submitted.

Now my question is why was i getting that error and what was the meaning of it ?



via Chebli Mohamed

wordpress contact form 7 plugin returns js error on console

wordpress contact form 7 plugin returns js error on console. this is the contact form . the error is on auto genarated code by the plugin itself

 <div class="row">

<div class="col-xs-12  col-sm-4">

[text* your-name class:wpcf7-form-control wpcf7-text placeholder "Your Name"] 

[email* your-email class:wpcf7-form-control wpcf7-text wpcf7-email placeholder "E-mail address" ] 

[text your-subject class:wpcf7-form-control wpcf7-text placeholder "Subject"]

</div>

<div class="col-xs-12  col-sm-8">

[textarea your-message class:wpcf7-form-control wpcf7-textarea class:txt placeholder "Message"] 

[submit class:wpcf7-form-control wpcf7-submit class:btn class:btn-primary "SEND MESSAGE" ]

  </div>

 </div>



via Chebli Mohamed

Stuck with wordpress Form 7

I'm using Wordpress "contact form 7" and the theme is "the 7" when I press submit .. here what I get (Failed to send your message. Please try later or contact the administrator by another method.) I've googled a lot .. and I mean a lot but nothing , I'm still a beginner and all what I have is Wordpress dashboard and my account panel on Arvixe .. so what to do in details please .



via Chebli Mohamed

lundi 23 novembre 2015

How to restrict user to use website on more than two website

I have developed a wordpress plugin, but I want that the user is not able to use that plugin on more than two websites.

How can I use this facility in my plugin ?



via Chebli Mohamed

How to add wordpress filter to search?

I'm trying to filter my search result in wordpress.
Does it exist a filter like add_filter('search_result', 'xxxx') ?

When I get the result, I need to apply a second custom filter...

I found this add_action( 'the_post', 'my_the_post_action' ); It loops on result but i don't know how to remove an item...

Any idea ? thanks



via Chebli Mohamed

Adding a "Create New" Button on main events page (Events-Manager plugin)

I am trying to add a "Create New" (event) button on the main event page. I am not a developer but I can usually figure things out. That said, none of the hacks i found online seem to work. Would be great if anyone could help me with this.

FYI - I am not allowing users to access the wp-admin so all events are currently created on the front end and i would like to keep it that way. thanks!

Best, Yvan



via Chebli Mohamed

ReOrder Post Within Categories - fatal error: call to a member function get_queried_object() on a non obect

I am using a wordpress plugin called 'ReOrder Post Within Categories'. Using this plugin we can sort all the posts inside each categories. After installed this, I received a php error like this

Fatal error: Call to a member function get_queried_object() on a non-object in /home/content/04/10980904/html/wp-content/plugins/reorder-post-within-categories/reorder-posts-within-categories.php on line 96

The code in line number 96 is

$queriedObj = $wp_query->get_queried_object();

Note: $wp_query is already declared as global variable,

global $wpdb,$wp_query;

Can anyone help me to solve this issue.



via Chebli Mohamed

WHMCS Bridge Affiliates link not working properly?

direct whmcs links work like a charm if you use http://ift.tt/1N8LhfK for example affiliate clicks get counted and also signups are tracked but if you use the bridge links like http://ift.tt/1ldJ6MX for example it doesn't work clicks also get counted but no signups the user can signup but he won't be counted as affiliate thats the issue so the full link looks similar to this: http://ift.tt/1N8LhfM



via Chebli Mohamed

Display Date of article in Yootheme Widgetkit 2 sliderset (wordpress Plugin)

The Problem i need to solve is to display the Date of an Article in YooThmes Widgetkit 2 slider to make it look like a news slider.

screenshot

I tried the Wordpress reference date data but it didn´t work.

<?php the_date('Y-m-d', '<h2>', '</h2>'); ?>

Maybe the solution is the same like in other Wordpress plugins but iam not very familiar with php or plugin development so i don´t really know.



via Chebli Mohamed

dimanche 22 novembre 2015

Wordpress throwing header error wp- admin

Here is the error

" Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/webpresenter-Qa/wp-content/plugins/QuoteForm/QuoteForm.php:397) in /Applications/MAMP/htdocs/webpresenter-Qa/wp-includes/pluggable.php on line 1196"

Can anyone please help



via Chebli Mohamed

Shipping per products, per quantity, per country in Woo-commerce

WordPress and plugin Guru! I am trying to shipping in shopping cart in my medicine site. But i have complex requirement of shipping part. In other hands, it is shipping per products, per quantity, per country. I used to installed woocommerce-shipping-pro plugin, this plugin supports shipping per quantity and country but not support per products. My shipping requirements: enter image description here

This is urgent question. Please help me. Thank you. Regards. Eric



via Chebli Mohamed

How do I move woocommerce-error before woocommerce wrapper?

By default woocommerce-error is inside the woocommerce wrapper. The woocommerce-error ul is in the woocommerce wrapper. I want to move the woocommerce-error ul before woocommerce wrapper. I want to move the woocommer error message before woocommerce wrapper.

How do I do that?

By default woocommerce-error is inside the woocommerce wrapper.



via Chebli Mohamed

How do I add woocommerce custom field shortcode in sprintf?

I want to add custom field shortcode in cart product name. Right now, I don't know how to display custom field value, because the code is in sprintf.

I create a custom field in woocommerce product. The customs field is called color. I want the cart product name to print out the custom field value.

custom field shortcode

   <?php echo get_post_meta( get_the_ID(), 'color', true ); ?>

cart product name

                        <?php
                            if ( ! $_product->is_visible() ) {
                                echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . '&nbsp;';
                            } else {
                                echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a class="items-info" href="%s">%s </a>', esc_url( $_product->get_permalink( $cart_item ) ), $_product->get_title() ), $cart_item, $cart_item_key );
                            }

                        ?>

For example,

My product name is "New york tee" and my custom field color value is "white" I want it to display like "New york tee - white" in my woocommerce cart product name. Also I want to add a dash before product name and custom field value. li "New york tee - white" Can someone help me? thank you.



via Chebli Mohamed

Best way to Read WordPress as JSON

I attend to create an android version of my WordPress blog. So, i do some google search and Stackoverflow search to find the best way to do this works:

  1. find the count of the post
  2. category's names.
  3. reed posts, page by page (or a number like read 10 post for every request)
  4. reed posts by they tag and act like 3.
  5. get the thumbnail for images.
  6. find the number of comment for each post.
  7. reed all comments.
  8. send comment.
  9. and ...

So in my research s i found some plugins and because of the company who make that, i think WP REST API is more trustful than the others but there is other plugin like JSON API. so based on my needs, what is the best choice?

PS: I find out the WP REST API have a version 2, but they say, it is not good enough to being used in large app. Thanks.



via Chebli Mohamed

Show Coming Soon Template in certain pages only?

I need to show Coming Soon Template in a certain page like contact page. I use most of the plugin but doesn't make sense. So i decided to make own. How can i replace the page to a coming soon template.



via Chebli Mohamed

samedi 21 novembre 2015

Extra fields for wordpress user management in dashboard

I need to add extra fields to the Add new user and Edit user pages in wordpress admin dashboard.

I can add this to Edit user using the hook edit_user_profile. But how to add it in Add new user page?

Also I want to add some extra columns to the user wp list table.

add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields( $user ) {

}



via Chebli Mohamed

How to stop menu wrapping?

Hi there I inserted this plugin code

<?php

/** * @package Menu_Image * @version 2.6 * @licence GPLv2 */

/* Plugin Name: Menu Image Plugin URI: http://ift.tt/21aX3fu Description: Provide uploading images to menu item Author: Alex Davyskiba aka Zviryatko Version: 2.6 Author URI: http://ift.tt/1MuQk8B */

/* Copyright 2013 Zviryatko (email : sanya.davyskiba@gmail.com)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

/** * Provide attaching images to menu items. * * @package Menu_Image */ class Menu_Image_Plugin {

/**
 * Self provided image sizes for most menu usage.
 *
 * @var array
 */
protected $image_sizes = array(
    'menu-24x24' => array( 24, 24, false ),
    'menu-36x36' => array( 36, 36, false ),
    'menu-48x48' => array( 48, 48, false ),
);

/**
 * List of used attachment ids grouped by size.
 *
 * Need to list all ids to prevent Jetpack Phonon in image_downsize filter.
 *
 * @var array
 */
private $used_attachments = array();

/**
 * List of file extensions that allowed to resize and display as image.
 *
 * @var array
 */
private $additionalDisplayableImageExtensions = array( 'ico' );

/**
 * Plugin constructor, add all filters and actions.
 */
public function __construct() {
    add_action( 'init', array( $this, 'menu_image_init' ) );
    add_filter( 'manage_nav-menus_columns', array( $this, 'menu_image_nav_menu_manage_columns' ), 11 );
    add_action( 'save_post_nav_menu_item', array( $this, 'menu_image_save_post_action' ), 10, 3 );
    add_action( 'admin_head-nav-menus.php', array( $this, 'menu_image_admin_head_nav_menus_action' ) );
    add_filter( 'wp_setup_nav_menu_item', array( $this, 'menu_image_wp_setup_nav_menu_item' ) );
    add_filter( 'walker_nav_menu_start_el', array( $this, 'menu_image_nav_menu_item_filter' ), 10, 4 );
    add_action( 'wp_enqueue_scripts', array( $this, 'menu_image_add_inline_style_action' ) );
    add_action( 'admin_action_delete-menu-item-image', array( $this, 'menu_image_delete_menu_item_image_action' ) );
    add_action( 'wp_ajax_set-menu-item-thumbnail', array( $this, 'wp_ajax_set_menu_item_thumbnail' ) );
    // Add support for additional image types
    add_filter( 'file_is_displayable_image', array( $this, 'file_is_displayable_image' ), 10, 2 );
    // Add support of WPML menus sync
    add_action( 'wp_update_nav_menu_item', array( $this, 'wp_update_nav_menu_item_action' ), 10, 2 );
    add_action( 'admin_init', array( $this, 'admin_init' ), 99 );
    add_filter( 'jetpack_photon_override_image_downsize', array( $this, 'jetpack_photon_override_image_downsize_filter' ), 10, 2 );
}

/**
 * Admin init action with lowest execution priority
 */
public function admin_init() {
    // Add custom field for menu edit walker
    if ( !has_action( 'wp_nav_menu_item_custom_fields' ) ) {
        add_filter( 'wp_edit_nav_menu_walker', array( $this, 'menu_image_edit_nav_menu_walker_filter' ) );
    }
    add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'menu_item_custom_fields' ), 10, 1 );
}

/**
 * Filter adds additional validation for image type
 *
 * @param bool   $result
 * @param string $path
 *
 * @return bool
 */
public function file_is_displayable_image( $result, $path ) {
    if ( $result ) {
        return true;
    }
    $fileExtension = pathinfo( $path, PATHINFO_EXTENSION );

    return in_array( $fileExtension, $this->additionalDisplayableImageExtensions );
}

/**
 * Initialization action.
 *
 * Adding image sizes for most popular menu icon sizes. Adding thumbnail
 *  support to menu post type.
 */
public function menu_image_init() {
    add_post_type_support( 'nav_menu_item', array( 'thumbnail' ) );

    $this->image_sizes = apply_filters( 'menu_image_default_sizes', $this->image_sizes );
    foreach ( $this->image_sizes as $name => $params ) {
        add_image_size( $name, $params[ 0 ], $params[ 1 ], $params[ 2 ] );
    }
    load_plugin_textdomain( 'menu-image', false, basename( dirname( __FILE__ ) ) . '/languages' );
}

/**
 * Adding images as screen options.
 *
 * If not checked screen option 'image', uploading form not showed.
 *
 * @param array $columns
 *
 * @return array
 */
public function menu_image_nav_menu_manage_columns( $columns ) {
    return $columns + array( 'image' => __( 'Image', 'menu-image' ) );
}

/**
 * Saving post action.
 *
 * Saving uploaded images and attach/detach to image post type.
 *
 * @param int     $post_id
 * @param WP_Post $post
 */
public function menu_image_save_post_action( $post_id, $post ) {
    $menu_image_settings = array(
        'menu_item_image_size',
        'menu_item_image_title_position'
    );
    foreach ( $menu_image_settings as $setting_name ) {
        if ( isset( $_POST[ $setting_name ][ $post_id ] ) && !empty( $_POST[ $setting_name ][ $post_id ] ) ) {
            if ( $post->{"_$setting_name"} != $_POST[ $setting_name ][ $post_id ] ) {
                update_post_meta( $post_id, "_$setting_name", esc_sql( $_POST[ $setting_name ][ $post_id ] ) );
            }
        }
    }
}

/**
 * Save item settings while WPML sync menus.
 *
 * @param $item_menu_id
 * @param $menu_item_db_id
 */
public function wp_update_nav_menu_item_action( $item_menu_id, $menu_item_db_id ) {
    global $sitepress, $icl_menus_sync;
    if ( class_exists( 'SitePress' ) && $sitepress instanceof SitePress && class_exists( 'ICLMenusSync' ) && $icl_menus_sync instanceof ICLMenusSync ) {
        static $run_times = array();
        $menu_image_settings = array(
            'menu_item_image_size',
            'menu_item_image_title_position',
            'thumbnail_id',
            'thumbnail_hover_id',
        );

        // iterate synchronized menus
        foreach ( $icl_menus_sync->menus as $menu_id => $menu_data ) {
            if ( !isset( $_POST[ 'sync' ][ 'add' ][ $menu_id ] ) ) {
                continue;
            }

            // remove cache and get language current item menu
            $cache_key   = md5( serialize( array( $item_menu_id, 'tax_nav_menu' ) ) );
            $cache_group = 'get_language_for_element';
            wp_cache_delete( $cache_key, $cache_group );
            $lang = $sitepress->get_language_for_element( $item_menu_id, 'tax_nav_menu' );

            if ( !isset( $run_times[ $menu_id ][ $lang ] ) ) {
                $run_times[ $menu_id ][ $lang ] = 0;
            }

            // Count static var for each menu id and saved item language
            // and get original item id from counted position of synchronized
            // items from POST data. That's all magic.
            $post_item_ids = array();
            foreach ( $_POST[ 'sync' ][ 'add' ][ $menu_id ] as $id => $lang_array ) {
                if ( array_key_exists( $lang, $lang_array ) ) {
                    $post_item_ids[ ] = $id;
                }
            }
            if ( !array_key_exists( $run_times[ $menu_id ][ $lang ], $post_item_ids ) ) {
                continue;
            }
            $orig_item_id = $post_item_ids[ $run_times[ $menu_id ][ $lang ] ];

            // iterate all item settings and save it for new item
            $orig_item_meta = get_metadata( 'post', $orig_item_id );
            foreach ( $menu_image_settings as $meta ) {
                if ( isset( $orig_item_meta[ "_$meta" ] ) && isset( $orig_item_meta[ "_$meta" ][ 0 ] ) ) {
                    update_post_meta( $menu_item_db_id, "_$meta", $orig_item_meta[ "_$meta" ][ 0 ] );
                }
            }
            $run_times[ $menu_id ][ $lang ] ++;
            break;
        }
    }
}

/**
 * Replacement edit menu walker class.
 *
 * @return string
 */
public function menu_image_edit_nav_menu_walker_filter() {
    return 'Menu_Image_Walker_Nav_Menu_Edit';
}

/**
 * Load menu image meta for each menu item.
 *
 * @since 2.0
 */
public function menu_image_wp_setup_nav_menu_item( $item ) {
    if ( !isset( $item->thumbnail_id ) ) {
        $item->thumbnail_id = get_post_thumbnail_id( $item->ID );
    }
    if ( !isset( $item->thumbnail_hover_id ) ) {
        $item->thumbnail_hover_id = get_post_meta( $item->ID, '_thumbnail_hover_id', true );
    }
    if ( !isset( $item->image_size ) ) {
        $item->image_size = get_post_meta( $item->ID, '_menu_item_image_size', true );
    }
    if ( !isset( $item->title_position ) ) {
        $item->title_position = get_post_meta( $item->ID, '_menu_item_image_title_position', true );
    }

    return $item;
}

/**
 * Replacement default menu item output.
 *
 * @param string $item_output Default item output
 * @param object $item        Menu item data object.
 * @param int    $depth       Depth of menu item. Used for padding.
 * @param object $args
 *
 * @return string
 */
public function menu_image_nav_menu_item_filter( $item_output, $item, $depth, $args ) {
    $attributes = !empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
    $attributes .= !empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
    $attributes .= !empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
    $attributes .= !empty( $item->url ) ? ' href="' . esc_attr( $item->url ) . '"' : '';

    $image_size = $item->image_size ? $item->image_size : apply_filters( 'menu_image_default_size', 'menu-36x36' );
    $position   = $item->title_position ? $item->title_position : apply_filters( 'menu_image_default_title_position', 'after' );
    $class      = "menu-image-title-{$position}";
    $this->setUsedAttachments( $image_size, $item->thumbnail_id );
    $image = '';
    if ( $item->thumbnail_hover_id ) {
        $this->setUsedAttachments( $image_size, $item->thumbnail_hover_id );
        $hover_image_src = wp_get_attachment_image_src( $item->thumbnail_hover_id, $image_size );
        $margin_size     = $hover_image_src[ 1 ];
        $image           = "<span class='menu-image-hover-wrapper'>";
        $image .= wp_get_attachment_image( $item->thumbnail_id, $image_size, false, "class=menu-image {$class}" );
        $image .= wp_get_attachment_image(
            $item->thumbnail_hover_id, $image_size, false, array(
                'class' => "hovered-image {$class}",
                'style' => "margin-left: -{$margin_size}px;",
            )
        );
        $image .= '</span>';;
        $class .= ' menu-image-hovered';
    } elseif ( $item->thumbnail_id ) {
        $image = wp_get_attachment_image( $item->thumbnail_id, $image_size, false, "class=menu-image {$class}" );
        $class .= ' menu-image-not-hovered';
    }

    $item_output = "{$args->before}<a{$attributes} class='{$class}'>";
    $link        = $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    $none        = ''; // Sugar.
    switch ( $position ) {
        case 'hide':
        case 'before':
        case 'above':
            $item_args = array( $none, $link, $image );
            break;
        case 'after':
        default:
            $item_args = array( $image, $link, $none );
            break;
    }
    $item_output .= vsprintf( '%s<span class="menu-image-title">%s</span>%s', $item_args );
    $item_output .= "</a>{$args->after}";

    return $item_output;
}

/**
 * Loading additional stylesheet.
 *
 * Loading custom stylesheet to fix images positioning in match themes
 */
public function menu_image_add_inline_style_action() {
    wp_register_style( 'menu-image', plugins_url( '', __FILE__ ) . '/menu-image.css', array(), '1.1', 'all' );
    wp_enqueue_style( 'menu-image' );
}

/**
 * Loading media-editor script ot nav-menus page.
 *
 * @since 2.0
 */
public function menu_image_admin_head_nav_menus_action() {
    wp_enqueue_script( 'menu-image-admin', plugins_url( 'menu-image-admin.js', __FILE__ ), array( 'jquery' ) );
    wp_localize_script(
        'menu-image-admin', 'menuImage', array(
            'l10n'     => array(
                'uploaderTitle'      => __( 'Chose menu image', 'menu-image' ),
                'uploaderButtonText' => __( 'Select', 'menu-image' ),
            ),
            'settings' => array(
                'nonce' => wp_create_nonce( 'update-menu-item' ),
            ),
        )
    );
    wp_enqueue_media();
    wp_enqueue_style( 'editor-buttons' );
}

/**
 * When menu item removed remove menu image metadata.
 */
public function menu_image_delete_menu_item_image_action() {

    $menu_item_id = (int) $_REQUEST[ 'menu-item' ];

    check_admin_referer( 'delete-menu_item_image_' . $menu_item_id );

    if ( is_nav_menu_item( $menu_item_id ) && has_post_thumbnail( $menu_item_id ) ) {
        delete_post_thumbnail( $menu_item_id );
        delete_post_meta( $menu_item_id, '_thumbnail_hover_id' );
        delete_post_meta( $menu_item_id, '_menu_item_image_size' );
        delete_post_meta( $menu_item_id, '_menu_item_image_title_position' );
    }
}

/**
 * Output HTML for the menu item images.
 *
 * @since 2.0
 *
 * @param int $item_id The post ID or object associated with the thumbnail, defaults to global $post.
 *
 * @return string html
 */
public function wp_post_thumbnail_only_html( $item_id ) {
    $default_size = apply_filters( 'menu_image_default_size', 'menu-36x36' );
    $markup       = '<p class="description description-thin" ><label>%s<br /><a title="%s" href="#" class="set-post-thumbnail button%s" data-item-id="%s" style="height: auto;">%s</a>%s</label></p>';

    $thumbnail_id = get_post_thumbnail_id( $item_id );
    $content      = sprintf(
        $markup,
        esc_html__( 'Menu image', 'menu-image' ),
        $thumbnail_id ? esc_attr__( 'Change menu item image', 'menu-image' ) : esc_attr__( 'Set menu item image', 'menu-image' ),
        '',
        $item_id,
        $thumbnail_id ? wp_get_attachment_image( $thumbnail_id, $default_size ) : esc_html__( 'Set image', 'menu-image' ),
        $thumbnail_id ? '<a href="#" class="remove-post-thumbnail">' . __( 'Remove', 'menu-image' ) . '</a>' : ''
    );

    $hover_id = get_post_meta( $item_id, '_thumbnail_hover_id', true );
    $content .= sprintf(
        $markup,
        esc_html__( 'Image on hover', 'menu-image' ),
        $hover_id ? esc_attr__( 'Change menu item image on hover', 'menu-image' ) : esc_attr__( 'Set menu item image on hover', 'menu-image' ),
        ' hover-image',
        $item_id,
        $hover_id ? wp_get_attachment_image( $hover_id, $default_size ) : esc_html__( 'Set image on hover', 'menu-image' ),
        $hover_id ? '<a href="#" class="remove-post-thumbnail hover-image">' . __( 'Remove', 'menu-image' ) . '</a>' : ''
    );

    return $content;
}

/**
 * Output HTML for the menu item images section.
 *
 * @since 2.0
 *
 * @param int $item_id The post ID or object associated with the thumbnail, defaults to global $post.
 *
 * @return string html
 */
public function wp_post_thumbnail_html( $item_id ) {
    $default_size = apply_filters( 'menu_image_default_size', 'menu-36x36' );
    $content      = $this->wp_post_thumbnail_only_html( $item_id );

    $image_size = get_post_meta( $item_id, '_menu_item_image_size', true );
    if ( !$image_size ) {
        $image_size = $default_size;
    }
    $title_position = get_post_meta( $item_id, '_menu_item_image_title_position', true );
    if ( !$title_position ) {
        $title_position = apply_filters( 'menu_image_default_title_position', 'after' );
    }

    ob_start(); ?>

    <div class="menu-item-image-options">
        <p class="description description-wide">
            <label for="edit-menu-item-image-size-<?php echo $item_id; ?>"><?php _e( 'Image size', 'menu-image' ); ?>
                <br />
                <select id="edit-menu-item-image-size-<?php echo $item_id; ?>"
                        class="widefat edit-menu-item-image-size"
                        name="menu_item_image_size[<?php echo $item_id; ?>]">
                    <option value='full' <?php echo $image_size == 'full' ? ' selected="selected"' : '' ?>><?php _e( 'Original Size', 'menu-image' ) ?></option>
                    <?php foreach ( get_intermediate_image_sizes() as $size ) :
                        printf(
                            "<option value='%s'%s>%s</option>\n",
                            esc_attr( $size ),
                            $image_size == $size ? ' selected="selected"' : '',
                            ucfirst( $size )
                        ); ?>
                    <?php endforeach; ?>
                </select>
            </label>
        </p>
        <p class="description description-wide">
            <label><?php _e( 'Title position', 'menu-image' ); ?></label><br />
            <?php
            $positions = array(
                'hide'   => __( 'Hide', 'menu-image' ),
                'above'  => __( 'Above', 'menu-image' ),
                'below'  => __( 'Below', 'menu-image' ),
                'before' => __( 'Before', 'menu-image' ),
                'after'  => __( 'After', 'menu-image' ),
            );
            foreach ( $positions as $position => $label ) :
                printf(
                    "<label><input type='radio' name='menu_item_image_title_position[%s]' value='%s'%s/> %s</label>%s",
                    $item_id,
                    esc_attr( $position ),
                    $title_position == $position ? ' checked="checked"' : '',
                    $label,
                    $position != 'after' ? ' | ' : ''
                );
            endforeach; ?>

        </p>
    </div>

    <?php
    $content = "<div class='menu-item-images' style='min-height:70px'>$content</div>" . ob_get_clean();

    /**
     * Filter the admin menu item thumbnail HTML markup to return.
     *
     * @since 2.0
     *
     * @param string $content Admin menu item images HTML markup.
     * @param int    $item_id Post ID.
     */
    return apply_filters( 'admin_menu_item_thumbnail_html', $content, $item_id );
}

/**
 * Update item thumbnail via ajax action.
 *
 * @since 2.0
 */
public function wp_ajax_set_menu_item_thumbnail() {
    $json = !empty( $_REQUEST[ 'json' ] );

    $post_ID = intval( $_POST[ 'post_id' ] );
    if ( !current_user_can( 'edit_post', $post_ID ) ) {
        wp_die( - 1 );
    }

    $thumbnail_id = intval( $_POST[ 'thumbnail_id' ] );
    $is_hovered   = (bool) $_POST[ 'is_hover' ];

    check_ajax_referer( "update-menu-item" );

    if ( $thumbnail_id == '-1' ) {
        if ( $is_hovered ) {
            $success = delete_post_meta( $post_ID, '_thumbnail_hover_id' );
        } else {
            $success = delete_post_thumbnail( $post_ID );
        }
    } else {
        if ( $is_hovered ) {
            $success = update_post_meta( $post_ID, '_thumbnail_hover_id', $thumbnail_id );
        } else {
            $success = set_post_thumbnail( $post_ID, $thumbnail_id );
        }
    }

    if ( $success ) {
        $return = $this->wp_post_thumbnail_only_html( $post_ID );
        $json ? wp_send_json_success( $return ) : wp_die( $return );
    }

    wp_die( 0 );
}

/**
 * Add custom fields to menu item as suggest to http://ift.tt/21aX3fw
 */
public function menu_item_custom_fields( $item_id ) { ?>
    <div class="field-image hide-if-no-js wp-media-buttons">
        <?php echo $this->wp_post_thumbnail_html( $item_id ) ?>
    </div>
<?php
}

/**
 * Prevent jetpack Phonon applied for menu item images.
 *
 * @param bool  $prevent
 * @param array $data
 *
 * @return bool
 */
public function jetpack_photon_override_image_downsize_filter( $prevent, $data ) {
    return $this->isAttachmentUsed( $data[ 'size' ], $data[ 'attachment_id' ] );
}

/**
 * Set used attachment ids.
 *
 * @param string $size
 * @param int    $id
 */
public function setUsedAttachments( $size, $id ) {
    $this->used_attachments[ $size ][ ] = $id;
}

/**
 * Check if attachment is used in menu items.
 *
 * @param string $size
 * @param int    $id
 *
 * @return bool
 */
public function isAttachmentUsed( $size, $id ) {
    return isset( $this->used_attachments[ $size ] ) && in_array( $id, $this->used_attachments[ $size ] );
}

}

$menu_image = new Menu_Image_Plugin();

require_once(ABSPATH . 'wp-admin/includes/nav-menu.php');

class Menu_Image_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {

public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
    global $_wp_nav_menu_max_depth;
    $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;

    ob_start();
    $item_id = esc_attr( $item->ID );
    $removed_args = array(
        'action',
        'customlink-tab',
        'edit-menu-item',
        'menu-item',
        'page-tab',
        '_wpnonce',
    );

    $original_title = '';
    if ( 'taxonomy' == $item->type ) {
        $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
        if ( is_wp_error( $original_title ) )
            $original_title = false;
    } elseif ( 'post_type' == $item->type ) {
        $original_object = get_post( $item->object_id );
        $original_title = get_the_title( $original_object->ID );
    }

    $classes = array(
        'menu-item menu-item-depth-' . $depth,
        'menu-item-' . esc_attr( $item->object ),
        'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
    );

    $title = $item->title;

    if ( ! empty( $item->_invalid ) ) {
        $classes[] = 'menu-item-invalid';
        /* translators: %s: title of menu item which is invalid */
        $title = sprintf( __( '%s (Invalid)' ), $item->title );
    } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
        $classes[] = 'pending';
        /* translators: %s: title of menu item in draft status */
        $title = sprintf( __('%s (Pending)'), $item->title );
    }

    $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;

    $submenu_text = '';
    if ( 0 == $depth )
        $submenu_text = 'style="display: none;"';

    ?>
    <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
        <dl class="menu-item-bar">
            <dt class="menu-item-handle">
                <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
                <span class="item-controls">
                    <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
                    <span class="item-order hide-if-js">
                        <a href="<?php
                            echo wp_nonce_url(
                                add_query_arg(
                                    array(
                                        'action' => 'move-up-menu-item',
                                        'menu-item' => $item_id,
                                    ),
                                    remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
                                ),
                                'move-menu_item'
                            );
                        ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
                        |
                        <a href="<?php
                            echo wp_nonce_url(
                                add_query_arg(
                                    array(
                                        'action' => 'move-down-menu-item',
                                        'menu-item' => $item_id,
                                    ),
                                    remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
                                ),
                                'move-menu_item'
                            );
                        ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
                    </span>
                    <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
                        echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
                    ?>"><?php _e( 'Edit Menu Item' ); ?></a>
                </span>
            </dt>
        </dl>

        <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
            <?php if( 'custom' == $item->type ) : ?>
                <p class="field-url description description-wide">
                    <label for="edit-menu-item-url-<?php echo $item_id; ?>">
                        <?php _e( 'URL' ); ?><br />
                        <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
                    </label>
                </p>
            <?php endif; ?>
            <p class="description description-thin">
                <label for="edit-menu-item-title-<?php echo $item_id; ?>">
                    <?php _e( 'Navigation Label' ); ?><br />
                    <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
                </label>
            </p>
            <p class="description description-thin">
                <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
                    <?php _e( 'Title Attribute' ); ?><br />
                    <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
                </label>
            </p>
            <p class="field-link-target description">
                <label for="edit-menu-item-target-<?php echo $item_id; ?>">
                    <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
                    <?php _e( 'Open link in a new window/tab' ); ?>
                </label>
            </p>
            <p class="field-css-classes description description-thin">
                <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
                    <?php _e( 'CSS Classes (optional)' ); ?><br />
                    <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
                </label>
            </p>
            <p class="field-xfn description description-thin">
                <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
                    <?php _e( 'Link Relationship (XFN)' ); ?><br />
                    <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
                </label>
            </p>

            <?php
            // This is the added section
            do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
            // end added section
            ?>

            <p class="field-description description description-wide">
                <label for="edit-menu-item-description-<?php echo $item_id; ?>">
                    <?php _e( 'Description' ); ?><br />
                    <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
                    <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
                </label>
            </p>

            <p class="field-move hide-if-no-js description description-wide">
                <label>
                    <span><?php _e( 'Move' ); ?></span>
                    <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></a>
                    <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></a>
                    <a href="#" class="menus-move menus-move-left" data-dir="left"></a>
                    <a href="#" class="menus-move menus-move-right" data-dir="right"></a>
                    <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></a>
                </label>
            </p>

            <div class="menu-item-actions description-wide submitbox">
                <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
                    <p class="link-to-original">
                        <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
                    </p>
                <?php endif; ?>
                <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
                echo wp_nonce_url(
                    add_query_arg(
                        array(
                            'action' => 'delete-menu-item',
                            'menu-item' => $item_id,
                        ),
                        admin_url( 'nav-menus.php' )
                    ),
                    'delete-menu_item_' . $item_id
                ); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
                    ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
            </div>

            <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
            <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
            <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
            <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
            <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
            <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
        </div><!-- .menu-item-settings-->
        <ul class="menu-item-transport"></ul>
    <?php
    $output .= ob_get_clean();
}

} how to stop the menu from wrapping when browser is resized?



via Chebli Mohamed

How to make ajax call for auto suggest in Ninja Forms?

I have wordpress installed on one server and I am using Ninja Forms plugin to create a form. See the form here :- http://ift.tt/1SbfF9c

I want to add auto suggest in the Location, Airport fields. I know that I need to make ajax call using Javascript/Jquery once user start typing and get the results to suggest users.

But where do I add this javascript to make it work ? Can I do this via admin panel ? If not which file I need to look for ?

Thanks in advance for the help.



via Chebli Mohamed

How do I display woocommerce message in different places?

I want to display the green color "your tee has been added to your cart." message under "add to cart" button. And I want to display the red message "Please choose product options…" before the "size" I create the attribute. By default, the woocommerce message are displaying at the same place. Is there a way to display them at different places. Please help!

I try to do this I put the "wc_print_notices" where I want the message to show. It works but "your tee has been added to your cart." and " "Please choose product options…" message display at the same place.

   <?php wc_print_notices(); ?>

And I put this in my function.php

   remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 ); /*Single Product*/

For example, I want the "Please choose product options…" message display like this. If you click add to bag without choosing size. DON'T choose size so the red message show up.

http://ift.tt/21agrt2

AND I want the "your tee has been added to your cart." message display like this. If you click add to bag you will see the add to cart message displaying under the button.

http://ift.tt/21agoxq



via Chebli Mohamed

how to setup wordpress like w3schools and tutorialpoint

If you have a collection of posts that you want your viewers to read in a certain sequence, then you need the following navigational features:

You need a navigation menu in the side column, which lists all the posts in the correct order
The navigation menu should only be visible when a viewer is on a post that is part of the series
There needs to be a “Previous” and “Next” links at the bottom of each post that allows the viewer to visit adjacent posts in the series.
The current post that a viewer is reading should appear as bold in the custom menu so that the viewer can where they are in the series



via Chebli Mohamed

Adding side panel on wordpress website

I am trying to make a site of the following type

http://ift.tt/1QVxA5i

in which you have a side panel, and as you click it a new video starts playing.I am using the themify theme in wordpress and wanted to know if this was possible in that?



via Chebli Mohamed

how to create order use wc_create_order with subscription product

I want to create a new order programmatically and I'm using the code below, this works well simple product type but my goal is to create a new order and convert this order to subscription product type with payment using the authorize.net

But I don't want customers to redirect to payment gateway, want to accept via API CALL.

<?php $address = array(
            'first_name' => 'Fresher',
            'last_name'  => 'StAcK OvErFloW',
            'company'    => 'stackoverflow',
            'email'      => 'test@test.com',
            'phone'      => '777-777-777-777',
            'address_1'  => '31 Main Street',
            'address_2'  => '', 
            'city'       => 'Chennai',
            'state'      => 'TN',
            'postcode'   => '12345',
            'country'    => 'IN'
        );

        $order = wc_create_order();
        $order->add_product( get_product( '4368' ), 2 ); //(get_product with id and next is for quantity)
        $order->set_address( $address, 'billing' );
        $order->set_address( $address, 'shipping' );
        //$order->add_coupon('Fresher','10','2'); // accepted param $couponcode, $couponamount,$coupon_tax
        $order->calculate_totals(); 
        $order->session->order_awaiting_payment = $order->id;

    // Process Payment
    $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
    $result = $available_gateways[ 'ideal' ]->process_payment( $order->id );

    // Redirect to success/confirmation/payment page
    if ( $result['result'] == 'success' ) {

        $result = apply_filters( 'woocommerce_payment_successful_result', $result, $order->id );

        wp_redirect( $result['redirect'] );
        exit;
    }

        ?>



via Chebli Mohamed