Commit 1e5c8f76 authored by Martin Lees's avatar Martin Lees
Browse files

Production ready version

parent 075985fc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
\ No newline at end of file
......@@ -81,27 +81,6 @@ class Steempress_sp_Admin {
}
/**
* Enqueue Gutenberg block assets for backend editor.
*
* `wp-blocks`: includes block type registration and related functions.
* `wp-element`: includes the WordPress Element abstraction for describing the structure of your blocks.
* `wp-i18n`: To internationalize the block's text.
*
* @since 1.0.0
*/
function my_block_cgb_editor_assets() {
// Scripts.
wp_enqueue_script(
'my_block-cgb-block-js', // Handle.
plugin_dir_url( __FILE__ ) . 'js/steempress_sp-admin.js', // Block.build.js: We register the block here. Built with Webpack.
array( 'wp-blocks', 'wp-i18n', 'wp-element' ), // Dependencies, defined above.
// filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: filemtime — Gets file modification time.
true // Enqueue the script in the footer.
);
} // End function my_block_cgb_editor_assets().
/**
* Register the JavaScript for the admin area.
*
......@@ -515,10 +494,7 @@ class Steempress_sp_Admin {
function saveSteemPublishField($post_id)
{
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if (!current_user_can('edit_post', $post_id))
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || !current_user_can('edit_post', $post_id) || $_POST == [])
return;
if (array_key_exists('steempress_sp_permlink', $_POST) && array_key_exists('steempress_sp_author', $_POST)) {
......@@ -526,29 +502,31 @@ class Steempress_sp_Admin {
update_post_meta($post_id,'steempress_sp_author',$_POST['steempress_sp_author']);
}
if (isset($_POST['Steempress_sp_steem_publish']) && $_POST['Steempress_sp_steem_publish'] === '1') {
if (isset($_POST['Steempress_sp_steem_publish'])) {
if ($_POST['Steempress_sp_steem_publish'] === '1') {
// If post is empty/ doesn't have the hidden_mm attribute this means that we are using gutenberg
if ($_POST == [] || !isset($_POST['hidden_mm'])) {
$this->Steempress_sp_publish($post_id);
}
// If post is empty/ doesn't have the hidden_mm attribute this means that we are using gutenberg
if ($_POST == [] || !isset($_POST['hidden_mm'])) {
$this->Steempress_sp_publish($post_id);
}
update_post_meta($post_id, 'Steempress_sp_steem_publish', $_POST['Steempress_sp_steem_publish']);
} else {
update_post_meta($post_id, 'Steempress_sp_steem_publish', '0');
update_post_meta($post_id, 'Steempress_sp_steem_publish', $_POST['Steempress_sp_steem_publish']);
} else {
update_post_meta($post_id, 'Steempress_sp_steem_publish', '0');
}
}
if (isset($_POST['Steempress_sp_steem_update']) && $_POST['Steempress_sp_steem_update'] === '1') {
// If post is empty/ doesn't have the hidden_mm attribute this means that we are using gutenberg
if ($_POST == [] || !isset($_POST['hidden_mm'])) {
$this->steempress_sp_update(181, false);
if (isset($_POST['Steempress_sp_steem_update'])) {
if ($_POST['Steempress_sp_steem_update'] === '1') {
// If post is empty/ doesn't have the hidden_mm attribute this means that we are using gutenberg
if ($_POST == [] || !isset($_POST['hidden_mm'])) {
$this->steempress_sp_update($post_id);
}
update_post_meta($post_id, 'Steempress_sp_steem_update', $_POST['Steempress_sp_steem_update']);
} else {
update_post_meta($post_id, 'Steempress_sp_steem_update', '0');
}
update_post_meta($post_id, 'Steempress_sp_steem_update', $_POST['Steempress_sp_steem_update']);
} else {
update_post_meta($post_id, 'Steempress_sp_steem_update', '0');
}
}
public function steempress_sp_custom_box_html($post)
......@@ -567,6 +545,7 @@ class Steempress_sp_Admin {
else
$checked = "checked";
wp_nonce_field('Steempress_sp_custom_nonce_'.$post_id, 'Steempress_sp_custom_nonce');
$body = '<label><input type="checkbox" value="1" '.$checked.' name="Steempress_sp_steem_publish" /> <input type="hidden" name="Steempress_sp_steem_do_not_publish" value="0" />Publish to steem </label>';
......
const { assign } = lodash;
const { __ } = wp.i18n;
const { Fragment } = wp.element;
const { addFilter } = wp.hooks;
const { TextControl, PanelBody } = wp.components;
const { createHigherOrderComponent } = wp.compose;
const { InspectorControls } = wp.editor;
/**
* Override the default edit UI to include a new block inspector control for
* adding our custom control.
*
* @param {function|Component} BlockEdit Original component.
*
* @return {string} Wrapped component.
*/
export const addMyCustomBlockControls = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
// If this block supports scheduling and is currently selected, add our UI
if ( isValidBlockType( props.name ) && props.isSelected ) {
return (
<Fragment>
<BlockEdit { ...props } />
<InspectorControls>
<PanelBody title={ __( 'My Custom Panel Heading' ) }>
<TextControl
label={ __( 'My Custom Control' ) }
help={ __( 'Some help text for my custom control.' ) }
value={ props.attributes.scheduledStart || '' }
onChange={ ( nextValue ) => {
props.setAttributes( {
scheduledStart: nextValue,
} );
} } />
</PanelBody>
</InspectorControls>
</Fragment>
);
}
return <BlockEdit { ...props } />;
};
}, 'addMyCustomBlockControls' );
addFilter( 'editor.BlockEdit', 'my-plugin/my-control', addMyCustomBlockControls );
/**
* Is the passed block name one which supports our custom field?
*
* @param {string} name The name of the block.
*/
function isValidBlockType( name ) {
const validBlockTypes = [
'core/paragraph',
'core/image',
'core/heading',
];
return validBlockTypes.includes( name );
}// end isValidBlockType()
/**
* Filters registered block settings, extending attributes with our custom data.
*
* @param {Object} settings Original block settings.
*
* @return {Object} Filtered block settings.
*/
export function addAttribute( settings ) {
// If this is a valid block
if ( isValidBlockType( settings.name ) ) {
// Use Lodash's assign to gracefully handle if attributes are undefined
settings.attributes = assign( settings.attributes, {
scheduledStart: {
type: 'string',
},
} );
}
return settings;
}// end addAttribute()
/**
* Override props assigned to save component to inject our custom data.
* This is only done if the component is a valid block type.
*
* @param {Object} extraProps Additional props applied to save element.
* @param {Object} blockType Block type.
* @param {Object} attributes Current block attributes.
*
* @return {Object} Filtered props applied to save element.
*/
export function addSaveProps( extraProps, blockType, attributes ) {
// If the current block is valid, add our prop.
if ( isValidBlockType( blockType.name ) ) {
extraProps.scheduledStart = attributes.scheduledStart;
}
return extraProps;
}// end addSaveProps()
addFilter( 'blocks.registerBlockType', 'my-plugin/add-attr', addAttribute );
addFilter( 'blocks.getSaveContent.extraProps', 'my-plugin/add-props', addSaveProps );
{
"name": "steempress",
"version": "1.0.0",
"description": "- Contributors: howo,fredrikaa - Requires at least: 4.7 - Tested up to: 4.9.2 - License: GPLv2 or later - License URI: http://www.gnu.org/licenses/gpl-2.0.html",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --mode production ./admin/js/source/*.js --output ./admin/js/steempress_sp-admin.js --module-bind js=babel-loader",
"dev": "webpack --mode development ./admin/js/source/*.js --output ./admin/js/steempress_sp-admin.js --module-bind js=babel-loader"
},
"repository": {
"type": "git",
"url": "git+https://github.com/drov0/steempress.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/drov0/steempress/issues"
},
"homepage": "https://github.com/drov0/steempress#readme",
"dependencies": {
"@babel/core": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.4",
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment