WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
This repository was archived by the owner on Oct 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ phpunit.xml
phpcs-report-*.txt

# Allowed vendor files
!vendor/freemius
!vendor/freemius
.vscode/launch.json
105 changes: 105 additions & 0 deletions assets/js/explanations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Explanations JS.
*/

( function( $ ) {

//
// Explanations AJAX handlers.
//

var statusLabel = $( '#status-label' ),
createLink = $( '#create-expl' ),
unPublishLink = $( '#unpublish-expl' ),
rowActions = $( '#expl-row-actions' );

var rowCreateLink = $( '.create-expl' );

/**
* AJAX handler for creating and associating a new explanation post.
*
* @param {object} event Event object.
*/
function createExplanation( event ) {
event.preventDefault();

wp.ajax.send( 'new_explanation', {
success: createExplSuccess,
error: createExplError,
data: {
nonce: $( this ).data( 'nonce' ),
post_id: $( this ).data( 'id' ),
context: event.data.context
}
} );
}

/**
* Success callback for creating a new explanation via AJAX.
*
* @param {object} data Data response object.
*/
function createExplSuccess( data ) {
var editLink = '<a href="post.php?post=' + data.post_id + '&action=edit">' + wporg.editContentLabel + '</a>';

if ( 'edit' == data.context ) {
// Action in the parsed post type edit screen.
createLink.hide();
rowActions.html( editLink );
statusLabel.text( wporg.statusLabel.draft );
} else {
// Row link in the list table.
$( '#post-' + data.parent_id + ' .add-expl' ).html( editLink + ' | ' );
}
}

/**
* Error callback for creating a new explanation via AJAX.
*
* @param {object} data Data response object.
*/
function createExplError( data ) {}

/**
* Handler for un-publishing an existing Explanation.
*
* @param {object} event Event object.
*/
function unPublishExplantaion( event ) {
event.preventDefault();

wp.ajax.send( 'un_publish', {
success: unPublishSuccess,
error: unPublishError,
data: {
nonce: $( this ).data( 'nonce' ),
post_id: $( this ).data( 'id' )
}
} );
}

/**
* Success callback for un-publishing an explanation via AJAX.
*
* @param {object} data Data response object.
*/
function unPublishSuccess( data ) {
if ( statusLabel.hasClass( 'pending' ) || statusLabel.hasClass( 'publish' ) ) {
statusLabel.removeClass( 'pending publish' ).text( wporg.statusLabel.draft );
}
unPublishLink.hide();
}

/**
* Error callback for un-publishing an explanation via AJAX.
*
* @param {object} data Data response object.
*/
function unPublishError( data ) {}

// Events.
createLink.on( 'click', { context: 'edit' }, createExplanation );
rowCreateLink.on( 'click', { context: 'list' }, createExplanation );
unPublishLink.on( 'click', unPublishExplantaion );

} )( jQuery );
7 changes: 7 additions & 0 deletions class-phpdoc-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ class Bootstrap {
public function plugins_loaded() {
$plugin = new Plugin();

// Run any actions for theme init.
add_action( 'after_setup_theme', array( $plugin, 'after_setup_theme' ) );

// Init the plugin.
add_action( 'init', array( $plugin, 'init' ) );

// Plugins loaded actions.
$plugin->plugins_loaded();
}
}

$phpdoc_plugin = new Bootstrap();
register_activation_hook( __FILE__, array( '\Pods\phpDoc_Plugin\Plugin', 'register_activation_hook' ) );

add_action( 'plugins_loaded', array( $phpdoc_plugin, 'plugins_loaded' ) );
Loading