Skip to content

Commit 6d8d5d1

Browse files
authored
Merge pull request #209 from my-language-skills/developer
Developer
2 parents 743ef80 + 117f76e commit 6d8d5d1

16 files changed

+957
-14
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
.idea
22
all-in-one-metadata/.idea
33
all-in-one-metadata/.vscode
4-
all-in-one-metadata/vendor

README.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ https://moz.com/learn/seo/duplicate-content
101101

102102
## Changelog
103103

104+
## 0.16
105+
* **ADDITIONS**
106+
* Multisite setting tab
107+
* Pre-defined options out-of-the-box (example for users to see how plugin works)
108+
* **ENHANCEMENTS**
109+
* Database cleaning after uninstalling
110+
* **List of Files Revised**
111+
* uninstall.php
112+
* class-pressbooks-metadata-activator.php
113+
* class-pressbooks-metadata-engine.php
114+
* pressbooks-metadata-admin-settings-schemaLocations.php
115+
104116
## 0.13
105117
* **ADDITIONS**
106118
* Added more types on creative workds and organisation parents
@@ -125,11 +137,12 @@ https://moz.com/learn/seo/duplicate-content
125137
* Fixed the overlap of metaboxes in the settings
126138
* **List of Files revised**
127139
* Schema type files
128-
* Engine file
129140
* All files in partials folder
130-
* Admin JavaScript file
131141
* All vocabulary files
132-
* Network admin files
142+
* class-pressbooks-metadata-engine.php
143+
* pressbooks-metadata-admin.js
144+
* class-pressbooks-metadata-net-sett-sections.php
145+
* class-pressbooks-metadata-network-admin.php
133146

134147
## 0.12
135148
* **ADDITIONS**
@@ -341,6 +354,9 @@ https://moz.com/learn/seo/duplicate-content
341354

342355
## Upgrade Notice
343356

357+
### 0.16
358+
Plugin now properly uninstalls itself, no remaining data in database is kept after uninstalling. In order for users to see how plugin works without requiring initial setting, we have added some enabled options out-of-the-box in order to see how actually plugin works. The predefined options can be disabled after activation. Schema location options now stays more logical, multisite control setting is also supported from this moment.
359+
344360
### 0.13
345361
Plugin now is much more efficient wasting less memory on the server as the engine file had improvements. The plugin had many improvements
346362
on both the visual interface and the engine. The user experience has improved as we are saving the tabs that were used before reloading the settings page.

all-in-one-metadata/admin/partials/pressbooks-metadata-admin-settings-schemaLocations.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
submit_button();
5858
?>
5959
</form>
60-
<p>Comming soon</p>
60+
<p></p>
6161
</div>
6262
<?php
6363
}

all-in-one-metadata/admin/schemaFunctions/class-pressbooks-metadata-create-metabox.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,17 @@ function overwritten_field( $field_slug, $field, $value ) {
111111
//Getting the origin for overwritten data
112112
$dataFrom = site_cpt::pressbooks_identify() ? 'Book-Info' : 'Site-Meta';
113113
$value = get_post_meta(get_the_ID(),$field_slug);
114-
$value = $value[0];
114+
if(array_key_exists(0, $value)){
115+
$value = $value[0];
116+
}else{
117+
$value = "";
118+
}
119+
115120
$broken_slug = explode('_',$field_slug);
116121
$property = ucfirst($broken_slug[1]);
117122
?>
118123
<hr />
119-
<p><strong><?=$property?></strong> is Overwritten by <?=$dataFrom?>. The value is "<?=$value?>".</p>
124+
<p><strong><?=$property?></strong> is Overwritten by <?=$dataFrom?>. <?php if ($value !== "") echo 'The value is "'.$value.'"'; else echo 'Check the predefined value there.';?></p>
120125
<input type="hidden" name="<?=$field_slug?>" value="<?=$value?>" />
121126
<hr />
122127
<?php

all-in-one-metadata/admin/schemaFunctions/class-pressbooks-metadata-engine.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function register_settings() {
127127
//Creating the sections
128128
add_settings_section($postLevelSection, "Choose On Which Post Types You Want to Display Schemas", null, $postLevelPage);
129129
add_settings_section($siteLevelSection, "Choose If You Want To Display Schemas On The Site Level", null, $siteLevelPage);
130-
add_settings_section($multiLevelSection, "-------MULTISITE-------", null, $multiLevelPage);
130+
add_settings_section($multiLevelSection, "Choose If You Want To Have a Superadmin Control", null, $multiLevelPage);
131131

132132
//Gathering post types
133133
$allPostTypes = $this->get_all_post_types();
@@ -136,11 +136,13 @@ public function register_settings() {
136136
foreach($allPostTypes as $post_type){
137137
if($post_type == 'metadata' || $post_type == 'site-meta'){
138138
new post_type_fields($post_type.'_checkbox',ucfirst($post_type),$siteLevelPage,$siteLevelSection);
139+
139140
if(is_multisite()) {
140-
new post_type_fields($post_type . '_saoverwr', 'Allow Overwrite', $siteLevelPage, $siteLevelSection);
141+
new post_type_fields($post_type . '_saoverwr', 'Allow Overwrite', $multiLevelPage, $multiLevelSection);
141142
}
142143
}else{
143144
new post_type_fields($post_type.'_checkbox',ucfirst($post_type),$postLevelPage,$postLevelSection);
145+
144146
}
145147
}
146148

@@ -189,7 +191,6 @@ public function register_settings() {
189191
$post_type.'_tab',
190192
$typeSettings
191193
);
192-
193194
foreach(structure::$allSchemaTypes as $type){
194195
$type_id = genFunc::get_type_id($type);
195196
$sectionId = $type_id.'_'.$post_type.'_level';

all-in-one-metadata/all-in-one-metadata.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Plugin Name: All In One Metadata
1717
* Plugin URI: https://github.com/Books4Languages/pressbooks-metadata
1818
* Description: This plugin adds metadata to wordpress and also has support for the pressbooks plugin
19-
* Version: 0.12
19+
* Version: 0.16
2020
* Author: My Language Skills
2121
* Author URI: http://books4languages.com
2222
* License: GPL-2.0+
@@ -73,3 +73,4 @@ function run_pressbooks_metadata() {
7373

7474
}
7575
run_pressbooks_metadata();
76+

all-in-one-metadata/includes/class-pressbooks-metadata-activator.php

+48-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3+
use adminFunctions\Pressbooks_Metadata_Site_Cpt as site_cpt;
4+
35
/**
46
* Fired during plugin activation
57
*
68
* @link https://github.com/Books4Languages/pressbooks-metadata
7-
* @since 0.1
9+
* @since 0.16
810
*
911
* @package Pressbooks_Metadata
1012
* @subpackage Pressbooks_Metadata/includes
@@ -15,7 +17,7 @@
1517
*
1618
* This class defines all code necessary to run during the plugin's activation.
1719
*
18-
* @since 0.1
20+
* @since 0.16
1921
* @package Pressbooks_Metadata
2022
* @subpackage Pressbooks_Metadata/includes
2123
* @author Vasilis Georgoudis <[email protected]>
@@ -31,6 +33,50 @@ class Pressbooks_Metadata_Activator {
3133
*/
3234
public static function activate() {
3335

36+
//get all the sites for multisite, if not a multisite, set blog id to 1
37+
if (is_multisite()) {
38+
$blogs_ids = get_sites();
39+
} else {
40+
$blogs_ids = ['blog_id' => 1];
41+
}
42+
foreach( $blogs_ids as $b ) {
43+
//if multisite, each iteration changes site
44+
if (is_multisite()) {
45+
switch_to_blog( $b->blog_id );
46+
}
47+
//activate post/chapter level meta for demonstration (these are gonna be created anyway)
48+
if ( site_cpt::pressbooks_identify() ) {
49+
update_option( 'chapter_checkbox', '1' );
50+
} else {
51+
update_option( 'post_checkbox', '1' );
52+
}
53+
54+
//activate site-level meta for demonstration (these are gonna be created anyway)
55+
if ( site_cpt::pressbooks_identify() ) {
56+
update_option( 'metadata_checkbox', '1' );
57+
} else {
58+
update_option( 'site-meta_checkbox', '1' );
59+
}
60+
61+
// set book type schema active for demonstration for posts/chapters (these are gonna be created anyway)
62+
if ( site_cpt::pressbooks_identify() ) {
63+
update_option( 'book_type_chapter_level', '1' );
64+
} else {
65+
update_option( 'corporation_type_post_level', '1' );
66+
}
67+
68+
//set book type schema active for demonstration for site-meta or metadata (these are gonna be created anyway)
69+
if ( site_cpt::pressbooks_identify() ) {
70+
update_option( 'book_type_metadata_level', '1' );
71+
} else {
72+
update_option( 'corporation_type_site-meta_level', '1' );
73+
}
74+
75+
}
76+
//if multisite is active, restore the blog which was used before updating options
77+
if (is_multisite()) {
78+
restore_current_blog();
79+
}
3480
}
3581

3682
}

all-in-one-metadata/uninstall.php

+75-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
2121
*
2222
* @link https://github.com/Books4Languages/pressbooks-metadata
23-
* @since 0.1
23+
* @since 0.16
2424
*
2525
* @package Pressbooks_Metadata
2626
*/
@@ -29,3 +29,77 @@
2929
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
3030
exit;
3131
}
32+
33+
//declaring global DB connection variable
34+
global $wpdb;
35+
36+
//get all the sites for multisite, if not a multisite, set blog id to 1
37+
if (is_multisite()) {
38+
$blogs_ids = get_sites();
39+
} else {
40+
$blogs_ids = [1];
41+
}
42+
43+
//delete plugin options and posts/chapter related metadata from every site
44+
foreach( $blogs_ids as $b ){
45+
//if multisite, each iteration changes site
46+
if (is_multisite()) {
47+
switch_to_blog( $b->blog_id );
48+
}
49+
50+
//get all the options from database
51+
$all_options = wp_load_alloptions();
52+
$plugin_options = [];
53+
$related_meta = [];
54+
55+
//check if PressBooks plugin is used
56+
if ((@include_once( WP_PLUGIN_DIR . '/pressbooks/pressbooks.php')) &&
57+
//Checking if the plugin is active
58+
is_plugin_active('pressbooks/pressbooks.php')) {
59+
$pb = true;
60+
}
61+
else{
62+
$pb = false;
63+
}
64+
65+
//gather all post types, including built-in of without PressBooks
66+
if($pb){
67+
$allPostTypes = get_post_types( array( 'public' => true, '_builtin' => false )) ;
68+
}else{
69+
$allPostTypes = get_post_types( array( 'public' => true)) ;
70+
}
71+
72+
$allPostTypes['site-meta'] = 'site-meta';
73+
$allPostTypes['metadata'] = 'metadata';
74+
75+
76+
//extract plugin options from all options
77+
foreach ( $all_options as $name => $value ) {
78+
foreach ($allPostTypes as $postType) {
79+
if ( stristr( $name, '_type_' . $postType ) || stristr( $name, '_type_' . $postType . '_level' )
80+
|| stristr( $name, '_type_overwrite' ) || stristr($name, 'saoverwr') || stristr($name, $postType.'_checkbox')
81+
|| stristr( $name, 'dublin_checkbox' ) || stristr($name, 'coins_checkbox') || stristr($name, 'educational_checkbox')) {
82+
$plugin_options[ $name ] = $value;
83+
84+
}
85+
}
86+
}
87+
88+
89+
//delete plugin options
90+
foreach ( $plugin_options as $key => $value ) {
91+
if ( get_option( $key ) || get_option($key, 'nonex') !== 'nonex') {
92+
delete_option( $key );
93+
}
94+
}
95+
96+
// Delete plugin related posts' meta
97+
//if blog is root, do not add blog number to table name
98+
$blog_id = $b->blog_id == 1 || $b = 1 ? '' : $b->blog_id.'_';
99+
//DELETE query to postmeta database
100+
$wpdb->query( "DELETE FROM `".$wpdb->prefix.$blog_id."postmeta` WHERE `meta_key` LIKE 'pb%type%'");
101+
$wpdb->query( "DELETE FROM `".$wpdb->prefix.$blog_id."postmeta` WHERE `meta_key` LIKE 'pb%vocab%'");
102+
}
103+
104+
105+
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
require_once __DIR__ . '/composer/autoload_real.php';
6+
7+
return ComposerAutoloaderInit86d7ba7740563f6e5d25c22c409a2835::getLoader();

0 commit comments

Comments
 (0)