• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

「クラスリファレンス」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
(英語版 [http://codex.wordpress.org/Class_Reference/] をコピペ)
 
(先にコピペした英語版は誤っていました。すみません)
1行目: 1行目:
== Description ==
+
{{Languages|
 +
{{en|Class Reference}}
 +
{{ja|Class Reference}}
 +
}}
 +
__TOC__
 +
The files of WordPress define many useful PHP Classes. This article will try to list all/most of the core classes.
  
The WordPress User Class allows accessing properties, roles and capabilities of a specific user.
+
==Classes==
  
== Usage ==
+
The following classes were created by WordPress developers:
  
To instantiate a specific user, you may use the class constructor :
+
* atomentry
<pre><?php $users = new WP_User( $id [, $name [, $blog_id ] ] ); ?></pre>
+
* atomfeed
 +
* atomparser
 +
* atomserver
 +
* custom_background
 +
* custom_image_header
 +
* definition
 +
* enchantspell
 +
* file_upload_upgrader
 +
* ftp
 +
* ftp_base
 +
* gettext_translations
 +
* googlespell
 +
* ixr_base64
 +
* ixr_client
 +
* ixr_clientmulticall
 +
* ixr_date
 +
* ixr_error
 +
* ixr_introspectionserver
 +
* ixr_message
 +
* ixr_request
 +
* ixr_server
 +
* ixr_value
 +
* magpierss
 +
* mo
 +
* moxiecode_json
 +
* moxiecode_jsonreader
 +
* moxiecode_logger
 +
* noop_translations
 +
* passwordhash
 +
* pclzip
 +
* phpmailer
 +
* po
 +
* pomo_cachedfilereader
 +
* pomo_cachedintfilereader
 +
* pomo_filereader
 +
* pomo_reader
 +
* pomo_stringreader
 +
* pop3
 +
* pspell
 +
* pspellshell
 +
* rsscache
 +
* services_json
 +
* services_json_error
 +
* simplepie
 +
* simplepie_author
 +
* simplepie_cache
 +
* simplepie_cache_db
 +
* simplepie_cache_file
 +
* simplepie_cache_mysql
 +
* simplepie_caption
 +
* simplepie_category
 +
* simplepie_content_type_sniffer
 +
* simplepie_copyright
 +
* simplepie_credit
 +
* simplepie_decode_html_entities
 +
* simplepie_enclosure
 +
* simplepie_file
 +
* simplepie_gzdecode
 +
* simplepie_http_parser
 +
* simplepie_iri
 +
* simplepie_item
 +
* simplepie_locator
 +
* simplepie_misc
 +
* simplepie_net_ipv6
 +
* simplepie_parse_date
 +
* simplepie_parser
 +
* simplepie_rating
 +
* simplepie_restriction
 +
* simplepie_sanitize
 +
* simplepie_source
 +
* simplepie_xml_declaration_parser
 +
* smtp
 +
* snoopy
 +
* spellchecker
 +
* text_diff
 +
* text_diff_engine_native
 +
* text_diff_engine_shell
 +
* text_diff_engine_string
 +
* text_diff_engine_xdiff
 +
* text_diff_op
 +
* text_diff_op_add
 +
* text_diff_op_change
 +
* text_diff_op_copy
 +
* text_diff_op_delete
 +
* text_diff_renderer
 +
* text_diff_renderer_inline
 +
* text_mappeddiff
 +
* translation_entry
 +
* translations
 +
* [[Class_Reference/Walker|Walker]]
 +
** Walker_Category
 +
** Walker_Category_Checklist
 +
** Walker_CategoryDropdown
 +
** Walker_Comment
 +
** Walker_Nav_Menu
 +
*** Walker_Nav_Menu_Checklist
 +
*** Walker_Nav_Menu_Edit
 +
** Walker_Page
 +
** Walker_PageDropdown
 +
* [[Class Reference/WP | WP]] - General request handling.
 +
* [[Class Reference/WP_Admin_Bar | WP_Admin_Bar]] - Controls display and creation of Admin bar.
 +
* [[Class Reference/WP Ajax Response | WP_Ajax_Response]] - Handles XML responses to AJAX requests.
 +
* [[Class_Reference/WP_Customize_Manager|WP_Customize_Manager]] - (Instanced) Handles customization of the [[Theme_Customization_API|Theme Customizer]]
 +
* WP_Dependencies
 +
* [[Class Reference/WP_Embed | WP_Embed]]
 +
* [[Class Reference/WP Error | WP_Error]] - Error handling.
 +
* WP_Feed_Cache
 +
* WP_Feed_Cache_Transient
 +
* [[Class_Reference/WP_Filesystem_Base|WP_Filesystem_Base]]
 +
** WP_Filesystem_Direct
 +
** WP_Filesystem_Ftpext
 +
** WP_Filesystem_ftpsockets
 +
** WP_Filesystem_SSH2
 +
* WP_http
 +
* WP_http_cookie
 +
* WP_http_curl
 +
* WP_http_encoding
 +
* WP_http_exthttp
 +
* WP_http_fopen
 +
* WP_http_fsockopen
 +
* WP_http_proxy
 +
* WP_http_streams
 +
* WP_importer
 +
* [[Class Reference/WP_List_Table | WP_List_Table]] - Renders admin list tables.
 +
* [[Class Reference/WP_Locale | WP_Locale]] - Handles date and time locales.
 +
* [[Class Reference/WP_matchesmapregex | WP_matchesmapregex]]
 +
* [[Class Reference/WP_nav_menu_widget | WP_nav_menu_widget]]
 +
* [[Class Reference/WP_Object_Cache | WP_Object_Cache ]] - Cache and regenerate data.
 +
* [[Class Reference/WP_Oembed | WP_Oembed]]
 +
* [[Class Reference/WP Query | WP_Query ]] - Request parsing and manipulation, posts fetching.
 +
* [[Class Reference/WP Rewrite | WP_Rewrite ]] - Rewrite rules.
 +
* [[Class Reference/WP_Role | WP_Role]]
 +
* [[Class Reference/WP_Roles | WP_Roles]]
 +
* [[Class Reference/WP_Theme| WP_Theme]]
 +
* [[Class Reference/WP_Screen | WP_Screen]] - Controls admin screens
 +
* [[Class Reference/WP_Scripts | WP_Scripts]] - JavaScript loading.
 +
* [[Class Reference/WP_Simplepie_File | WP_Simplepie_File]]
 +
* [[Class Reference/WP_Styles | WP_Styles]] - CSS stylesheet loading.
 +
* [[Class Reference/WP_Text_diff_renderer_inline | WP_Text_diff_renderer_inline]]
 +
* [[Class Reference/WP_Text_diff_renderer_table | WP_Text_diff_renderer_table]]
 +
* [[Class Reference/WP_Upgrader | WP_Upgrader]]
 +
** [[Class Reference/Core_Upgrader | Core_Upgrader]]
 +
** [[Class Reference/Plugin_Upgrader | Plugin_Upgrader]]
 +
** [[Class Reference/Theme_Upgrader | Theme_Upgrader]]
 +
* WP_Upgrader_Skin
 +
** Bulk_Upgrader_Skin
 +
*** Bulk_Plugin_Upgrader_Skin
 +
*** Bulk_Theme_Upgrader_Skin
 +
** Plugin_Installer_Skin
 +
** Plugin_Upgrader_Skin
 +
** Theme_Installer_Skin
 +
** Theme_Upgrader_Skin
 +
* [[Class Reference/WP_User | WP_User]]
 +
* [[Class Reference/WP User Query | WP_User_Query]] - Queries for users in the database.
 +
* [[Class Reference/WP_Widget | WP_Widget]]
 +
** [[Class Reference/WP_Widget_Archives | WP_Widget_Archives]]
 +
** [[Class Reference/WP_Widget_Calendar | WP_Widget_Calendar]]
 +
** [[Class Reference/WP_Widget_Categories | WP_Widget_Categories]]
 +
** [[Class Reference/WP_Widget_Links | WP_Widget_Links]]
 +
** [[Class Reference/WP_Widget_Meta | WP_Widget_Meta]]
 +
** [[Class Reference/WP_Widget_Pages | WP_Widget_Pages]]
 +
** [[Class Reference/WP_Widget_Recent_comments | WP_Widget_Recent_comments]]
 +
** [[Class Reference/WP_Widget_Recent_posts | WP_Widget_Recent_posts]]
 +
** [[Class Reference/WP_Widget_RSS | WP_Widget_RSS]]
 +
** [[Class Reference/WP_Widget_Search | WP_Widget_Search]]
 +
** [[Class Reference/WP_Widget_Tag_cloud | WP_Widget_Tag_cloud]]
 +
** [[Class Reference/WP_Widget_Text | WP_Widget_Text]]
 +
* [[Class Reference/WP_Widget_Factory | WP_Widget_Factory]]
 +
* [[Class Reference/WP_XMLRPC_Server | WP_XMLRPC_Server]]
 +
* [[Class Reference/wpdb | wpdb]] - Database interface.
  
You can also use the <tt>[[Function_Reference/wp_get_current_user|wp_get_current_user]]</tt> global function to get a <tt>WP_User</tt> object matching the current logged user.
+
== External Classes ==
  
<pre><?php $current_user = wp_get_current_user(); ?></pre>
+
The following classes were created by non-wordpress developers:
  
== Constructor ==
+
* [http://scripts.incutio.com/xmlrpc/ IXR] - XML-RPC Classes
 +
* [http://sourceforge.net/projects/snoopy/ Snoopy] - HTTP client
 +
* [http://savannah.nongnu.org/projects/php-gettext/ gettext_reader] (part of PHP-gettext) - Localization Class
 +
* [http://magpierss.sourceforge.net/ RSS Classes (MagpieRSS and RSSCache)]
 +
* <tt>POP3</tt> - SquirrelMail wrapper
 +
* <tt>StreamReader, StringReader, FileReader, CachedFileReader</tt>
  
The <tt>WP_User</tt> constructor allows the following parameters :
+
== Resources ==
  
* '''<tt>id</tt>''' (''int'') - the user's id. Let empty to use login name instead.
+
* [http://phpxref.com/xref/wordpress/_classes/index.html PHPXref for WordPress Classes]
* '''<tt>name</tt>''' (''string'') - the user's login name. Ignored if id is set.
+
* [http://phpdoc.wordpress.org/trunk/classtrees_WordPress.html WordPress PHPdoc Class trees]
* '''<tt>blog_id</tt>''' (''int'') - the blog id on a multisite environment. Defaults to the current blog id.
+
  
The semantics seem rather fuzzy.  If id is a WP_User or other object, or an array of properties, it seems to clone it without touching the cache.  Otherwise if id is a number it seems to try to read it possibly from the cache, or from the database using ->get_data_by(), which can also update the cache.  If id is empty it reads by login name.
+
==Related==
  
== Public Properties ==
+
[[Category:Classes|*]]
 
+
[[Category:Advanced Topics]]
* '''<tt>ID</tt>''' (''int'') - the user's ID.
+
[[Category:WordPress Development]]
* '''<tt>caps</tt>''' (''array'') - the individual capabilities the user has been given.
+
* '''<tt>cap_key</tt>''' (''string'') -
+
* '''<tt>roles</tt>''' (''array'') - the roles the user is part of.
+
* '''<tt>allcaps</tt>''' (''array'') - all capabilities the user has, including individual and role based.
+
* '''<tt>first_name</tt>''' (''string'') - first name of the user.
+
* '''<tt>last_name</tt>''' (''string'') - last name of the user.
+
 
+
''Note:'' If called with the "id" or "name" parameter, the constructor queries the [[Database_Description#Table:_wp_users|wp_users table]]. If successful, the additional row data become properties of the object: '''user_login''', '''user_pass''', '''user_nicename''', '''user_email''', '''user_url''', '''user_registered''', '''user_activation_key''', '''user_status''', '''display_name''', '''spam''' (multisite only), '''deleted''' (multisite only).
+
 
+
== Magic Methods ==
+
 
+
=== <tt>__get( $key )</tt> ===
+
 
+
Magic method for accessing custom fields.
+
 
+
;Parameters :
+
* '''<tt>key</tt>''' (''string'') - property.
+
 
+
;Returns : (''string'') Single value of the property filtered.
+
 
+
;Since : 3.3.0
+
 
+
=== <tt>__isset( $key )</tt> ===
+
 
+
Determine whether a property or meta key is set from the users and usermeta tables.
+
 
+
;Parameters :
+
* '''<tt>key</tt>''' (''string'') - property.
+
 
+
;Returns : (''bool'') <tt>true</tt> if user has property, <tt>false</tt> otherwise.
+
 
+
;Since : 3.3.0
+
 
+
=== <tt>__set( $key, $value )</tt> ===
+
 
+
Magic method for setting custom fields.
+
 
+
;Parameters :
+
* '''<tt>key</tt>''' (''string'') - property.
+
* '''<tt>value</tt>''' (''string'') - value.
+
 
+
;Returns : Nothing.
+
 
+
;Since : 3.3.0
+
 
+
 
+
== Public Methods ==
+
 
+
=== <tt>exists()</tt> ===
+
 
+
Determine whether the user exists in the database.
+
 
+
It actually tests !empty(ID), which will normally indicate that the user record was in the database at some stage.  It does not access the database.
+
 
+
;Parameters : None
+
 
+
;Returns : (''bool'') <tt>true</tt> if user exists, <tt>false</tt> otherwise.
+
 
+
;Since : 3.4.0
+
 
+
=== <tt>get( $key )</tt> ===
+
 
+
Retrieve the value of a property or meta key from the users and usermeta tables.
+
 
+
;Parameters :
+
* '''<tt>key</tt>''' (''string'') - property.
+
 
+
;Returns : (''mixed'') String of the property filtered if single value, or array if value is stored as a serialized array
+
 
+
;Since : 3.3.0
+
 
+
=== <tt>has_prop( $key )</tt> ===
+
 
+
Determine whether a property or meta key is set from the users and usermeta tables.
+
 
+
;Parameters :
+
* '''<tt>key</tt>''' (''string'') - property.
+
 
+
;Returns : (''bool'') <tt>true</tt> if user has property, <tt>false</tt> otherwise.
+
 
+
;Since : 3.3.0
+
 
+
=== <tt>get_role_caps()</tt> ===
+
 
+
Retrieve all of the role capabilities and merge with individual capabilities.
+
 
+
All of the capabilities of the roles the user belongs to are merged with the users individual roles. This also means that the user can be denied specific roles that their role might have, but the specific user isn't granted permission to.
+
 
+
Sets the <tt>roles</tt> and <tt>allcaps</tt> properties.
+
 
+
;Parameters : None
+
 
+
;Returns : Nothing
+
 
+
;Since : 2.0.0
+
 
+
=== <tt>add_role( $role )</tt> ===
+
 
+
Add role to user.
+
 
+
Updates the user's meta data option with capabilities and roles.
+
 
+
;Parameters :
+
* '''<tt>role</tt>''' (''string'') - role name.
+
 
+
;Returns : Nothing
+
 
+
;Since : 2.0.0
+
 
+
=== <tt>remove_role($role)</tt> ===
+
 
+
Remove role from user.
+
 
+
;Parameters :
+
* '''<tt>role</tt>''' (''string'') - role name.
+
 
+
;Returns : Nothing
+
 
+
;Since : 2.0.0
+
 
+
=== <tt>set_role($role)</tt> ===
+
 
+
Set the role of the user.
+
 
+
This will remove the previous roles of the user and assign the user the new one. You can set the role to an empty string and it will remove all of the roles from the user.
+
 
+
;Parameters :
+
* '''<tt>role</tt>''' (''string'') - role name.
+
 
+
;Returns : Nothing
+
 
+
;Since : 2.0.0
+
 
+
;Related actions : * '''[[Plugin_API/Action_Reference/set_user_role|set_user_role]]'''
+
 
+
=== <tt>add_cap($cap [, $grant ] )</tt> ===
+
 
+
Add capability and grant or deny access to capability.
+
 
+
;Parameters :
+
 
+
* '''<tt>cap</tt>''' (''string'') - capability name.
+
* '''<tt>grant</tt>''' (''bool'') - whether to grant capability to user. Default to <tt>true</tt>.
+
 
+
;Returns : Nothing
+
 
+
;Since : 2.0.0
+
 
+
=== <tt>remove_cap($cap)</tt> ===
+
 
+
Remove capability from user.
+
 
+
;Parameters :
+
* '''<tt>cap</tt>''' (''string'') - capability name.
+
 
+
;Returns : Nothing
+
 
+
;Since : 2.0.0
+
 
+
=== <tt>remove_all_caps()</tt> ===
+
 
+
Remove all of the capabilities of the user.
+
 
+
;Parameters : None
+
 
+
;Returns : Nothing
+
 
+
;Since : 2.1.0
+
 
+
=== <tt>has_cap($cap)</tt> ===
+
 
+
Whether user has capability or role name.
+
 
+
;Parameters :
+
* '''<tt>cap</tt>''' (''string'') - capability or role name to search.
+
 
+
;Returns : (''bool'') <tt>true</tt> if user has capability, <tt>false</tt> if they do not have the capability.
+
 
+
;Since : 2.0.0
+
 
+
== Examples ==
+
 
+
Checking if the current user can edit user profiles :
+
 
+
<pre>
+
<?php
+
    $cu = wp_get_current_user();
+
    if ($cu->has_cap('edit_users')) {
+
      // do something
+
    }   
+
?>
+
</pre>
+
 
+
Check if user exists:
+
<pre>
+
<?php
+
    $user = wp_get_current_user();
+
    if ( $user->exists() ) {
+
      // do something
+
    }   
+
?>
+
</pre>
+
 
+
Check if user has a property:
+
<pre>
+
<?php
+
    $user = wp_get_current_user();
+
    if ( $user->has_prop( 'twitter' ) ) {
+
      // do something
+
    }   
+
?>
+
</pre>
+
 
+
== Change Log ==
+
 
+
;Updated : [[Version 3.4.0|3.4.0]]
+
 
+
;Updated : [[Version 3.3.0|3.3.0]]
+
 
+
;Since : [[Version 2.0|2.0.0]]
+
 
+
== Source File ==
+
 
+
<tt>WP_User</tt> is located in {{Trac|wp-includes/capabilities.php}}.
+
 
+
== Related ==
+
 
+
* [[Function_Reference/get_user_by|get_user_by]]
+
* [[Function_Reference/get_userdata|get_userdata]]
+
* [[Function_Reference/wp_set_current_user|wp_set_current_user]]
+
* [[Function_Reference/wp_get_current_user|wp_get_current_user]]
+
* [[Class_Reference/WP_Role|WP_Role]]
+
* [[Class_Reference/WP_Roles|WP_Roles]]
+
* [[Class_Reference/WP_User_Query|WP_User_Query]]
+
 
+
== External Links ==
+
 
+
* [http://scribu.net/wordpress/the-magic-of-wp_user.html Accessing custom fields using WP_User]
+
* [http://wpsmith.net/?p=17709 An Introduction to WP_User Class]
+
 
+
{{Class Footer}}
+
 
+
[[Category:Classes]]
+

2013年5月11日 (土) 19:10時点における版

[http://wpdocs.sourceforge.jp{{localurl: テンプレート:en テンプレート:ja }} 日本語] •

The files of WordPress define many useful PHP Classes. This article will try to list all/most of the core classes.

Classes

The following classes were created by WordPress developers:

External Classes

The following classes were created by non-wordpress developers:

Resources

Related