{"id":3339,"date":"2016-11-05T10:30:36","date_gmt":"2016-11-05T10:30:36","guid":{"rendered":"http:\/\/musilda.cz\/?p=3339"},"modified":"2016-11-05T10:30:36","modified_gmt":"2016-11-05T10:30:36","slug":"vlastni-hromadne-upravy-ve-wordpress-4-7","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/vlastni-hromadne-upravy-ve-wordpress-4-7\/","title":{"rendered":"Vlastn\u00ed hromadn\u00e9 \u00fapravy ve WordPress 4.7"},"content":{"rendered":"
Dal\u0161\u00ed novinkou, se kterou se ve WordPress 4.7 potk\u00e1me, je mo\u017enost vytvo\u0159en\u00ed vlastn\u00ed hromadn\u00e9 \u00fapravy.<\/p>\n
Hromadn\u00e1 \u00faprava je zn\u00e1m\u00e1 featura WordPressu, kde si m\u016f\u017eeme v selectu vybrat, co chceme ud\u011blat s vybran\u00fdmi posty.<\/p>\n
<\/p>\n
Vytvo\u0159en\u00ed vlastn\u00ed akce, m\u016f\u017eeme rozd\u011blit do t\u0159\u00ed krok\u016f:<\/strong><\/p>\n P\u0159id\u00e1n\u00ed funkce do v\u00fdb\u011bru:<\/strong><\/p>\n Pro registraci funkce pou\u017eijeme filter bulk_actions-{screen-id} a na konec pole v\u00fdb\u011bru p\u0159id\u00e1me na\u0161i polo\u017eku:<\/p>\n Dal\u0161\u00ed novinkou, se kterou se ve WordPress 4.7 potk\u00e1me, je mo\u017enost vytvo\u0159en\u00ed vlastn\u00ed hromadn\u00e9 \u00fapravy. Hromadn\u00e1 \u00faprava je zn\u00e1m\u00e1 featura WordPressu, kde si m\u016f\u017eeme v selectu vybrat, co chceme ud\u011blat s vybran\u00fdmi posty. Vytvo\u0159en\u00ed vlastn\u00ed akce, m\u016f\u017eeme rozd\u011blit do t\u0159\u00ed krok\u016f: P\u0159id\u00e1n\u00ed akce do v\u00fdb\u011bru Callback funkce pro proveden\u00ed zam\u00fd\u0161len\u00fdch \u00faprav Admin notice pro<\/p>\n","protected":false},"author":1,"featured_media":8647,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,30],"tags":[107,469],"class_list":["post-3339","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-novinky","category-wordpress","tag-custom-bulk-action","tag-wordpress-4-7"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/3339"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=3339"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/3339\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8647"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=3339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=3339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=3339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\n
add_filter( <\/code>
'bulk_actions-edit-post'<\/code>
, <\/code>
'register_my_bulk_actions'<\/code>
);<\/code><\/div>\n
function<\/code>
register_my_bulk_actions(<\/code>
$bulk_actions<\/code>
) {<\/code><\/div>\n
\u00a0\u00a0<\/code>
$bulk_actions<\/code>
[<\/code>
'moje_akce'<\/code>
] = __( <\/code>
'Moje akce'<\/code>
, <\/code>
'lang_domain'<\/code>
);<\/code><\/div>\n
\u00a0\u00a0<\/code>
return<\/code>
$bulk_actions<\/code>
;<\/code><\/div>\n
}<\/code><\/div>\n
add_filter( <\/code>
'handle_bulk_actions-edit-post'<\/code>
, <\/code>
'my_bulk_action_handler'<\/code>
, 10, 3 );<\/code><\/div>\n
function<\/code>
my_bulk_action_handler( <\/code>
$redirect_to<\/code>
, <\/code>
$doaction<\/code>
, <\/code>
$post_ids<\/code>
) {<\/code><\/div>\n
\u00a0\u00a0<\/code>
if<\/code>
( <\/code>
$doaction<\/code>
!== <\/code>
'moje_akce'<\/code>
) {<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0<\/code>
return<\/code>
$redirect_to<\/code>
;<\/code><\/div>\n
\u00a0\u00a0<\/code>
}<\/code><\/div>\n
\u00a0\u00a0<\/code>
foreach<\/code>
( <\/code>
$post_ids<\/code>
as<\/code>
$post_id<\/code>
) {<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0<\/code>
update_post_meta( $post_id, '_check_post_by_admin', 'zkontrolov\u00e1no' );\u00a0<\/code><\/div>\n
\u00a0\u00a0<\/code>
}<\/code><\/div>\n
\u00a0\u00a0<\/code>
$redirect_to<\/code>
= add_query_arg( <\/code>
'bulk_moje_akce_posts'<\/code>
, <\/code>
count<\/code>
( <\/code>
$post_ids<\/code>
), <\/code>
$redirect_to<\/code>
);<\/code><\/div>\n
\u00a0\u00a0<\/code>
return<\/code>
$redirect_to<\/code>
;<\/code><\/div>\n
}<\/code><\/div>\n<\/div>\n
add_action( <\/code>
'admin_notices'<\/code>
, <\/code>
'my_bulk_action_admin_notice'<\/code>
);<\/code><\/div>\n
function<\/code>
my_bulk_action_admin_notice() {<\/code><\/div>\n
\u00a0\u00a0<\/code>
if<\/code>
( ! <\/code>
empty<\/code>
( <\/code>
$_REQUEST<\/code>
[<\/code>
'bulk_moje_akce_posts'<\/code>
] ) ) {<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0<\/code>
$posts_count<\/code>
= <\/code>
intval<\/code>
( <\/code>
$_REQUEST<\/code>
[<\/code>
'bulk_moje_akce_posts'<\/code>
] );<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0<\/code>
printf( <\/code>
'<div id=\"message\" class=\"updated fade\">'<\/code>
.<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code>
_n( <\/code>
'Zkotrolov\u00e1no %s \u010dl\u00e1nk\u016f.'<\/code>
,<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code>
'Zkotrolov\u00e1no %s \u010dl\u00e1nk\u016f.'<\/code>
,<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code>
$posts_count <\/code>
,<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code>
'moje_akce'<\/code><\/div>\n
\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code>
) . <\/code>
'<\/div>'<\/code>
, <\/code>
$posts_count <\/code>
);<\/code><\/div>\n
\u00a0\u00a0<\/code>
}<\/code><\/div>\n
}<\/code><\/div>\n<\/div>\n