Advertisement
Menekko

Untitled

Oct 24th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.33 KB | None | 0 0
  1. //class-dportfolio.php
  2.  
  3. <?php
  4.  
  5. if ( ! defined( 'ABSPATH' ) ) exit;
  6.  
  7. class DPortfolio {
  8.  
  9.     private static $_instance = null;
  10.  
  11.     public $settings = null;
  12.     public $_version;
  13.     public $_token;
  14.     public $file;
  15.     public $dir;
  16.     public $assets_dir;
  17.     public $assets_url;
  18.  
  19.     public function __construct ( $file = '', $version = '1.0' ) {
  20.  
  21.         $this->_version = $version;
  22.         $this->_token = 'dportfolio';
  23.  
  24.         $this->file = $file;
  25.         $this->dir = dirname( $this->file );
  26.         $this->assets_dir = trailingslashit( $this->dir ) . 'assets';
  27.         $this->assets_url = get_template_directory_uri() . '/library/dportfolio/assets/';
  28.  
  29.         register_activation_hook( $this->file, array( $this, 'install' ) );
  30.  
  31.         add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ));
  32.         add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ));
  33.  
  34.         $this->load_plugin_textdomain();
  35.         add_action( 'init', array( $this, 'load_localisation' ), 0 );
  36.  
  37.     }
  38.  
  39.     public function enqueue_styles () {
  40.         wp_register_style( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'css/frontend.css', array(), $this->_version );
  41.         wp_enqueue_style( $this->_token . '-frontend' );
  42.     }
  43.  
  44.     public function enqueue_scripts () {
  45.  
  46.         wp_register_script( $this->_token . '-imagesloaded', esc_url( $this->assets_url ) . 'js/imagesloaded.pkgd.min.js', array( 'jquery' ), $this->_version, true );
  47.         wp_enqueue_script( $this->_token . '-imagesloaded' );
  48.  
  49.         wp_enqueue_script('masonry');  
  50.  
  51.         wp_register_script( $this->_token . '-multipleFilterMasonry', esc_url( $this->assets_url ) . 'js/multipleFilterMasonry.js', array( 'jquery' ), $this->_version, true );
  52.         wp_enqueue_script( $this->_token . '-multipleFilterMasonry' );
  53.  
  54.         wp_register_script( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'js/frontend.js', array( 'jquery' ), $this->_version, true );
  55.         wp_enqueue_script( $this->_token . '-frontend' );
  56.  
  57.     }
  58.  
  59.     public function load_localisation () {
  60.         load_plugin_textdomain( 'dportfolio', false, dirname( plugin_basename( $this->file ) ) . '/languages/' );
  61.     }
  62.  
  63.     public function load_plugin_textdomain () {
  64.  
  65.         $domain = 'dportfolio';
  66.         $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
  67.  
  68.         load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
  69.         load_plugin_textdomain( $domain, false, dirname( plugin_basename( $this->file ) ) . '/languages/' );
  70.  
  71.     }
  72.  
  73.     public function dportfolio_get_category() {
  74.  
  75.     global $post;
  76.  
  77.     $terms = get_the_terms( $post->ID, 'dportfolio_categories' );
  78.     $content = '';
  79.  
  80.     foreach ($terms as $term) {
  81.  
  82.         $content .= '<a href="'. $term->slug .'">'. $term->name .'</a>';
  83.  
  84.     }
  85.  
  86.     return $content;
  87.  
  88. }
  89.  
  90.     public static function instance ( $file = '', $version = '1.0.0' ) {
  91.  
  92.         if ( is_null( self::$_instance ) ) {
  93.  
  94.             self::$_instance = new self( $file, $version );
  95.  
  96.         }
  97.  
  98.         return self::$_instance;
  99.  
  100.     }
  101.  
  102.     public function __clone () {
  103.         _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), $this->_version );
  104.     }
  105.  
  106.     public function __wakeup () {
  107.         _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), $this->_version );
  108.     }
  109.  
  110.     public function install () {
  111.  
  112.         $this->_log_version_number();
  113.  
  114.         flush_rewrite_rules();
  115.  
  116.     }
  117.  
  118.     private function _log_version_number () {
  119.  
  120.         update_option( $this->_token . '_version', $this->_version );
  121.  
  122.     }
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement