Plugin Directory

Changeset 1233647


Ignore:
Timestamp:
08/29/2015 11:02:55 AM (11 years ago)
Author:
ronshe
Message:

Add the ability to activate on selected pages or posts categories.

Location:
pixterme/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pixterme/trunk/admin.php

    r1213398 r1233647  
    4747        "default" => "img"
    4848        ),
     49    array(
     50        "type" => "cond",
     51        "name" => __("Show on pages (shows all if off)", 'pixter-me'),
     52        "desc" => __("When opened, you must select on which pages you want to show pixter-me", 'pixter-me'),
     53        "id" => "show_pages",
     54        "fields" => array(
     55            array(
     56                "type" => "posts",
     57                "name" => __("Show button on the following pages only", 'pixter-me'),
     58                "id" => "pages",
     59                "options" => array('args' => array('post_type' => 'page', 'numberposts' => -1), 'type' => 'checkbox_list'),
     60                'class' => 'no-toggle',
     61                ),
     62            ),
     63        ),
     64    array(
     65        "type" => "cond",
     66        "name" => __("Show on posts by categories (shows all if off)", 'pixter-me'),
     67        "desc" => __("When opened, you must select on which posts categories you want to show pixter-me", 'pixter-me'),
     68        "id" => "show_posts",
     69        "fields" => array(
     70            array(
     71                "type" => "taxonomy",
     72                "name" => __("Show button on the following posts categories", 'pixter-me'),
     73                "id" => "taxonomies",
     74                "options" => array('taxonomy' => 'category', 'args' => array('hide_empty' => false), 'type' => 'checkbox_list'),
     75                'class' => 'no-toggle',
     76                ),
     77            ),
     78        ),
    4979    );
     80
     81/*  Support custom post types not working because the loading timing. TBD
     82$custom_post_type = get_post_types(array('public' => true, '_builtin' => false));
     83if (!empty($custom_post_type))
     84    $fields[] = array(
     85        "type" => "cond",
     86        "name" => __("Show on post types", 'pixter-me'),
     87        "desc" => __("By default will show on all post types", 'pixter-me'),
     88        "id" => "show_post_types",
     89        "fields" => array(
     90            array(
     91                "type" => "checkbox_list",
     92                "name" => __("Show button on the following custom post types", 'pixter-me'),
     93                "id" => "custom_post_type",
     94                "desc" => __("Will show only on selected custom post types.", 'pixter-me'),
     95                "options" => $custom_post_type,
     96                'class' => 'no-toggle',
     97            ),
     98        ),
     99    );
     100*/
    50101
    51102$pixter_me_user = get_option('pixter_me_user');
     
    196247        $logo = plugins_url( 'logo.png', __FILE__ );
    197248        echo "
    198             <style> .wp-admin #wpfooter { position: static; }   </style>
     249            <style>
     250                .wp-admin #wpfooter { position: static; }
     251                .conditinal_container {  margin: 0 0 15px 5%; }
     252            </style>
    199253            <div style='margin: 20px 10px 0'>
    200254                <a href='http://www.pixter-media.com' target='_blank'><img src='$logo'></a>
  • pixterme/trunk/pixter-me.php

    r1213398 r1233647  
    2323function plugins_loaded_pixter_me()
    2424{
    25     // embed the javascript file that makes the AJAX request
    26     wp_enqueue_script( 'pixter-me-script', plugin_dir_url( __FILE__ ) . 'script.js', array( 'jquery' ) );
    27     wp_localize_script( 'pixter-me-script', 'pixterAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
    28 
     25    if (is_admin())
     26    {
     27        // embed the javascript file that makes the AJAX request
     28        wp_enqueue_script( 'pixter-me-script', plugin_dir_url( __FILE__ ) . 'script.js', array( 'jquery' ), false, true );
     29        wp_localize_script( 'pixter-me-script', 'pixterAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
     30    }
    2931    load_plugin_textdomain( 'pixter-me', false, dirname( plugin_basename( __FILE__ )).'/languages' );
    3032}
     
    4345register_activation_hook( __FILE__, 'pixter_me_activate' );
    4446
    45 function pixter_me_init()
     47//  function pixter_me_init()
     48//  {
     49//      // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php)
     50//  //  wp_enqueue_script( 'pixter-me-global', 'http://ddd.rrr.com/x.js', array(), '0.1', true );
     51//  }
     52//  add_action( 'init', 'pixter_me_init');
     53
     54function show_pixter()
    4655{
    47     // declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php)
    48 //  wp_enqueue_script( 'pixter-me-global', 'http://ddd.rrr.com/x.js', array(), '0.1', true );
     56    global $post;
     57
     58    $options = (object)get_option('pixter_me_options');
     59    $post_type = get_post_type();
     60    switch ($post_type)
     61    {
     62        case 'page':
     63            if (!empty($options->show_pages) && $options->show_pages['enabled'] == 'on')
     64            {
     65                $pages = $options->show_pages['pages'];
     66                if (empty($pages) || !is_array($pages) || !in_array($post->ID, $pages))
     67                    return false;
     68            }
     69            break;
     70        case 'post':
     71            if (!empty($options->show_posts) && $options->show_posts['enabled'] == 'on')
     72            {
     73                $taxonomies = $options->show_posts['taxonomies'];
     74                if (empty($taxonomies))
     75                    return false;
     76
     77                $categories = wp_get_post_categories($post->ID, array('fields' => 'slugs'));
     78                foreach ($categories as $cat)
     79                    if (in_array($cat, $taxonomies))
     80                        return true;
     81
     82                return false;
     83            }
     84            break;
     85        default:
     86            break;
     87    }
     88    return true;
    4989}
    50 add_action( 'init', 'pixter_me_init');
    5190
    5291function pixter_me_inline_script()
    5392{
    54     $apiKey = get_option('pixter_me_user'); 
    55     if (!empty($apiKey) && !wp_script_is( 'pixter_me_inline', 'done' ) )
     93    $apiKey = get_option('pixter_me_user');
     94    if (!empty($apiKey) && !wp_script_is( 'pixter_me_inline', 'done' ) && show_pixter())
    5695    {
    5796        $options = (object)get_option('pixter_me_options');
     97
    5898        $button_text = $options->button_text;
    5999        $button_bg_color = $options->button_bg_color;
     
    67107            case 'bottom-left':     $cssPos = "left: 5px; top: auto!important; bottom: 5px;";   break;
    68108            case 'bottom-right':    $cssPos = "left: auto!important; right: 5px; top: auto!important; bottom: 5px;";    break;
    69         }       
    70        
     109        }
     110
    71111        */
    72112        $selector = $options->selector;
     
    80120        "selectors":"$selector", "minHeight":150, "minWidth":150, "position":"top-left",
    81121        "text":"$button_text", "textColor":"$button_text_color", "buttonColor":"$button_bg_color"
    82     }); 
     122    });
    83123}
    84124</script>
     
    88128        global $wp_scripts;
    89129        $wp_scripts->done[] = 'pixter_me_inline';
    90     }   
    91    
     130    }
     131
    92132}
    93133add_action( 'wp_footer', 'pixter_me_inline_script', 99999 );
Note: See TracChangeset for help on using the changeset viewer.