PluginProbe
Translation with DeepL API / trunk
Translation with DeepL API vtrunk
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 trunk, at admin/deepl-admin-hooks.php

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