Update dependencies and create a new wp-ajax for get sample permalink
This commit is contained in:
parent
4add863f81
commit
c34bb699ae
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
|
@ -10,7 +10,6 @@
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
"buefy": "^0.6.6",
|
"buefy": "^0.6.6",
|
||||||
"bulma": "^0.7.1",
|
"bulma": "^0.7.1",
|
||||||
"html-to-json": "^0.6.0",
|
|
||||||
"mdi": "^2.2.43",
|
"mdi": "^2.2.43",
|
||||||
"moment": "^2.22.2",
|
"moment": "^2.22.2",
|
||||||
"npm": "^6.1.0",
|
"npm": "^6.1.0",
|
||||||
|
@ -23,25 +22,25 @@
|
||||||
"vuex": "^3.0.1"
|
"vuex": "^3.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^8.6.4",
|
"autoprefixer": "^8.6.5",
|
||||||
"babel-core": "^6.26.3",
|
"babel-core": "^6.26.3",
|
||||||
"babel-loader": "^7.1.4",
|
"babel-loader": "^7.1.5",
|
||||||
"babel-preset-env": "^1.7.0",
|
"babel-preset-env": "^1.7.0",
|
||||||
"babel-preset-stage-3": "^6.24.1",
|
"babel-preset-stage-3": "^6.24.1",
|
||||||
"cross-env": "^5.2.0",
|
"cross-env": "^5.2.0",
|
||||||
"css-loader": "^0.28.11",
|
"css-loader": "^1.0.0",
|
||||||
"cypress": "^3.0.2",
|
"cypress": "^3.0.2",
|
||||||
"element-theme-chalk": "^2.4.3",
|
"element-theme-chalk": "^2.4.3",
|
||||||
"eslint": "^5.0.1",
|
"eslint": "^5.1.0",
|
||||||
"eslint-loader": "^2.0.0",
|
"eslint-loader": "^2.0.0",
|
||||||
"eslint-plugin-vue": "^4.5.0",
|
"eslint-plugin-vue": "^4.5.0",
|
||||||
"file-loader": "^1.1.11",
|
"file-loader": "^1.1.11",
|
||||||
"node-sass": "^4.9.1",
|
"node-sass": "^4.9.2",
|
||||||
"postcss-loader": "^2.1.5",
|
"postcss-loader": "^2.1.6",
|
||||||
"sass-loader": "^7.0.3",
|
"sass-loader": "^7.0.3",
|
||||||
"style-loader": "^0.21.0",
|
"style-loader": "^0.21.0",
|
||||||
"uglifyjs-webpack-plugin": "^1.2.7",
|
"uglifyjs-webpack-plugin": "^1.2.7",
|
||||||
"vue-custom-element": "^3.2.1",
|
"vue-custom-element": "^3.2.2",
|
||||||
"vue-loader": "^15.2.4",
|
"vue-loader": "^15.2.4",
|
||||||
"vue-template-compiler": "^2.5.16",
|
"vue-template-compiler": "^2.5.16",
|
||||||
"webpack": "^4.15.1",
|
"webpack": "^4.15.1",
|
||||||
|
|
|
@ -18,7 +18,9 @@ class Admin {
|
||||||
|
|
||||||
private function __construct() {
|
private function __construct() {
|
||||||
|
|
||||||
add_action( 'wp_ajax_tainacan_date_i18n', array( &$this, 'ajax_date_i18n') );
|
add_action( 'wp_ajax_tainacan-date-i18n', array( &$this, 'ajax_date_i18n') );
|
||||||
|
add_action( 'wp_ajax_tainacan-sample-permalink', array( &$this, 'ajax_sample_permalink') );
|
||||||
|
|
||||||
add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) );
|
add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) );
|
||||||
add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
|
add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
|
||||||
|
|
||||||
|
@ -119,7 +121,7 @@ class Admin {
|
||||||
|
|
||||||
wp_localize_script( 'tainacan-user-admin', 'tainacan_plugin', $settings );
|
wp_localize_script( 'tainacan-user-admin', 'tainacan_plugin', $settings );
|
||||||
wp_enqueue_media();
|
wp_enqueue_media();
|
||||||
wp_enqueue_script('undescore', includes_url('js') . '/underscore.min.js' );
|
wp_enqueue_script('underscore', includes_url('js') . '/underscore.min.js' );
|
||||||
wp_enqueue_script('jcrop');
|
wp_enqueue_script('jcrop');
|
||||||
wp_enqueue_script( 'customize-controls' );
|
wp_enqueue_script( 'customize-controls' );
|
||||||
|
|
||||||
|
@ -170,7 +172,6 @@ class Admin {
|
||||||
'root_wp_api' => esc_url_raw( rest_url() ) . 'wp/v2/',
|
'root_wp_api' => esc_url_raw( rest_url() ) . 'wp/v2/',
|
||||||
'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
|
'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||||
'sample_permalink_nonce' => wp_create_nonce( 'samplepermalink' ),
|
|
||||||
'components' => $components,
|
'components' => $components,
|
||||||
'i18n' => $tainacan_admin_i18n,
|
'i18n' => $tainacan_admin_i18n,
|
||||||
'user_caps' => $user_caps,
|
'user_caps' => $user_caps,
|
||||||
|
@ -242,5 +243,61 @@ class Admin {
|
||||||
wp_die();
|
wp_die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ajax_sample_permalink(){
|
||||||
|
|
||||||
|
$id = $_POST['post_id'];
|
||||||
|
$title = $_POST['new_title'];
|
||||||
|
$name = $_POST['new_slug'];
|
||||||
|
|
||||||
|
$post = get_post( $id );
|
||||||
|
if ( ! $post )
|
||||||
|
return array( '', '' );
|
||||||
|
|
||||||
|
$ptype = get_post_type_object($post->post_type);
|
||||||
|
|
||||||
|
// Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
|
||||||
|
if ( in_array( $post->post_status, array( 'auto-draft', 'draft', 'pending', 'future' ) ) ) {
|
||||||
|
$post->post_status = 'publish';
|
||||||
|
$post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the user wants to set a new name -- override the current one
|
||||||
|
// Note: if empty name is supplied -- use the title instead, see #6072
|
||||||
|
if ( !is_null($name) )
|
||||||
|
$post->post_name = sanitize_title($name ? $name : $title, $post->ID);
|
||||||
|
|
||||||
|
$post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
|
||||||
|
|
||||||
|
$post->filter = 'sample';
|
||||||
|
|
||||||
|
$permalink = get_permalink($post, true);
|
||||||
|
|
||||||
|
// Replace custom post_type Token with generic pagename token for ease of use.
|
||||||
|
$permalink = str_replace("%$post->post_type%", '%pagename%', $permalink);
|
||||||
|
|
||||||
|
// Handle page hierarchy
|
||||||
|
if ( $ptype->hierarchical ) {
|
||||||
|
$uri = get_page_uri($post);
|
||||||
|
if ( $uri ) {
|
||||||
|
$uri = untrailingslashit($uri);
|
||||||
|
$uri = strrev( stristr( strrev( $uri ), '/' ) );
|
||||||
|
$uri = untrailingslashit($uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This filter is documented in wp-admin/edit-tag-form.php */
|
||||||
|
$uri = apply_filters( 'editable_slug', $uri, $post );
|
||||||
|
if ( !empty($uri) )
|
||||||
|
$uri .= '/';
|
||||||
|
$permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This filter is documented in wp-admin/edit-tag-form.php */
|
||||||
|
$permalink = array( 'permalink' => $permalink, 'slug' => apply_filters( 'editable_slug', $post->post_name, $post ) );
|
||||||
|
|
||||||
|
echo json_encode($permalink);
|
||||||
|
|
||||||
|
wp_die();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -396,7 +396,6 @@
|
||||||
import { mapActions } from 'vuex';
|
import { mapActions } from 'vuex';
|
||||||
import wpMediaFrames from '../../js/wp-media-frames';
|
import wpMediaFrames from '../../js/wp-media-frames';
|
||||||
import { wpAjax } from '../../js/mixins';
|
import { wpAjax } from '../../js/mixins';
|
||||||
import htmlToJSON from 'html-to-json'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'CollectionEditionForm',
|
name: 'CollectionEditionForm',
|
||||||
|
@ -485,18 +484,8 @@ export default {
|
||||||
this.isUpdatingSlug = true;
|
this.isUpdatingSlug = true;
|
||||||
|
|
||||||
this.getSamplePermalink(this.collectionId, this.form.name, this.form.slug)
|
this.getSamplePermalink(this.collectionId, this.form.name, this.form.slug)
|
||||||
.then(samplePermalink => {
|
.then((res) => {
|
||||||
|
this.form.slug = res.data.slug;
|
||||||
let promise = htmlToJSON.parse(samplePermalink, {
|
|
||||||
permalink($doc) {
|
|
||||||
return $doc.find('#editable-post-name-full').text();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
promise.done((result) => {
|
|
||||||
this.form.slug = result.permalink;
|
|
||||||
//this.$console.info(this.form.slug);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.isUpdatingSlug = false;
|
this.isUpdatingSlug = false;
|
||||||
this.formErrorMessage = '';
|
this.formErrorMessage = '';
|
||||||
|
|
|
@ -135,8 +135,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { wpAjax } from "../../js/mixins";
|
import { wpAjax } from "../../js/mixins";
|
||||||
import { mapActions, mapGetters } from 'vuex';
|
import { mapActions, mapGetters } from 'vuex';
|
||||||
import TermsList from '../lists/terms-list.vue'
|
import TermsList from '../lists/terms-list.vue';
|
||||||
import htmlToJSON from 'html-to-json';
|
|
||||||
import CustomDialog from '../other/custom-dialog.vue';
|
import CustomDialog from '../other/custom-dialog.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -268,18 +267,8 @@
|
||||||
this.isUpdatingSlug = true;
|
this.isUpdatingSlug = true;
|
||||||
|
|
||||||
this.getSamplePermalink(this.taxonomyId, this.form.name, this.form.slug)
|
this.getSamplePermalink(this.taxonomyId, this.form.name, this.form.slug)
|
||||||
.then(samplePermalink => {
|
.then((res) => {
|
||||||
|
this.form.slug = res.data.slug;
|
||||||
let promise = htmlToJSON.parse(samplePermalink, {
|
|
||||||
permalink($doc) {
|
|
||||||
return $doc.find('#editable-post-name-full').text();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
promise.done((result) => {
|
|
||||||
this.form.slug = result.permalink;
|
|
||||||
//this.$console.info(this.form.slug);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.isUpdatingSlug = false;
|
this.isUpdatingSlug = false;
|
||||||
this.formErrorMessage = '';
|
this.formErrorMessage = '';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Overrides lodash by original WordPress Underscore Library
|
// Overrides lodash by original WordPress Underscore Library
|
||||||
window.lodash = _.noConflict();
|
//window.lodash = _.noConflict();
|
||||||
window.underscore = _.noConflict();
|
//window.underscore = _.noConflict();
|
||||||
|
|
||||||
// Main imports
|
// Main imports
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
|
@ -15,30 +15,20 @@ export const wpAjax = {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getSamplePermalink(id, newTitle, newSlug){
|
getSamplePermalink(id, newTitle, newSlug){
|
||||||
return new Promise((resolve, reject) => {
|
return this.axiosWPAjax.post('', qs.stringify({
|
||||||
this.axiosWPAjax.post('', qs.stringify({
|
action: 'tainacan-sample-permalink',
|
||||||
action: 'sample-permalink',
|
|
||||||
post_id: id,
|
post_id: id,
|
||||||
new_title: newTitle,
|
new_title: newTitle,
|
||||||
new_slug: newSlug,
|
new_slug: newSlug,
|
||||||
samplepermalinknonce: tainacan_plugin.sample_permalink_nonce,
|
nonce: tainacan_plugin.nonce,
|
||||||
}))
|
}));
|
||||||
.then(res => {
|
|
||||||
resolve(res.data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
getDatei18n(dateString){
|
getDatei18n(dateString){
|
||||||
this.axiosWPAjax.post('', qs.stringify({
|
return this.axiosWPAjax.post('', qs.stringify({
|
||||||
action: 'tainacan_date_i18n',
|
action: 'tainacan-date-i18n',
|
||||||
date_string: dateString,
|
date_string: dateString,
|
||||||
nonce: tainacan_plugin.nonce,
|
nonce: tainacan_plugin.nonce,
|
||||||
})).then(res => {
|
}));
|
||||||
return res.data
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue