SHARE
TWEET

class-dportfolio

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