Skip to content

Commit

Permalink
Update campaign id and text domain.Refer to issue #147
Browse files Browse the repository at this point in the history
  • Loading branch information
sudipto-me committed Feb 3, 2022
1 parent 86466b6 commit 7ea8275
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 81 deletions.
88 changes: 44 additions & 44 deletions includes/action-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@ function wpcp_handle_manual_campaign() {
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'wpcp_run_campaign' ) ) {
wp_die( __( 'No Cheating', 'wp-content-pilot' ) );
}

$campaign_id = intval( $_REQUEST['campaign_id'] );


$target = wpcp_get_post_meta( $campaign_id, '_campaign_target', 0 );
$posted = wpcp_get_post_meta( $campaign_id, '_post_count', 0 );
$edit_link = admin_url( sprintf( 'post.php?post=%d&action=edit', $campaign_id ) );

$campaign_post = get_post( $campaign_id );

if ( empty( $campaign_post ) || 'wp_content_pilot' !== $campaign_post->post_type ) {
wp_die( __( 'Invalid post action', 'wp-content-pilot' ) );
}

$campaign_type = wpcp_get_post_meta( $campaign_id, '_campaign_type', 'feed' );

if ( $posted >= $target ) {
wpcp_disable_campaign( $campaign_id );
wpcp_admin_notice( 'Campaign reached its targeted posts, automatically disabled.', 'error' );
wp_safe_redirect( $edit_link );
exit();
}

$article_id = content_pilot()->modules()->load( $campaign_type )->process_campaign( $campaign_id, '', 'user' );

if ( is_wp_error( $article_id ) ) {
wpcp_admin_notice( $article_id->get_error_message(), 'error' );
wp_safe_redirect( $edit_link );
exit();
}

$title = empty( get_the_title( $article_id ) ) ? 'Untitled' : get_the_title( $article_id );
$article_title = '<strong><a href="' . get_the_permalink( $article_id ) . '" target="_blank">' . $title . '</a></strong>';
$message = sprintf( __( 'A post successfully created by %s titled %s', 'wp-content-pilot' ), '<strong>' . get_the_title( $campaign_id ) . '</strong>', $article_title );
wpcp_admin_notice( $message );


wp_safe_redirect( $edit_link );
exit();
}
Expand All @@ -61,20 +61,20 @@ function wpcp_run_automatic_campaign() {
global $wpdb;
$sql = "select * from {$wpdb->posts} p left join {$wpdb->postmeta} m on p.id = m.post_id having m.meta_key = '_campaign_status' AND m.meta_value = 'active' AND p.post_status <> 'trash'";
$campaigns = $wpdb->get_results( $sql );

if ( empty( $campaigns ) ) {
return;
}


$campaigns = wp_list_pluck( $campaigns, 'ID' );

$last_campaign = get_option( 'wpcp_last_ran_campaign', '' );
if ( ! empty( $last_campaign ) && count( $campaigns ) > 1 ) {
unset( $campaigns[ $last_campaign ] );
}


if ( ! empty( $campaigns ) ) {
// $automatic_campaign = new WPCP_Automatic_Campaign();
foreach ( $campaigns as $campaign_id ) {
Expand All @@ -87,20 +87,20 @@ function wpcp_run_automatic_campaign() {
if ( $diff < $frequency ) {
continue;
}

if ( $posted >= $target ) {
wpcp_logger()->info( __( 'Reached campaign post limit. So campaign stopping publish new post', 'wp-content-pilot' ), $campaign_id );
wpcp_disable_campaign( $campaign_id );
continue;
}

$campaign_type = wpcp_get_post_meta( $campaign_id, '_campaign_type', '' );
if ( ! empty( $campaign_type ) ) {
content_pilot()->modules()->load( $campaign_type )->process_campaign( $campaign_id, '', 'cron' );
}
}
}

}

add_action( 'wpcp_per_minute_scheduled_events', 'wpcp_run_automatic_campaign' );
Expand All @@ -112,28 +112,28 @@ function wpcp_delete_all_campaign_posts() {
if ( ! isset( $_REQUEST['nonce'] ) || ! isset( $_REQUEST['camp_id'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'wpcp_delete_posts' ) ) {
wp_send_json_error( 'Unauthorized!!!' );
}

$camp_id = isset( $_REQUEST['camp_id'] ) && ! empty( $_REQUEST['camp_id'] ) ? $_REQUEST['camp_id'] : false;
if ( ! $camp_id ) {
wp_send_json_error( 'Invalid campaign ID.' );
}

$args = array(
'meta_key' => '_campaign_id',
'meta_value' => $camp_id,
'posts_per_page' => - 1,
'post_type' => wpcp_get_post_meta( $camp_id, '_post_type', 'post' ),

);

$posts = wpcp_get_posts( $args );

if ( is_array( $posts ) && count( $posts ) ) {
foreach ( $posts as $post ) {
wp_delete_post( $post->ID, true );
}
}

wp_send_json_success( 'Done' );
}

Expand All @@ -143,7 +143,7 @@ function wpcp_clear_logs() {
if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'wpcp_clear_logs' ) ) {
wp_send_json_error( 'Unauthorized!!!' );
}

global $wpdb;
$wpdb->query( "TRUNCATE TABLE $wpdb->wpcp_logs" );
wp_send_json_success( 'success' );
Expand All @@ -156,7 +156,7 @@ function wpcp_clear_logs() {
if ( ! function_exists( 'wpcp_pro_get_keyword_suggestion' ) ):
function wpcp_pro_get_keyword_suggestion() {
$word = $_REQUEST['input'];

$curl = new Curl\Curl();
$curl->setOpt( CURLOPT_FOLLOWLOCATION, true );
$curl->setOpt( CURLOPT_TIMEOUT, 30 );
Expand All @@ -169,7 +169,7 @@ function wpcp_pro_get_keyword_suggestion() {
'q' => $word,
'client' => 'firefox',
) );

if ( is_wp_error( $curl->isError() ) ) {
wp_send_json_success( [] );
}
Expand All @@ -187,7 +187,7 @@ function wpcp_pro_get_keyword_suggestion() {
// }
}
}

$suggestion = array_unique( $suggestion );
wp_send_json_success( $suggestion );
}
Expand Down Expand Up @@ -221,7 +221,7 @@ function wpcp_post_publish_mail_notification( $post_id, $campaign_id, $article )
} else {
$excerpt = $article['excerpt'];
}

$post_link = get_the_permalink( $post_id );
$subject = __( 'Post Publish', 'wp-content-pilot' );
$body = sprintf( "<h4>Post Title: %s</h4>
Expand All @@ -230,7 +230,7 @@ function wpcp_post_publish_mail_notification( $post_id, $campaign_id, $article )
<a href='%s'>View Post</a>", esc_html( $title ), $excerpt, esc_url( $post_link )
);
$headers = array( 'Content-Type: text/html; charset=UTF-8' );

wp_mail( $to, $subject, $body, $headers );
}

Expand Down Expand Up @@ -260,13 +260,13 @@ function wpcp_campaign_reset_search_campaign() {
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'wpcp_campaign_reset_search' ) ) {
wp_die( __( 'No Cheating', 'wp-content-pilot' ) );
}

$campaign_id = intval( $_REQUEST['campaign_id'] );

$delete_query = "DELETE FROM {$wpdb->postmeta} where post_id=$campaign_id AND meta_key NOT IN ('_post_count','_campaign_type','_post_status','_campaign_target','_last_run','_last_post')";

$clear_query = "DELETE FROM {$wpdb->wpcp_links} where camp_id=$campaign_id";

$wpdb->query( $delete_query );
$wpdb->query( $clear_query );
wp_safe_redirect( get_edit_post_link( $campaign_id, 'edit' ) );
Expand All @@ -282,13 +282,13 @@ function wpcp_ajax_run_manual_campaign() {
'time' => date( 'H:i:s', current_time( 'timestamp' ) )
] );
}

$campaign_id = intval( $_REQUEST['campaign_id'] );
$instance = intval( $_REQUEST['instance'] );
if ( ! defined( 'WPCP_CAMPAIGN_INSTANCE' ) ) {
define( 'WPCP_CAMPAIGN_INSTANCE', $instance );
}

$campaign_post = get_post( $campaign_id );
if ( empty( $campaign_post ) || 'wp_content_pilot' !== $campaign_post->post_type ) {
wp_send_json( [
Expand All @@ -297,12 +297,12 @@ function wpcp_ajax_run_manual_campaign() {
'time' => date( 'H:i:s', current_time( 'timestamp' ) )
] );
}

global $current_user;
wpcp_logger()->info( sprintf( __( 'Campaign <strong>%s</strong> manually initiated by <strong>%s</strong>', 'wp-content-pilot' ), get_the_title( $campaign_id ), $current_user->display_name ) );
wpcp_logger()->info( sprintf( __( 'Campaign <strong>%s</strong> manually initiated by <strong>%s</strong>', 'wp-content-pilot' ), get_the_title( $campaign_id ), $current_user->display_name ), $campaign_id );

$campaign_type = wpcp_get_post_meta( $campaign_id, '_campaign_type', 'feed' );

$article_id = content_pilot()->modules()->load( $campaign_type )->process_campaign( $campaign_id, '', 'user' );
if ( is_wp_error( $article_id ) ) {
wp_send_json( [
Expand Down Expand Up @@ -346,7 +346,7 @@ function wpcp_get_campaign_instance_log() {
]
] );
}

global $wpdb;
$data = $wpdb->get_results( "select `level`, message, DATE_FORMAT(created_at, '%H:%i:%s') as time from {$wpdb->prefix}wpcp_logs where instance_id={$instance} order by id ASC limit 9999 offset {$offset}" );
wp_send_json( $data );
Expand Down
10 changes: 5 additions & 5 deletions includes/admin/class-wpcp-help.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function help_page() {
</style>
<div class="wrap">

<h2>WP Content Pilot - Help </h2>
<h2><?php echo esc_html__( 'WP Content Pilot - Help', 'wp-content-pilot' ); ?> </h2>

<div class="ever-help-page">
<?php foreach ( $blocks as $block ): ?>
Expand All @@ -140,12 +140,12 @@ public function help_page() {
</div>
<?php if ( ! defined( 'WPCP_PRO_VERSION' ) ): ?>
<div class="free-vs-pro">
<h3>Are you looking for more? Checkout our Pro Version.</h3>
<h3><?php echo esc_html__( 'Are you looking for more? Checkout our Pro Version.', 'wp-content-pilot' ); ?></h3>
<table class="widefat">
<tr>
<th>Features</th>
<th>Free</th>
<th>Pro</th>
<th><?php echo esc_html__( 'Features', 'wp-content-pilot' ); ?></th>
<th><?php echo esc_html__( 'Free', 'wp-content-pilot' ); ?></th>
<th><?php echo esc_html__( 'Pro', 'wp-content-pilot' ); ?></th>
</tr>
<?php foreach ( $features as $feature ): ?>
<tr>
Expand Down
16 changes: 8 additions & 8 deletions includes/admin/metabox-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ function wpcp_target_rel_field() {
function wpcp_search_replace_metafield( $post ) {
?>
<div class="wpcp-repeater form-field wpcp-field _wpcp_custom_meta_fields-field pro">
<label class="wpcp-label">Search Replace</label>
<label class="wpcp-label"><?php echo esc_html__( 'Search Replace', 'wp-content-pilot' ); ?></label>

<table class="striped widefat wp-list-table">
<thead>
<tr>
<th>Search</th>
<th>Replace</th>
<th><?php echo esc_html__( 'Search', 'wp-content-pilot' ); ?></th>
<th><?php echo esc_html__( 'Replace', 'wp-content-pilot' ); ?></th>
<th></th>
</tr>
</thead>
Expand All @@ -379,7 +379,7 @@ function wpcp_search_replace_metafield( $post ) {
</tr>
</tbody>
</table>
<button data-repeater-create type="button" class="button" disabled>Add New</button>
<button data-repeater-create type="button" class="button" disabled><?php echo esc_html__( 'Add New', 'wp-content-pilot' ); ?></button>
</div>
<?php
}
Expand All @@ -390,13 +390,13 @@ function wpcp_search_replace_metafield( $post ) {
function wpcp_post_meta_metafield( $post ) {
?>
<div class="wpcp-repeater form-field wpcp-field _wpcp_custom_meta_fields-field pro">
<label class="wpcp-label">Post Meta</label>
<label class="wpcp-label"><?php echo esc_html__( 'Post Meta', 'wp-content-pilot' ); ?></label>

<table class="striped widefat wp-list-table">
<thead>
<tr>
<th>Meta Key</th>
<th>Meta Value</th>
<th><?php echo esc_html__( 'Meta Key', 'wp-content-pilot' ); ?></th>
<th><?php echo esc_html__( 'Meta Value', 'wp-content-pilot' ); ?></th>
<th></th>
</tr>
</thead>
Expand All @@ -409,7 +409,7 @@ function wpcp_post_meta_metafield( $post ) {
</tbody>
</table>

<button data-repeater-create type="button" class="button" disabled>Add New</button>
<button data-repeater-create type="button" class="button" disabled><?php echo esc_html__( 'Add New', 'wp-content-pilot' ); ?></button>
</div>
<?php
}
Expand Down
8 changes: 4 additions & 4 deletions includes/admin/views/metabox/advanced-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
'label' => __( 'Limit Title', 'wp-content-pilot' ),
'type' => 'number',
'name' => '_title_limit',
'tooltip' => 'Input the number of words to limit the title. Default full title.',
'tooltip' => __( 'Input the number of words to limit the title. Default full title.', 'wp-content-pilot' )
) );

echo WPCP_HTML::text_input( array(
'label' => __( 'Limit Content', 'wp-content-pilot' ),
'type' => 'number',
'name' => '_content_limit',
'tooltip' => 'Input the number of words to limit content. Default full content.',
'tooltip' => __( 'Input the number of words to limit content. Default full content.', 'wp-content-pilot' )
) );

echo WPCP_HTML::text_input( array(
Expand All @@ -36,8 +36,8 @@
'wrapper_class' => 'pro',
'options' => array(
'' => __( 'No Translation', 'wp-content-pilot' ),
'yandex' => 'Yandex',
'deepl' => 'deepL',
'yandex' => __( 'Yandex', 'wp-content-pilot' ),
'deepl' => __( 'deepL', 'wp-content-pilot' )
),
'attrs' => array(
'disabled' => 'disabled',
Expand Down
10 changes: 5 additions & 5 deletions includes/admin/views/page/help-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
</style>
<div class="wrap">

<h2>WP Content Pilot - Help </h2>
<h2><?php echo esc_html__( 'WP Content Pilot - Help', 'wp-content-pilot' ); ?> </h2>

<div class="wpcp-help-page">
<?php foreach ( $blocks as $block ): ?>
Expand All @@ -323,12 +323,12 @@
</div>
<?php if ( ! defined( 'WPCP_PRO_VERSION' ) ): ?>
<div class="free-vs-pro">
<h3>Are you looking for more? Checkout our Pro Version.</h3>
<h3><?php echo esc_html__( 'Are you looking for more? Checkout our Pro Version.', 'wp-content-pilot' ); ?></h3>
<table class="widefat">
<tr>
<th>Features</th>
<th>Free</th>
<th>Pro</th>
<th><?php echo esc_html__( 'Features', 'wp-content-pilot' ); ?></th>
<th><?php echo esc_html__( 'Free', 'wp-content-pilot' ); ?></th>
<th><?php echo esc_html__( 'Pro', 'wp-content-pilot' ); ?></th>
</tr>
<?php foreach ( $features as $feature ): ?>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wpcp-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function warning( $message, $campaign_id = 0 ) {
* @return void
*/
public function error( $message, $campaign_id = 0 ) {
$this->writeLog( $message, 'ERROR', $campaign_id = 0 );
$this->writeLog( $message, 'ERROR', $campaign_id );
}

/**
Expand Down
Loading

0 comments on commit 7ea8275

Please sign in to comment.