Last active
April 10, 2020 17:38
-
-
Save glaubersilva/d81a0000fcf39d0c4ef1f3db7e451e8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [SmartCrawl] Grants Editor Role access to Social Admin page | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: Changes the attribute "capability" of the instance from "Smartcrawl Social Settings" class to "edit_others_posts" (that is what makes the social menu visible for editors) and make the social admin page also work with the capabilitie "edit_others_posts" that is what makes possible the editors save the options. | |
* Author: Glauber Silva @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* Task: 0/11289012348292/1167803562365536 | |
* License: GPLv2 or later | |
* | |
* @package SmartCrawl_Grants_Editor_Role_Access_to_Social_Admin_page | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
/** | |
* Catches the instance of the social menu and changes the minimum capability necessary to see the social menu to another capability - edit_other_posts - that editors has. | |
*/ | |
function wpmudev_display_social_menu_for_editors() { | |
if ( class_exists( 'Smartcrawl_Social_Settings' ) ) { | |
$social_menu = Smartcrawl_Social_Settings::get_instance(); | |
$social_menu->capability = 'edit_others_posts'; | |
} | |
} | |
add_action( 'init', 'wpmudev_display_social_menu_for_editors' ); | |
/** | |
* Allows editors save social options | |
* | |
* @param string $cap Default minimum capability - manage_options - necessary for save options that only admins has. | |
* | |
* @return string Returns a new minimum capability - edit_other_posts - that allowed editors save social options. | |
*/ | |
function wpmudev_social_options_capability( $cap ) { | |
if ( ! current_user_can( $cap ) ) { | |
return 'edit_others_posts'; | |
} | |
} | |
add_filter( 'option_page_capability_wds_social_options', 'wpmudev_social_options_capability' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment