Skip to content

Commit a38fb9d

Browse files
authored
Merge pull request #4 from positiwise/dev
ADD: Admin Settings + Plugin Functionalities
2 parents 79d8c40 + 94b399e commit a38fb9d

9 files changed

+484
-1
lines changed
Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,86 @@
11
/**
22
* All of the CSS for your admin-specific functionality should be
33
* included in this file.
4-
*/
4+
*/
5+
6+
.wp_sil_options_fields {
7+
padding: 2rem;
8+
}
9+
10+
.wp_sil_nevigation_links {
11+
background: #fff;
12+
}
13+
14+
.wp_sil_setting_row {
15+
max-height: 25rem;
16+
overflow: auto;
17+
}
18+
19+
.wp_sil_nevigation_links .navigation_link_wrap {
20+
display: inline-block;
21+
padding: 1rem;
22+
border-right: thin solid #e2e2e2;
23+
}
24+
25+
.wp_sil_nevigation_links a,
26+
.wp_sil_nevigation_links a:active,
27+
.wp_sil_nevigation_links a:focus {
28+
text-decoration: none;
29+
box-shadow: none;
30+
}
31+
32+
.wp_sil_options_fields {
33+
background: #f4f4f4;
34+
}
35+
36+
.wp_sil_options_fields .wp_sil_options_save_button {
37+
margin-top: 1rem;
38+
}
39+
40+
.wp_sil_add_row {
41+
padding: 1rem 0;
42+
}
43+
44+
.wp_sil_setting_rows {
45+
margin-top: 1rem;
46+
}
47+
48+
.wp_sil_add_row a,
49+
.wp_sil_add_row a:active
50+
.wp_sil_add_row a:focus {
51+
text-decoration: none;
52+
box-shadow: none;
53+
cursor: pointer;
54+
}
55+
56+
.wp_sil_keyword{
57+
width: 20rem;
58+
}
59+
60+
.wp_sil_link{
61+
width: 45rem;
62+
}
63+
64+
.wp_sil_priority {
65+
margin: 0 2em !important;
66+
}
67+
68+
.wp_sil_setting_table th {
69+
text-align: left;
70+
}
71+
72+
.wp_sil_info_help {
73+
display: inline-table;
74+
color: #fff;
75+
background-color: #000;
76+
border-radius: 100%;
77+
height: 20px;
78+
width: 20px;
79+
text-align: center;
80+
cursor: pointer;
81+
}
82+
83+
.wp_sil_core_settings td select,
84+
.wp_sil_core_settings td input[type=number] {
85+
width: 15rem;
86+
}

admin/js/wordpress-seo-internal-linking-admin.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,24 @@
2929
* practising this, we should strive to set a better example in our own work.
3030
*/
3131

32+
$(document ).ready( function(){
33+
$( '.wp_sil_add_row a' ).click( function(){
34+
var data_row_num = parseInt( $('.wp_sil_options_fields').attr( 'data-key' ) ) + 1 ;
35+
console.log( data_row_num );
36+
var row_html = "<tr class='wp_sil_setting_row' id='"+ data_row_num +"'><td><input class='wp_sil_keyword' name='wp_sil_plugin_options[keyword][" + data_row_num + "]' type='text' placeholder='Keyword' /></td><td><input class='wp_sil_link' name='wp_sil_plugin_options[link][" + data_row_num + "]' type='url' placeholder='Link URL' /></td><td><input class='wp_sil_priority' name='wp_sil_plugin_options[priority]["+ data_row_num +"]' type='checkbox' /></td><td><a class='wp_sil_remove_row button button-secondary' data-rem-id='" + data_row_num + "'>- Remove</a></td></tr>";
37+
38+
$( '.wp_sil_setting_table tbody' ).append( row_html );
39+
40+
$('.wp_sil_options_fields').attr( 'data-key', data_row_num );
41+
42+
} );
43+
44+
} );
45+
46+
$( 'a.wp_sil_remove_row ' ).ready( function() {
47+
$( 'a.wp_sil_remove_row ' ).click( function() {
48+
$( 'tr#' + $( this ).data( 'rem-id' ) ).remove();
49+
} );
50+
} );
51+
3252
})( jQuery );
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
class Wordpress_Seo_Internal_Linking_Admin_Settings {
4+
5+
private $wp_sil_nevigation_links;
6+
7+
public function __construct(){
8+
9+
$page_link = "?page=wp-seo-internal-linking-plugin";
10+
11+
$this->wp_sil_nevigation_links = [
12+
"Settings" => $page_link,
13+
"Keywords" => $page_link . "&tab=keywords-links",
14+
"Import / Export" => $page_link . "&tab=import-export",
15+
];
16+
17+
}
18+
19+
public function addAdminSettings(){
20+
add_options_page(
21+
'WP SEO Internal Linking Settings',
22+
'WP SEO Internal Linking Settings',
23+
'manage_options',
24+
'wp-seo-internal-linking-plugin',
25+
array( $this, 'renderPluginSettings' )
26+
);
27+
}
28+
29+
public function renderPluginSettings(){
30+
?>
31+
<div class="wrap wp_sil_options_head_wrap">
32+
<h2><?php _e( "WordPress SEO Internal Linking Settings", "wordpress-seo-internal-linking" ); ?></h2>
33+
<p>Configure Plugin Settings Here</p>
34+
<div class="wp_sil_nevigation_links">
35+
<?php
36+
foreach( $this->wp_sil_nevigation_links as $nevigation_link => $nevigation_url ){
37+
echo "<a href='" . $nevigation_url . "'><div class='navigation_link_wrap'>" . $nevigation_link . "</div></a>";
38+
}
39+
?>
40+
</div>
41+
</div>
42+
<?php
43+
if ( isset( $_GET['tab'] ) && 'import-export' == $_GET['tab'] ) {
44+
45+
require_once 'wordpress-seo-internal-linking-settings-import-export.php';
46+
$import_export_page = new Wordpress_Seo_Internal_Linking_Settings_Import_Export();
47+
$import_export_page->renderImportExport();
48+
49+
} else if ( isset( $_GET['tab'] ) && 'keywords-links' == $_GET['tab'] ) {
50+
51+
require_once 'wordpress-seo-internal-linking-keywords.php';
52+
$import_export_page = new WordpressSeoInternalLinkingKeywords();
53+
$import_export_page->renderKeywordsSettings();
54+
55+
} else {
56+
57+
require_once 'wordpress-seo-internal-linking-core-settings.php';
58+
$import_export_page = new WordpressSeoInternalLinkingCoreSettings();
59+
$import_export_page->renderCoreSettings();
60+
61+
}
62+
}
63+
64+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
class WordpressSeoInternalLinkingCoreSettings
4+
{
5+
private $wp_sil_core_options;
6+
7+
public function __construct() {
8+
if( isset( $_POST['wp_sil_core_settings'] ) ) {
9+
$this->saveWpSilOptions( $_POST['wp_sil_core_settings'] );
10+
}
11+
12+
$this->wp_sil_core_options = get_option( 'wp_sil_plugin_core_options' );
13+
14+
}
15+
16+
public function renderCoreSettings() {
17+
18+
$trubleshoot = ( isset( $this->wp_sil_core_options['trubleshoot'] ) ) ? $this->wp_sil_core_options['trubleshoot'] : "";
19+
$target = ( isset( $this->wp_sil_core_options['target'] ) ) ? $this->wp_sil_core_options['target'] : "";
20+
$count = ( isset( $this->wp_sil_core_options['count'] ) ) ? $this->wp_sil_core_options['count'] : "2";
21+
22+
?>
23+
<div class="wrap">
24+
25+
<form action="" method="post">
26+
<div class="wp_sil_options_fields" data-key="<?php echo $last_key ?? 0; ?>">
27+
<table class="wp_sil_setting_table wp_sil_core_settings">
28+
29+
<tr class="wp_sil_setting_row">
30+
<th>
31+
<div>Enable Trubleshooting?</div>
32+
</th>
33+
<td>
34+
<input type="checkbox" name="wp_sil_core_settings[trubleshoot]" <?php echo ( "on" == $trubleshoot ) ? 'checked="checked"' : "" ; ?> />
35+
<span class="wp_sil_info_help" title="This will temporarily remove all linkings until unchecked and saved.">?</span>
36+
</td>
37+
</tr>
38+
39+
<tr class="wp_sil_setting_row">
40+
<th>
41+
<div>Target</div>
42+
</th>
43+
<td>
44+
<select name="wp_sil_core_settings[target]">
45+
<option value="" <?php echo ( "" == $target ) ? 'selected="selected"' : ''; ?>>Same Window</option>
46+
<option value="_blank" <?php echo ( "_blank" == $target ) ? 'selected="selected"' : ''; ?>>New Window</option>
47+
</select>
48+
</td>
49+
</tr>
50+
<tr class="wp_sil_setting_row">
51+
<th>
52+
<div>Number of Target Keywords</div>
53+
</th>
54+
<td>
55+
<input type="number" name="wp_sil_core_settings[count]" placeholder="Number of Target Keywords" value="<?php echo $count; ?>" name="wp_sil_core_settings" />
56+
<span class="wp_sil_info_help" title="Maximum how many keywords do you want to target in each paragraph?">?</span>
57+
</td>
58+
</tr>
59+
60+
</table>
61+
<div class="wp_sil_options_save_button">
62+
<input name="submit" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Save Core Settings' ); ?>" />
63+
</div>
64+
</div>
65+
</form>
66+
</div>
67+
<?php
68+
}
69+
70+
public function saveWpSilOptions( $coreOptions ) {
71+
if( update_option( 'wp_sil_plugin_core_options', $coreOptions ) ) {
72+
add_action( 'admin_notices', function() {
73+
?>
74+
<div class="notice notice-success is-dismissible">
75+
<p><?php _e( 'Settings Saved Successfully!', 'wordpress-seo-internal-linking' ); ?></p>
76+
</div>
77+
<?php
78+
} );
79+
}
80+
}
81+
82+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
class WordpressSeoInternalLinkingKeywords
4+
{
5+
6+
private $wp_sil_options;
7+
8+
public function __construct() {
9+
if( isset( $_POST['wp_sil_plugin_options'] ) ) {
10+
$this->saveWpSilOptions( $_POST['wp_sil_plugin_options'] );
11+
}
12+
13+
$this->wp_sil_options = get_option( 'wp_sil_plugin_options' );
14+
}
15+
16+
public function renderKeywordsSettings() {
17+
$options = $this->wp_sil_options;
18+
$keywords = ( isset( $options['keyword'] ) && !empty( $options['keyword'] ) ) ? $options['keyword'] : [];
19+
$links = ( isset( $options['link'] ) && !empty( $options['link'] ) ) ? $options['link'] : [];
20+
$priority = ( isset( $options['priority'] ) && !empty( $options['priority'] ) ) ? $options['priority'] : [];
21+
22+
$last_key = array_key_last( $keywords );
23+
24+
?>
25+
<div class="wrap">
26+
27+
<form action="" method="post">
28+
<div class="wp_sil_options_fields" data-key="<?php echo $last_key ?? 0; ?>">
29+
<table class="wp_sil_setting_table">
30+
<tr>
31+
<td>Keyword</td>
32+
<td>URL</td>
33+
<td>Priority?</td>
34+
</tr>
35+
<?php if( "" === $options ){ ?>
36+
<tr class="wp_sil_setting_row">
37+
<td>
38+
<input class='wp_sil_keyword' name='wp_sil_plugin_options[keyword][0]' type='text' placeholder='Keyword' />
39+
</td>
40+
<td>
41+
<input class='wp_sil_link' name='wp_sil_plugin_options[link][0]' type='url' placeholder='Link URL' />
42+
</td>
43+
<td>
44+
<input class='wp_sil_priority' name='wp_sil_plugin_options[priority][0]' type='checkbox' />
45+
</td>
46+
</tr>
47+
<?php } ?>
48+
<?php foreach( $keywords as $key => $word ) { ?>
49+
<tr class="wp_sil_setting_row" id="<?php echo $key; ?>">
50+
<td>
51+
<input class='wp_sil_keyword' name='wp_sil_plugin_options[keyword][<?php echo $key; ?>]' type='text' placeholder='Keyword' value='<?php echo $keywords[$key]; ?>' />
52+
</td>
53+
<td>
54+
<input class='wp_sil_link' name='wp_sil_plugin_options[link][<?php echo $key; ?>]' type='url' placeholder='Link URL' value='<?php echo $links[$key]; ?>' />
55+
</td>
56+
<td>
57+
<input class='wp_sil_priority' name='wp_sil_plugin_options[priority][<?php echo $key; ?>]' type='checkbox' <?php echo ( isset( $priority[$key] ) && "on" == $priority[$key] ) ? 'checked=checked' : ''; ?> />
58+
</td>
59+
<?php if( 0 !== $key ) { ?>
60+
<td>
61+
<a class='wp_sil_remove_row button button-secondary' data-rem-id='<?php echo $key; ?>'>- Remove</a>
62+
</td>
63+
<?php } ?>
64+
</tr>
65+
<?php } ?>
66+
67+
</table>
68+
<div class="wp_sil_add_row">
69+
<a class='button button-secondary'>+ Add Row</a>
70+
</div>
71+
<div class="wp_sil_options_save_button">
72+
<input name="submit" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Save Keywords Settings' ); ?>" />
73+
</div>
74+
</div>
75+
</form>
76+
</div>
77+
<?php
78+
}
79+
80+
public function saveWpSilOptions( $options ){
81+
update_option( 'wp_sil_plugin_options', $options );
82+
}
83+
}

0 commit comments

Comments
 (0)