PluginProbe
FakerPress / 0.1.1
FakerPress v0.1.1
0.9.2 trunk 0.1.0 0.1.1 0.1.2 0.1.3 0.5.2 0.5.3 0.6.1 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.7.0 0.7.1 0.7.2 0.8.0 0.9.0 0.9.1
fakerpress / classes / plugin.php

plugin.php in FakerPress 0.1.1, at classes/plugin.php

130 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace FakerPress;
3
4 class Plugin {
5 /**
6 * Plugin version, used for cache-busting of style and script file references.
7 *
8 * @since 0.1.0
9 * @var string
10 */
11 const version = '0.1.1';
12
13 /**
14 * A static variable that holds a dinamic instance of the class
15 *
16 * @since 0.1.0
17 * @var null|object The dynamic version of this class
18 */
19 public static $instance = null;
20
21 /**
22 * A static variable that holds a dinamic instance of the class of the admin
23 *
24 * @since 0.1.0
25 * @var null|object The dynamic version of this class
26 */
27 public static $admin = null;
28
29 /**
30 * Variable holding the folder name of the plugin
31 *
32 * @since 0.1.0
33 * @var string
34 */
35 public static $folder = 'fakerpress';
36
37 /**
38 * Variable holding the slug name of the plugin
39 *
40 * @since 0.1.0
41 * @var string
42 */
43 public static $slug = 'fakerpress';
44
45 /**
46 * The __FILE__ that initialized the plugin
47 *
48 * @since 0.1.0
49 * @var string/path
50 */
51 public static $_file = __FP_FILE__;
52
53 /**
54 * Return a Path relative to the plugin root
55 *
56 * @since 0.1.0
57 * @param string $append A string to be appended to the root path
58 * @uses plugin_dir_path
59 * @return string The path after been appended by the variable
60 */
61 public static function path( $append = '' ) {
62 return (string) plugin_dir_path( self::$_file ) . str_replace( '/', DIRECTORY_SEPARATOR, $append );
63 }
64
65 /**
66 * Return a URL relative to the plugin root
67 *
68 * @since 0.1.0
69 * @param string $file A string to be appended to the root url
70 * @uses plugins_url
71 * @return string The url to the file
72 */
73 public static function url( $file = '' ) {
74 return (string) plugins_url( $file, self::basename() );
75 }
76
77 /**
78 * Return a URL relative to the plugin's administration page
79 *
80 * @since 0.1.0
81 * @param string|array $args Arguments for the admin URL
82 * @param string $hash Hash for the admin URL
83 * @uses admin_url
84 * @uses wp_parse_args
85 * @uses add_query_arg
86 * @return string The url to the file
87 */
88 public static function admin_url( $args = '', $hash = false ) {
89 /**
90 * Define the array of defaults
91 */
92 $defaults = array(
93 'page' => self::$slug,
94 );
95
96 /**
97 * Parse incoming $args into an array and merge it with $defaults
98 */
99 $args = wp_parse_args( $args, $defaults );
100
101 return add_query_arg( $args, admin_url( 'admin.php' ) ) . ( $hash !== false ? "#{$hash}" : '' );
102 }
103
104 /**
105 * Return the plugin basename
106 *
107 * @since 0.1.0
108 * @uses plugin_basename
109 * @return string plugin_basename from __FILE__
110 */
111 public static function basename() {
112 $_link = WP_PLUGIN_DIR . '/' . self::$folder;
113 $_file = self::$_file;
114
115 if ( is_link( $_link ) && readlink( $_link ) == dirname( $_file ) ) {
116 $_file = $_link . '/' . end( explode( '/', $_file ) );
117 }
118 return (string) plugin_basename( $_file );
119 }
120
121 /**
122 * The initialization of the static and dynamic variables
123 *
124 * @since 0.1.0
125 */
126 public function __construct(){
127 // Setup the global version of the class, this only runs once...
128 null === self::$instance and self::$instance = &$this;
129 }
130 }