Skip to content

Commit

Permalink
add WPNuxt in left menu
Browse files Browse the repository at this point in the history
  • Loading branch information
vernaillen committed Aug 3, 2024
1 parent 6fb0420 commit 6e6f741
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"plugins": [
"."
]
],
"port": 4000
}
62 changes: 21 additions & 41 deletions wpnuxt-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,25 @@ function plugin_action_links_wpnuxt($links)
/**
* Add the options page
*/
add_action('admin_menu', function () {
add_options_page('WPNuxt Options', 'WPNuxt', 'manage_options', 'wpnuxt', 'wpNuxtOptionsPageHtml');
add_action( 'admin_menu', function () {
$nuxtIcon = 'data:image/svg+xml;base64,' . base64_encode('<svg width="22" height="22" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M281.44 397.667H438.32C443.326 397.667 448.118 395.908 452.453 393.427C456.789 390.946 461.258 387.831 463.76 383.533C466.262 379.236 468.002 374.36 468 369.399C467.998 364.437 466.266 359.563 463.76 355.268L357.76 172.947C355.258 168.65 352.201 165.534 347.867 163.053C343.532 160.573 337.325 158.813 332.32 158.813C327.315 158.813 322.521 160.573 318.187 163.053C313.852 165.534 310.795 168.65 308.293 172.947L281.44 219.587L227.733 129.13C225.229 124.834 222.176 120.307 217.84 117.827C213.504 115.346 208.713 115 203.707 115C198.701 115 193.909 115.346 189.573 117.827C185.238 120.307 180.771 124.834 178.267 129.13L46.8267 355.268C44.3208 359.563 44.0022 364.437 44 369.399C43.9978 374.36 44.3246 379.235 46.8267 383.533C49.3288 387.83 53.7979 390.946 58.1333 393.427C62.4688 395.908 67.2603 397.667 72.2667 397.667H171.2C210.401 397.667 238.934 380.082 258.827 346.787L306.88 263.4L332.32 219.587L410.053 352.44H306.88L281.44 397.667ZM169.787 352.44H100.533L203.707 174.36L256 263.4L221.361 323.784C208.151 345.387 193.089 352.44 169.787 352.44Z" fill="#00DC82"/></svg>');
add_menu_page(
'WPNuxt Options',
'WPNuxt',
'manage_options',
'wpnuxt',
false,
$nuxtIcon,
80
);
add_submenu_page(
'WPNuxt Options',
'WPNuxt',
'Dashboard',
'manage_options',
'wpnuxt',
'wpNuxtOptionsPageHtml',
);
});

function wpNuxtOptionsPageHtml()
Expand Down Expand Up @@ -182,39 +199,6 @@ function registerWPNuxtSettings()
add_settings_section('global_setting', 'Global Settings', 'global_setting_callback', 'wpnuxt');
}

/**
* Registers admin bar menu
*
* @param \WP_Admin_Bar $admin_bar The Admin Bar Instance
*
* @return void
*/
function register_admin_bar_menu( WP_Admin_Bar $admin_bar ) {
if ( ! current_user_can( 'manage_options' )) {
return;
}

$nuxtIcon = 'data:image/svg+xml;base64,' . base64_encode('<svg width="22" height="22" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M281.44 397.667H438.32C443.326 397.667 448.118 395.908 452.453 393.427C456.789 390.946 461.258 387.831 463.76 383.533C466.262 379.236 468.002 374.36 468 369.399C467.998 364.437 466.266 359.563 463.76 355.268L357.76 172.947C355.258 168.65 352.201 165.534 347.867 163.053C343.532 160.573 337.325 158.813 332.32 158.813C327.315 158.813 322.521 160.573 318.187 163.053C313.852 165.534 310.795 168.65 308.293 172.947L281.44 219.587L227.733 129.13C225.229 124.834 222.176 120.307 217.84 117.827C213.504 115.346 208.713 115 203.707 115C198.701 115 193.909 115.346 189.573 117.827C185.238 120.307 180.771 124.834 178.267 129.13L46.8267 355.268C44.3208 359.563 44.0022 364.437 44 369.399C43.9978 374.36 44.3246 379.235 46.8267 383.533C49.3288 387.83 53.7979 390.946 58.1333 393.427C62.4688 395.908 67.2603 397.667 72.2667 397.667H171.2C210.401 397.667 238.934 380.082 258.827 346.787L306.88 263.4L332.32 219.587L410.053 352.44H306.88L281.44 397.667ZM169.787 352.44H100.533L203.707 174.36L256 263.4L221.361 323.784C208.151 345.387 193.089 352.44 169.787 352.44Z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OCA0Ny43TTkwLjkgMTM3Yy05LjYgMTYuNy0zMSAyMi40LTQ3LjcgMTIuOC0xNi43LTkuNi0yMi40LTMxLTEyLjgtNDcuNyA5LjYtMTYuNyAzMS0yMi40IDQ3LjctMTIuOCAxNi43IDkuNyAyMi40IDMxIDEyLjggNDcuN00zMC41IDI5Ny45Yy05LjYtMTYuNy0zLjktMzggMTIuOC00Ny43IDE2LjctOS42IDM4LTMuOSA0Ny43IDEyLjggOS42IDE2LjcgMy45IDM4LTEyLjggNDcuNy0xNi44IDkuNi0zOC4xIDMuOS00Ny43LTEyLjhNMzA5LjEgMTM3Yy05LjYtMTYuNy0zLjktMzggMTIuOC00Ny43IDE2LjctOS42IDM4LTMuOSA0Ny43IDEyLjggOS42IDE2LjcgMy45IDM4LTEyLjggNDcuNy0xNi43IDkuNi0zOC4xIDMuOS00Ny43LTEyLjhNMjAwIDM5NS44Yy0xOS4zIDAtMzQuOS0xNS42LTM0LjktMzQuOSAwLTE5LjMgMTUuNi0zNC45IDM0LjktMzQuOSAxOS4zIDAgMzQuOSAxNS42IDM0LjkgMzQuOSAwIDE5LjItMTUuNiAzNC45LTM0LjkgMzQuOU0yMDAgNzRjLTE5LjMgMC0zNC45LTE1LjYtMzQuOS0zNC45IDAtMTkuMyAxNS42LTM0LjkgMzQuOS0zNC45IDE5LjMgMCAzNC45IDE1LjYgMzQuOSAzNC45IDAgMTkuMy0xNS42IDM0LjktMzQuOSAzNC45Ii8+PC9zdmc+';

$icon = sprintf(
'<span class="custom-icon" style="
background-image:url(\'%s\'); float:left; width:22px !important; height:22px !important;
margin-left: 5px !important; margin-top: 5px !important; margin-right: 2px !important;
"></span>',
$nuxtIcon
);

$admin_bar->add_menu(
[
'id' => 'wpnuxt',
'title' => $icon . __( '<span class="font-serif">WP</span>Nuxt', 'wpnuxt' ),
'href' => trailingslashit( admin_url() ) . 'admin.php?page=wpnuxt',
]
);
}
add_action( 'admin_bar_menu', 'register_admin_bar_menu', 500);

// Section callback
function requiredPluginsCallback()
{
Expand Down Expand Up @@ -364,10 +348,7 @@ function requiredPluginsCallback()
}
}

$site_name = get_bloginfo('name');
$gql_settings = get_option('graphql_general_settings');
$gql_endpoint = isset($gql_settings['graphql_endpoint']) ? $gql_settings['graphql_endpoint'] : 'graphql';
$endpoint = get_site_url() . '/' . $gql_endpoint;
$faustwp_settings = get_option('faustwp_settings');

$permalink_structure = get_option( 'permalink_structure' );
Expand Down Expand Up @@ -438,7 +419,6 @@ function requiredPluginsCallback()
function global_setting_callback()
{
$options = get_option('wpnuxt_options');
$primary_color = isset($options['primary_color']) ? $options['primary_color'] : '#7F54B2';
?>

<div class="global_setting wpnuxt-section">
Expand All @@ -448,7 +428,7 @@ function global_setting_callback()
<tr>
<th scope="row"><label for="wpnuxt_options[frontEndUrl]">Front End URL</label></th>
<td>
<input type="text" class="widefat" name="wpnuxt_options[frontEndUrl]" value="<?php echo isset($options['frontEndUrl']) ? $options['frontEndUrl'] : ''; ?>" placeholder="e.g. https://mysite.netlify.app" />
<input type="text" class="widefat" name="wpnuxt_options[frontEndUrl]" value="<?php echo isset($options['frontEndUrl']) ? $options['frontEndUrl'] : ''; ?>" placeholder="e.g. https://my-nuxt-frontend.netlify.app" />
<p class="description">This is the URL of your Nuxt site not the WordPress site.</p>
</td>
</tr>
Expand All @@ -469,4 +449,4 @@ function global_setting_callback()
echo is_plugin_active($plugin_file) ? 'installed' : 'not_installed';

wp_die();
});
});

0 comments on commit 6e6f741

Please sign in to comment.