Promoted changes/fixes to 0.2 for Echologics launch (23:31)
Showing
14 changed files
with
144 additions
and
97 deletions
| ... | @@ -33,7 +33,7 @@ class Auth { | ... | @@ -33,7 +33,7 @@ class Auth { |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | $auth = _signon(Array( | 35 | $auth = _signon(Array( |
| 36 | 'user_login' => $username | 36 | 'user_login' => esc_sql($username) |
| 37 | , 'user_password' => esc_sql($password) | 37 | , 'user_password' => esc_sql($password) |
| 38 | , 'remember' => $remember | 38 | , 'remember' => $remember |
| 39 | )); | 39 | )); |
| ... | @@ -63,9 +63,23 @@ class Auth { | ... | @@ -63,9 +63,23 @@ class Auth { |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | public static function register($user_data = Array(), $registration_method) { | 65 | public static function register($user_data = Array(), $registration_method) { |
| 66 | require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php'); | ||
| 67 | |||
| 68 | $valid = new Auth_Validation($user_data); | ||
| 69 | if (count($valid->errors) > 0) { | ||
| 70 | throw new BadMethodCallException(implode("\n", $valid->errors)); | ||
| 66 | } | 71 | } |
| 67 | 72 | ||
| 68 | public static function activate() { | 73 | array_filter($user_data, 'esc_sql'); |
| 74 | $id = (int)_insert_user($user_data); | ||
| 75 | |||
| 76 | global $wpdb; | ||
| 77 | $wpdb->query("UPDATE `{$wpdb->users}` SET `user_status` = 1 WHERE `ID` = {$id}"); | ||
| 78 | |||
| 79 | return $id; | ||
| 80 | } | ||
| 81 | |||
| 82 | public static function activate($username, $activation_key) { | ||
| 69 | do_action(self::ACTION_ACTIVATE, $user_id); | 83 | do_action(self::ACTION_ACTIVATE, $user_id); |
| 70 | } | 84 | } |
| 71 | 85 | ||
| ... | @@ -74,64 +88,49 @@ class Auth { | ... | @@ -74,64 +88,49 @@ class Auth { |
| 74 | } | 88 | } |
| 75 | } | 89 | } |
| 76 | 90 | ||
| 77 | class Auth_Validation { | 91 | class Auth_Validation extends Validation { |
| 78 | public static $errors = Array(); | ||
| 79 | |||
| 80 | /** | 92 | /** |
| 81 | * @rule Not blank | 93 | * @rule Not blank |
| 82 | * @rule Valid WordPress username | 94 | * @rule Valid WordPress username |
| 83 | * @returns Boolean | 95 | * @returns Boolean |
| 84 | */ | 96 | */ |
| 85 | public static function username($val) { | 97 | protected function username($val) { |
| 86 | if (empty($val)) { | 98 | if (empty($val)) { |
| 87 | self::$errors[] = 'Username is blank'; | 99 | throw new Exception('Username is blank'); |
| 88 | return false; | ||
| 89 | } | 100 | } |
| 90 | 101 | ||
| 91 | require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php'); | 102 | require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'registration.php'); |
| 92 | if (!validate_username($val)) { | 103 | if (!validate_username($val)) { |
| 93 | self::$errors[] = 'Username must be at least 4 characters, letters and numbers only'; | 104 | throw new Exception('Username must be at least 4 characters, letters and numbers only'); |
| 94 | return false; | ||
| 95 | } | 105 | } |
| 96 | 106 | ||
| 97 | if (username_exists($_POST['reg_username'])) { | 107 | if (username_exists($_POST['reg_username'])) { |
| 98 | self::$errors[] = 'Username already exists'; | 108 | throw new Exception('Username already exists'); |
| 99 | return false; | ||
| 100 | } | 109 | } |
| 101 | |||
| 102 | return true; | ||
| 103 | } | 110 | } |
| 104 | 111 | ||
| 105 | /** | 112 | /** |
| 106 | * @rule Not blank | 113 | * @rule Not blank |
| 107 | * @returns Boolean | 114 | * @returns Boolean |
| 108 | */ | 115 | */ |
| 109 | public static function password($val) { | 116 | protected function password($val) { |
| 110 | if (empty($val)) { | 117 | if (empty($val)) { |
| 111 | self::$errors[] = 'Password can not be blank'; | 118 | throw new Exception('Password can not be blank'); |
| 112 | return false; | ||
| 113 | } | 119 | } |
| 114 | self::$pass_check = $val; | ||
| 115 | |||
| 116 | return true; | ||
| 117 | } | 120 | } |
| 118 | 121 | ||
| 119 | /** | 122 | /** |
| 120 | * @rule Valid email address (*@*.*) | 123 | * @rule Valid email address (*@*.*) |
| 121 | * @returns Boolean | 124 | * @returns Boolean |
| 122 | */ | 125 | */ |
| 123 | public static function email($val) { | 126 | protected function email($val) { |
| 124 | if (!(boolean)filter_var($val, FILTER_VALIDATE_EMAIL)) { | 127 | if (!(boolean)filter_var($val, FILTER_VALIDATE_EMAIL)) { |
| 125 | self::$errors[] = 'Invalid email address'; | 128 | throw new Exception('Invalid email address'); |
| 126 | return false; | ||
| 127 | } | 129 | } |
| 128 | 130 | ||
| 129 | if (false !== email_exists($val)) { | 131 | if (false !== email_exists($val)) { |
| 130 | self::$errors[] = 'Email address already registered'; | 132 | throw new Exception('Email address already registered'); |
| 131 | return false; | ||
| 132 | } | 133 | } |
| 133 | |||
| 134 | return true; | ||
| 135 | } | 134 | } |
| 136 | } | 135 | } |
| 137 | ?> | 136 | ?> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -7,7 +7,7 @@ class Branding { | ... | @@ -7,7 +7,7 @@ class Branding { |
| 7 | 7 | ||
| 8 | class Branding_Actions { | 8 | class Branding_Actions { |
| 9 | public static function admin_print_styles() { | 9 | public static function admin_print_styles() { |
| 10 | _enqueue_style('branding-style', plugins_url('css/tenzing.css', __FILE__)); | 10 | _enqueue_style('branding-style', TzTools::tools_url('css/tenzing.css', __FILE__)); |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | public static function admin_head() { | 13 | public static function admin_head() { |
| ... | @@ -22,7 +22,7 @@ class Branding_Actions { | ... | @@ -22,7 +22,7 @@ class Branding_Actions { |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | public static function login_head() { | 24 | public static function login_head() { |
| 25 | echo '<link rel="stylesheet" type="text/css" href="' . plugins_url('css/tz_login.css', __FILE__) . '" />'; | 25 | echo '<link rel="stylesheet" type="text/css" href="' . TzTools::tools_url('css/tz_login.css', __FILE__) . '" />'; |
| 26 | } | 26 | } |
| 27 | } | 27 | } |
| 28 | 28 | ... | ... |
| ... | @@ -8,6 +8,8 @@ | ... | @@ -8,6 +8,8 @@ |
| 8 | } else { | 8 | } else { |
| 9 | echo($current_user->user_login); | 9 | echo($current_user->user_login); |
| 10 | } | 10 | } |
| 11 | ?></a> | <a href="<?php echo wp_logout_url(); ?>">Log Out</a> | 11 | ?></a> |
| 12 | | <a href="<?php echo get_settings('siteurl');?>">Home</a> | ||
| 13 | | <a href="<?php echo _logout_url(); ?>">Log Out</a> | ||
| 12 | </div> | 14 | </div> |
| 13 | </div> | 15 | </div> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -70,7 +70,7 @@ class PagePermissions { | ... | @@ -70,7 +70,7 @@ class PagePermissions { |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | // Meta value hasn't been set, getting settings defaults | 72 | // Meta value hasn't been set, getting settings defaults |
| 73 | if ('' === $data = get_custom_data(self::META, $post_id)) { | 73 | if (NULL === $data = array_shift(get_post_meta($post_id, self::META))) { |
| 74 | $data = Array(self::ELE_SEL => $settings[self::ELE_SEL], self::ELE_CUST => $settings[self::ELE_CUST]); | 74 | $data = Array(self::ELE_SEL => $settings[self::ELE_SEL], self::ELE_CUST => $settings[self::ELE_CUST]); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| ... | @@ -201,10 +201,10 @@ class PagePermissionsAdmin { | ... | @@ -201,10 +201,10 @@ class PagePermissionsAdmin { |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | public static function viewMetaBox($post, $box_info) { | 203 | public static function viewMetaBox($post, $box_info) { |
| 204 | $selected = ($post->ID == 0 ? self::getOptions() : get_custom_data(PagePermissions::META, $post->ID)); | 204 | $selected = ($post->ID == 0 ? self::getOptions() : array_shift(get_post_meta($post->ID, PagePermissions::META))); |
| 205 | 205 | ||
| 206 | // If the post doesn't have the field saved get defaults | 206 | // If the post doesn't have the field saved get defaults |
| 207 | if (empty($selected)) { | 207 | if (is_null($selected)) { |
| 208 | $selected = self::getOptions(); | 208 | $selected = self::getOptions(); |
| 209 | } | 209 | } |
| 210 | 210 | ||
| ... | @@ -262,6 +262,27 @@ class PagePermissions_Actions { | ... | @@ -262,6 +262,27 @@ class PagePermissions_Actions { |
| 262 | if ($file == '/wp-admin/media-new.php' && !PagePermissions::is_admin()) { | 262 | if ($file == '/wp-admin/media-new.php' && !PagePermissions::is_admin()) { |
| 263 | header("Location: " . $file . "?flash=0"); | 263 | header("Location: " . $file . "?flash=0"); |
| 264 | } | 264 | } |
| 265 | |||
| 266 | // This is hackey, but WP does't have hooks for this for some reason... | ||
| 267 | // Ideally this is in its own `edit_attachment` method...but that isn't working | ||
| 268 | if (isset($_POST['action']) && $_POST['action'] == 'editattachment') { | ||
| 269 | $real_id = $_POST['attachment_id']; | ||
| 270 | $current = array_shift(get_post_meta($real_id, PagePermissions::META)); | ||
| 271 | |||
| 272 | $new = Array(); | ||
| 273 | $new[PagePermissions::ELE_SEL] = $_POST[PagePermissions::ELE_SEL]; | ||
| 274 | if (isset($_POST[PagePermissions::ELE_CUST])) { | ||
| 275 | $new[PagePermissions::ELE_CUST] = $_POST[PagePermissions::ELE_CUST]; | ||
| 276 | } else { | ||
| 277 | $new[PagePermissions::ELE_CUST] = Array(); | ||
| 278 | } | ||
| 279 | |||
| 280 | if (is_null($current)) { | ||
| 281 | add_post_meta($real_id, PagePermissions::META, $new, true); | ||
| 282 | } else { | ||
| 283 | update_post_meta($real_id, PagePermissions::META, $new); | ||
| 284 | } | ||
| 285 | } | ||
| 265 | } | 286 | } |
| 266 | 287 | ||
| 267 | public static function admin_menu() { | 288 | public static function admin_menu() { |
| ... | @@ -274,8 +295,8 @@ class PagePermissions_Actions { | ... | @@ -274,8 +295,8 @@ class PagePermissions_Actions { |
| 274 | public static function admin_print_scripts() { | 295 | public static function admin_print_scripts() { |
| 275 | $innerhtml = ''; | 296 | $innerhtml = ''; |
| 276 | if ('0' !== ($change_field = (isset($_GET['attachment_id']) ? 'attachments[' . $_GET['attachment_id'] . '][' . PagePermissions::META . ']' : '0'))) { | 297 | if ('0' !== ($change_field = (isset($_GET['attachment_id']) ? 'attachments[' . $_GET['attachment_id'] . '][' . PagePermissions::META . ']' : '0'))) { |
| 277 | $selected = get_custom_data(PagePermissions::META, $_GET['attachment_id']); | 298 | $selected = array_shift(get_post_meta($_GET['attachment_id'], PagePermissions::META)); |
| 278 | if (empty($selected)) { | 299 | if (is_null($selected)) { |
| 279 | $selected = PagePermissionsAdmin::getOptions(); | 300 | $selected = PagePermissionsAdmin::getOptions(); |
| 280 | } | 301 | } |
| 281 | 302 | ||
| ... | @@ -285,16 +306,13 @@ class PagePermissions_Actions { | ... | @@ -285,16 +306,13 @@ class PagePermissions_Actions { |
| 285 | ob_end_clean(); | 306 | ob_end_clean(); |
| 286 | } | 307 | } |
| 287 | 308 | ||
| 288 | _enqueue_script('page-permissions', plugins_url('PagePermissions.js', __FILE__)); | 309 | _enqueue_script('page-permissions', TzTools::tools_url('PagePermissions.js', __FILE__)); |
| 289 | _localize_script('page-permissions', 'TzPagePermissionsData', Array( | 310 | _localize_script('page-permissions', 'TzPagePermissionsData', Array( |
| 290 | 'trigger' => PagePermissions::ELE_SEL | 311 | 'trigger' => PagePermissions::ELE_SEL |
| 291 | , 'focus' => PagePermissions::OPT_CUST | 312 | , 'focus' => PagePermissions::OPT_CUST |
| 292 | , 'change_field' => $change_field | 313 | , 'change_field' => $change_field |
| 293 | , 'innerHTML' => rawurlencode($innerhtml) | 314 | , 'innerHTML' => rawurlencode($innerhtml) |
| 294 | )); | 315 | )); |
| 295 | |||
| 296 | //attachments[304][accessible_to_roles] | ||
| 297 | //a:2:{s:14:"general_access";s:1:"1";s:5:"roles";a:1:{s:6:"editor";s:1:"1";}} | ||
| 298 | } | 316 | } |
| 299 | 317 | ||
| 300 | public static function save_post($post_id) { | 318 | public static function save_post($post_id) { |
| ... | @@ -305,7 +323,7 @@ class PagePermissions_Actions { | ... | @@ -305,7 +323,7 @@ class PagePermissions_Actions { |
| 305 | if (false === ($real_id = _is_post_revision($post_id))) { | 323 | if (false === ($real_id = _is_post_revision($post_id))) { |
| 306 | $real_id = $post_id; | 324 | $real_id = $post_id; |
| 307 | } | 325 | } |
| 308 | $current = get_custom_data(PagePermissions::META, $real_id); | 326 | $current = array_shift(get_post_meta($real_id, PagePermissions::META)); |
| 309 | 327 | ||
| 310 | $new = Array(); | 328 | $new = Array(); |
| 311 | $new[PagePermissions::ELE_SEL] = $_POST[PagePermissions::ELE_SEL]; | 329 | $new[PagePermissions::ELE_SEL] = $_POST[PagePermissions::ELE_SEL]; |
| ... | @@ -315,7 +333,7 @@ class PagePermissions_Actions { | ... | @@ -315,7 +333,7 @@ class PagePermissions_Actions { |
| 315 | $new[PagePermissions::ELE_CUST] = Array(); | 333 | $new[PagePermissions::ELE_CUST] = Array(); |
| 316 | } | 334 | } |
| 317 | 335 | ||
| 318 | if (empty($current)) { | 336 | if (is_null($current)) { |
| 319 | add_post_meta($real_id, PagePermissions::META, $new, true); | 337 | add_post_meta($real_id, PagePermissions::META, $new, true); |
| 320 | } else { | 338 | } else { |
| 321 | update_post_meta($real_id, PagePermissions::META, $new); | 339 | update_post_meta($real_id, PagePermissions::META, $new); | ... | ... |
| ... | @@ -110,7 +110,7 @@ class ShortCodes_Actions { | ... | @@ -110,7 +110,7 @@ class ShortCodes_Actions { |
| 110 | 110 | ||
| 111 | public static function admin_print_scripts() { | 111 | public static function admin_print_scripts() { |
| 112 | if ($GLOBALS['editing']) { | 112 | if ($GLOBALS['editing']) { |
| 113 | _enqueue_script('shortcoder', plugins_url('shortcoder.js', __FILE__), Array('jquery')); | 113 | _enqueue_script('shortcoder', TzTools::tools_url('shortcoder.js', __FILE__), Array('jquery')); |
| 114 | 114 | ||
| 115 | echo "<script type=\"text/javascript\">\n/* <![CDATA[ */\n"; | 115 | echo "<script type=\"text/javascript\">\n/* <![CDATA[ */\n"; |
| 116 | echo 'var TzRegisteredShortCodes = ' . json_encode(ShortCodes::getRegistered()); | 116 | echo 'var TzRegisteredShortCodes = ' . json_encode(ShortCodes::getRegistered()); | ... | ... |
| ... | @@ -4,7 +4,7 @@ class MenuWidget extends WP_Widget { | ... | @@ -4,7 +4,7 @@ class MenuWidget extends WP_Widget { |
| 4 | register_widget(__CLASS__); | 4 | register_widget(__CLASS__); |
| 5 | 5 | ||
| 6 | if (is_admin()) { | 6 | if (is_admin()) { |
| 7 | _enqueue_script('tz-menu-widget', plugins_url('MenuWidget.js', __FILE__), Array('addEvent')); | 7 | _enqueue_script('tz-menu-widget', TzTools::tools_url('MenuWidget.js', __FILE__), Array('addEvent')); |
| 8 | } | 8 | } |
| 9 | } | 9 | } |
| 10 | 10 | ... | ... |
lib/Validation.php
0 → 100644
| 1 | <?php | ||
| 2 | abstract class Validation { | ||
| 3 | /** | ||
| 4 | * Associative array of valid fields | ||
| 5 | * @type Array | ||
| 6 | * @public | ||
| 7 | * @read-only | ||
| 8 | */ | ||
| 9 | private $valid = Array(); | ||
| 10 | |||
| 11 | /** | ||
| 12 | * Associative array if invalid fields | ||
| 13 | * @type Array | ||
| 14 | * @public | ||
| 15 | * @read-only | ||
| 16 | */ | ||
| 17 | private $errors = Array(); | ||
| 18 | |||
| 19 | /** | ||
| 20 | * @param {Array} $data Associative array of data to validate | ||
| 21 | */ | ||
| 22 | final public function __construct(Array $data) { | ||
| 23 | foreach ($data as $key => $val) { | ||
| 24 | if (method_exists($this, $key)) { | ||
| 25 | try { | ||
| 26 | call_user_func(Array($this, $key), $val); | ||
| 27 | $this->valid[$key] = $val; | ||
| 28 | } catch (Exception $e) { | ||
| 29 | $this->errors[$key] = $e->getMessage(); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | /** | ||
| 36 | * @private | ||
| 37 | */ | ||
| 38 | final public function __get($key) { | ||
| 39 | $private = $key; | ||
| 40 | if (isset($this->$private)) { | ||
| 41 | return $this->$private; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | ?> |
| ... | @@ -11,17 +11,20 @@ class WP_Option implements ArrayAccess, Countable { | ... | @@ -11,17 +11,20 @@ class WP_Option implements ArrayAccess, Countable { |
| 11 | $this->_ns = $ns; | 11 | $this->_ns = $ns; |
| 12 | $this->_data = get_option($ns); | 12 | $this->_data = get_option($ns); |
| 13 | 13 | ||
| 14 | $changed = false; | ||
| 14 | if (is_array($defaults)) { | 15 | if (is_array($defaults)) { |
| 15 | foreach ($this->_data as $key => $val) { | 16 | foreach ($defaults as $key => $val) { |
| 16 | $defaults[$key] = $val; | 17 | if (!isset($this->_data[$key])) { |
| 18 | $this->_data[$key] = $val; | ||
| 19 | $changed = true; | ||
| 20 | } | ||
| 21 | } | ||
| 17 | } | 22 | } |
| 18 | 23 | ||
| 19 | if ($this->_data != $defaults) { | 24 | if ($changed) { |
| 20 | $this->_data = $defaults; | ||
| 21 | $this->save(); | 25 | $this->save(); |
| 22 | } | 26 | } |
| 23 | } | 27 | } |
| 24 | } | ||
| 25 | 28 | ||
| 26 | public function offsetExists($var) { | 29 | public function offsetExists($var) { |
| 27 | return (isset($this->_data[$var]) ? true : false); | 30 | return (isset($this->_data[$var]) ? true : false); | ... | ... |
File moved
File moved
| ... | @@ -2,28 +2,28 @@ | ... | @@ -2,28 +2,28 @@ |
| 2 | /* | 2 | /* |
| 3 | Plugin Name: Tenzing Tools | 3 | Plugin Name: Tenzing Tools |
| 4 | Version: 0.2 | 4 | Version: 0.2 |
| 5 | Description: Various classes to help out with stuff | 5 | Description: Various classes and functions to help out with stuff |
| 6 | Author: Tenzing | ||
| 7 | */ | 6 | */ |
| 8 | 7 | ||
| 9 | if (version_compare(PHP_VERSION, '5.2.2') !== 1) { | 8 | TzTools::make(); |
| 10 | die('PHP version 5.2.2 or greater is required'); | ||
| 11 | } | ||
| 12 | |||
| 13 | TzTools::load(); | ||
| 14 | 9 | ||
| 15 | class TzTools { | 10 | class TzTools { |
| 16 | public static function load() { | 11 | public static function make() { |
| 17 | spl_autoload_register(Array(__CLASS__, 'autoloader')); | 12 | spl_autoload_register(Array(__CLASS__, 'autoloader')); |
| 18 | 13 | ||
| 19 | require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wp_functions.php'); | 14 | require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'wp_functions.php'); |
| 20 | 15 | ||
| 21 | _register_script('addEvent', plugins_url('addEvent.js', __FILE__)); | 16 | _register_script('addEvent', self::tools_url('scripts/addEvent.js', __FILE__)); |
| 22 | _register_script('xmlhttpHandler', plugins_url('xmlhttpHandler.js', __FILE__)); | 17 | _register_script('xmlhttpHandler', self::tools_url('scripts/xmlhttpHandler.js', __FILE__)); |
| 23 | _register_script('fireEvent', plugins_url('fireEvent.js', __FILE__)); | 18 | _register_script('fireEvent', self::tools_url('scripts/fireEvent.js', __FILE__)); |
| 24 | 19 | ||
| 20 | // This is (hopefully) getting canned in 3.0 | ||
| 25 | add_action('widgets_init', Array('MenuWidget', 'init')); | 21 | add_action('widgets_init', Array('MenuWidget', 'init')); |
| 22 | |||
| 26 | self::import('ShortCodes'); | 23 | self::import('ShortCodes'); |
| 24 | if (defined('TZ_DEBUG') && TZ_DEBUG === true) { | ||
| 25 | self::import('Debug'); | ||
| 26 | } | ||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | public static function import($com) { | 29 | public static function import($com) { |
| ... | @@ -40,6 +40,14 @@ class TzTools { | ... | @@ -40,6 +40,14 @@ class TzTools { |
| 40 | include($file); | 40 | include($file); |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | |||
| 44 | public static function tools_url($script, $base_file = false) { | ||
| 45 | $base_dir = (false === $base_file ? dirname(__FILE__) : dirname($base_file)); | ||
| 46 | $rel_path = str_replace(ABSPATH, '', $base_dir); | ||
| 47 | $script = site_url() . '/' . $rel_path . '/' . $script; | ||
| 48 | |||
| 49 | return $script; | ||
| 50 | } | ||
| 43 | } | 51 | } |
| 44 | 52 | ||
| 45 | function add_actions($class) { | 53 | function add_actions($class) { |
| ... | @@ -65,42 +73,4 @@ function add_filters($class) { | ... | @@ -65,42 +73,4 @@ function add_filters($class) { |
| 65 | add_filter($method->name, Array($class, $method->name)); | 73 | add_filter($method->name, Array($class, $method->name)); |
| 66 | } | 74 | } |
| 67 | } | 75 | } |
| 68 | |||
| 69 | function get_custom_data($name, $post_id = false) { | ||
| 70 | if (false === $type = get_post_type($post_id)) { | ||
| 71 | throw new InvalidArgumentException("Post {$post_id} does not exist"); | ||
| 72 | } | ||
| 73 | |||
| 74 | $raw_data = call_user_func_array("_custom_{$type}", Array($post_id, $name)); | ||
| 75 | |||
| 76 | if (null === $raw_data) { | ||
| 77 | return ''; | ||
| 78 | } | ||
| 79 | |||
| 80 | return $raw_data; | ||
| 81 | } | ||
| 82 | |||
| 83 | function _custom_attachment($post_id, $custom_name) { | ||
| 84 | if (false === ($tax_object = get_the_terms($post_id, $custom_name))) { | ||
| 85 | return ''; | ||
| 86 | } | ||
| 87 | $tax_data = array_shift($tax_object); | ||
| 88 | |||
| 89 | return $tax_data->name; | ||
| 90 | } | ||
| 91 | |||
| 92 | function _custom_page($post_id, $custom_name) { | ||
| 93 | $custom = get_post_meta($post_id, $custom_name); | ||
| 94 | return array_shift($custom); | ||
| 95 | } | ||
| 96 | |||
| 97 | function _custom_post() { | ||
| 98 | $args = func_get_args(); | ||
| 99 | return call_user_func_array('_custom_page', $args); | ||
| 100 | } | ||
| 101 | |||
| 102 | function _custom_revision() { | ||
| 103 | $args = func_get_args(); | ||
| 104 | return call_user_func_array('_custom_page', $args); | ||
| 105 | } | ||
| 106 | ?> | 76 | ?> | ... | ... |
| ... | @@ -149,4 +149,14 @@ function _update_user() { | ... | @@ -149,4 +149,14 @@ function _update_user() { |
| 149 | $params = func_get_args(); | 149 | $params = func_get_args(); |
| 150 | return call_user_func_array('wp' . __FUNCTION__, $params); | 150 | return call_user_func_array('wp' . __FUNCTION__, $params); |
| 151 | } | 151 | } |
| 152 | |||
| 153 | function _make_link_relative() { | ||
| 154 | $params = func_get_args(); | ||
| 155 | return call_user_func_array('wp' . __FUNCTION__, $params); | ||
| 156 | } | ||
| 157 | |||
| 158 | function _logout_url() { | ||
| 159 | $params = func_get_args(); | ||
| 160 | return call_user_func_array('wp' . __FUNCTION__, $params); | ||
| 161 | } | ||
| 152 | ?> | 162 | ?> | ... | ... |
-
Please register or sign in to post a comment