| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Internals |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'WPSEO_VERSION' ) ) { |
| 9 |
header( 'Status: 403 Forbidden' ); |
| 10 |
header( 'HTTP/1.1 403 Forbidden' ); |
| 11 |
exit(); |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Initializes the admin bar. |
| 16 |
* |
| 17 |
* @return void |
| 18 |
*/ |
| 19 |
function wpseo_initialize_admin_bar() { |
| 20 |
$admin_bar_menu = new WPSEO_Admin_Bar_Menu(); |
| 21 |
$admin_bar_menu->register_hooks(); |
| 22 |
} |
| 23 |
add_action( 'wp_loaded', 'wpseo_initialize_admin_bar' ); |
| 24 |
|
| 25 |
/** |
| 26 |
* Allows editing of the meta fields through weblog editors like Marsedit. |
| 27 |
* |
| 28 |
* @param array $required_capabilities Capabilities that must all be true to allow action. |
| 29 |
* @param array $capabilities Array of capabilities to be checked, unused here. |
| 30 |
* @param array $args List of arguments for the specific capabilities to be checked. |
| 31 |
* |
| 32 |
* @return array Filtered capabilities. |
| 33 |
*/ |
| 34 |
function allow_custom_field_edits( $required_capabilities, $capabilities, $args ) { |
| 35 |
if ( ! in_array( $args[0], [ 'edit_post_meta', 'add_post_meta' ], true ) ) { |
| 36 |
return $required_capabilities; |
| 37 |
} |
| 38 |
|
| 39 |
// If this is provided, it is the post ID. |
| 40 |
if ( empty( $args[2] ) ) { |
| 41 |
return $required_capabilities; |
| 42 |
} |
| 43 |
|
| 44 |
// If this is provided, it is the custom field. |
| 45 |
if ( empty( $args[3] ) ) { |
| 46 |
return $required_capabilities; |
| 47 |
} |
| 48 |
|
| 49 |
// If the meta key is part of the plugin, grant capabilities accordingly. |
| 50 |
if ( strpos( $args[3], WPSEO_Meta::$meta_prefix ) === 0 && current_user_can( 'edit_post', $args[2] ) ) { |
| 51 |
$required_capabilities[ $args[0] ] = true; |
| 52 |
} |
| 53 |
|
| 54 |
return $required_capabilities; |
| 55 |
} |
| 56 |
|
| 57 |
add_filter( 'user_has_cap', 'allow_custom_field_edits', 0, 3 ); |
| 58 |
|