Tic Tac Toe (new draft)

I have implemented suggestion and created new draft of the Tic Tac Toe program. Please review and let me know where I can improve.

import random

def update_board():
    """Play game"""
    board = ((3 * row + col for col in range(1, 4)) for row in range(3))

    total_count = 0
    UserTurn = False

    while total_count < 9:
        available_number = remaining_num(board)
        message = ''
        if total_count == 0 :
            board(1)(1) = 'X'
            UserTurn = True
        elif UserTurn == False :
            #Computer's Turn
            num = random.choice(available_number)
            num_indx = find_index(num, board)
            board(num_indx(0)(0))(num_indx(0)(1)) = 'X'
            UserTurn = True
        elif UserTurn == True :
            #User's Turn
            UserTurn = False
            num = int(input(f'select number {available_number}: '))
            num_indx = find_index(num, board)
            if num_indx:
                board(num_indx(0)(0))(num_indx(0)(1)) = 'O'
            else :
                print('Selected number is invalid!')
        total_count += 1
        message = check(board, message)
        if message:
            draw_board(board)
            print(message)
            break
        elif message == '' and len(available_number) <= 1:
            draw_board(board)
            print('Tie !!')
            break
        draw_board(board)


def find_index(num,board):
    """Find index of the number"""
    num_indx = ((indx1, indx2) for indx1, val1 in enumerate(board)
                for indx2, val2 in enumerate(val1)
                if val2 == num)
    return num_indx

def remaining_num (board):
   """Available number list."""
   avail_num = (board(i)(j) 
                for i in range(len(board)) 
                for j in range(len(board)) 
                if board(i)(j) not in ('X', 'O'))
   return avail_num



def check(board,message):
    """Ckeck for win."""
    if board(0)(0) == board(0)(1) == board(0)(2) == 'X' or 
       board(1)(0) == board(1)(1) == board(1)(2) == 'X' or 
       board(2)(0) == board(2)(1) == board(2)(2) == 'X' or 
       board(0)(0) == board(1)(0) == board(2)(0) == 'X' or 
       board(0)(1) == board(1)(1) == board(2)(1) == 'X' or 
       board(0)(2) == board(1)(2) == board(2)(2) == 'X' or 
       board(0)(0) == board(1)(1) == board(2)(2) == 'X' or 
       board(0)(2) == board(1)(1) == board(2)(0) == 'X' :
                message = 'Computer win !!'
    elif board(0)(0) == board(0)(1) == board(0)(2) == 'O' or 
         board(1)(0) == board(1)(1) == board(1)(2) == 'O' or 
         board(2)(0) == board(2)(1) == board(2)(2) == 'O' or 
         board(0)(0) == board(1)(0) == board(2)(0) == 'O' or 
         board(0)(1) == board(1)(1) == board(2)(1) == 'O' or 
         board(0)(2) == board(1)(2) == board(2)(2) == 'O' or 
         board(0)(0) == board(1)(1) == board(2)(2) == 'O' or 
         board(0)(2) == board(1)(1) == board(2)(0) == 'O' :
                message = 'User win !!'
    return message

def draw_board(board):
    """Draw board"""
    for i in range(3):
        print('+' + '-' * 5 + '+' + '-' * 5 + '+' + '-' * 5 + '+', )
        print('|' + ' ' * 5 + '|' + ' ' * 5 + '|' + ' ' * 5 + '|')
        for j in range(3):
            print('| ' + str(board(i)(j))+ ' ' * 3, end='')
        print('|')
        print('|' + ' ' * 5 + '|' + ' ' * 5 + '|' + ' ' * 5 + '|')
    print('+' + '-' * 5 + '+' + '-' * 5 + '+' + '-' * 5 + '+')



if __name__ == "__main__":
    update_board()

plugins – wp_update_post does not change post status from draft to publish

I’m writing a post approval utility for the front end, because we don’t want our editor to be able to access the admin dashboard. There are questions on Stack nearly identical to what I’m trying to accomplish, but that guy’s problem has to do with the infinite loop issue. Otherwise, he claims his code works:

How to change post status from publish to draft using hook in wordpress?

I’m writing a plugin to do this (in my case I want to change ‘draft’ to ‘publish’). I don’t want to have to edit the functions.php in the child theme, because I want the plugin to be standalone, for any WordPress site. So all code is in my plugin’s main php file.

  • I can get all posts with status of ‘draft’.
  • I can use an html checkbox, javascript, and WP’s ajax functions to select the post I want to change by ID.

The “change status” code looks like this (in the plugin main php file):

/* This function should toggle a post status from 'draft' to 'publish' */
add_action( 'wp_ajax_approvepost', 'approvepost_callback' );
add_action( 'wp_ajax_nopriv_approvepost', 'approvepost_callback' );
function approvepost_callback(){
    $post = array( 
                    'ID' => $_POST('postid'), // e.g., 28
                    'post_status' => 'publish',
                    'edit_date' => true
                );
    $_POST('result') = wp_update_post($post,true);
    echo json_encode($_POST);
    wp_die(); 
}

wp_update_post returns a 1, so I take that to mean there were no errors. But when I refresh the front-end page, the post shows up again, meaning it is still in draft mode, and when I inspect the post in the WP admin dashboard, sure enough, it’s still in draft. What am I doing wrong or missing?

wordpress redirect to home page after save a post as draft

by default after saving a post as draft, the page redirects to edit page with id of that post, e.g: site.com/wp-admin/post.php?post=13727&action=edit&classic-editor.

my problem is that after saving a post as draft, the page redirects to my home page instead of edit.php page!
I couldn’t find any solution to fix this.
is there a way to force WP to redirect to edit page for that post?

How to fetch all images from a WordPress draft using PHP?

I’m trying to fetch and download all the images from a new Gutenberg draft. It’s really slow having to download each image for web optimization. So, I’m trying to create a plugin that automatically fetches all the images. Any ideas on how I can do that?

8 – What is the status code for “Draft” in content moderation?

I implemented Content moderation workflow for my headless D8 project and created workflows and enabled for all content types. Salesforce is the fronend application which uses graphql to get the content from headless drupal. Currently I’m able to show published content on salesforce application. But when I try to query draft content from salesforce graphql, getting error message “moderation_state” not found in Drupal logs.
Can someone please help! Below is the example query.

”’graphQlQuery Testquery :{“query”:”{nodeQuery(filter: { conditions: ({field:”title”,value:”Test-Test”,operator:EQUAL},{field:”type”,value:”XXXX_content_type”,operator:EQUAL},
{field:”status”,value:”0″,operator:EQUAL},
{field:”moderation_state”,value:”draft,”,operator:EQUAL},)})
{count entities{entityTranslation(language:EN)
{… on NodeXXXXContentType{fieldXXXX body{processed summaryProcessed }title uuid }}}}}”}”’

Note 8 – new text message is prepopulated with old text from a draft

Every time I go to create a new text message im presented with body text instead of an empty message box.

I’ve cleared messaging cache, deleted all drafts, sent the draft as a message to someone. Nothing is clearing it.

Where is the template file and can I edit it without root?

How can I delete a draft message when it is an attachment and not text?

I accidentally selected the wrong contact initially. I’m not seeing a way to delete the draft. There isn’t any text to delete.

I am using Message+ 6.7.12 on a Samsung Galaxy S8.

How to draft posts after being published with x days


Your privacy


By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.




plugins – Can’t delete Draft Post

I am new to wordpress and was happily blogging along when I ran into a weird issue. I tried uploading a gif into the draft and the editor crashed. I refreshed the browser and then found that I couldn’t access all posts or the drafts of posts from my post dashboard.

Where you would expect to see the table of posts I see this error, and the drafts table doesn’t populate at all despite showing one draft:enter image description here

You’ll notice the posts I created after the error no problem, but the posts from before the error aren’t shown.

I tried following the guides I could online to fix the issue, and I figured out that when I disable all my plugins I can see it in the drafts:
enter image description here

However, when I try to ‘trash’ the draft, it gives me a critical error.

Please let me know if there is any additional troubleshooting information that you need to help, otherwise thank you for your time and attention.