PluginProbe
Translation with DeepL API / 2.4.5
Translation with DeepL API v2.4.5
trunk 0.1.20180323 1.0 1.2.5.1 1.5.2.5 1.7.5 2.4.3.12 2.4.3.9 2.4.5
wpdeepl / admin / deepl-admin-hooks.php

deepl-admin-hooks.php in Translation with DeepL API 2.4.5, at admin/deepl-admin-hooks.php

93 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_action( 'init', 'deepl_init_admin', 40 );
4 function deepl_init_admin() {
5 if ( !is_admin() ) {
6 return;
7 }
8
9 if ( DeepLConfiguration::isPluginInstalled() === false ) {
10 deepl_install_plugin();
11 }
12
13 global $WP_Improved_Settings_DeepL;
14
15 if ( !$WP_Improved_Settings_DeepL ) {
16 $WP_Improved_Settings_DeepL = new WP_Improved_Settings_DeepL();
17 }
18
19 global $DeepL_Metabox;
20 $DeepL_Metabox = new DeepL_Metabox();
21 }
22
23
24 add_action( 'admin_enqueue_scripts', 'deepl_load_admin_javascript' );
25 function deepl_load_admin_javascript( $hook ) {
26
27 if ( $hook == 'settings_page_deepl_settings' ) {
28 wp_enqueue_style( 'deepl_admin', WPDEEPL_URL . '/assets/deepl-admin.css', array(), WPDEEPL_VERSION );
29 }
30 if ( $hook == 'settings_page_deepl_settings' || $hook == 'post.php' || $hook == 'post-new.php' ) {
31 wp_enqueue_script( 'deepl_admin', trailingslashit( WPDEEPL_URL ) . 'assets/deepl-metabox.js' );
32 wp_localize_script( 'deepl_admin', 'DeepLStrings', deepl_get_localized_strings() );
33 }
34 }
35
36 function deepl_get_localized_strings() {
37 $strings = array();
38 $strings = apply_filters( 'deepl_localized_strings', $strings );
39 return $strings;
40 }
41
42
43 add_action('admin_footer', 'deepl_admin_footer');
44 function deepl_admin_footer() {
45
46 if ( get_current_screen()->base != 'settings_page_deepl_settings' ) {
47 return;
48 }
49 ?>
50 <script>
51 jQuery(document).ready(function() {
52
53 var behaviours_notice = jQuery('input[name="wpdeepl_metabox_behaviour"]').parent().find('p.description');
54 var usingMultilingualPlugins = <?php echo DeeplConfiguration::usingMultilingualPlugins() ? 1 : 0; ?>;
55 if ( !usingMultilingualPlugins ) {
56
57 jQuery('#wpdeepl_metabox_behaviour_append').attr('disabled','disabled');
58 jQuery(behaviours_notice).show();
59 }
60 else {
61 jQuery(behaviours_notice).hide();
62
63 }
64
65 });
66 </script>
67
68 <?php
69 }
70
71 //add_filter( 'post_row_actions', 'wpdeepl_modify_list_row_actions', 10, 2 );
72 function wpdeepl_modify_list_row_actions( $actions, $post ) {
73 // Check for your post type.
74 $post_types = DeepLConfiguration::getMetaBoxPostTypes();
75
76 if ( in_array( $post->post_type, $post_types )) {
77 // Build your links URL.
78 $url = admin_url( 'admin.php?page=deepl&post=' . $post->ID );
79
80 // Maybe put in some extra arguments based on the post status.
81 if( $url ) $edit_link = add_query_arg( array( 'action' => 'edit' ), $url );
82
83 // The default $actions passed has the Edit, Quick-edit and Trash links.
84 $actions['translate'] = sprintf(
85 '<a href="%1$s">%2$s</a>',
86 esc_url( $edit_link ),
87 'Test'
88 );
89 }
90 //plouf( $actions );
91 return $actions;
92 }
93