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