本文整理汇总了PHP中current_user_can函数的典型用法代码示例。如果您正苦于以下问题:PHP current_user_can函数的具体用法?PHP current_user_can怎么用?PHP current_user_can使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了current_user_can函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate_ryuzine_stylesheets
function generate_ryuzine_stylesheets()
{
// verify this came from the our screen and with proper authorization.
if (!wp_verify_nonce($_POST['ryu_regenstyles_noncename'], 'ryuzine-regenstyles_install')) {
return;
}
// Check permissions
if (!current_user_can('administrator')) {
echo "<div class='error'><p>Sorry, you do not have the correct priveledges to install the files.</p></div>";
return;
}
$my_query = null;
$my_query = new WP_Query(array('post_type' => 'ryuzine'));
if ($my_query->have_posts()) {
while ($my_query->have_posts()) {
$my_query->the_post();
$stylesheet = "";
$issuestyles = get_post_meta(get_the_ID(), '_ryustyles', false);
if (!empty($issuestyles)) {
foreach ($issuestyles as $appendstyle) {
// If there are multiple ryustyles append them //
$stylesheet = $stylesheet . $appendstyle;
}
}
if ($stylesheet != "") {
ryu_create_css($stylesheet, get_the_ID());
}
}
}
// reset css check //
// update_option('ryu_css_admin',0);
wp_reset_query();
return;
}
示例2: sf_sc_button
function sf_sc_button()
{
if (current_user_can('edit_posts') && current_user_can('edit_pages')) {
add_filter('mce_external_plugins', 'sf_add_tinymce_plugin');
add_filter('mce_buttons', 'sf_register_shortcode_button');
}
}
示例3: post_save
/**
* Save Force SSL option to post or page
*
* @param int $post_id
* @return int $post_id
*/
public function post_save($post_id)
{
if (array_key_exists($this->getPlugin()->getSlug(), $_POST)) {
if (!wp_verify_nonce($_POST[$this->getPlugin()->getSlug()], $this->getPlugin()->getSlug())) {
return $post_id;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
if (@$_POST['post_type'] == 'page') {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
} else {
if (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
}
$force_ssl = @$_POST['force_ssl'] == 1 ? true : false;
if ($force_ssl) {
update_post_meta($post_id, 'force_ssl', 1);
} else {
delete_post_meta($post_id, 'force_ssl');
}
$force_ssl_children = @$_POST['force_ssl_children'] == 1 ? true : false;
if ($force_ssl_children) {
update_post_meta($post_id, 'force_ssl_children', 1);
} else {
delete_post_meta($post_id, 'force_ssl_children');
}
}
return $post_id;
}
示例4: to_json
/**
* Refresh the parameters passed to the JavaScript via JSON.
*
* @since 3.4.0
* @since 4.2.0 Moved from WP_Customize_Upload_Control.
*
* @see WP_Customize_Control::to_json()
*/
public function to_json()
{
parent::to_json();
$this->json['label'] = html_entity_decode($this->label, ENT_QUOTES, get_bloginfo('charset'));
$this->json['mime_type'] = $this->mime_type;
$this->json['button_labels'] = $this->button_labels;
$this->json['canUpload'] = current_user_can('upload_files');
$value = $this->value();
if (is_object($this->setting)) {
if ($this->setting->default) {
// Fake an attachment model - needs all fields used by template.
// Note that the default value must be a URL, NOT an attachment ID.
$type = in_array(substr($this->setting->default, -3), array('jpg', 'png', 'gif', 'bmp')) ? 'image' : 'document';
$default_attachment = array('id' => 1, 'url' => $this->setting->default, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($this->setting->default));
if ('image' === $type) {
$default_attachment['sizes'] = array('full' => array('url' => $this->setting->default));
}
$this->json['defaultAttachment'] = $default_attachment;
}
if ($value && $this->setting->default && $value === $this->setting->default) {
// Set the default as the attachment.
$this->json['attachment'] = $this->json['defaultAttachment'];
} elseif ($value) {
$this->json['attachment'] = wp_prepare_attachment_for_js($value);
}
}
}
示例5: add_admin_bar_menu
/**
* Adds menu item to the admin bar
*/
function add_admin_bar_menu()
{
global $wp_admin_bar;
if (current_user_can('NextGEN Change options')) {
$wp_admin_bar->add_menu(array('parent' => 'ngg-menu', 'id' => 'ngg-menu-display_settings', 'title' => __('Gallery Settings', 'nggallery'), 'href' => admin_url('admin.php?page=ngg_display_settings')));
}
}
示例6: InitClass
static function InitClass()
{
wp_enqueue_style(WPFB . '-admin', WPFB_PLUGIN_URI . 'css/admin.css', array(), WPFB_VERSION, 'all');
wp_register_script('jquery-deserialize', WPFB_PLUGIN_URI . 'bower_components/jquery-deserialize/dist/jquery.deserialize.min.js', array('jquery'), WPFB_VERSION);
if (isset($_GET['page'])) {
$page = $_GET['page'];
if ($page == 'wpfilebase_files') {
wp_enqueue_script('postbox');
wp_enqueue_style('dashboard');
} elseif ($page == 'wpfilebase' && isset($_GET['action']) && $_GET['action'] == 'sync') {
do_action('wpfilebase_sync');
wp_die("Filebase synced.");
}
}
add_action('wp_dashboard_setup', array(__CLASS__, 'AdminDashboardSetup'));
//wp_register_widget_control(WPFB_PLUGIN_NAME, "[DEPRECATED]".WPFB_PLUGIN_NAME .' '. __('File list','wp-filebase'), array(__CLASS__, 'WidgetFileListControl'), array('description' => __('DEPRECATED','wp-filebase')));
add_action('admin_print_scripts', array('WPFB_AdminLite', 'AdminPrintScripts'));
self::CheckChangedVer();
if (basename($_SERVER['PHP_SELF']) === "plugins.php") {
if (isset($_GET['wpfb-uninstall']) && current_user_can('edit_files')) {
update_option('wpfb_uninstall', !empty($_GET['wpfb-uninstall']) && $_GET['wpfb-uninstall'] != "0");
}
if (get_option('wpfb_uninstall')) {
function wpfb_uninstall_warning()
{
echo "\n\t\t\t\t<div id='wpfb-warning' class='updated fade'><p><strong>" . __('WP-Filebase will be uninstalled completely when deactivating the Plugin! All settings and File/Category Info will be deleted. Actual files in the upload directory will not be removed.', 'wp-filebase') . ' <a href="' . add_query_arg('wpfb-uninstall', '0') . '">' . __('Cancel') . "</a></strong></p></div>\n\t\t\t\t";
}
add_action('admin_notices', 'wpfb_uninstall_warning');
}
}
}
示例7: my_plugin_options
function my_plugin_options()
{
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
?>
<center>
<h1>Add Menu</h1>
<label for="name">Add a New Menu to the site: </label><br/>
<input type="text" id="name" name="name" placeholder="Enter Menu Name"/>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button class="btn btn-info" onclick="anthonyportfolioajax()">Add New Menu</button>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script>
function anthonyportfolioajax()
{
var name = $('#name').val();
var data = {
'action': 'process_add',
'name': name
};
$.post( ajaxurl, data, function(response ){
var mes = "Menu has been added Successfully";
$("#myDiv").text( mes );
var name = $('#name').val();
alert(ajaxurl);
console.log(response);
}
);
}
</script>
</center>
<?php
}
示例8: ultimatum_meta_save_postdata
function ultimatum_meta_save_postdata( $post_id, $post ) {
//echo '<pre>';print_r($_POST);die();
//* Verify the nonce
if ( ! isset( $_POST[ 'ultimatum_additional_meta_nonce' ] ) || ! wp_verify_nonce( $_POST[ 'ultimatum_additional_meta_nonce' ], 'ultimatum_additional_meta' ) )
return;
//* Don't try to save the data under autosave, ajax, or future post.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
return;
if ( defined( 'DOING_CRON' ) && DOING_CRON )
return;
//* Grab the post object
$post = get_post( $post );
//* Don't save if WP is creating a revision (same as DOING_AUTOSAVE?)
if ( 'revision' === $post->post_type )
return;
//* Check that the user is allowed to edit the post
if ( ! current_user_can( 'edit_post', $post->ID ) )
return;
$mydata = $_POST['ultimatum_video'];
update_post_meta($post->ID, 'ultimatum_video', $mydata);
$mydata = $_POST['ultimatum_author'];
update_post_meta($post->ID, 'ultimatum_author', $mydata);
}
示例9: um_admin_user_actions_hook
function um_admin_user_actions_hook($actions)
{
$actions = null;
if (!um_user('super_admin')) {
if (um_user('account_status') == 'awaiting_admin_review') {
$actions['um_approve_membership'] = array('label' => __('Approve Membership', 'ultimatemember'));
$actions['um_reject_membership'] = array('label' => __('Reject Membership', 'ultimatemember'));
}
if (um_user('account_status') == 'rejected') {
$actions['um_approve_membership'] = array('label' => __('Approve Membership', 'ultimatemember'));
}
if (um_user('account_status') == 'approved') {
$actions['um_put_as_pending'] = array('label' => __('Put as Pending Review', 'ultimatemember'));
}
if (um_user('account_status') == 'awaiting_email_confirmation') {
$actions['um_resend_activation'] = array('label' => __('Resend Activation E-mail', 'ultimatemember'));
}
if (um_user('account_status') != 'inactive') {
$actions['um_deactivate'] = array('label' => __('Deactivate this account', 'ultimatemember'));
}
if (um_user('account_status') == 'inactive') {
$actions['um_reenable'] = array('label' => __('Reactivate this account', 'ultimatemember'));
}
if (um_current_user_can('delete', um_profile_id())) {
$actions['um_delete'] = array('label' => __('Delete this user', 'ultimatemember'));
}
}
if (current_user_can('delete_users')) {
$actions['um_switch_user'] = array('label' => __('Login as this user', 'ultimatemember'));
}
um_fetch_user(um_profile_id());
return $actions;
}
示例10: process
/**
* Process the request
* @todo Setting for reassigning user's posts
*/
public function process()
{
// Verify the security nonce and die if it fails
if (!isset($_POST['wp_delete_user_accounts_nonce']) || !wp_verify_nonce($_POST['wp_delete_user_accounts_nonce'], 'wp_delete_user_accounts_nonce')) {
wp_send_json(array('status' => 'fail', 'title' => __('Error!', 'wp-delete-user-accounts'), 'message' => __('Request failed security check.', 'wp-delete-user-accounts')));
}
// Don't permit admins to delete their own accounts
if (current_user_can('manage_options')) {
wp_send_json(array('status' => 'fail', 'title' => __('Error!', 'wp-delete-user-accounts'), 'message' => __('Administrators cannot delete their own accounts.', 'wp-delete-user-accounts')));
}
// Get the current user
$user_id = get_current_user_id();
// Get user meta
$meta = get_user_meta($user_id);
// Delete user's meta
foreach ($meta as $key => $val) {
delete_user_meta($user_id, $key);
}
// Destroy user's session
wp_logout();
// Delete the user's account
$deleted = wp_delete_user($user_id);
if ($deleted) {
// Send success message
wp_send_json(array('status' => 'success', 'title' => __('Success!', 'wp-delete-user-accounts'), 'message' => __('Your account was successfully deleted. Fair well.', 'wp-delete-user-accounts')));
} else {
wp_send_json(array('status' => 'fail', 'title' => __('Error!', 'wp-delete-user-accounts'), 'message' => __('Request failed.', 'wp-delete-user-accounts')));
}
}
示例11: wptreehouse_badges_options_page
function wptreehouse_badges_options_page()
{
if (!current_user_can('manage_options')) {
wp_die('You do not have sufficient permissions to access this page.');
}
global $plugin_url;
global $options;
global $display_json;
if (isset($_POST['wptreehouse_form_submitted'])) {
$hidden_field = esc_html($_POST['wptreehouse_form_submitted']);
if ($hidden_field == 'Y') {
$wptreehouse_username = esc_html($_POST['wptreehouse_username']);
$wptreehouse_profile = wptreehouse_badges_get_profile($wptreehouse_username);
$options['wptreehouse_username'] = $wptreehouse_username;
$options['wptreehouse_profile'] = $wptreehouse_profile;
$options['last_updated'] = time();
update_option('wptreehouse_badges', $options);
}
}
$options = get_option('wptreehouse_badges');
if ($options != '') {
$wptreehouse_username = $options['wptreehouse_username'];
$wptreehouse_profile = $options['wptreehouse_profile'];
}
require 'inc/options-page-wrapper.php';
}
开发者ID:ariwinokur,项目名称:official-treehouse-badges-widgets-and-shortcodes,代码行数:26,代码来源:wptreehouse-badges.php
示例12: comcon_meta_save
function comcon_meta_save()
{
global $post;
$post_id = $post->ID;
if (!isset($_POST['comcon-form-nonce']) || !wp_verify_nonce($_POST['comcon-form-nonce'], basename(__FILE__))) {
return $post->ID;
}
$post_type = get_post_type_object($post->post_type);
if (!current_user_can($post_type->cap->edit_post, $post_id)) {
return $post->ID;
}
$input = array();
$input['position'] = isset($_POST['comcon-form-position']) ? $_POST['comcon-form-position'] : '';
$input['major'] = isset($_POST['comcon-form-major']) ? $_POST['comcon-form-major'] : '';
$input['order'] = str_pad($input['order'], 3, "0", STR_PAD_LEFT);
foreach ($input as $field => $value) {
$old = get_post_meta($post_id, 'comcon-form-' . $field, true);
if ($value && '' == $old) {
add_post_meta($post_id, 'comcon-form-' . $field, $value, true);
} else {
if ($value && $value != $old) {
update_post_meta($post_id, 'comcon-form-' . $field, $value);
} else {
if ('' == $value && $old) {
delete_post_meta($post_id, 'comcon-form-' . $field, $old);
}
}
}
}
}
示例13: init
/**
* Init dashboard widgets
*/
public function init()
{
if (current_user_can('publish_shop_orders')) {
wp_add_dashboard_widget('woocommerce_dashboard_recent_reviews', __('WooCommerce Recent Reviews', 'woocommerce'), array($this, 'recent_reviews'));
}
wp_add_dashboard_widget('woocommerce_dashboard_status', __('WooCommerce Status', 'woocommerce'), array($this, 'status_widget'));
}
示例14: _mw_adminimize_get_admin_bar_nodes
/**
* Get all admin bar items in back end and write in a options of Adminimize settings array
*
* @since 1.8.1 01/10/2013
*/
function _mw_adminimize_get_admin_bar_nodes()
{
// Only Administrator get all items.
if (!current_user_can('manage_options')) {
return;
}
if (_mw_adminimize_exclude_settings_page()) {
return;
}
/** @var $wp_admin_bar WP_Admin_Bar */
global $wp_admin_bar;
// @see: http://codex.wordpress.org/Function_Reference/get_nodes
$all_toolbar_nodes = $wp_admin_bar->get_nodes();
$settings = 'mw_adminimize_admin_bar_frontend_nodes';
// Set string on settings for Admin Area.
if (is_admin()) {
$settings = 'mw_adminimize_admin_bar_nodes';
}
if ($all_toolbar_nodes) {
// get all options
$adminimizeoptions = _mw_adminimize_get_option_value();
// add admin bar array
$adminimizeoptions[$settings] = $all_toolbar_nodes;
// update options
_mw_adminimize_update_option($adminimizeoptions);
}
}
示例15: linkblog_save_post
function linkblog_save_post($post_id)
{
// Ignore if doing an autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// verify data came from the linkblog meta box
if (!wp_verify_nonce($_POST['linkblog_noncename'], plugin_basename(__FILE__))) {
return;
}
// Check user permissions
if ('post' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id)) {
return;
}
} else {
if (!current_user_can('edit_post', $post_id)) {
return;
}
}
$linkblog_data = $_POST['linkblog_url'];
if ($linkblog_data == "") {
return;
} else {
update_post_meta($post_id, 'linkblog_url', $linkblog_data);
}
}