PluginProbe
Edit Flow / trunk
Edit Flow vtrunk
0.11.1 0.11.0 0.7.2 0.7.3 0.7.4 0.7.5 0.7.6 0.8 0.8.1 0.8.2 0.9 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 trunk 0.1.5 0.10.0 0.10.1 0.10.2 All 44 releases
edit-flow / wpcom-helper.php

wpcom-helper.php in Edit Flow trunk, at wpcom-helper.php

75 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WordPress.com helper for Edit Flow.
4 *
5 * Ensures Edit Flow is instantiated and provides necessary
6 * capability filters and fixes for the WordPress.com environment.
7 *
8 * @package EditFlow
9 */
10
11 // Ensure Edit Flow is instantiated.
12 add_action( 'after_setup_theme', 'EditFlow' );
13
14 /**
15 * Don't load caps on install for WP.com. Instead, let's add
16 * them with the WP.com + core caps approach
17 */
18 add_filter( 'ef_kill_add_caps_to_role', '__return_true' );
19 add_filter( 'ef_view_calendar_cap', function () {
20 return 'edit_posts';
21 } );
22 add_filter( 'ef_view_story_budget_cap', function () {
23 return 'edit_posts';
24 } );
25 add_filter( 'ef_edit_post_subscriptions_cap', function () {
26 return 'edit_others_posts';
27 } );
28 add_filter( 'ef_manage_usergroups_cap', function () {
29 return 'manage_options';
30 } );
31
32 add_filter( 'redirect_canonical', 'edit_flow_wpcom_redirect_canonical' );
33
34 /**
35 * Disable canonical redirect for Share A Draft links.
36 *
37 * Share A Draft on WordPress.com breaks when redirect canonical is enabled
38 * because get_permalink() doesn't respect custom statuses.
39 *
40 * @see http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/canonical.php#L113
41 *
42 * @param string|false $redirect The redirect URL or false.
43 * @return string|false The redirect URL or false to disable.
44 */
45 function edit_flow_wpcom_redirect_canonical( $redirect ) {
46 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only check for shareadraft parameter.
47 if ( ! empty( $_GET['shareadraft'] ) ) {
48 return false;
49 }
50
51 return $redirect;
52 }
53
54 add_filter( 'ef_fix_post_name_post', 'edit_flow_fix_fix_post_name' );
55
56 /**
57 * Fix caching race condition for post slugs.
58 *
59 * This should fix a caching race condition that can sometimes create
60 * a published post with an empty slug.
61 *
62 * @param WP_Post $post The post object.
63 * @return WP_Post The post object with refreshed status.
64 */
65 function edit_flow_fix_fix_post_name( $post ) {
66 global $wpdb;
67 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Intentionally bypassing cache to get fresh post_status value.
68 $post_status = $wpdb->get_var( $wpdb->prepare( 'SELECT post_status FROM ' . $wpdb->posts . ' WHERE ID = %d', $post->ID ) );
69 if ( null !== $post_status ) {
70 $post->post_status = $post_status;
71 }
72
73 return $post;
74 }
75